Skip to content

Commit

Permalink
Remove Live Logs | Patch Gameday | Patch Welcome Logs
Browse files Browse the repository at this point in the history
  • Loading branch information
TisMeCastle committed Oct 6, 2023
1 parent 16aeec0 commit 879eb6b
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 159 deletions.
11 changes: 0 additions & 11 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,13 @@ for (const file of eventFiles) {
}
}

// Log files and their paths for the commands and events directories
logFilesAndPaths('./commands');
logFilesAndPaths('./events');

client.login(process.env.TOKEN);

// Your custom console.log and console.error functions
(function () {
var _log = console.log;
var _error = console.error;

console.error = function (errMessage) {
_error.apply(console, arguments);
client.channels.cache.find(channel => channel.id === '1059563002875084900').send("<@821248918214017034> error: " + errMessage);
};

console.log = function (logMessage) {
client.channels.cache.find(channel => channel.id === '1059563002875084900').send("log: " + logMessage);
_log.apply(console, arguments);
};
})();
31 changes: 30 additions & 1 deletion commands/Esport/Gameday_SVG.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
324 changes: 178 additions & 146 deletions commands/Esport/gameday.js
Original file line number Diff line number Diff line change
@@ -1,153 +1,185 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { convertFile } = require('convert-svg-to-png');
const { convertFile } = require("convert-svg-to-png");
const { MessageActionRow, MessageButton } = require("discord.js");
const { TwitterApi } = require('twitter-api-v2');
const { TwitterApi } = require("twitter-api-v2");

const client = new TwitterApi({
appKey: process.env.TWITTER_CONSUMER_KEY,
appSecret: process.env.TWITTER_CONSUMER_SECRET,
accessToken: process.env.TWITTER_ACCESS_TOKEN,
accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
appKey: process.env.TWITTER_CONSUMER_KEY,
appSecret: process.env.TWITTER_CONSUMER_SECRET,
accessToken: process.env.TWITTER_ACCESS_TOKEN,
accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
});

module.exports = {
data: new SlashCommandBuilder()
.setName("gameday")
.setDescription("Creates a gameday graphic using an SVG")
.addStringOption((option) =>
option
.setName("opposition_logo_url")
.setDescription("Send their logo so I can add it to the graphic")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("game_time")
.setDescription("What time is the game at?")
.setRequired(true)
.addChoices(
{ name: '11pm EST', value: '11pm EST' },
{ name: '10pm EST', value: '10pm EST' },
{ name: '9pm EST', value: '9pm EST' },
{ name: '8pm EST', value: '8pm EST' },
{ name: '7pm EST', value: '7pm EST' },
{ name: '6pm EST', value: '6pm EST' },
{ name: '5pm EST', value: '5pm EST' },
{ name: '4pm EST', value: '4pm EST' },
)
),
async execute(interaction) {
interaction.deferReply()

var fs = require('fs')
await fs.readFile("./commands/Esport/Gameday_SVG.svg", 'utf8', async function (err, data) {
if (err) {
return console.log(err);
}
const r = data.replace('opplogo', `${interaction.options.getString("opposition_logo_url")}`);


fs.writeFile('./commands/Esport/result.svg', r, function (err) {
if (err) return console.log(err);
});


const inputFilePath = './commands/Esport/result.svg'

if (fs.existsSync('./commands/Esport/result.svg')) {
console.log('not lit')
} else {
setTimeout(() => {
fs.existsSync('./commands/Esport/result.svg')
console.log('lit')
}, 500)
}


const outputFilePath = await convertFile(inputFilePath, {
headless: "new",
puppeteer: {
headless: "new",
args: ['--no-sandbox', '--disable-setuid-sandbox'],
ignoreDefaultArgs: ['--disable-extensions'],
},
headless: "new"
});

const buttonData = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('sendGameTweet')
.setLabel('Send Tweet')
.setStyle(3)
);

interaction.editReply({
components: [buttonData],
files: [{
attachment: outputFilePath,
}],
})

const filter = (interaction) => interaction.customId === 'sendGameTweet'
const collector = interaction.channel.createMessageComponentCollector({ filter });

collector.on('collect', async i => {
i.update({ content: `Tweet is sending!`, ephemeral: true, components: [], files: [] });

try {
const tweetText = `Gameday! The boys are playing at ${interaction.options.getString("game_time")}, we will be posting the results after the series!`
const mediaId = await client.v1.uploadMedia("./commands/Esport/result.png")
var tweetID;

async function postTweet(tweetText) {
try {
const tweet = await client.v2.tweet({
text: tweetText,
media: { media_ids: [mediaId] },
});

console.log(`Tweet posted with ID ${tweet.data.id}`);
tweetID = tweet.data.id
} catch (error) {
console.error(`Failed to post tweet: ${error}`);
}
}
postTweet(tweetText);

setTimeout(() => {
interaction.editReply(`**__Gameday Twitter Post__**\n> https://twitter.com/Clovarity/status/${tweetID}`)
}, 750)

setTimeout(() => {
try {
fs.unlinkSync('./commands/Esport/result.png');
fs.unlinkSync('./commands/Esport/result.svg');
console.log('Game files deleted!')
} catch (err) {
console.error(err);
}
}, 10000)

} catch {

try {
fs.unlinkSync('./commands/Esport/result.png');
console.log('Game files deleted!')
} catch (err) {
console.error(err);
}

try {
fs.unlinkSync('./commands/Esport/result.svg');
console.log('Game files deleted!')
} catch (err) {
console.error(err);
}

await interaction.editReply({ content: 'It broke :skull:\nTry again pls' });
}
})
});
}
}
data: new SlashCommandBuilder()
.setName("gamedaytest")
.setDescription("Creates a gameday graphic using an SVG")
.addStringOption((option) =>
option
.setName("opposition_logo_url")
.setDescription("Send their logo so I can add it to the graphic")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("game_time")
.setDescription("What time is the game at?")
.setRequired(true)
.addChoices(
{ name: "11pm EST", value: "11pm EST" },
{ name: "10pm EST", value: "10pm EST" },
{ name: "9pm EST", value: "9pm EST" },
{ name: "8pm EST", value: "8pm EST" },
{ name: "7pm EST", value: "7pm EST" },
{ name: "6pm EST", value: "6pm EST" },
{ name: "5pm EST", value: "5pm EST" },
{ name: "4pm EST", value: "4pm EST" }
)
)
.addStringOption((option) =>
option.setName("name_1").setDescription("Name of the first player!").setRequired(false)
)
.addStringOption((option) =>
option.setName("name_2").setDescription("Name of the second player!").setRequired(false)
)
.addStringOption((option) =>
option.setName("name_3").setDescription("Name of the third player!").setRequired(false)
)
.addStringOption((option) =>
option.setName("name_4").setDescription("Name of the fourth player!").setRequired(false)
),
async execute(interaction) {
interaction.deferReply();

const name1 = interaction.options.getString("name_1") || "Sparta";
const name2 = interaction.options.getString("name_2") || "Laggy";
const name3 = interaction.options.getString("name_3") || "TBA";
const name4 = interaction.options.getString("name_4") || "Xal";

const name1UpperCase = name1 ? name1.toUpperCase() : "Sparta";
const name2UpperCase = name2 ? name2.toUpperCase() : "Laggy";
const name3UpperCase = name3 ? name3.toUpperCase() : "TBA";
const name4UpperCase = name4 ? name4.toUpperCase() : "Xal";

const fs = require("fs");
try {
const data = fs.readFileSync("./commands/Esport/Gameday_SVG.svg", "utf8");

const r = data.replace("opplogo", `${interaction.options.getString("opposition_logo_url")}`);
const r1 = r.replace("name1", name1UpperCase);
const r2 = r1.replace("name2", name2UpperCase);
const r3 = r2.replace("name3", name3UpperCase);
const r4 = r3.replace("name4", name4UpperCase);

fs.writeFileSync("./commands/Esport/result.svg", r4);
const inputFilePath = "./commands/Esport/result.svg";

if (!fs.existsSync(inputFilePath)) {
console.log("Input file does not exist");
interaction.followUp("An error occurred while reading the SVG file.");
return;
}

const outputFilePath = await convertFile(inputFilePath, {
headless: "new",
puppeteer: {
headless: "new",
args: ["--no-sandbox", "--disable-setuid-sandbox"],
ignoreDefaultArgs: ["--disable-extensions"],
},
});

const buttonData = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId("sendGameTweet")
.setLabel("Send Tweet")
.setStyle(3)
);

interaction.editReply({
components: [buttonData],
files: [
{
attachment: outputFilePath,
},
],
});


let buttonPressed = false;

const filter = (interaction) => interaction.customId === "sendGameTweet";
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 15000 });

collector.on('collect', async i => {
if (!i.member.roles.cache.has("1059579999495139378")) {
i.reply({ content: "You do not have the required role to perform this action.", ephemeral: true });
}

buttonPressed = true;
i.update({ content: "Tweet is sending!", ephemeral: true, components: [], files: [] });

try {
const tweetText = `Gameday! The boys are playing at ${interaction.options.getString("game_time")}, we will be posting the results after the series!`;
const mediaId = await client.v1.uploadMedia("./commands/Esport/result.png");
var tweetID;

async function postTweet(tweetText) {
try {
const tweet = await client.v2.tweet({
text: tweetText,
media: { media_ids: [mediaId] },
});
tweetID = tweet.data.id;
} catch (error) {
console.error(`Failed to post tweet: ${error}`);
}
}
postTweet(tweetText);

setTimeout(() => {
interaction.editReply(`**__Gameday Twitter Post__**\n> https://twitter.com/Clovarity/status/${tweetID}`);
}, 750);

setTimeout(() => {
try {
fs.unlinkSync("./commands/Esport/result.png");
fs.unlinkSync("./commands/Esport/result.svg");
} catch (err) {
console.error(err);
}
}, 10000);
} catch (error) {
console.error(error);
try {
fs.unlinkSync("./commands/Esport/result.png");
fs.unlinkSync("./commands/Esport/result.svg");
} catch (err) {
console.error(err);
}

if (!buttonPressed) {
console.log("An error occurred while processing the tweet.");
interaction.followUp("An error occurred while processing the tweet.");
}
}
});

collector.on('end', async collected => {
await interaction.editReply({ content: "Timed Out!", components: [], files: [ { attachment: outputFilePath } ] });
try {
fs.unlinkSync("./commands/Esport/result.png");
fs.unlinkSync("./commands/Esport/result.svg");
console.log(`Files Deleted`)
} catch (err) {
console.error(err);
}
});

} catch (error) {
console.error(error);
// Step 11: Handle errors when reading SVG file
interaction.followUp("An error occurred while reading the SVG file.");
}
},
};
2 changes: 1 addition & 1 deletion events/guildMemberAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {

const channel = await member.guild.channels.cache.get(welcome)
try {
await channel.send({ content: `<@\`${member.user.id}\`> Welcome To Clovarity!`, embeds: [message] })
await channel.send({ content: `<@${member.user.id}> Welcome To Clovarity!`, embeds: [message] })
} catch {
member.guild.channels.cache.get('1059563002875084900').send(`<@${member.id}> \`${member.id}\` \`${member.user.tag}\` somehow tried to double send their welcome message!`)
}
Expand Down

0 comments on commit 879eb6b

Please sign in to comment.