From 5f457c2604955d0d16c811d09ae087a54c0fd0e1 Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Fri, 14 Apr 2023 20:47:58 +1000 Subject: [PATCH] Turning the bot back to JS. --- .gitignore | 1 + package.json | 4 ++- src/client.ts | 52 ++++++++++++++++----------------- src/commands/ban.ts | 2 +- src/commands/bannedWords.ts | 2 +- src/commands/bonk.ts | 2 +- src/commands/case.ts | 2 +- src/commands/contributors.ts | 2 +- src/commands/dev.ts | 6 ++-- src/commands/faq.ts | 2 +- src/commands/kick.ts | 2 +- src/commands/mp.ts | 2 +- src/commands/mute.ts | 2 +- src/commands/ping.ts | 2 +- src/commands/purge.ts | 2 +- src/commands/randomcolor.ts | 2 +- src/commands/rank.ts | 4 +-- src/commands/roleinfo.ts | 2 +- src/commands/softban.ts | 2 +- src/commands/statistics.ts | 14 ++++----- src/commands/suggest.ts | 2 +- src/commands/unpunish.ts | 2 +- src/commands/warn.ts | 2 +- src/commands/whois.ts | 2 +- src/config.json | 4 +-- src/events/guildBanAdd.ts | 2 +- src/events/guildBanRemove.ts | 2 +- src/events/guildMemberAdd.ts | 2 +- src/events/guildMemberRemove.ts | 2 +- src/events/guildMemberUpdate.ts | 2 +- src/events/interactionCreate.ts | 4 +-- src/events/inviteCreate.ts | 2 +- src/events/inviteDelete.ts | 2 +- src/events/messageCreate.ts | 6 ++-- src/events/messageDelete.ts | 2 +- src/events/messageDeleteBulk.ts | 2 +- src/events/messageUpdate.ts | 6 ++-- src/index.ts | 13 +++++---- src/models/MPServer.ts | 2 +- src/models/bannedWords.ts | 2 +- src/models/bonkCount.ts | 2 +- src/models/punishments.ts | 4 +-- src/models/suggestion.ts | 2 +- src/models/userLevels.ts | 2 +- tsconfig.json | 34 +++++++++++---------- 45 files changed, 111 insertions(+), 105 deletions(-) diff --git a/.gitignore b/.gitignore index 2407e12..2bd3fba 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ node_modules/ package-lock.json .ncurc.json # Bot stuff +dist/ src/database/ src/tokens.json src/Toast-Testbot.config.json diff --git a/package.json b/package.json index 6a2d24e..8d111dd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "name": "daggerbot-ts", "description": "TypeScript version of the original JavaScript-based bot for Official Daggerwin Discord.", - "main": "src/index.ts", + "main": "dist/index.js", + "type": "module", "repository": { "type": "git", "url": "git+https://github.com/AnxietyisReal/Daggerbot-TS.git" @@ -35,6 +36,7 @@ "xml-js": "1.6.11" }, "devDependencies": { + "@types/ms": "0.7.31", "@types/node": "18.15.11", "ts-node": "10.9.1" } diff --git a/src/client.ts b/src/client.ts index 452c991..8320a15 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,27 +1,26 @@ import Discord, { Client, WebhookClient, GatewayIntentBits, Partials } from 'discord.js'; import fs from 'node:fs'; -import { exec } from 'node:child_process'; -import timeNames from './timeNames'; +import {exec} from 'node:child_process'; +import timeNames from './timeNames.js'; import mongoose from 'mongoose'; -import { formatTimeOpt, Tokens, Config, repeatedMessages } from './typings/interfaces'; -import bannedWords from './models/bannedWords'; -import userLevels from './models/userLevels'; -import suggestion from './models/suggestion'; -import punishments from './models/punishments'; -import bonkCount from './models/bonkCount'; -import MPServer from './models/MPServer'; +import {formatTimeOpt, Tokens, Config, repeatedMessages} from './typings/interfaces'; +import bannedWords from './models/bannedWords.js'; +import userLevels from './models/userLevels.js'; +import suggestion from './models/suggestion.js'; +import punishments from './models/punishments.js'; +import bonkCount from './models/bonkCount.js'; +import MPServer from './models/MPServer.js'; +import xjs from 'xml-js'; import axios from 'axios'; import moment from 'moment'; -import tokens from './tokens.json'; +import tokens from './tokens.json' assert { type: 'json'}; let importconfig:Config try{ - importconfig = require('./DB-Beta.config.json') + importconfig = JSON.parse(fs.readFileSync('src/DB-Beta.config.json', {encoding:'utf8'})); 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') + importconfig = JSON.parse(fs.readFileSync('src/config.json', {encoding:'utf8'})) console.log('Using production config') } @@ -37,7 +36,7 @@ export default class TClient extends Client { messageCollector: any; attachmentBuilder: any; moment: typeof moment; - xjs: any; + xjs: typeof xjs; axios: typeof axios; ms: any; userLevels: userLevels; @@ -77,9 +76,9 @@ export default class TClient extends Client { this.messageCollector = Discord.MessageCollector; this.attachmentBuilder = Discord.AttachmentBuilder; this.moment = moment; - this.xjs = require('xml-js'); + this.xjs = xjs; this.axios = axios; - this.ms = require('ms'); + this.ms = import('ms').then(i=>i); this.userLevels = new userLevels(this); this.bonkCount = new bonkCount(this); this.punishments = new punishments(this); @@ -102,17 +101,17 @@ export default class TClient extends Client { socketTimeoutMS: 30000, family: 4 }).then(()=>console.log(this.logTime(), 'Successfully connected to MongoDB')).catch((err)=>{console.error(this.logTime(), `Failed to connect to MongoDB\n${err.reason}`); exec('pm2 stop Daggerbot')}) - await this.login(this.tokens.main); - const commandFiles = fs.readdirSync('src/commands').filter(file=>file.endsWith('.ts')); + await this.login(this.tokens.beta); + fs.readdirSync('dist/events').forEach(async file=>{ + const eventFile = await import(`./events/${file}`); + this.on(file.replace('.js', ''), async(...args)=>eventFile.default.run(this,...args)); + }); + const commandFiles = fs.readdirSync('dist/commands').filter(file=>file.endsWith('.js')); for (const file of commandFiles){ - const command = require(`./commands/${file}`); - this.commands.set(command.default.data.name, command) + const command = await import(`./commands/${file}`); + this.commands.set(command.default.data.name, {command, uses: 0}) this.registry.push(command.default.data.toJSON()) } - fs.readdirSync('src/events').forEach((file)=>{ - const eventFile = require(`./events/${file}`); - this.on(file.replace('.ts', ''), async(...args)=>eventFile.default.run(this,...args)); - }); } formatTime(integer: number, accuracy = 1, options?: formatTimeOpt){ let achievedAccuracy = 0; @@ -170,7 +169,7 @@ export default class TClient extends Client { let error; try { - await this.axios.get(`https://www.youtube.com/feeds/videos.xml?channel_id=${YTChannelID}`, {timeout: 5000}).then((xml:any)=>Data = this.xjs.xml2js(xml.data, {compact: true, spaces: 2})) + await this.axios.get(`https://www.youtube.com/feeds/videos.xml?channel_id=${YTChannelID}`, {timeout: 5000}).then((xml:any)=>Data = this.xjs.xml2js(xml.data, {compact: true})) } catch(err){ error = true; console.log(this.logTime(), `${YTChannelName} YT fail`) @@ -194,6 +193,7 @@ export class WClient extends WebhookClient { super({ url: tokens.webhook_url }) + this.tokens = tokens as Tokens; } } // hi tae, ik you went to look for secret hello msgs in here too. \ No newline at end of file diff --git a/src/commands/ban.ts b/src/commands/ban.ts index a11c8a3..5cc1016 100644 --- a/src/commands/ban.ts +++ b/src/commands/ban.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ client.punish(client, interaction, 'ban'); diff --git a/src/commands/bannedWords.ts b/src/commands/bannedWords.ts index 7c13c8a..074c9f5 100644 --- a/src/commands/bannedWords.ts +++ b/src/commands/bannedWords.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; import {writeFileSync} from 'node:fs'; import path from 'node:path'; export default { diff --git a/src/commands/bonk.ts b/src/commands/bonk.ts index d59e99d..dfdfdbe 100644 --- a/src/commands/bonk.ts +++ b/src/commands/bonk.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ //if (!client.isStaff(interaction.member) && interaction.channelId == '468835415093411863') return interaction.reply('This command is restricted to staff only in this channel due to high usage.') diff --git a/src/commands/case.ts b/src/commands/case.ts index 6464778..1e01378 100644 --- a/src/commands/case.ts +++ b/src/commands/case.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from "discord.js"; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ if (!client.isStaff(interaction.member)) return client.youNeedRole(interaction, 'dcmod'); diff --git a/src/commands/contributors.ts b/src/commands/contributors.ts index f05a111..1dac52b 100644 --- a/src/commands/contributors.ts +++ b/src/commands/contributors.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ interaction.reply({embeds: [new client.embed().setColor(client.config.embedColor).setTitle('Daggerbot contributors').setDescription([ diff --git a/src/commands/dev.ts b/src/commands/dev.ts index 5217bcb..4c19e2f 100644 --- a/src/commands/dev.ts +++ b/src/commands/dev.ts @@ -1,9 +1,9 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; import {Octokit} from '@octokit/rest'; import {exec} from 'node:child_process'; -import {readFileSync} from 'node:fs'; +import fs from 'node:fs'; import util from 'node:util'; -import TClient from '../client'; +import TClient from '../client.js'; import path from 'node:path'; const removeUsername = (text: string)=>{ let matchesLeft = true; @@ -100,7 +100,7 @@ export default { }, statsgraph: ()=>{ 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()}***`) + interaction.reply(`Successfully set to \`${client.statsGraph}\`\n*Total data points: **${JSON.parse(fs.readFileSync(path.join(__dirname, '../database/MPPlayerData.json'), {encoding: 'utf8'})).length.toLocaleString()}***`) }, logs: ()=>{ interaction.deferReply(); diff --git a/src/commands/faq.ts b/src/commands/faq.ts index dcc524f..7bba593 100644 --- a/src/commands/faq.ts +++ b/src/commands/faq.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ ({ diff --git a/src/commands/kick.ts b/src/commands/kick.ts index d38a1ab..c2548ab 100644 --- a/src/commands/kick.ts +++ b/src/commands/kick.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ client.punish(client, interaction, 'kick'); diff --git a/src/commands/mp.ts b/src/commands/mp.ts index c2cc3e4..21dad43 100644 --- a/src/commands/mp.ts +++ b/src/commands/mp.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; import path from 'node:path'; import canvas from 'canvas'; import fs from 'node:fs'; diff --git a/src/commands/mute.ts b/src/commands/mute.ts index b3a2981..a84cf1a 100644 --- a/src/commands/mute.ts +++ b/src/commands/mute.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ client.punish(client, interaction, 'mute'); diff --git a/src/commands/ping.ts b/src/commands/ping.ts index 9c3d2e6..ef9f876 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ const msg = await interaction.reply({content: 'Pinging...', fetchReply: true}) diff --git a/src/commands/purge.ts b/src/commands/purge.ts index dad204c..7255d1c 100644 --- a/src/commands/purge.ts +++ b/src/commands/purge.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ if (!client.isStaff(interaction.member)) return client.youNeedRole(interaction, 'dcmod'); diff --git a/src/commands/randomcolor.ts b/src/commands/randomcolor.ts index e576bcf..9e11ab7 100644 --- a/src/commands/randomcolor.ts +++ b/src/commands/randomcolor.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ const embed = new client.embed().setColor(Math.floor(Math.random()*16777215)); diff --git a/src/commands/rank.ts b/src/commands/rank.ts index 02fec9f..3e3450b 100644 --- a/src/commands/rank.ts +++ b/src/commands/rank.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; import path from 'node:path'; import fs from 'node:fs'; import canvas from 'canvas'; @@ -30,7 +30,7 @@ export default { const messageCountsTotal = allData.reduce((a, b) => a + b.messages, 0); const timeActive = Math.floor((Date.now() - client.config.LRSstart)/1000/60/60/24); - const dailyMsgsPath = path.join(__dirname, '../database/dailyMsgs.json'); + const dailyMsgsPath = path.join('./src/database/dailyMsgs.json'); const data = JSON.parse(fs.readFileSync(dailyMsgsPath, 'utf8')).map((x: Array, i: number, a: any) => { const yesterday = a[i - 1] || []; return x[1] - (yesterday[1] || x[1]); diff --git a/src/commands/roleinfo.ts b/src/commands/roleinfo.ts index 1c5083e..e29c949 100644 --- a/src/commands/roleinfo.ts +++ b/src/commands/roleinfo.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ const role = interaction.options.getRole('role') as Discord.Role; diff --git a/src/commands/softban.ts b/src/commands/softban.ts index 1d252fc..b8b6fb2 100644 --- a/src/commands/softban.ts +++ b/src/commands/softban.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ client.punish(client, interaction, 'softban'); diff --git a/src/commands/statistics.ts b/src/commands/statistics.ts index 6e3c76e..c0a49b3 100644 --- a/src/commands/statistics.ts +++ b/src/commands/statistics.ts @@ -1,7 +1,7 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import {version} from 'typescript'; +import pkg from 'typescript'; import si from 'systeminformation'; -import TClient from 'src/client'; +import TClient from '../client.js'; import os from 'node:os'; export default { async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ @@ -15,7 +15,7 @@ export default { const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; }; - var DJSver = require('discord.js').version; + var DJSver = (await import('discord.js')).version; const cpu = await si.cpu(); const ram = await si.mem(); const osInfo = await si.osInfo(); @@ -25,11 +25,11 @@ export default { const columns = ['Command name', 'Count']; const includedCommands = client.commands.filter(x=>x.uses).sort((a,b)=>b.uses - a.uses); if (includedCommands.size == 0) return interaction.reply(`No commands have been used yet.\nUptime: **${client.formatTime(client.uptime as number, 3, {longNames: true, commas: true})}**`); - const nameLength = Math.max(...includedCommands.map(x=>x.default.data.name.length), columns[0].length) + 2; + const nameLength = Math.max(...includedCommands.map(x=>x.command.default.data.name.length), columns[0].length) + 2; const amountLength = Math.max(...includedCommands.map(x=>x.uses.toString().length), columns[1].length) + 1; const rows = [`${columns[0] + ' '.repeat(nameLength - columns[0].length)}|${' '.repeat(amountLength - columns[1].length) + columns[1]}\n`, '-'.repeat(nameLength) + '-'.repeat(amountLength) + '\n']; includedCommands.forEach(command=>{ - const name = command.default.data.name; + const name = command.command.default.data.name; const count = command.uses.toString(); rows.push(`${name + ' '.repeat(nameLength - name.length)}${' '.repeat(amountLength - count.length) + count}\n`); }); @@ -50,7 +50,7 @@ export default { } else embed.addFields({name: '\u200b', value: `\`\`\`\n${rows.join('')}\`\`\``}); embed.addFields( {name: '> __Dependencies__', value: [ - `**TypeScript:** ${version}`, + `**TypeScript:** ${pkg.version}`, `**NodeJS:** ${process.version}`, `**DiscordJS:** ${DJSver}`, `**Axios:** ${client.axios.VERSION}` @@ -64,7 +64,7 @@ export default { `**Uptime:**\nHost: ${client.formatTime((os.uptime()*1000), 2, {longNames: true, commas: true})}\nBot: ${client.formatTime(client.uptime as number, 2, {commas: true, longNames: true})}` ].join('\n')} ); - interaction.reply({embeds: [embed], fetchReply: true}).then((x)=>x.edit({embeds: [new client.embed(x.embeds[0].data).setFooter({text: `Load time: ${client.formatTime(x.createdTimestamp - interaction.createdTimestamp, 2, {longNames: true, commas: true})}`})]})) + interaction.reply({embeds: [embed], fetchReply: true}).then(x=>x.edit({embeds: [new client.embed(x.embeds[0].data).setFooter({text: `Load time: ${client.formatTime(x.createdTimestamp - interaction.createdTimestamp, 2, {longNames: true, commas: true})}`})]})) }, data: new SlashCommandBuilder()// Nice .setName('statistics') diff --git a/src/commands/suggest.ts b/src/commands/suggest.ts index dc5d7ac..aede0a0 100644 --- a/src/commands/suggest.ts +++ b/src/commands/suggest.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient,{WClient} from '../client'; +import TClient,{WClient} from '../client.js'; export default { async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ const replyInDM = interaction.options.getString('message'); diff --git a/src/commands/unpunish.ts b/src/commands/unpunish.ts index 7443078..0265838 100644 --- a/src/commands/unpunish.ts +++ b/src/commands/unpunish.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ if (!client.isStaff(interaction.member as Discord.GuildMember)) return client.youNeedRole(interaction, 'dcmod'); diff --git a/src/commands/warn.ts b/src/commands/warn.ts index 9bc58ae..93279e2 100644 --- a/src/commands/warn.ts +++ b/src/commands/warn.ts @@ -1,5 +1,5 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; export default { run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ client.punish(client, interaction, 'warn'); diff --git a/src/commands/whois.ts b/src/commands/whois.ts index a20d7d6..5a2e903 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -1,5 +1,5 @@ import Discord,{GuildMember, SlashCommandBuilder} from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; function convert(status?:Discord.ClientPresenceStatus){ if (status) return { diff --git a/src/config.json b/src/config.json index d86e79a..6c50fa7 100644 --- a/src/config.json +++ b/src/config.json @@ -20,9 +20,9 @@ }, "botPresence": { "activities": [ - {"name": "the audio", "url": "https://www.youtube.com/watch?v=HQnC1UHBvWA", "type": 1} + {"name": "the server", "url": "https://www.youtube.com/watch?v=1P17ct4e5OE", "type": 1} ], - "status": "idle" + "status": "online" }, "eval": { "allowed": true, diff --git a/src/events/guildBanAdd.ts b/src/events/guildBanAdd.ts index a55fc0f..fc1e4bd 100644 --- a/src/events/guildBanAdd.ts +++ b/src/events/guildBanAdd.ts @@ -1,5 +1,5 @@ import Discord, { AuditLogEvent } from 'discord.js'; -import TClient from '../client'; +import TClient from '../client.js'; export default { async run(client:TClient, member:Discord.GuildMember){ if (member.guild?.id != client.config.mainServer.id) return; diff --git a/src/events/guildBanRemove.ts b/src/events/guildBanRemove.ts index 457c48a..7c42866 100644 --- a/src/events/guildBanRemove.ts +++ b/src/events/guildBanRemove.ts @@ -1,5 +1,5 @@ import Discord, { AuditLogEvent } from 'discord.js'; -import TClient from '../client'; +import TClient from '../client.js'; export default { async run(client:TClient, member:Discord.GuildMember){ if (member.guild?.id != client.config.mainServer.id) return; diff --git a/src/events/guildMemberAdd.ts b/src/events/guildMemberAdd.ts index c21c3b3..b07bee5 100644 --- a/src/events/guildMemberAdd.ts +++ b/src/events/guildMemberAdd.ts @@ -1,5 +1,5 @@ import Discord from 'discord.js'; -import TClient from '../client'; +import TClient from '../client.js'; export default { async run(client:TClient, member:Discord.GuildMember){ if (member.partial || member.guild?.id != client.config.mainServer.id) return; diff --git a/src/events/guildMemberRemove.ts b/src/events/guildMemberRemove.ts index 27520c7..2838c6f 100644 --- a/src/events/guildMemberRemove.ts +++ b/src/events/guildMemberRemove.ts @@ -1,5 +1,5 @@ import Discord from 'discord.js'; -import TClient from '../client'; +import TClient from '../client.js'; export default { async run(client:TClient, member:Discord.GuildMember){ if (!client.config.botSwitches.logs) return; diff --git a/src/events/guildMemberUpdate.ts b/src/events/guildMemberUpdate.ts index d83c183..fb3b6e9 100644 --- a/src/events/guildMemberUpdate.ts +++ b/src/events/guildMemberUpdate.ts @@ -1,5 +1,5 @@ import Discord from 'discord.js'; -import TClient from '../client'; +import TClient from '../client.js'; export default { run(client:TClient, oldMember:Discord.GuildMember, newMember:Discord.GuildMember){ if (oldMember.guild.id != client.config.mainServer.id) return; diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index f1d4dd0..e852ce3 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -1,5 +1,5 @@ import Discord from 'discord.js'; -import TClient from '../client'; +import TClient from '../client.js'; export default { run(client:TClient, interaction:Discord.BaseInteraction){ if (!interaction.inGuild() || !interaction.inCachedGuild()) return; @@ -9,7 +9,7 @@ export default { if (!client.config.botSwitches.commands && !client.config.eval.whitelist.includes(interaction.user.id)) return interaction.reply({content: 'Bot is currently being run in development mode.', ephemeral: true}); if (commandFile){ try{ - commandFile.default.run(client, interaction); + commandFile.command.default.run(client, interaction); commandFile.uses ? commandFile.uses++ : commandFile.uses = 1; } catch (error){ console.log(`An error occurred while running command "${interaction.commandName} ${interaction.options.getSubcommand(false) ?? ''}"`, error, error.stack); diff --git a/src/events/inviteCreate.ts b/src/events/inviteCreate.ts index cfc6160..1e1ceda 100644 --- a/src/events/inviteCreate.ts +++ b/src/events/inviteCreate.ts @@ -1,5 +1,5 @@ import Discord from 'discord.js'; -import TClient from '../client'; +import TClient from '../client.js'; export default { async run(client:TClient, invite: Discord.Invite){ if (!invite.guild) return; diff --git a/src/events/inviteDelete.ts b/src/events/inviteDelete.ts index 9216ed7..f0c712b 100644 --- a/src/events/inviteDelete.ts +++ b/src/events/inviteDelete.ts @@ -1,5 +1,5 @@ import Discord from 'discord.js'; -import TClient from '../client'; +import TClient from '../client.js'; export default { run(client:TClient, invite: Discord.Invite){ client.invites.delete(invite.code) diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index e8e4c81..49239e9 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -1,8 +1,8 @@ -import Discord, { ChannelType } from 'discord.js'; -import TClient from '../client'; +import Discord from 'discord.js'; +import TClient from 'src/client'; export default { async run(client:TClient, message:Discord.Message){ - if (message.author.bot || message.channel.type === ChannelType.DM) return; + if (message.author.bot || message.channel.type === Discord.ChannelType.DM) return; const msgarr = message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n]/g, ' ').split(' '); let automodded: boolean; diff --git a/src/events/messageDelete.ts b/src/events/messageDelete.ts index 7a0b017..3c63e63 100644 --- a/src/events/messageDelete.ts +++ b/src/events/messageDelete.ts @@ -1,5 +1,5 @@ import Discord from 'discord.js'; -import TClient from '../client'; +import TClient from '../client.js'; export default { run(client:TClient, msg:Discord.Message){ if (!client.config.botSwitches.logs) return; diff --git a/src/events/messageDeleteBulk.ts b/src/events/messageDeleteBulk.ts index e84e5bd..8620485 100644 --- a/src/events/messageDeleteBulk.ts +++ b/src/events/messageDeleteBulk.ts @@ -1,5 +1,5 @@ import Discord from 'discord.js'; -import TClient from '../client'; +import TClient from '../client.js'; export default { run(client:TClient, messages:Discord.Collection>){ if (!client.config.botSwitches.logs) return; diff --git a/src/events/messageUpdate.ts b/src/events/messageUpdate.ts index ca8e44a..6c4f150 100644 --- a/src/events/messageUpdate.ts +++ b/src/events/messageUpdate.ts @@ -1,5 +1,5 @@ -import Discord, { ActionRowBuilder, ButtonBuilder } from 'discord.js'; -import TClient from '../client'; +import Discord from 'discord.js'; +import TClient from '../client.js'; export default { async run(client:TClient, oldMsg:Discord.Message, newMsg:Discord.Message){ if (!client.config.botSwitches.logs) return; @@ -8,6 +8,6 @@ export default { const msgarr = newMsg.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n]/g, ' ').split(' '); if (await client.bannedWords._content.findOne({_id:msgarr}) && (!client.isStaff(newMsg.member))) newMsg.delete(); if (newMsg.content === oldMsg.content) return; - (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds: [new client.embed().setColor(client.config.embedColor).setTimestamp().setAuthor({name: `Author: ${oldMsg.author.tag} (${oldMsg.author.id})`, iconURL: `${oldMsg.author.displayAvatarURL()}`}).setTitle('Message edited').setDescription(`<@${oldMsg.author.id}>\nOld content:\n\`\`\`\n${oldMsg.content.length < 1 ? '(Attachment)' : oldMsg.content}\n\`\`\`\nNew content:\n\`\`\`\n${newMsg.content}\`\`\`\nChannel: <#${oldMsg.channelId}>`)], components: [new ActionRowBuilder().addComponents(new ButtonBuilder().setStyle(5).setURL(`${oldMsg.url}`).setLabel('Jump to message'))]}); + (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds: [new client.embed().setColor(client.config.embedColor).setTimestamp().setAuthor({name: `Author: ${oldMsg.author.tag} (${oldMsg.author.id})`, iconURL: `${oldMsg.author.displayAvatarURL()}`}).setTitle('Message edited').setDescription(`<@${oldMsg.author.id}>\nOld content:\n\`\`\`\n${oldMsg.content.length < 1 ? '(Attachment)' : oldMsg.content}\n\`\`\`\nNew content:\n\`\`\`\n${newMsg.content}\`\`\`\nChannel: <#${oldMsg.channelId}>`)], components: [new Discord.ActionRowBuilder().addComponents(new Discord.ButtonBuilder().setStyle(5).setURL(`${oldMsg.url}`).setLabel('Jump to message'))]}); } } diff --git a/src/index.ts b/src/index.ts index d2bebe7..71da5ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import Discord from 'discord.js'; -import TClient from './client'; +import TClient from './client.js'; const client = new TClient; client.init(); import fs from 'node:fs'; @@ -78,10 +78,11 @@ setInterval(async()=>{ if (results[1].status == 204) embed.setImage('https://http.cat/204'); FScsg.fetchResult = `DagMP CSG failed with ${results[1].status + ' ' + results[1].statusText}`; embed.addFields({name: 'CSG Status', value: results[1].status + ' ' + results[1].statusText}) - } else FScsg.data = client.xjs.xml2js(results[1].data,{compact:true,spaces:2}).careerSavegame as FSCareerSavegame; + } else FScsg.data = (client.xjs.xml2js(results[1].data,{compact:true}) as any).careerSavegame as FSCareerSavegame; }).catch((error)=>console.log(error)) if (FSdss.fetchResult.length != 0){ error = true; + if (FSdss.data.slots === undefined) return; console.log(client.logTime(), FSdss.fetchResult); } if (FScsg.fetchResult.length != 0){ @@ -94,9 +95,9 @@ setInterval(async()=>{ return; } - const DB = JSON.parse(fs.readFileSync(__dirname + '/database/MPPlayerData.json', {encoding: 'utf8'})); + const DB = JSON.parse(fs.readFileSync('src/database/MPPlayerData.json', {encoding: 'utf8'})); DB.push(FSdss.data.slots.used) - fs.writeFileSync(__dirname + '/database/MPPlayerData.json', JSON.stringify(DB)) + fs.writeFileSync('src/database/MPPlayerData.json', JSON.stringify(DB)) // Number format function function formatNumber(number: any, digits: any, icon: any){ @@ -143,13 +144,13 @@ setInterval(async()=>{ }); const formattedDate = Math.floor((now - lrsStart)/1000/60/60/24); - const dailyMsgs = JSON.parse(fs.readFileSync(__dirname + '/database/dailyMsgs.json', {encoding: 'utf8'})) + const dailyMsgs = JSON.parse(fs.readFileSync('./src/database/dailyMsgs.json', {encoding: 'utf8'})) if (!dailyMsgs.some((x:Array)=>x[0] === formattedDate)){ let total = (await client.userLevels._content.find({})).reduce((a,b)=>a + b.messages, 0); // sum of all users const yesterday = dailyMsgs.find((x:Array)=>x[0] === formattedDate - 1); if (total < yesterday) total = yesterday // messages went down. dailyMsgs.push([formattedDate, total]); - fs.writeFileSync(__dirname + '/database/dailyMsgs.json', JSON.stringify(dailyMsgs)) + fs.writeFileSync('./src/database/dailyMsgs.json', JSON.stringify(dailyMsgs)) console.log(client.logTime(), `Pushed [${formattedDate}, ${total}] to dailyMsgs`); client.guilds.cache.get(client.config.mainServer.id).commands.fetch().then((commands)=>(client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send(`:pencil: Pushed \`[${formattedDate}, ${total}]\` to x.name == 'rank').id}>`)) } diff --git a/src/models/MPServer.ts b/src/models/MPServer.ts index bddc8aa..420a82f 100644 --- a/src/models/MPServer.ts +++ b/src/models/MPServer.ts @@ -1,4 +1,4 @@ -import TClient from 'src/client'; +import TClient from '../client.js'; import mongoose from 'mongoose'; const Schema = mongoose.model('mpserver', new mongoose.Schema({ diff --git a/src/models/bannedWords.ts b/src/models/bannedWords.ts index ea40529..2fdc26a 100644 --- a/src/models/bannedWords.ts +++ b/src/models/bannedWords.ts @@ -1,4 +1,4 @@ -import TClient from 'src/client'; +import TClient from '../client.js'; import mongoose from 'mongoose'; const Schema = mongoose.model('bannedWords', new mongoose.Schema({ diff --git a/src/models/bonkCount.ts b/src/models/bonkCount.ts index 4040df2..96d51ab 100644 --- a/src/models/bonkCount.ts +++ b/src/models/bonkCount.ts @@ -1,4 +1,4 @@ -import TClient from 'src/client'; +import TClient from '../client.js'; import mongoose from 'mongoose'; const Schema = mongoose.model('bonkCount', new mongoose.Schema({ diff --git a/src/models/punishments.ts b/src/models/punishments.ts index 480c66d..6c9242f 100644 --- a/src/models/punishments.ts +++ b/src/models/punishments.ts @@ -1,8 +1,8 @@ import Discord from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; import mongoose from 'mongoose'; import ms from 'ms'; -import {Punishment} from 'src/typings/interfaces'; +import {Punishment} from '../typings/interfaces.js'; const Schema = mongoose.model('punishments', new mongoose.Schema({ _id: {type: Number, required: true}, diff --git a/src/models/suggestion.ts b/src/models/suggestion.ts index 3898268..69fc929 100644 --- a/src/models/suggestion.ts +++ b/src/models/suggestion.ts @@ -1,4 +1,4 @@ -import TClient from 'src/client'; +import TClient from '../client.js'; import mongoose from 'mongoose'; const Schema = mongoose.model('suggestion', new mongoose.Schema({ diff --git a/src/models/userLevels.ts b/src/models/userLevels.ts index 5ebae20..0637209 100644 --- a/src/models/userLevels.ts +++ b/src/models/userLevels.ts @@ -1,5 +1,5 @@ import Discord from 'discord.js'; -import TClient from 'src/client'; +import TClient from '../client.js'; import mongoose from 'mongoose'; const Schema = mongoose.model('userLevels', new mongoose.Schema({ diff --git a/tsconfig.json b/tsconfig.json index e1bdec5..b212cb7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,18 +1,20 @@ { - "transpileOnly": true, - "compilerOptions": { - "esModuleInterop": true, - "resolveJsonModule": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "target": "ESNext", - "module": "NodeNext", - "baseUrl": "./", - "rootDir": "src/", - "outDir": "dist/", - "moduleResolution": "Node", - "typeRoots": [ "node_modules/@types", "./src/typings" ], - }, - "include": [ "node_modules/@types", "src/**/*" ], - "exclude": [ "dist", "node_modules" ], + "transpileOnly": true, + "compilerOptions": { + "skipLibCheck": true, + "esModuleInterop": true, + "resolveJsonModule": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "ES2022", + "module": "ESNext", + "baseUrl": "./", + "rootDir": "src/", + "outDir": "dist/", + "moduleResolution": "bundler", + "typeRoots": [ "node_modules/@types", "./src/typings" ], + }, + "include": [ "node_modules/@types", "src/" ], + "exclude": [ "node_modules", ".git", "src/config.json", "src/DB-Beta.config.json", "src/Toast-Testbot.config.json" ], } \ No newline at end of file