1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 04:10:59 -05:00

Compare commits

..

No commits in common. "1856c81782a744286bf8a7edfda000b1b0971f76" and "cf0ae319bb07aa08f97c20c7320681185100107a" have entirely different histories.

8 changed files with 29 additions and 178 deletions

3
.gitignore vendored
View File

@ -9,4 +9,5 @@
# Bot stuff # Bot stuff
dist/ dist/
src/database/ src/database/
src/*.json src/tokens.json
src/*.config.json

30
.pnp.cjs generated
View File

@ -33,11 +33,11 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@octokit/auth-token", "npm:4.0.0"],\ ["@octokit/auth-token", "npm:4.0.0"],\
["@octokit/rest", "npm:20.0.1"],\ ["@octokit/rest", "npm:20.0.1"],\
["@types/ms", "npm:0.7.31"],\ ["@types/ms", "npm:0.7.31"],\
["@types/node", "npm:20.5.0"],\ ["@types/node", "npm:20.4.10"],\
["axios", "npm:1.4.0"],\ ["axios", "npm:1.4.0"],\
["canvas", "npm:2.11.2"],\ ["canvas", "npm:2.11.2"],\
["discord-player", "virtual:20c353e2d6536e37339997f03975c6a660f4d296e664d291bd43620c6162cca8eb5ef90b0998dc9db75ff6862e5da587d0530bae26805f5fadc8f17aaa4ff794#npm:6.6.2"],\ ["discord-player", "virtual:20c353e2d6536e37339997f03975c6a660f4d296e664d291bd43620c6162cca8eb5ef90b0998dc9db75ff6862e5da587d0530bae26805f5fadc8f17aaa4ff794#npm:6.6.2"],\
["discord.js", "npm:14.13.0-dev.1691971783-188877c50.0"],\ ["discord.js", "npm:14.13.0-dev.1691841828-9ed1b59df.0"],\
["libsodium-wrappers", "npm:0.7.11"],\ ["libsodium-wrappers", "npm:0.7.11"],\
["moment", "npm:2.29.4"],\ ["moment", "npm:2.29.4"],\
["mongoose", "npm:7.4.3"],\ ["mongoose", "npm:7.4.3"],\
@ -513,19 +513,19 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
}]\ }]\
]],\ ]],\
["@types/node", [\ ["@types/node", [\
["npm:20.4.10", {\
"packageLocation": "./.yarn/cache/@types-node-npm-20.4.10-a66bd58ee3-02a1ca415d.zip/node_modules/@types/node/",\
"packageDependencies": [\
["@types/node", "npm:20.4.10"]\
],\
"linkType": "HARD"\
}],\
["npm:20.4.8", {\ ["npm:20.4.8", {\
"packageLocation": "./.yarn/cache/@types-node-npm-20.4.8-f8f2d8d349-86a3963c0c.zip/node_modules/@types/node/",\ "packageLocation": "./.yarn/cache/@types-node-npm-20.4.8-f8f2d8d349-86a3963c0c.zip/node_modules/@types/node/",\
"packageDependencies": [\ "packageDependencies": [\
["@types/node", "npm:20.4.8"]\ ["@types/node", "npm:20.4.8"]\
],\ ],\
"linkType": "HARD"\ "linkType": "HARD"\
}],\
["npm:20.5.0", {\
"packageLocation": "./.yarn/cache/@types-node-npm-20.5.0-ea170d5dd7-659bc5fc93.zip/node_modules/@types/node/",\
"packageDependencies": [\
["@types/node", "npm:20.5.0"]\
],\
"linkType": "HARD"\
}]\ }]\
]],\ ]],\
["@types/webidl-conversions", [\ ["@types/webidl-conversions", [\
@ -941,11 +941,11 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@octokit/auth-token", "npm:4.0.0"],\ ["@octokit/auth-token", "npm:4.0.0"],\
["@octokit/rest", "npm:20.0.1"],\ ["@octokit/rest", "npm:20.0.1"],\
["@types/ms", "npm:0.7.31"],\ ["@types/ms", "npm:0.7.31"],\
["@types/node", "npm:20.5.0"],\ ["@types/node", "npm:20.4.10"],\
["axios", "npm:1.4.0"],\ ["axios", "npm:1.4.0"],\
["canvas", "npm:2.11.2"],\ ["canvas", "npm:2.11.2"],\
["discord-player", "virtual:20c353e2d6536e37339997f03975c6a660f4d296e664d291bd43620c6162cca8eb5ef90b0998dc9db75ff6862e5da587d0530bae26805f5fadc8f17aaa4ff794#npm:6.6.2"],\ ["discord-player", "virtual:20c353e2d6536e37339997f03975c6a660f4d296e664d291bd43620c6162cca8eb5ef90b0998dc9db75ff6862e5da587d0530bae26805f5fadc8f17aaa4ff794#npm:6.6.2"],\
["discord.js", "npm:14.13.0-dev.1691971783-188877c50.0"],\ ["discord.js", "npm:14.13.0-dev.1691841828-9ed1b59df.0"],\
["libsodium-wrappers", "npm:0.7.11"],\ ["libsodium-wrappers", "npm:0.7.11"],\
["moment", "npm:2.29.4"],\ ["moment", "npm:2.29.4"],\
["mongoose", "npm:7.4.3"],\ ["mongoose", "npm:7.4.3"],\
@ -1076,7 +1076,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@types/discord-player__extractor", null],\ ["@types/discord-player__extractor", null],\
["@types/discord.js", null],\ ["@types/discord.js", null],\
["@types/youtube-sr", null],\ ["@types/youtube-sr", null],\
["discord.js", "npm:14.13.0-dev.1691971783-188877c50.0"],\ ["discord.js", "npm:14.13.0-dev.1691841828-9ed1b59df.0"],\
["libsodium-wrappers", "npm:0.7.11"],\ ["libsodium-wrappers", "npm:0.7.11"],\
["youtube-sr", "npm:4.3.4"]\ ["youtube-sr", "npm:4.3.4"]\
],\ ],\
@ -1092,10 +1092,10 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
}]\ }]\
]],\ ]],\
["discord.js", [\ ["discord.js", [\
["npm:14.13.0-dev.1691971783-188877c50.0", {\ ["npm:14.13.0-dev.1691841828-9ed1b59df.0", {\
"packageLocation": "./.yarn/cache/discord.js-npm-14.13.0-dev.1691971783-188877c50.0-96206ff672-3e03a228ec.zip/node_modules/discord.js/",\ "packageLocation": "./.yarn/cache/discord.js-npm-14.13.0-dev.1691841828-9ed1b59df.0-5205132e1c-c584c642a6.zip/node_modules/discord.js/",\
"packageDependencies": [\ "packageDependencies": [\
["discord.js", "npm:14.13.0-dev.1691971783-188877c50.0"],\ ["discord.js", "npm:14.13.0-dev.1691841828-9ed1b59df.0"],\
["@discordjs/builders", "npm:1.6.4"],\ ["@discordjs/builders", "npm:1.6.4"],\
["@discordjs/collection", "npm:1.5.2"],\ ["@discordjs/collection", "npm:1.5.2"],\
["@discordjs/formatters", "npm:0.3.1"],\ ["@discordjs/formatters", "npm:0.3.1"],\

View File

@ -48,6 +48,6 @@
}, },
"devDependencies": { "devDependencies": {
"@types/ms": "0.7.31", "@types/ms": "0.7.31",
"@types/node": "20.5.0" "@types/node": "20.4.10"
} }
} }

View File

@ -1,5 +1,5 @@
import Discord, {Client, WebhookClient, GatewayIntentBits, Partials} from 'discord.js'; import Discord, {Client, WebhookClient, GatewayIntentBits, Partials} from 'discord.js';
import {readFileSync, readdirSync} from 'node:fs'; import {readFileSync, readdirSync, promises} from 'node:fs';
import {exec} from 'node:child_process'; import {exec} from 'node:child_process';
import mongoose from 'mongoose'; import mongoose from 'mongoose';
import {formatTimeOpt, Tokens, Config, repeatedMessages, MPServerCache} from './typings/interfaces'; import {formatTimeOpt, Tokens, Config, repeatedMessages, MPServerCache} from './typings/interfaces';
@ -7,7 +7,6 @@ import bannedWords from './models/bannedWords.js';
import userLevels from './models/userLevels.js'; import userLevels from './models/userLevels.js';
import suggestion from './models/suggestion.js'; import suggestion from './models/suggestion.js';
import punishments from './models/punishments.js'; import punishments from './models/punishments.js';
import tags from './models/tagSystem.js';
import bonkCount from './models/bonkCount.js'; import bonkCount from './models/bonkCount.js';
import MPServer from './models/MPServer.js'; import MPServer from './models/MPServer.js';
import xjs from 'xml-js'; import xjs from 'xml-js';
@ -47,7 +46,6 @@ export default class TClient extends Client {
MPServer: MPServer; MPServer: MPServer;
MPServerCache: MPServerCache; MPServerCache: MPServerCache;
suggestion: suggestion; suggestion: suggestion;
tags: tags;
repeatedMessages: repeatedMessages; repeatedMessages: repeatedMessages;
statsGraph: number; statsGraph: number;
@ -87,7 +85,6 @@ export default class TClient extends Client {
this.MPServer = new MPServer(this); this.MPServer = new MPServer(this);
this.MPServerCache = {players: [], status: null, name: null} as MPServerCache; this.MPServerCache = {players: [], status: null, name: null} as MPServerCache;
this.suggestion = new suggestion(this); this.suggestion = new suggestion(this);
this.tags = new tags(this);
this.repeatedMessages = {}; this.repeatedMessages = {};
this.setMaxListeners(45); this.setMaxListeners(45);
this.statsGraph = -60; this.statsGraph = -60;

View File

@ -1,117 +0,0 @@
import Discord from 'discord.js';
import TClient from '../client.js';
export default {
async autocomplete(client: TClient, interaction: Discord.AutocompleteInteraction){
const array = (await client.tags?._content.find())?.map(x=>x._id).filter(c=>c.startsWith(interaction.options.getFocused()));
await interaction?.respond(array?.map(c=>({name: c, value: c})));
// If you question all those '?.', let me tell you: Discord.JS is fricking stupid and I am too stressed to find a solution for it.
},
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
if (interaction.options.getSubcommandGroup() === 'management' && !client.isStaff(interaction.member) && !client.config.whitelist.includes(interaction.member.id)) return client.youNeedRole(interaction, 'dcmod');
const tagData = async()=>await client.tags._content.findOne({_id: interaction.options.getString('name')});
const tagMeta = {
isEmbedTrue: async()=>(await tagData()).embedBool,
title: async()=>(await tagData())._id,
message: async()=>(await tagData()).message,
creatorName: async()=>(await client.users.fetch((await tagData()).user._id)).displayName
};
({
send: async()=>{
if (!await tagData()) return interaction.reply({content:'This tag is not available in the database.',ephemeral:true});
let targetField = '';
const targetMember = interaction.options.getMember('target_user');
if (targetMember) targetField = `*This tag is for <@${targetMember.id}>*`;
const embedTemplate = new client.embed().setColor(client.config.embedColor).setTitle(await tagMeta.title()).setDescription(await tagMeta.message()).setFooter({text: `Tag creator: ${await tagMeta.creatorName()}`});
const messageTemplate = [
targetField ? targetField : '',
`**${await tagMeta.title()}**`,
await tagMeta.message(),
'',
`Tag creator: **${await tagMeta.creatorName()}**`
].join('\n');
if (await tagMeta.isEmbedTrue()) return interaction.reply({content: targetField ? targetField : null, embeds: [embedTemplate], allowedMentions:{parse:['users']}});
else return interaction.reply({content: messageTemplate, allowedMentions:{parse:['users']}})
},
create: async()=>await client.tags._content.create({
_id: interaction.options.getString('name'),
message: interaction.options.getString('message').replaceAll(/\\n/g, '\n'),
embedBool: interaction.options.getBoolean('embed'),
user: {
_id: interaction.member.id,
name: interaction.user.username
}
})
.then(()=>interaction.reply('Tag is now created and available to use.'))
.catch(err=>interaction.reply(`There was an error while trying to create your tag:\n\`\`\`${err}\`\`\``)),
delete: async()=>await client.tags._content.findByIdAndDelete(interaction.options.getString('name')).then(()=>interaction.reply('Tag successfully deleted.')).catch(err=>interaction.reply(`Failed to delete the tag:\n\`\`\`${err}\`\`\``)),
edit: async()=>await client.tags._content.findByIdAndUpdate(interaction.options.getString('name'), {
$set: {
message: interaction.options.getString('new-message').replaceAll(/\\n/g, '\n'),
embedBool: interaction.options.getBoolean('embed')
}
})
.then(()=>interaction.reply('Tag successfully updated, enjoy!'))
.catch(err=>interaction.reply(`Tag couldn\'t be updated:\n\`\`\`${err}\`\`\``))
} as any)[interaction.options.getSubcommand() ?? interaction.options.getSubcommandGroup()]();
},
data: new Discord.SlashCommandBuilder()
.setName('tag')
.setDescription('Send user the resources/FAQ provided in the tag')
.addSubcommand(x=>x
.setName('send')
.setDescription('Send a resource tag')
.addStringOption(x=>x
.setName('name')
.setDescription('Name of an existing tag to send')
.setAutocomplete(true)
.setRequired(true))
.addUserOption(x=>x
.setName('target_user')
.setDescription('Directly mention the target with this tag')))
.addSubcommandGroup(x=>x
.setName('management')
.setDescription('Add a new tag or delete/edit your current tag')
.addSubcommand(x=>x
.setName('create')
.setDescription('Create a new tag')
.addStringOption(x=>x
.setName('name')
.setDescription('Name of your tag, must be within 3-25 characters')
.setMinLength(3)
.setMaxLength(25)
.setRequired(true))
.addStringOption(x=>x
.setName('message')
.setDescription('Message to be included in your tag; e.g, you\'re giving the user some instructions, newline: \\n')
.setMinLength(6)
.setMaxLength(2048)
.setRequired(true))
.addBooleanOption(x=>x
.setName('embed')
.setDescription('Toggle this option if you want your message to be inside the embed or not')
.setRequired(true)))
.addSubcommand(x=>x
.setName('delete')
.setDescription('Delete a tag')
.addStringOption(x=>x
.setName('name')
.setDescription('Name of the tag to be deleted')
.setAutocomplete(true)
.setRequired(true)))
.addSubcommand(x=>x
.setName('edit')
.setDescription('Edit an existing tag')
.addStringOption(x=>x
.setName('name')
.setDescription('Name of the tag to be edited')
.setAutocomplete(true)
.setRequired(true))
.addStringOption(x=>x
.setName('new-message')
.setDescription('Replace the current tag\'s message with a new one, newline: \\n')
.setRequired(true))
.addBooleanOption(x=>x
.setName('embed')
.setDescription('Toggle this option on an existing tag to be updated with embed or not')
.setRequired(true))))
}

View File

@ -1,29 +1,21 @@
import Discord from 'discord.js'; import Discord from 'discord.js';
import TClient from '../client.js'; import TClient from '../client.js';
export default { export default {
async run(client:TClient, interaction:Discord.BaseInteraction){ run(client:TClient, interaction:Discord.BaseInteraction){
if (!interaction.inGuild() || !interaction.inCachedGuild()) return; if (!interaction.inGuild() || !interaction.inCachedGuild()) return;
if (interaction.isChatInputCommand()){ if (interaction.isChatInputCommand()){
const commandFile = client.commands.get(interaction.commandName); const commandFile = client.commands.get(interaction.commandName);
console.log(client.logTime(), `${interaction.user.username} used /${interaction.commandName} ${interaction.options.getSubcommandGroup(false) ?? ''} ${interaction.options.getSubcommand(false) ?? ''} in #${interaction.channel.name}`); console.log(client.logTime(), `${interaction.user.username} used /${interaction.commandName} ${interaction.options.getSubcommand(false) ?? ''} in #${interaction.channel.name}`);
if (!client.config.botSwitches.commands && !client.config.whitelist.includes(interaction.user.id)) return interaction.reply({content: `I am currently operating in development mode.\nPlease notify <@${client.config.whitelist[0]}> if this is a mistake.`, ephemeral: true}); if (!client.config.botSwitches.commands && !client.config.whitelist.includes(interaction.user.id)) return interaction.reply({content: `I am currently operating in development mode.\nPlease notify <@${client.config.whitelist[0]}> if this is a mistake.`, ephemeral: true});
if (commandFile){ if (commandFile){
try{ try{
commandFile.command.default.run(client, interaction); commandFile.command.default.run(client, interaction);
commandFile.command.default.autocomplete ? commandFile.command.default.autocomplete(interaction) : undefined;
commandFile.uses ? commandFile.uses++ : commandFile.uses = 1; commandFile.uses ? commandFile.uses++ : commandFile.uses = 1;
} catch (error){ } catch (error){
console.log(`An error occurred while running command "${interaction.commandName} ${interaction.options.getSubcommand(false) ?? ''}"`, error, error.stack); console.log(`An error occurred while running command "${interaction.commandName} ${interaction.options.getSubcommand(false) ?? ''}"`, error, error.stack);
return interaction.reply('An error occurred while executing that command.'); return interaction.reply('An error occurred while executing that command.');
} }
} }
} else if (interaction.isAutocomplete()){
const AC = client.commands.get(interaction.commandName);
try {
await AC.command.default.autocomplete(client, interaction)
} catch (error){
return console.log('An error occurred while running autocomplete:\n', error)
}
} else if (interaction.isButton()){ } else if (interaction.isButton()){
if (interaction.customId.startsWith('reaction-') && client.config.botSwitches.buttonRoles){ if (interaction.customId.startsWith('reaction-') && client.config.botSwitches.buttonRoles){
const RoleID = interaction.customId.replace('reaction-',''); const RoleID = interaction.customId.replace('reaction-','');

View File

@ -1,22 +0,0 @@
import TClient from '../client.js';
import mongoose from 'mongoose';
const Schema = mongoose.model('tags', new mongoose.Schema({
_id: {type: String, required:true},
message: {type: String, required:true},
embedBool: {type: Boolean, required:true},
user: {required:true, type: new mongoose.Schema({
name: {type: String, required:true},
_id: {type: String, required:true}
}, {versionKey: false})}
}, {versionKey: false}));
export default class tags extends Schema {
client: TClient;
_content: typeof Schema;
constructor(client:TClient){
super();
this.client = client;
this._content = Schema;
}
}

View File

@ -386,10 +386,10 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@types/node@npm:20.5.0": "@types/node@npm:20.4.10":
version: 20.5.0 version: 20.4.10
resolution: "@types/node@npm:20.5.0" resolution: "@types/node@npm:20.4.10"
checksum: 659bc5fc93b5c02bd88ca4bfae4f6b9dc307d45884d1dd9d69df85819a9943cdc00cd3c87eec3048866df6a67f52297f74d170e47a44f61edb3e8f770d94e85e checksum: 02a1ca415d9cc91144c4250383aa0ef1e48241bd36067ed7d1b239d8bacc2a11139dd90e223e11ac289345eeae624cc5dcf73359e684bd2e5a6c31bdfbab4811
languageName: node languageName: node
linkType: hard linkType: hard
@ -757,7 +757,7 @@ __metadata:
"@octokit/auth-token": 4.0.0 "@octokit/auth-token": 4.0.0
"@octokit/rest": 20.0.1 "@octokit/rest": 20.0.1
"@types/ms": 0.7.31 "@types/ms": 0.7.31
"@types/node": 20.5.0 "@types/node": 20.4.10
axios: 1.4.0 axios: 1.4.0
canvas: 2.11.2 canvas: 2.11.2
discord-player: 6.6.2 discord-player: 6.6.2
@ -863,8 +863,8 @@ __metadata:
linkType: hard linkType: hard
"discord.js@npm:dev": "discord.js@npm:dev":
version: 14.13.0-dev.1691971783-188877c50.0 version: 14.13.0-dev.1691841828-9ed1b59df.0
resolution: "discord.js@npm:14.13.0-dev.1691971783-188877c50.0" resolution: "discord.js@npm:14.13.0-dev.1691841828-9ed1b59df.0"
dependencies: dependencies:
"@discordjs/builders": ^1.6.4 "@discordjs/builders": ^1.6.4
"@discordjs/collection": ^1.5.2 "@discordjs/collection": ^1.5.2
@ -880,7 +880,7 @@ __metadata:
tslib: ^2.6.1 tslib: ^2.6.1
undici: ^5.22.1 undici: ^5.22.1
ws: ^8.13.0 ws: ^8.13.0
checksum: 3e03a228ec2a87951d2fa92723325806e8a850ff3c8377d2a3ebc064f5bf04fb5bfe06b58e8b02ffd466631e7f61f044db4933af22d29a8a040c1067e89c63bd checksum: c584c642a6ddb971d5059b44a01ec3b184fe4280e62d5b14261389514ddf897d3398f84bb7fd6eeeb6115c4eaf45c2fce0077182c5f9bc073f516310281b9b07
languageName: node languageName: node
linkType: hard linkType: hard