mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-12-27 04:15:38 -05:00
my tired self cant take it for tonite (Push part 4)
This commit is contained in:
parent
7d5def0cfc
commit
b86e7d01c4
5
src/Sharding.ts
Normal file
5
src/Sharding.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import {token_main} from './tokens.json'
|
||||||
|
import { ShardingManager } from "discord.js";
|
||||||
|
const sharder = new ShardingManager('./index.ts',{token: token_main, totalShards: 1, mode: 'worker'})
|
||||||
|
sharder.on('shardCreate',async(shard)=>{console.log(`Shard ${shard.id} launched`)})
|
||||||
|
sharder.spawn();
|
125
src/client.ts
125
src/client.ts
@ -7,6 +7,16 @@ interface formatTimeOpt {
|
|||||||
longNames: boolean,
|
longNames: boolean,
|
||||||
commas: boolean
|
commas: boolean
|
||||||
}
|
}
|
||||||
|
interface CommandInfoOpt {
|
||||||
|
insertNewline: boolean,
|
||||||
|
parts: string[], //idfk
|
||||||
|
titles: string[]
|
||||||
|
}
|
||||||
|
interface punOpt {
|
||||||
|
time?: string,
|
||||||
|
reason?: string;
|
||||||
|
interaction?: any
|
||||||
|
}
|
||||||
interface Punishment {
|
interface Punishment {
|
||||||
id: number;
|
id: number;
|
||||||
type: string;
|
type: string;
|
||||||
@ -19,25 +29,33 @@ interface Punishment {
|
|||||||
cancels?: number;
|
cancels?: number;
|
||||||
duration?: number;
|
duration?: number;
|
||||||
}
|
}
|
||||||
interface CommandInfoOpt {
|
interface punData {
|
||||||
insertNewline: boolean,
|
id: number;
|
||||||
parts: string[], //idfk
|
type: string;
|
||||||
titles: string[]
|
member: string;
|
||||||
|
moderator: string;
|
||||||
|
expired?: boolean;
|
||||||
|
time?: number;
|
||||||
|
reason: string;
|
||||||
|
endTime?: number;
|
||||||
|
cancels?: number;
|
||||||
|
duration?: number;
|
||||||
}
|
}
|
||||||
import Discord, { Client, GatewayIntentBits, Partials } from 'discord.js';
|
import Discord, { Client, GatewayIntentBits, Partials } from 'discord.js';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import { Database } from './database';
|
import { Database } from './database';
|
||||||
import timeNames from './timeNames';
|
import timeNames from './timeNames';
|
||||||
export class TClient extends Client {
|
export class TClient extends Client {
|
||||||
invites: any;
|
invites: Map<any, any>;
|
||||||
commands: any;
|
commands: Discord.Collection<string, any>;
|
||||||
|
registry: Array<Discord.ApplicationCommandDataResolvable>;
|
||||||
config: any;
|
config: any;
|
||||||
tokens: any;
|
tokens: any;
|
||||||
categoryNames: any;
|
categoryNames: any;
|
||||||
commandPages: any;
|
commandPages: any;
|
||||||
helpDefaultOptions: any;
|
helpDefaultOptions: any;
|
||||||
YTCache: any;
|
YTCache: any;
|
||||||
embed: any;
|
embed: typeof Discord.EmbedBuilder;
|
||||||
collection: any;
|
collection: any;
|
||||||
messageCollector: any;
|
messageCollector: any;
|
||||||
attachmentBuilder: any;
|
attachmentBuilder: any;
|
||||||
@ -45,12 +63,11 @@ export class TClient extends Client {
|
|||||||
xjs: any;
|
xjs: any;
|
||||||
axios: any;
|
axios: any;
|
||||||
memberCount_LastGuildFetchTimestamp: any;
|
memberCount_LastGuildFetchTimestamp: any;
|
||||||
userLevels: Database;
|
userLevels: userLevels;
|
||||||
punishments: Database;
|
punishments: punishments;
|
||||||
bonkCount: Database;
|
bonkCount: bonkCount;
|
||||||
bannedWords: Database;
|
bannedWords: bannedWords;
|
||||||
repeatedMessages: any;
|
repeatedMessages: any;
|
||||||
setMaxListeners: any;
|
|
||||||
|
|
||||||
constructor(){
|
constructor(){
|
||||||
super({
|
super({
|
||||||
@ -69,6 +86,7 @@ export class TClient extends Client {
|
|||||||
})
|
})
|
||||||
this.invites = new Map();
|
this.invites = new Map();
|
||||||
this.commands = new Discord.Collection();
|
this.commands = new Discord.Collection();
|
||||||
|
this.registry = [];
|
||||||
this.config = require('./config.json');
|
this.config = require('./config.json');
|
||||||
this.tokens = require('./tokens.json');
|
this.tokens = require('./tokens.json');
|
||||||
this.categoryNames;
|
this.categoryNames;
|
||||||
@ -89,10 +107,10 @@ export class TClient extends Client {
|
|||||||
this.xjs = import('xml-js');
|
this.xjs = import('xml-js');
|
||||||
this.axios = import('axios');
|
this.axios = import('axios');
|
||||||
this.memberCount_LastGuildFetchTimestamp = 0;
|
this.memberCount_LastGuildFetchTimestamp = 0;
|
||||||
this.userLevels = new Database('./database/userLevels.json', 'object');
|
this.userLevels(this);
|
||||||
this.bonkCount = new Database('./database/bonkCount.json', 'object');
|
this.bonkCount(this);
|
||||||
this.punishments = new Database('./database/punishments.json', 'array');
|
this.punishments(this);
|
||||||
this.bannedWords = new Database('./database/bannedWords.json', 'array');
|
this.bannedWords(this);
|
||||||
this.repeatedMessages = {};
|
this.repeatedMessages = {};
|
||||||
this.setMaxListeners(80)
|
this.setMaxListeners(80)
|
||||||
}
|
}
|
||||||
@ -102,6 +120,12 @@ export class TClient extends Client {
|
|||||||
this.bannedWords.initLoad();
|
this.bannedWords.initLoad();
|
||||||
this.bonkCount.initLoad();
|
this.bonkCount.initLoad();
|
||||||
this.userLevels.initLoad().intervalSave(15000).disableSaveNotifs();
|
this.userLevels.initLoad().intervalSave(15000).disableSaveNotifs();
|
||||||
|
const commandFiles = fs.readdirSync('./commands/slash').filter(file=>file.endsWith('.ts'));
|
||||||
|
for (const file of commandFiles){
|
||||||
|
const command = require(`./commands/slash/${file}`);
|
||||||
|
this.commands.set(command.data.name, command)
|
||||||
|
this.registry.push(command.data.toJSON())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
commandInfo(client: TClient, command: any, options?: CommandInfoOpt){
|
commandInfo(client: TClient, command: any, options?: CommandInfoOpt){
|
||||||
let text = ':small_orange_diamond: ';
|
let text = ':small_orange_diamond: ';
|
||||||
@ -369,3 +393,72 @@ export class TClient extends Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//class
|
||||||
|
class bannedWords extends Database {
|
||||||
|
client: TClient;
|
||||||
|
constructor(client: TClient){
|
||||||
|
super('./database/bannedWords.json', 'array');
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class punishments extends Database {
|
||||||
|
client: TClient;
|
||||||
|
constructor(client: TClient){
|
||||||
|
super('./database/punishments.json', 'array');
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
createId(){
|
||||||
|
return Math.max(...this.client.punishments._content.map((x:punData)=>x.id), 0)+1;
|
||||||
|
}
|
||||||
|
async addPunishment(type: string, member: any, options: punOpt, moderator: string){
|
||||||
|
const now = Date.now();
|
||||||
|
const {time, reason, interaction}=options;
|
||||||
|
const ms = require('ms');
|
||||||
|
let timeInMillis;
|
||||||
|
if(type !== 'mute'){
|
||||||
|
timeInMillis = time ? ms(time) : null;
|
||||||
|
} else {
|
||||||
|
timeInMillis = time ? ms(time) : 2419200000;
|
||||||
|
}
|
||||||
|
switch (type) {
|
||||||
|
case 'ban':
|
||||||
|
const banData: punData={type, id: this.createId(), member: member.id, moderator, time: now};
|
||||||
|
const dm1: Discord.Message = await member.send(`You've been banned from ${interaction.guild.name} ${timeInMillis ? `for ${this.client.formatTime(timeInMillis, 4, {longNames: true, commas: true})} (${timeInMillis}ms)` : 'forever'} for reason \`${reason || 'Unspecified'}\` (Case #${banData.id})`).catch(()=>{return interaction.channel.send('Failed to DM user.')})
|
||||||
|
const banResult = await interaction.guild.bans.create(member.id, {reason: `${reason || 'Unspecified'} | Case #${banData.id}`}).catch((err:Error)=>err.message);
|
||||||
|
case 'softban':
|
||||||
|
case 'kick':
|
||||||
|
case 'warn':
|
||||||
|
case 'mute':
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class userLevels extends Database {
|
||||||
|
client: TClient;
|
||||||
|
constructor(client: TClient){
|
||||||
|
super('./database/userLevels.json', 'object');
|
||||||
|
this.client = client
|
||||||
|
}
|
||||||
|
incrementUser(userid: string){
|
||||||
|
const data = this._content[userid];
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
this._content[userid].messages++;
|
||||||
|
if (data.messages >= this.algorithm(data.level+2)){
|
||||||
|
while (data.messages > this.algorithm(data.level+1)){
|
||||||
|
this._content[userid].level++;
|
||||||
|
console.log(`${userid} EXTENDED LEVELUP ${this._content[userid].level}`)
|
||||||
|
}
|
||||||
|
} else if (data.messages >= this.algorithm(data.level+1)){
|
||||||
|
this._content[userid].level++;
|
||||||
|
(this.client.channels.resolve(this.client.config.mainServer.channels.thismeanswar) as Discord.TextChannel).send({content: `<@${userid}> has reached level **${data.level}**. GG!`})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this._content[userid] = {messages: 1, level: 0};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
algorithm(level: number){
|
||||||
|
return level*level*15;
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,7 @@ export default {
|
|||||||
output = await eval(code)
|
output = await eval(code)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
error = true
|
error = true
|
||||||
const embed = new client.embed().setColor('ff0000').setTitle('__Eval__').addFields(
|
const embed = new client.embed().setColor('#ff0000').setTitle('__Eval__').addFields(
|
||||||
{name: 'Input', value: `\`\`\`js\n${code.slice(0, 1010)}\n\`\`\``},
|
{name: 'Input', value: `\`\`\`js\n${code.slice(0, 1010)}\n\`\`\``},
|
||||||
{name: 'Output', value: `\`\`\`\n${err}\`\`\``}
|
{name: 'Output', value: `\`\`\`\n${err}\`\`\``}
|
||||||
)
|
)
|
||||||
@ -39,11 +39,6 @@ export default {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (error) return;
|
if (error) return;
|
||||||
if (typeof output !== 'string') {
|
|
||||||
output = 'js\n'+util.formatWithOptions({depth: 1}, '%O', output)
|
|
||||||
} else {
|
|
||||||
output = '\n' + String(output);
|
|
||||||
}
|
|
||||||
if (typeof output == 'object') {
|
if (typeof output == 'object') {
|
||||||
output = 'js\n'+util.formatWithOptions({depth: 1}, '%O', output)
|
output = 'js\n'+util.formatWithOptions({depth: 1}, '%O', output)
|
||||||
} else {
|
} else {
|
||||||
|
60
src/commands/slash/eval.ts
Normal file
60
src/commands/slash/eval.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import Discord,{SlashCommandBuilder} from 'discord.js';
|
||||||
|
import { TClient } from 'src/client';
|
||||||
|
import * as util from 'node:util';
|
||||||
|
const removeUsername = (text: string)=>{
|
||||||
|
let matchesLeft = true;
|
||||||
|
const array = text.split('\/');
|
||||||
|
while (matchesLeft){
|
||||||
|
let usersIndex = array.indexOf('home');
|
||||||
|
if (usersIndex<1) matchesLeft = false;
|
||||||
|
else {
|
||||||
|
let usernameIndex = usersIndex+1;
|
||||||
|
if(array[usernameIndex].length == 0) usernameIndex += 1;
|
||||||
|
array[usernameIndex] = '*'.repeat(array[usernameIndex].length);
|
||||||
|
array[usersIndex] = 'ho\u200bme';
|
||||||
|
}
|
||||||
|
} return array.join('\/');
|
||||||
|
};
|
||||||
|
export default {
|
||||||
|
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>) {
|
||||||
|
if (!client.config.eval.allowed) return interaction.reply({content: 'Eval is disabled.', ephemeral: true});
|
||||||
|
if (!client.config.eval.whitelist.includes(interaction.user.id)) return interaction.reply({content: 'You\'re not allowed to use this command.', ephemeral: true});
|
||||||
|
const code = interaction.options.getString('code') as string;
|
||||||
|
let output = 'error';
|
||||||
|
let error = false;
|
||||||
|
try {
|
||||||
|
output = await eval(code);
|
||||||
|
} catch (err: any) {
|
||||||
|
error = true
|
||||||
|
const embed = new client.embed().setColor('#ff0000').setTitle('__Eval__').addFields(
|
||||||
|
{name: 'Input', value: `\`\`\`js\n${code.slice(0, 1010)}\n\`\`\``},
|
||||||
|
{name: 'Output', value: `\`\`\`\n${err}\`\`\``}
|
||||||
|
)
|
||||||
|
interaction.reply({embeds: [embed]}).catch(()=>(interaction.channel as Discord.TextChannel).send({embeds: [embed]})).then(errorEmbedMessage=>{
|
||||||
|
const filter = (x:any)=>x.content === 'stack' && x.author.id === interaction.user.id
|
||||||
|
const messagecollector = (interaction.channel as Discord.TextChannel).createMessageCollector({filter, max: 1, time: 60000});
|
||||||
|
messagecollector.on('collect', collected=>{
|
||||||
|
collected.reply({content: `\`\`\`\n${removeUsername(err.stack)}\n\`\`\``, allowedMentions: {repliedUser: false}});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (error) return;
|
||||||
|
if (typeof output == 'object') {
|
||||||
|
output = 'js\n'+util.formatWithOptions({depth: 1}, '%O', output)
|
||||||
|
} else {
|
||||||
|
output = '\n' + String(output);
|
||||||
|
}
|
||||||
|
[client.tokens.token_main,client.tokens.token_beta,client.tokens.token_toast,client.tokens.token_tae].forEach((x)=>{
|
||||||
|
const regexp = new RegExp(x as string,'g');
|
||||||
|
output = output.replace(regexp, 'TOKEN_LEAK');
|
||||||
|
})
|
||||||
|
const embed = new client.embed().setColor(client.config.embedColor).setTitle('__Eval__').addFields(
|
||||||
|
{name: 'Input', value: `\`\`\`js\n${code.slice(0,1010)}\n\`\`\``},
|
||||||
|
{name: 'Output', value: `\`\`\`${removeUsername(output).slice(0,1016)}\n\`\`\``}
|
||||||
|
);
|
||||||
|
interaction.reply({embeds: [embed]}).catch(()=>(interaction.channel as Discord.TextChannel).send({embeds: [embed]}))
|
||||||
|
},
|
||||||
|
name: 'eval',
|
||||||
|
description: 'Run code for debugging purposes',
|
||||||
|
category: 'bot'
|
||||||
|
}
|
@ -7,6 +7,7 @@
|
|||||||
"embedColorBCA": "#ff69b4",
|
"embedColorBCA": "#ff69b4",
|
||||||
"LRSstart": 1661236321433,
|
"LRSstart": 1661236321433,
|
||||||
"botSwitches": {
|
"botSwitches": {
|
||||||
|
"registerCommands": false,
|
||||||
"commands": false,
|
"commands": false,
|
||||||
"logs": false,
|
"logs": false,
|
||||||
"automod": false,
|
"automod": false,
|
||||||
@ -47,6 +48,7 @@
|
|||||||
"console": "904192878140608563",
|
"console": "904192878140608563",
|
||||||
"errors": "904192878140608563",
|
"errors": "904192878140608563",
|
||||||
"bot_status": "904192878140608563",
|
"bot_status": "904192878140608563",
|
||||||
|
"thismeanswar": "904192878140608563",
|
||||||
"logs": "904192878140608563",
|
"logs": "904192878140608563",
|
||||||
"welcome": "904192878140608563",
|
"welcome": "904192878140608563",
|
||||||
"botcommands": "904192878140608563"
|
"botcommands": "904192878140608563"
|
||||||
|
@ -11,6 +11,7 @@ client.on('ready', async()=>{
|
|||||||
client.user.setPresence({activities: [{ name: 'Running under TS', type: 0 }], status: 'online'});
|
client.user.setPresence({activities: [{ name: 'Running under TS', type: 0 }], status: 'online'});
|
||||||
// Playing: 0, Streaming (Requires YT/Twitch URL to work): 1, Listening to: 2, Watching: 3, Competing in: 5
|
// Playing: 0, Streaming (Requires YT/Twitch URL to work): 1, Listening to: 2, Watching: 3, Competing in: 5
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
if (client.config.botSwitches.registerCommands) (client.guilds.cache.get(client.config.mainServer.id) as Discord.Guild).commands.set(client.registry).catch((e)=>{console.log(`Couldn't register slash commands: ${e}`)})
|
||||||
setInterval(()=>{
|
setInterval(()=>{
|
||||||
const guild = client.guilds.cache.get(client.config.mainServer.id) as Discord.Guild;
|
const guild = client.guilds.cache.get(client.config.mainServer.id) as Discord.Guild;
|
||||||
guild.invites.fetch().then((invs)=>{
|
guild.invites.fetch().then((invs)=>{
|
||||||
@ -51,7 +52,6 @@ for (const file of commandFiles){
|
|||||||
const command = require(`./commands/${file}`);
|
const command = require(`./commands/${file}`);
|
||||||
client.commands.set(command.name, command)
|
client.commands.set(command.name, command)
|
||||||
}
|
}
|
||||||
// Slash command handler todo
|
|
||||||
|
|
||||||
// Daggerwin MP loop
|
// Daggerwin MP loop
|
||||||
setInterval(async()=>{
|
setInterval(async()=>{
|
||||||
|
Loading…
Reference in New Issue
Block a user