From 46ae4ffea946612011d427bd4d197039114301e6 Mon Sep 17 00:00:00 2001 From: SrIzan10 <66965250+SrIzan10@users.noreply.github.com> Date: Thu, 24 Nov 2022 17:19:03 +0100 Subject: [PATCH] feat: dev mode :D --- .gitignore | 1 + commands/handlers/sugerencias.ts | 4 +- commands/moderation/ban.ts | 2 +- commands/moderation/kick.ts | 2 +- commands/moderation/prune.ts | 2 +- commands/moderation/slowmode.ts | 2 +- commands/moderation/timeoutUser.ts | 2 +- events/guildMemberAdd.ts | 2 +- events/guildMemberRemove.ts | 2 +- index.ts | 33 ++++-- package-lock.json | 155 ++++++++++++++++++++++++++--- package.json | 6 +- util/birthdays.ts | 4 +- util/twitternotifications.ts | 4 +- util/youtubenotifications.ts | 4 +- 15 files changed, 182 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index 69b0425..bc16299 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .env +.env.dev node_modules/ json.sqlite dist/ \ No newline at end of file diff --git a/commands/handlers/sugerencias.ts b/commands/handlers/sugerencias.ts index 069742e..566f364 100644 --- a/commands/handlers/sugerencias.ts +++ b/commands/handlers/sugerencias.ts @@ -38,8 +38,8 @@ export default commandModule({ .setLabel('0') .setStyle(ButtonStyle.Danger), ) - const message1 = await (await modal.client.guilds.fetch('928018226330337280')) - .channels.fetch('1007269448140476436') as TextChannel; + const message1 = await (await modal.client.guilds.fetch(process.env.GUILDID!)) + .channels.fetch(process.env.SUGGESTIONS_CHANNEL!) as TextChannel; const message2 = await message1.send({ embeds: [embed], components: [buttons] }); message2.startThread({ name: `Sugerencia de ${modal.user.username}`, diff --git a/commands/moderation/ban.ts b/commands/moderation/ban.ts index b9c12f1..feb03d0 100644 --- a/commands/moderation/ban.ts +++ b/commands/moderation/ban.ts @@ -26,7 +26,7 @@ export default commandModule({ const userToBan = options[1].getMember('usuario') as GuildMember const reason = options[1].getString('razon') as string userToBan.ban({reason: reason}) - const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257') as TextChannel + const sendToMods = ctx.client.guilds.cache.get(process.env.GUILDID!)!.channels.cache.get(process.env.MODLOGS_CHANNEL!) as TextChannel await sendToMods.send({content: `Se ha baneado a ${userToBan}.\nBan efectuado por ${ctx.user} con razón "${reason}."`}) await ctx.reply({content: 'Baneado correctamente!', ephemeral: true}) } catch (e) { diff --git a/commands/moderation/kick.ts b/commands/moderation/kick.ts index d9e6796..dd9d2fe 100644 --- a/commands/moderation/kick.ts +++ b/commands/moderation/kick.ts @@ -28,7 +28,7 @@ export default commandModule({ const userToKick = options[1].getMember('usuario'); const reason = options[1].getString('razon') as string; (userToKick as GuildMember).kick(reason) - const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257') as TextChannel + const sendToMods = ctx.client.guilds.cache.get(process.env.GUILDID!)!.channels.cache.get(process.env.MODLOGS_CHANNEL!) as TextChannel await sendToMods!.send({content: `Se ha expulsado a ${userToKick}.\nKick efectuado por ${ctx.user} con razón "${reason}."`}) await ctx.reply({content: 'Expulsado correctamente!'}) } catch (e) { diff --git a/commands/moderation/prune.ts b/commands/moderation/prune.ts index a3a3149..fd64df1 100644 --- a/commands/moderation/prune.ts +++ b/commands/moderation/prune.ts @@ -24,7 +24,7 @@ export default commandModule({ console.error(err); ctx.reply({content: 'Ha habido un error eliminando mensajes! (mira la consola, Sr Izan)', ephemeral: true});}); await ctx.reply({content: `Se han eliminado ${amount} mensajes.`}) - const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257') as TextChannel + const sendToMods = ctx.client.guilds.cache.get(process.env.GUILDID!)!.channels.cache.get(process.env.MODLOGS_CHANNEL!) as TextChannel await sendToMods.send({content: `Se han eliminado ${amount} mensajes en ${ctx.channel}\nEfectuado por ${ctx.user}.`}) } catch (e){ ctx.reply({content: 'Ha habido un error eliminando mensajes! Error reportado automáticamente.', ephemeral: true})}; diff --git a/commands/moderation/slowmode.ts b/commands/moderation/slowmode.ts index 5a2e907..76a65ad 100644 --- a/commands/moderation/slowmode.ts +++ b/commands/moderation/slowmode.ts @@ -31,7 +31,7 @@ export default commandModule({ (ctx.channel as TextChannel).setRateLimitPerUser(seconds, reason) ctx.reply({content: `Se han añadido ${seconds} segundos de modo lento al canal de voz actual`}) - const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257') as TextChannel + const sendToMods = ctx.client.guilds.cache.get(process.env.GUILDID!)!.channels.cache.get(process.env.MODLOGS_CHANNEL!) as TextChannel await sendToMods.send({content: `Se ha aplicado modo lento al canal ${ctx.channel}.\nEfectuado por ${ctx.user} con ${seconds} segundos de retardo.\nRazón: ${reason}`}) } catch (e) { ctx.reply({content: `No se ha podido aplicar modo lento al canal.`}) diff --git a/commands/moderation/timeoutUser.ts b/commands/moderation/timeoutUser.ts index b93d3c3..507747f 100644 --- a/commands/moderation/timeoutUser.ts +++ b/commands/moderation/timeoutUser.ts @@ -41,7 +41,7 @@ export default commandModule({ const razon = options[1].getString('razon', true); const minutosToMilisegundos = minutos * 60 * 1000 usuario.timeout(minutosToMilisegundos, razon).then(() => {ctx.reply({content: `Se ha silenciado a ${usuario} correctamente.`, ephemeral: true})}) - const sendToMods = ctx.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1004118323258208257') as TextChannel + const sendToMods = ctx.client.guilds.cache.get(process.env.GUILDID!)!.channels.cache.get(process.env.MODLOGS_CHANNEL!) as TextChannel await sendToMods.send({content: `Se ha silenciado a ${usuario}.\nSlencio efectuado por ${ctx.user} con ${minutos} minutos de duración.\nRazón: ${razon}`}) } catch (e) { await ctx.reply({content: `ERROR: No puedo hacer este comando porque a lo mejor soy inferior que el rol de esa persona o estoy usándolo contra admins.`}) diff --git a/events/guildMemberAdd.ts b/events/guildMemberAdd.ts index 98c9556..dba90be 100644 --- a/events/guildMemberAdd.ts +++ b/events/guildMemberAdd.ts @@ -13,7 +13,7 @@ export default eventModule({ .setThumbnail(member.user.displayAvatarURL()) .setTimestamp(); - const channel = member.client.guilds.cache.get('928018226330337280')!.channels.cache.get('993599947364634694') as TextChannel + const channel = member.client.guilds.cache.get(process.env.GUILDID!)!.channels.cache.get(process.env.JOINSANDLEAVES_CHANNEL!) as TextChannel channel.send({embeds: [newMemberEmbed]}) } }); \ No newline at end of file diff --git a/events/guildMemberRemove.ts b/events/guildMemberRemove.ts index bc9fc56..b8bee0b 100644 --- a/events/guildMemberRemove.ts +++ b/events/guildMemberRemove.ts @@ -14,7 +14,7 @@ export default eventModule({ .setThumbnail(member.user.displayAvatarURL()) .setTimestamp(); - const channel = member.client.guilds.cache.get('928018226330337280')!.channels.cache.get('993599947364634694') as TextChannel + const channel = member.client.guilds.cache.get(process.env.GUILDID!)!.channels.cache.get(process.env.JOINSANDLEAVES_CHANNEL!) as TextChannel channel.send({embeds: [leaveEmbed]}) } }); \ No newline at end of file diff --git a/index.ts b/index.ts index 5f69fe0..3bee751 100644 --- a/index.ts +++ b/index.ts @@ -2,7 +2,14 @@ import { SernEmitter } from '@sern/handler'; import { ActivityType } from 'discord.js'; import { Client, GatewayIntentBits } from 'discord.js'; import { Sern } from '@sern/handler'; -import 'dotenv/config'; +import { config as dotenv } from 'dotenv'; +let devMode +if (process.argv[2] === '--dev') { + devMode = true + dotenv({path: './.env.dev'}) +} else { + dotenv() +} import mongoose from 'mongoose'; import express from 'express'; import youtubenotifications from './util/youtubenotifications.js'; @@ -23,7 +30,7 @@ const client = new Client({ ], }); -export const db = mongoose.connect(process.env.MONGODB as string).then(() => { +export const db = mongoose.connect(process.env.MONGODB!).then(() => { console.log('Connected to MongoDB'); }); @@ -51,17 +58,21 @@ client.on('ready', async () => { client.user!.setActivity(randomStatus); }, 10000); - setIntervalAsync(async () => { - await youtubenotifications(client); - }, 120_000); + if (!devMode) { + setIntervalAsync(async () => { + await youtubenotifications(client); + }, 120_000); - setIntervalAsync(async () => { - await twitternotifications(client); - }, 120_000); + setIntervalAsync(async () => { + await twitternotifications(client); + }, 120_000); - setIntervalAsync(async () => { - await birthdays(client); - }, 3_600_000); + setIntervalAsync(async () => { + await birthdays(client); + }, 3_600_000); + } else { + console.log('DevMode got activated, there are no checkers in this version.') + } }); client.on('rateLimit', async () => { diff --git a/package-lock.json b/package-lock.json index b4fa6c5..aefba7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,6 @@ "@discordjs/opus": "^0.9.0", "@discordjs/voice": "^0.13.0", "@sern/handler": "^1.2.1", - "@xmldom/xmldom": "^0.8.5", "axios": "^1.0.0", "dayjs": "^1.11.6", "discord-bot-youtube-notifications": "^1.1.4", @@ -29,6 +28,7 @@ "tweetnacl": "^1.0.3" }, "devDependencies": { + "@types/express": "^4.17.14", "ts-node": "10.9.1", "tsc-watch": "^5.0.3", "typescript": "4.9.3" @@ -352,6 +352,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/body-parser": { + "version": "1.19.2", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz", + "integrity": "sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==", + "dev": true, + "dependencies": { + "@types/connect": "*", + "@types/node": "*" + } + }, "node_modules/@types/cacheable-request": { "version": "6.0.2", "license": "MIT", @@ -362,6 +372,38 @@ "@types/responselike": "*" } }, + "node_modules/@types/connect": { + "version": "3.4.35", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz", + "integrity": "sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/express": { + "version": "4.17.14", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.14.tgz", + "integrity": "sha512-TEbt+vaPFQ+xpxFLFssxUDXj5cWCxZJjIcB7Yg0k0GMHGtgtQgpvx/MUQUeAkNbA9AAGrwkAsoeItdTgS7FMyg==", + "dev": true, + "dependencies": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^4.17.18", + "@types/qs": "*", + "@types/serve-static": "*" + } + }, + "node_modules/@types/express-serve-static-core": { + "version": "4.17.31", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.31.tgz", + "integrity": "sha512-DxMhY+NAsTwMMFHBTtJFNp5qiHKJ7TeqOo23zVEM9alT1Ml27Q3xcTH0xwxn7Q0BbMcVEJOs/7aQtUWupUQN3Q==", + "dev": true, + "dependencies": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*" + } + }, "node_modules/@types/http-cache-semantics": { "version": "4.0.1", "license": "MIT" @@ -373,10 +415,28 @@ "@types/node": "*" } }, + "node_modules/@types/mime": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz", + "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==", + "dev": true + }, "node_modules/@types/node": { "version": "18.8.3", "license": "MIT" }, + "node_modules/@types/qs": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", + "integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==", + "dev": true + }, + "node_modules/@types/range-parser": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz", + "integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==", + "dev": true + }, "node_modules/@types/responselike": { "version": "1.0.0", "license": "MIT", @@ -384,6 +444,16 @@ "@types/node": "*" } }, + "node_modules/@types/serve-static": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.0.tgz", + "integrity": "sha512-z5xyF6uh8CbjAu9760KDKsH2FcDxZ2tFCsA4HIMWE6IkiYMXfVoa+4f9KX+FN0ZLsaMw1WNG2ETLA6N+/YA+cg==", + "dev": true, + "dependencies": { + "@types/mime": "*", + "@types/node": "*" + } + }, "node_modules/@types/webidl-conversions": { "version": "7.0.0", "license": "MIT" @@ -403,14 +473,6 @@ "@types/node": "*" } }, - "node_modules/@xmldom/xmldom": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.5.tgz", - "integrity": "sha512-0dpjDLeCXYThL2YhqZcd/spuwoH+dmnFoND9ZxZkAYxp1IJUB2GP16ow2MJRsjVxy8j1Qv8BJRmN5GKnbDKCmQ==", - "engines": { - "node": ">=10.0.0" - } - }, "node_modules/agent-base": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", @@ -3105,6 +3167,16 @@ "version": "1.0.3", "dev": true }, + "@types/body-parser": { + "version": "1.19.2", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz", + "integrity": "sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==", + "dev": true, + "requires": { + "@types/connect": "*", + "@types/node": "*" + } + }, "@types/cacheable-request": { "version": "6.0.2", "requires": { @@ -3114,6 +3186,38 @@ "@types/responselike": "*" } }, + "@types/connect": { + "version": "3.4.35", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz", + "integrity": "sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/express": { + "version": "4.17.14", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.14.tgz", + "integrity": "sha512-TEbt+vaPFQ+xpxFLFssxUDXj5cWCxZJjIcB7Yg0k0GMHGtgtQgpvx/MUQUeAkNbA9AAGrwkAsoeItdTgS7FMyg==", + "dev": true, + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^4.17.18", + "@types/qs": "*", + "@types/serve-static": "*" + } + }, + "@types/express-serve-static-core": { + "version": "4.17.31", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.31.tgz", + "integrity": "sha512-DxMhY+NAsTwMMFHBTtJFNp5qiHKJ7TeqOo23zVEM9alT1Ml27Q3xcTH0xwxn7Q0BbMcVEJOs/7aQtUWupUQN3Q==", + "dev": true, + "requires": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*" + } + }, "@types/http-cache-semantics": { "version": "4.0.1" }, @@ -3123,15 +3227,43 @@ "@types/node": "*" } }, + "@types/mime": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz", + "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==", + "dev": true + }, "@types/node": { "version": "18.8.3" }, + "@types/qs": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", + "integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==", + "dev": true + }, + "@types/range-parser": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz", + "integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==", + "dev": true + }, "@types/responselike": { "version": "1.0.0", "requires": { "@types/node": "*" } }, + "@types/serve-static": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.0.tgz", + "integrity": "sha512-z5xyF6uh8CbjAu9760KDKsH2FcDxZ2tFCsA4HIMWE6IkiYMXfVoa+4f9KX+FN0ZLsaMw1WNG2ETLA6N+/YA+cg==", + "dev": true, + "requires": { + "@types/mime": "*", + "@types/node": "*" + } + }, "@types/webidl-conversions": { "version": "7.0.0" }, @@ -3148,11 +3280,6 @@ "@types/node": "*" } }, - "@xmldom/xmldom": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.5.tgz", - "integrity": "sha512-0dpjDLeCXYThL2YhqZcd/spuwoH+dmnFoND9ZxZkAYxp1IJUB2GP16ow2MJRsjVxy8j1Qv8BJRmN5GKnbDKCmQ==" - }, "agent-base": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", diff --git a/package.json b/package.json index 1faa009..442b692 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,10 @@ "main": "index.ts", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "dev": "tsc-watch --onSuccess \"node ./dist/index.js\"", + "dev": "tsc-watch --onSuccess \"node ./dist/index.js --dev\"", "compile": "tsc --build", "build": "tsc --build", - "web": "node webserver.js", - "start": "ts-node index.ts" + "web": "node webserver.js" }, "repository": { "type": "git", @@ -45,6 +44,7 @@ "tweetnacl": "^1.0.3" }, "devDependencies": { + "@types/express": "^4.17.14", "ts-node": "10.9.1", "tsc-watch": "^5.0.3", "typescript": "4.9.3" diff --git a/util/birthdays.ts b/util/birthdays.ts index 5434e66..fd13cf4 100644 --- a/util/birthdays.ts +++ b/util/birthdays.ts @@ -15,8 +15,8 @@ db.find({}, (err, user) => { if (finduser!.alreadysent === true && dayjs().format('D-M') !== finduser!.date) return saveit() if (finduser!.alreadysent === true) return const sendtochannel = (await ( - await client.guilds.fetch("928018226330337280") - ).channels.fetch("1039613653269352449")) as TextChannel; + await client.guilds.fetch(process.env.GUILDID!) + ).channels.fetch(process.env.BIRTHDAYS_CHANNEL!)) as TextChannel; const message = await sendtochannel.send({ content: `Hola <@&1039613683422208020>!\nHoy es el cumpleaños de <@${finduser!.id}> 🎉🎉🎉\nMuchas felicidades!` }) message.react('🎉') message.react('<:Pog:1030169609178976346>') diff --git a/util/twitternotifications.ts b/util/twitternotifications.ts index f269381..9737b13 100644 --- a/util/twitternotifications.ts +++ b/util/twitternotifications.ts @@ -17,8 +17,8 @@ export default async function twitternotifications(client: Client) { .then((res) => res.data) ).data[0].id; const fetchTextChannel = (await ( - await client.guilds.fetch('928018226330337280') - ).channels.fetch('948690278498320404')) as TextChannel; + await client.guilds.fetch(process.env.GUILDID!) + ).channels.fetch(process.env.SOCIALS_CHANNEL!)) as TextChannel; if (request === db?.id) return; else { db!.id = request; diff --git a/util/youtubenotifications.ts b/util/youtubenotifications.ts index b7d7769..0556d02 100644 --- a/util/youtubenotifications.ts +++ b/util/youtubenotifications.ts @@ -15,8 +15,8 @@ export default async function youtubenotifications(client: Client) { ) .then((res) => res.data); const fetchTextChannel = (await ( - await client.guilds.fetch('928018226330337280') - ).channels.fetch('948690278498320404')) as TextChannel; + await client.guilds.fetch(process.env.GUILDID!) + ).channels.fetch(process.env.SOCIALS_CHANNEL!)) as TextChannel; if (request === db!.id) return; else { db!.id = request;