From 0980b0b6663b14a9af19e3cb38bc04a3a106d049 Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Wed, 11 Jan 2023 19:33:38 +1100 Subject: [PATCH] Add randomcolor and adjust few things --- src/client.ts | 2 ++ src/commands/randomcolor.ts | 12 ++++++++++++ src/commands/rank.ts | 8 +++----- src/index.ts | 15 ++++++++------- 4 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 src/commands/randomcolor.ts diff --git a/src/client.ts b/src/client.ts index 65c7400..c3fa5e4 100644 --- a/src/client.ts +++ b/src/client.ts @@ -12,6 +12,8 @@ let importconfig:Config try{ importconfig = require('./DB-Beta.config.json') console.log('Using development config : Daggerbot Beta') + //importconfig = require('./Toast-Testbot.config.json') + //console.log('Using development config : Toast-Testbot') } catch(e){ importconfig = require('./config.json') console.log('Using production config') diff --git a/src/commands/randomcolor.ts b/src/commands/randomcolor.ts new file mode 100644 index 0000000..c4b2ba4 --- /dev/null +++ b/src/commands/randomcolor.ts @@ -0,0 +1,12 @@ +import Discord,{SlashCommandBuilder} from 'discord.js'; +import { TClient } from 'src/client'; +export default { + async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ + const embed = new client.embed().setColor(Math.floor(Math.random()*16777215)); + embed.addFields({name: 'Hex code', value: `#${embed.data.color.toString(16).toUpperCase()}`}); + interaction.reply({embeds: [embed]}); + }, + data: new SlashCommandBuilder() + .setName('randomcolor') + .setDescription('Generate a random hex code') +} \ No newline at end of file diff --git a/src/commands/rank.ts b/src/commands/rank.ts index d757adb..478dee5 100644 --- a/src/commands/rank.ts +++ b/src/commands/rank.ts @@ -138,12 +138,10 @@ export default { ctx.fillText('time ->', tx, ty); const yeahok = new client.attachmentBuilder(img.toBuffer(), {name: 'dailymsgs.png'}) - const embed = new client.embed() - .setTitle('Ranking leaderboard') - .setDescription(`Level System was created **${timeActive}** days ago. Since then, a total of **${messageCountsTotal.toLocaleString('en-US')}** messages have been sent in this server.`) + const embed = new client.embed().setTitle('Ranking leaderboard') + .setDescription(`Level System was created **${timeActive}** days ago. Since then, a total of **${messageCountsTotal.toLocaleString('en-US')}** messages have been sent in this server.\nGraph updates daily @ `) .addFields({name: 'Top users by messages sent:', value: Object.entries(client.userLevels._content).sort((a, b) => b[1].messages - a[1].messages).slice(0, 10).map((x, i) => `\`${i + 1}.\` <@${x[0]}>: ${x[1].messages.toLocaleString('en-US')}`).join('\n')}) - .setImage('attachment://dailymsgs.png') - .setColor(client.config.embedColor) + .setImage('attachment://dailymsgs.png').setColor(client.config.embedColor) interaction.reply({embeds: [embed], files: [yeahok]}); return; } else if (subCmd === "view") { diff --git a/src/index.ts b/src/index.ts index b3a113a..1da686f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,17 +43,18 @@ client.on('ready', async()=>{ }) // Handle errors -process.on('unhandledRejection', async(error: Error)=>{ +function DZ(error:Error){ console.log(error); - (client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send({embeds: [new client.embed().setColor('#420420').setTitle('Error caught!').setDescription(`**Error:** \`${error.message}\`\n\n**Stack:** \`${`${error.stack}`.slice(0, 2500)}\``)]}) + (client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send({embeds: [new client.embed().setColor('#EC5254').setTitle('Error caught!').setDescription(`**Error:** \`${error.message}\`\n\n**Stack:** \`${`${error.stack}`.slice(0, 2500)}\``)]}) +} +process.on('unhandledRejection', async(error: Error)=>{ + DZ(error) }); process.on('uncaughtException', async(error: Error)=>{ - console.log(error); - (client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send({embeds: [new client.embed().setColor('#420420').setTitle('Error caught!').setDescription(`**Error:** \`${error.message}\`\n\n**Stack:** \`${`${error.stack}`.slice(0, 2500)}\``)]}) + DZ(error) }); process.on('error', async(error: Error)=>{ - console.log(error); - (client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send({embeds: [new client.embed().setColor('#420420').setTitle('Error caught!').setDescription(`**Error:** \`${error.message}\`\n\n**Stack:** \`${`${error.stack}`.slice(0, 2500)}\``)]}) + DZ(error) }); // Daggerwin MP loop @@ -164,7 +165,7 @@ setInterval(async()=>{ }); const formattedDate = Math.floor((now - lrsStart)/1000/60/60/24); - const dailyMsgs = require('./database/dailyMsgs.json'); + const dailyMsgs = JSON.parse(fs.readFileSync(__dirname + '/database/dailyMsgs.json', {encoding: 'utf8'})) if (!dailyMsgs.some((x:Array)=>x[0] === formattedDate)){ let total = Object.values(client.userLevels._content).reduce((a,b)=>a + b.messages, 0); // sum of all users const yesterday = dailyMsgs.find((x:Array)=>x[0] === formattedDate - 1);