From 0b9cd5af116969171ef046c5cb1a4634a59d0d72 Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Fri, 3 Feb 2023 02:45:48 +1100 Subject: [PATCH] Revamp guild registration and add other stuff. --- src/commands/dev.ts | 58 +++++++++++++++++++++++++++++++++++++ src/config.json | 9 ++++++ src/index.ts | 9 +++--- src/typings/interfaces.d.ts | 2 ++ 4 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/commands/dev.ts b/src/commands/dev.ts index ec24a21..460386f 100644 --- a/src/commands/dev.ts +++ b/src/commands/dev.ts @@ -88,6 +88,36 @@ export default { client.statsGraph = -(interaction.options.getInteger('number', true)) interaction.reply(`Successfully set to \`${client.statsGraph}\`\n*Total data points: **${JSON.parse(readFileSync(path.join(__dirname, '../database/MPPlayerData.json'), {encoding: 'utf8'})).length.toLocaleString()}***`); break + case 'presence': + function convertType(Type?: number){ + switch (Type) { + case 0: return 'Playing'; + case 1: return 'Streaming'; + case 2: return 'Listening to'; + case 3: return 'Watching'; + case 5: return 'Competing in'; + } + }; + const status = interaction.options.getString('status') as Discord.PresenceStatusData | null; + const type = interaction.options.getInteger('type'); + const name = interaction.options.getString('name'); + const url = interaction.options.getString('url'); + const currentActivities = client.config.botPresence.activities as Discord.ActivitiesOptions[]; + + if (status) client.config.botPresence.status = status; + if (type) currentActivities[0].type = type; + if (name) currentActivities[0].name = name; + if (url) currentActivities[0].url = url; + + client.user.setPresence(client.config.botPresence); + interaction.reply([ + 'Presence updated:', + `Status: **${client.config.botPresence.status}**`, + `Type: **${convertType(currentActivities[0].type)}**`, + `Name: **${currentActivities[0].name}**`, + `URL: \`${currentActivities[0].url}\`` + ].join('\n')) + break } }, data: new SlashCommandBuilder() @@ -116,4 +146,32 @@ export default { .setName('number') .setDescription('Number of data points to pull') .setRequired(true))) + .addSubcommand((optt)=>optt + .setName('presence') + .setDescription('Update the bot\'s presence') + .addIntegerOption((hiTae)=>hiTae + .setName('type') + .setDescription('Set an activity type') + .addChoices( + {name: 'Playing', value: Discord.ActivityType.Playing}, + {name: 'Streaming', value: Discord.ActivityType.Streaming}, + {name: 'Listening to', value: Discord.ActivityType.Listening}, + {name: 'Watching', value: Discord.ActivityType.Watching}, + {name: 'Competing in', value: Discord.ActivityType.Competing} + )) + .addStringOption((hiAgain)=>hiAgain + .setName('name') + .setDescription('Set a message for the activity status')) + .addStringOption((hiAgainx2)=>hiAgainx2 + .setName('url') + .setDescription('Set an url for streaming status')) + .addStringOption((hiAgainx3)=>hiAgainx3 + .setName('status') + .setDescription('Set a status indicator for the bot') + .setChoices( + {name: 'Online', value: Discord.PresenceUpdateStatus.Online}, + {name: 'Idle', value: Discord.PresenceUpdateStatus.Idle}, + {name: 'Do Not Distrub', value: Discord.PresenceUpdateStatus.DoNotDisturb}, + {name: 'Invisible', value: Discord.PresenceUpdateStatus.Offline} + ))) } diff --git a/src/config.json b/src/config.json index 881ad58..d960c87 100644 --- a/src/config.json +++ b/src/config.json @@ -7,6 +7,9 @@ "embedColorBCA": "#ff69b4", "embedColorXmas": "#FFFFFF", "LRSstart": 1661236321433, + "whitelistedServers": [ + "929807948748832798", "468835415093411861", "1058183358267543552" + ], "botSwitches": { "registerCommands": true, "commands": true, @@ -15,6 +18,12 @@ "mpstats": true, "autores": true }, + "botPresence": { + "activities": [ + {"name": "the days go by", "url": "https://www.youtube.com/watch?v=8UVNT4wvIGY", "type": 1} + ], + "status": "online" + }, "eval": { "allowed": true, "whitelist": [ diff --git a/src/index.ts b/src/index.ts index 6d39af2..192ea1d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,12 +9,10 @@ import {Punishment, UserLevels, FSData, FSCareerSavegame} from './typings/interf client.on('ready', async()=>{ client.guilds.cache.forEach(async(e)=>{await e.members.fetch()}); setInterval(async()=>{ - client.user.setPresence({activities: [{ name: 'the days go by', type: 3, url: 'https://www.youtube.com/watch?v=D-UmfqFjpl0' }], status: 'online'}); - // Playing: 0, Streaming (Requires YT/Twitch URL to work): 1, Listening to: 2, Watching: 3, Competing in: 5 - }, 60000); - // ['929807948748832798', '468835415093411861', '1058183358267543552', '549114074273677314'] - 0=Dev Server, 1=Main Server, 2=Throne, 3=Toast's test server + client.user.setPresence(client.config.botPresence); + }, 300000); if (client.config.botSwitches.registerCommands){ - ['929807948748832798', '468835415093411861', '1058183358267543552'].forEach((guildId)=>(client.guilds.cache.get(guildId) as Discord.Guild).commands.set(client.registry).catch((e:Error)=>{ + client.config.whitelistedServers.forEach((guildId)=>(client.guilds.cache.get(guildId) as Discord.Guild).commands.set(client.registry).catch((e:Error)=>{ console.log(`Couldn't register slash commands for ${guildId} because`, e.stack); (client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send(`Cannot register slash commands for **${client.guilds.cache.get(guildId).name}** (\`${guildId}\`):\n\`\`\`${e.message}\`\`\``) })); @@ -30,6 +28,7 @@ client.on('ready', async()=>{ }, 500000); console.log(`${client.user.tag} has logged into Discord API and now ready for operation`); console.log(client.config.botSwitches); + console.log(client.config.whitelistedServers); (client.channels.resolve(client.config.mainServer.channels.bot_status) as Discord.TextChannel).send(`${client.user.username} is active\n\`\`\`json\n${Object.entries(client.config.botSwitches).map((hi)=>`${hi[0]}: ${hi[1]}`).join('\n')}\`\`\``); // Event handler diff --git a/src/typings/interfaces.d.ts b/src/typings/interfaces.d.ts index e3e91a6..69ea66f 100644 --- a/src/typings/interfaces.d.ts +++ b/src/typings/interfaces.d.ts @@ -132,7 +132,9 @@ export interface Config { embedColorBCA: ColorResolvable, embedColorXmas: ColorResolvable, LRSstart: number, + whitelistedServers: Array, botSwitches: botSwitches, + botPresence: Discord.PresenceData, eval: Eval, mainServer: mainServer }