1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-12-27 04:15:38 -05:00

Stupid GitHub formatting...

This commit is contained in:
AnxietyisReal 2023-03-05 21:04:10 +11:00
parent f0045d5980
commit 1fae7257b6
37 changed files with 1659 additions and 1709 deletions

View File

@ -1,2 +1,3 @@
# Daggerbot-TS
TypeScript-based Daggerbot converted from JavaScript at [SpaceManBuzz/DaggerBot-](https://github.com/SpaceManBuzz/DaggerBot-)
![https://discord.gg/4SnUAFu](https://cdn.discordapp.com/attachments/1015195575693627442/1081877631068295178/DaggerwinServerBanner2023.gif)
# Daggerbot-TS Description
This is 1st generation bot that is a TypeScript-based Daggerbot converted from JavaScript at (now archived and privated) ~~[SpaceManBuzz/DaggerBot-](https://github.com/SpaceManBuzz/DaggerBot-)~~

View File

@ -53,7 +53,7 @@ export default class TClient extends Client {
super({
intents: [
GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildBans, GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildModeration, GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildPresences, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages
],
partials: [
@ -91,6 +91,7 @@ export default class TClient extends Client {
this.statsGraph = -60;
}
async init(){
console.time('Startup');
mongoose.set('strictQuery', true);
await mongoose.connect(this.tokens.mongodb_uri, {
replicaSet: 'toastyy',
@ -123,9 +124,7 @@ export default class TClient extends Client {
achievedAccuracy++;
text += fullTimelengths + (options?.longNames ? (' '+timeName.name+(fullTimelengths === 1 ? '' : 's')) : timeName.name.slice(0, timeName.name === 'month' ? 2 : 1)) + (options?.commas ? ', ' : ' ');
integer -= fullTimelengths*timeName.length;
} else {
break;
}
} else break;
}
if (text.length == 0) text = integer + (options?.longNames ? ' milliseconds' : 'ms') + (options?.commas ? ', ' : '');
if (options?.commas){
@ -137,24 +136,19 @@ export default class TClient extends Client {
}
} return text.trim();
}
isStaff(guildMember: Discord.GuildMember){
return this.config.mainServer.staffRoles.map((x: string)=>this.config.mainServer.roles[x]).some((x: string)=>guildMember.roles.cache.has(x))
}
youNeedRole(interaction: Discord.CommandInteraction, role:string){
return interaction.reply(`This command is restricted to <@&${this.config.mainServer.roles[role]}>`)
}
logTime(){
return `[${this.moment().format('DD/MM/YY HH:mm:ss')}]`
}
isStaff = (guildMember:Discord.GuildMember)=>this.config.mainServer.staffRoles.map((x: string)=>this.config.mainServer.roles[x]).some((x: string)=>guildMember.roles.cache.has(x));
youNeedRole = (interaction:Discord.CommandInteraction, role:string)=>interaction.reply(`This command is restricted to <@&${this.config.mainServer.roles[role]}>`);
logTime = ()=>`[${this.moment().format('DD/MM/YY HH:mm:ss')}]`;
alignText(text: string, length: number, alignment: string, emptyChar = ' '){
if (alignment == 'right'){
text = emptyChar.repeat(length - text.length)+text;
} else if (alignment == 'middle'){
if (alignment == 'right') text = emptyChar.repeat(length - text.length)+text;
else if (alignment == 'middle'){
const emptyCharsPerSide = (length - text.length)/2;
text = emptyChar.repeat(Math.floor(emptyCharsPerSide))+text+emptyChar.repeat(Math.floor(emptyCharsPerSide));
} else {
text = text + emptyChar.repeat(length - text.length);
} return text;
} else text = text + emptyChar.repeat(length - text.length);
return text;
}
async punish(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>, type: string){
if (!client.isStaff(interaction.member as Discord.GuildMember)) return client.youNeedRole(interaction, "dcmod");
@ -176,9 +170,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, spaces: 2}))
} catch(err){
error = true;
console.log(this.logTime(), `${YTChannelName} YT fail`)
@ -196,5 +188,12 @@ export default class TClient extends Client {
}
}
export class WClient extends WebhookClient {tokens: Tokens; constructor(){super({url: tokens.webhook_url})}}
export class WClient extends WebhookClient {
tokens: Tokens;
constructor(){
super({
url: tokens.webhook_url
})
}
}
// hi tae, ik you went to look for secret hello msgs in here too.

View File

@ -1,7 +1,7 @@
import Discord,{SlashCommandBuilder} from 'discord.js';
import TClient from 'src/client';
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
client.punish(client, interaction, 'ban');
},
data: new SlashCommandBuilder()

View File

@ -21,11 +21,11 @@ export default {
},
data: new SlashCommandBuilder()
.setName('bannedwords')
.setDescription('description placeholder')
/*.addSubcommand((opt)=>opt
.setDescription('description placeholder')/*
.addSubcommand((opt)=>opt
.setName('view')
.setDescription('View the list of currently banned words.'))
*/.addSubcommand((opt)=>opt
.setDescription('View the list of currently banned words.'))*/
.addSubcommand((opt)=>opt
.setName('add')
.setDescription('What word do you want to add?')
.addStringOption((optt)=>optt

View File

@ -1,7 +1,7 @@
import Discord,{SlashCommandBuilder} from "discord.js";
import TClient from 'src/client';
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
if (!client.isStaff(interaction.member)) return client.youNeedRole(interaction, 'dcmod');
const caseId = interaction.options.getInteger('id');
({

View File

@ -1,7 +1,7 @@
import Discord,{SlashCommandBuilder} from 'discord.js';
import TClient from 'src/client';
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
interaction.reply({embeds: [new client.embed().setColor(client.config.embedColor).setTitle('Daggerbot contributors').setDescription([
'**Thanks to those below that contributed to the bot!**',
'Toast <@190407856527376384>',

View File

@ -20,7 +20,7 @@ const removeUsername = (text: string)=>{
} return array.join('\\');
};
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>) {
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>) {
if (!client.config.eval.whitelist.includes(interaction.user.id)) return client.youNeedRole(interaction, 'bottech');
({
eval: async()=>{
@ -45,11 +45,9 @@ export default {
});
}
if (error) return;
if (typeof output == 'object') {
output = 'js\n'+util.formatWithOptions({depth: 1}, '%O', output)
} else {
output = '\n' + String(output);
}
if (typeof output == 'object') output = 'js\n'+util.formatWithOptions({depth: 1}, '%O', output)
else output = '\n' + String(output);
[client.tokens.main,client.tokens.beta,client.tokens.toast,client.tokens.tae,client.tokens.webhook_url,client.tokens.webhook_url_test,client.tokens.mongodb_uri,client.tokens.mongodb_uri_dev].forEach((x)=>{
const regexp = new RegExp(x as string,'g');
output = output.replace(regexp, ':noblank: No token?');
@ -67,13 +65,9 @@ export default {
const fetchCommitAuthor = await octokit.repos.getCommit(githubRepo).then(x=>x.data.commit.author.name).catch(err=>{console.log(err); interaction.reply({content: 'Placeholder error for `fetchCommitAuthor`', ephemeral: true})});
const clarkson = await interaction.reply({content: 'Pulling from repository...', fetchReply: true});
exec('git pull',(err:Error,stdout)=>{
if (err){
clarkson.edit(`\`\`\`${removeUsername(err.message)}\`\`\``)
} else if (stdout.includes('Already up to date')){
clarkson.edit('Bot is already up to date with the repository, did you forgor to push the changes? :skull:')
} else {
setTimeout(()=>{clarkson.edit(`Commit: **${fetchCommitMsg}**\nCommit author: **${fetchCommitAuthor}**\n\nUptime before restarting: **${client.formatTime(client.uptime as number, 3, {commas: true, longNames: true})}**`).then(()=>exec('pm2 restart Daggerbot'))},650)
}
if (err) clarkson.edit(`\`\`\`${removeUsername(err.message)}\`\`\``)
else if (stdout.includes('Already up to date')) clarkson.edit('Bot is already up to date with the repository, did you forgor to push the changes? :skull:')
else setTimeout(()=>clarkson.edit(`Commit: **${fetchCommitMsg}**\nCommit author: **${fetchCommitAuthor}**\n\nUptime before restarting: **${client.formatTime(client.uptime as number, 3, {commas: true, longNames: true})}**`).then(()=>exec('pm2 restart Daggerbot')),650)
});
},
presence: ()=>{
@ -112,9 +106,7 @@ export default {
interaction.deferReply();
(client.channels.resolve(client.config.mainServer.channels.console) as Discord.TextChannel).send({content: `Uploaded the current console dump as of <t:${Math.round(Date.now()/1000)}:R>`, files: [`${process.env.pm2_home}/logs/Daggerbot-out-0.log`, `${process.env.pm2_home}/logs/Daggerbot-error-0.log`]}).then(()=>interaction.editReply('It has been uploaded to dev server.')).catch((e:Error)=>interaction.editReply(`\`${e.message}\``))
},
restart: ()=>{
interaction.reply(`Uptime before restarting: **${client.formatTime(client.uptime as number, 3, {commas: true, longNames: true})}**`).then(()=>exec('pm2 restart Daggerbot'))
}
restart: ()=>interaction.reply(`Uptime before restarting: **${client.formatTime(client.uptime as number, 3, {commas: true, longNames: true})}**`).then(()=>exec('pm2 restart Daggerbot'))
} as any)[interaction.options.getSubcommand()]();
},
data: new SlashCommandBuilder()

View File

@ -1,7 +1,7 @@
import Discord,{SlashCommandBuilder} from 'discord.js';
import TClient from 'src/client';
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
({
srp: ()=>interaction.reply('Ballyspring is the map that is used in Survival Roleplay S4.'),
dlskin: ()=>interaction.reply({embeds: [new client.embed().setColor(client.config.embedColor).setTitle('Daggerwin Logistics hex code').setDescription('The main color will be Onyx (`#353839`) with red bumpers.').setImage('https://cdn.discordapp.com/attachments/801965516947324969/806871878736019456/image0.png')]}),

View File

@ -1,7 +1,7 @@
import Discord,{SlashCommandBuilder} from 'discord.js';
import TClient from 'src/client';
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
client.punish(client, interaction, 'kick');
},
data: new SlashCommandBuilder()

View File

@ -24,12 +24,11 @@ async function MPdata(client:TClient, interaction:Discord.ChatInputCommandIntera
embed.setColor(client.config.embedColorRed);
console.log(client.logTime(), 'DagMP failed to fetch, host didn\'t respond in time.');
return interaction.reply('Server didn\'t respond in time.');
}
return FSserver
} return FSserver
}
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
if (interaction.channelId == '468835769092669461' && !client.isStaff(interaction.member) && ['status', 'players'].includes(interaction.options.getSubcommand())) {
interaction.reply(`Please use <#739084625862852715> for \`/mp status/players\` commands to prevent clutter in this channel.`).then((msg)=>{setTimeout(()=>{interaction.deleteReply()}, 6000)});
return;
@ -41,14 +40,13 @@ export default {
if (!FSserver0?.data) return console.log('FSserver0 failed - status');
try {
if (FSserver0.data.server.name.length > 1){
embed0.setTitle('Status/Details').setColor(client.config.embedColor).addFields(
interaction.reply({embeds: [embed0.setTitle('Status/Details').setColor(client.config.embedColor).addFields(
{name: 'Server name', value: `${FSserver0?.data.server.name.length == 0 ? '\u200b' : `\`${FSserver0?.data.server.name}\``}`, inline: true},
{name: 'Players', value: `${FSserver0.data.slots.used} out of ${FSserver0.data.slots.capacity}`, inline: true},
{name: 'Current map', value: `${FSserver0?.data.server.mapName.length == 0 ? '\u200b' : FSserver0.data.server.mapName}`, inline: true},
{name: 'Version', value: `${FSserver0?.data.server.version.length == 0 ? '\u200b' : FSserver0.data.server.version}`, inline: true},
{name: 'In-game Time', value: `${('0' + Math.floor((FSserver0.data.server.dayTime/3600/1000))).slice(-2)}:${('0' + Math.floor((FSserver0.data.server.dayTime/60/1000)%60)).slice(-2)}`, inline: true}
)
interaction.reply({embeds: [embed0]})
)]})
} else if (FSserver0.data.server.name.length == 0) interaction.reply('Server is currently offline.')
} catch (err){
console.log(err)
@ -60,7 +58,7 @@ export default {
const FSserver2 = await MPdata(client, interaction, embed2)
if (!FSserver2?.data) return console.log('FSserver2 failed - info')
const MPURL = await client.MPServer._content.findById(interaction.guildId);
embed2.setDescription([
interaction.reply({embeds: [embed2.setDescription([
`**Server name**: \`${FSserver2?.data.server.name.length == 0 ? '\u200b' : FSserver2?.data.server.name}\``,
'**Password:** `mf4700`',
'**Crossplay server**',
@ -68,9 +66,8 @@ export default {
`**Mods:** [Click here](${MPURL.ip}/mods.html) **|** [Direct Download](${MPURL.ip}/all_mods_download?onlyActive=true)`,
'**Filters:** [Click here](https://discord.com/channels/468835415093411861/468835769092669461/926581585938120724)',
'Please see <#543494084363288637> for additional information.'
].join('\n'));
].join('\n'))]});
if (FSserver2?.data.server.name.length == 0) embed2.setFooter({text: 'Server is currently offline.'})
interaction.reply({embeds: [embed2]})
},
url: async()=>{
if (client.config.mainServer.id == interaction.guildId) {
@ -170,11 +167,9 @@ export default {
}
function colorAtPlayercount(playercount: number) {
if (playercount === first_graph_top) {
return client.config.embedColorRed as string;
} else if (playercount > 9) {
return client.config.embedColorYellow as string;
} else {return client.config.embedColorGreen as string}
if (playercount === first_graph_top) return client.config.embedColorRed as string;
else if (playercount > 9) return client.config.embedColorYellow as string;
else return client.config.embedColorGreen as string
}
let lastCoords: Array<number> = [];
data.forEach((curPC: number /* current player count */, i: number) => {
@ -197,9 +192,7 @@ export default {
grd.addColorStop(stop, client.config.embedColorYellow as string); // add a yellow stop to the gradient
}
ctx.strokeStyle = grd;
} else {
ctx.strokeStyle = colorAtPlayercount(curPC);
}
} else ctx.strokeStyle = colorAtPlayercount(curPC);
ctx.beginPath();
if (lastCoords.length > 0) ctx.moveTo(lastCoords[0], lastCoords[1]);
// if the line being drawn is horizontal, make it go until it has to go down
@ -209,16 +202,13 @@ export default {
if (data[j] === curPC) newX += nodeWidth; else break;
}
ctx.lineTo(newX, y);
} else {
ctx.lineTo(x, y);
}
} else ctx.lineTo(x, y);
lastCoords = [x, y];
ctx.stroke();
ctx.closePath();
if (curPC === prvPC && curPC === nexPC) {
return; // no ball because no vertical difference to next or prev point
} else {
if (curPC === prvPC && curPC === nexPC) return; // no ball because no vertical difference to next or prev point
else {
// ball
ctx.fillStyle = colorAtPlayercount(curPC);
ctx.beginPath();
@ -257,9 +247,7 @@ export default {
embed1.setTitle(FSserver1?.data.server.name.length == 0 ? 'Offline' : FSserver1?.data.server.name)
.setDescription(`${FSserver1?.data.slots.used}/${FSserver1?.data.slots.capacity}`)
.setColor(FSserver1?.data.server.name.length == 0 ? client.config.embedColorRed : client.config.embedColor);
FSserver1?.data.slots.players.filter(x=>x.isUsed).forEach(player=>{
embed1.addFields({name: `${player.name} ${player.isAdmin ? '| admin' : ''}`, value: `Farming for ${(Math.floor(player.uptime/60))} hr, ${('0' + (player.uptime % 60)).slice(-2)} min`})
})
FSserver1?.data.slots.players.filter(x=>x.isUsed).forEach(player=>embed1.addFields({name: `${player.name} ${player.isAdmin ? '| admin' : ''}`, value: `Farming for ${(Math.floor(player.uptime/60))} hr, ${('0' + (player.uptime % 60)).slice(-2)} min`}))
interaction.reply({embeds: [embed1], files: [Image]})
}/*,
series: ()=>{
@ -293,8 +281,8 @@ export default {
.setDescription('View the URL for this server\'s FSMP server or update the URL')
.addStringOption((opt)=>opt
.setName('address')
.setDescription('Insert a \'dedicated-server-stats\' URL')))
/* .addSubcommand((opt)=>opt
.setDescription('Insert a \'dedicated-server-stats\' URL')))/*
.addSubcommand((opt)=>opt
.setName('series')
.setDescription('Step-by-step on joining Daggerwin\'s MP series'))*/
}

View File

@ -1,7 +1,7 @@
import Discord,{SlashCommandBuilder} from 'discord.js';
import TClient from 'src/client';
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
client.punish(client, interaction, 'mute');
},
data: new SlashCommandBuilder()

View File

@ -10,15 +10,13 @@ export default {
let messagesArray: Array<string> = [];
if (user){
(interaction.channel as Discord.TextChannel).messages.fetch({limit: amount}).then((msgs)=>{
(interaction.channel as Discord.TextChannel).messages.fetch({limit: amount}).then(msgs=>{
const msgList = msgs.filter(x=>x.author.id == user.id);
(interaction.channel as Discord.TextChannel).bulkDelete(msgList);
})
} else {
(interaction.channel as Discord.TextChannel).messages.fetch({limit: amount}).then(async messages=>{
messages.forEach(message=>{
messagesArray.push(message.id);
});
messages.forEach(message=>messagesArray.push(message.id));
await (interaction.channel as Discord.TextChannel).bulkDelete(messagesArray);
})
}

View File

@ -1,7 +1,7 @@
import Discord,{SlashCommandBuilder} from 'discord.js';
import TClient from 'src/client';
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
const embed = new client.embed().setColor(Math.floor(Math.random()*16777215));
embed.addFields({name: 'Hex code', value: `#${embed.data.color.toString(16).toUpperCase()}`});
interaction.reply({embeds: [embed]});

View File

@ -1,7 +1,7 @@
import Discord,{SlashCommandBuilder} from 'discord.js';
import TClient from 'src/client';
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
const role = interaction.options.getRole('role') as Discord.Role;
const permissions = role.permissions.toArray();
const Role = role.members.map((e:Discord.GuildMember)=>`**${e.user.tag}**`).join('\n') || '';

View File

@ -1,7 +1,7 @@
import Discord,{SlashCommandBuilder} from 'discord.js';
import TClient from 'src/client';
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
client.punish(client, interaction, 'softban');
},
data: new SlashCommandBuilder()

View File

@ -5,7 +5,7 @@ import TClient from 'src/client';
import os from 'node:os';
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
// Host specification (L9-L22, L55-L70)
// Host specification (L9-L22, L51-L66)
// Bytes conversion
function formatBytes(bytes:number, decimals:number = 2) {
if (bytes === 0) return '0 Bytes';
@ -21,7 +21,7 @@ export default {
const osInfo = await si.osInfo();
const currentLoad = await si.currentLoad();
// Command usage (L25-L54)
// Command usage (L25-L50)
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})}**`);
@ -44,14 +44,10 @@ export default {
if (fieldValue.length + row.length > 1024){
embed.addFields({name: '\u200b', value: `\`\`\`\n${fieldValue}\`\`\``});
fieldValue = row;
} else {
fieldValue += row;
}
} else fieldValue += row
});
embed.addFields({name: '\u200b', value: `\`\`\`\n${fieldValue}\`\`\``});
} else {
embed.addFields({name: '\u200b', value: `\`\`\`\n${rows.join('')}\`\`\``})
};
} else embed.addFields({name: '\u200b', value: `\`\`\`\n${rows.join('')}\`\`\``});
embed.addFields(
{name: '> __Dependencies__', value: [
`**TypeScript:** ${version}`,
@ -66,11 +62,11 @@ export default {
`**NodeJS:** ${formatBytes(process.memoryUsage().heapUsed)}/${formatBytes(process.memoryUsage().heapTotal)}`,
`**Load Usage:**\nUser: ${currentLoad.currentLoadUser.toFixed(1)}%\nSystem: ${currentLoad.currentLoadSystem.toFixed(1)}%`,
`**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')} // Nice
].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})}`})]}))
},
data: new SlashCommandBuilder()
data: new SlashCommandBuilder()// Nice
.setName('statistics')
.setDescription('See a list of commands ordered by their usage or host stats')
}

View File

@ -56,7 +56,7 @@ export default {
]});
await client.suggestion._content.findByIdAndUpdate(suggestionIDReply, {state: 'Rejected'});
return interaction.reply({embeds:[new client.embed().setColor(client.config.embedColorRed).setTitle(`Suggestion rejected | ${suggestionIDReply}`).setDescription(stateChanged)]});
},
}
} as any)[interaction.options.getSubcommand()]();
},
data: new SlashCommandBuilder()

View File

@ -1,7 +1,7 @@
import Discord,{SlashCommandBuilder} from 'discord.js';
import TClient from 'src/client';
export default {
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
client.punish(client, interaction, 'warn');
},
data: new SlashCommandBuilder()

View File

@ -2,15 +2,12 @@ import Discord,{GuildMember, SlashCommandBuilder} from 'discord.js';
import TClient from 'src/client';
function convert(status?:Discord.ClientPresenceStatus){
if (status){
return {
if (status) return {
idle: '🟡',
dnd: '🔴',
online: '🟢'
}[status];
} else {
return '⚫'
}
else return '⚫'
}
export default {
@ -31,11 +28,9 @@ export default {
const presence = member.presence?.clientStatus as Discord.ClientPresenceStatusData;
const embedArray = [];
let title = 'Member';
if (member.user.bot) {
title = 'Bot'
} else if (member.user.id == interaction.guild.ownerId) {
title = ':crown: Server Owner'
};
if (member.user.bot) title = 'Bot';
else if (member.user.id == interaction.guild.ownerId) title = ':crown: Server Owner';
const embed = new client.embed()
.setColor(member.displayColor || client.config.embedColor)
.setURL(`https://discord.com/users/${member.user.id}`)

View File

@ -15,26 +15,17 @@ export class Database {
this._content = dataType === 'array' ? [] : {};
}
addData(data: any, data1?: any){
if (Array.isArray(this._content)){
this._content.push(data);
} else if (typeof this._content === 'object'){
this._content[data] = data1;
}
if (Array.isArray(this._content)) this._content.push(data);
else if (typeof this._content === 'object') this._content[data] = data1;
return this;
}
removeData(key: any, type: number, element: any){
if (this._dataType === 'array'){
switch (type){
case 0:
this._content = this._content.filter((x:any)=>x != key);
break;
case 1:
this._content = this._content.filter((x:any)=>x[element] != key);
break;
}
} else if (this._dataType === 'object'){
delete this._content[key];
}
({
0: ()=>this._content = this._content.filter((x:any)=>x!=key),
1: ()=>this._content = this._content.filter((x:any)=>x[element]!=key)
})[type]()
} else if (this._dataType === 'object') delete this._content[key];
return this;
}
initLoad(){
@ -64,6 +55,4 @@ export class Database {
console.log(this._path + ' "DB saved" Notifications disabled');
return this;
}
} // Nice.
}

View File

@ -7,14 +7,11 @@ export default {
const banLog = fetchBanlog.entries.first();
if (!banLog) return console.log(`${member.user.tag} was banned from ${member.guild.name} but no audit log for this user.`)
const {executor, target, reason } = banLog;
if (target.id == member.user.id) {
(client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds: [
if (target.id == member.user.id) (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds: [
new client.embed().setColor(client.config.embedColorRed).setTimestamp().setThumbnail(member.user.displayAvatarURL({size: 2048})).setTitle(`Member Banned: ${target.tag}`).setDescription(`🔹 **User**\n<@${target.id}>\n\`${target.id}\``).addFields(
{name: '🔹 Moderator', value: `<@${executor.id}>\n\`${executor.id}\``},
{name: '🔹 Reason', value: `${reason == null ? 'Reason unspecified': reason}`}
)]})
} else {
console.log(`${target.tag} was banned from ${member.guild.name} but no audit log could be fetched.`)
}
)]});
else console.log(`${target.tag} was banned from ${member.guild.name} but no audit log could be fetched.`)
}
}

View File

@ -7,14 +7,11 @@ export default {
const unbanLog = fetchUnbanlog.entries.first();
if (!unbanLog) return console.log(`${member.user.tag} was unbanned from ${member.guild.name} but no audit log for this user.`)
const { executor, target, reason } = unbanLog;
if (target.id == member.user.id) {
(client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds: [
if (target.id == member.user.id) (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds: [
new client.embed().setColor(client.config.embedColorGreen).setTimestamp().setThumbnail(member.user.displayAvatarURL({size: 2048})).setTitle(`Member Unbanned: ${target.tag}`).setDescription(`🔹 **User**\n<@${target.id}>\n\`${target.id}\``).addFields(
{name: '🔹 Moderator', value: `<@${executor.id}>\n\`${executor.id}\``},
{name: '🔹 Reason', value: `${reason == null ? 'Reason unspecified.': reason}`}
)]})
} else {
console.log(`${target.tag} was unbanned from ${member.guild.name} but no audit log could be fetched.`)
}
)]});
else console.log(`${target.tag} was unbanned from ${member.guild.name} but no audit log could be fetched.`)
}
}

View File

@ -6,16 +6,14 @@ export default {
const index = member.guild.memberCount;
const suffix = ((index)=>{
const numbers = index.toString().split('').reverse(); // eg 1850 --> [0,5,8,1]
if (numbers[1] === '1'){// this is some -teen
return 'th';
} else {
if (numbers[1] === '1') return 'th'; // this is some -teen
else {
if (numbers[0] === '1') return 'st';
else if (numbers[0] === '2') return 'nd';
else if (numbers[0] === '3') return 'rd';
else return 'th';
}
})(index);
(client.channels.resolve(client.config.mainServer.channels.welcome) as Discord.TextChannel).send({embeds: [new client.embed().setColor(client.config.embedColor).setThumbnail(member.user.displayAvatarURL({size: 2048}) || member.user.defaultAvatarURL).setTitle(`Welcome to Daggerwin, ${member.user.tag}!`).setFooter({text: `${index}${suffix} member`})]})
if (!client.config.botSwitches.logs) return;
const newInvites = await member.guild.invites.fetch();

View File

@ -1,7 +1,7 @@
import Discord from 'discord.js';
import TClient from '../client';
export default {
async run(client:TClient, oldMember:Discord.GuildMember, newMember:Discord.GuildMember){
run(client:TClient, oldMember:Discord.GuildMember, newMember:Discord.GuildMember){
if (oldMember.guild.id != client.config.mainServer.id) return;
if (!client.config.botSwitches.logs) return;
const channel = (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel)

View File

@ -1,7 +1,7 @@
import Discord from 'discord.js';
import TClient from '../client';
export default {
async run(client:TClient, interaction:Discord.BaseInteraction){
run(client:TClient, interaction:Discord.BaseInteraction){
if (!interaction.inGuild() || !interaction.inCachedGuild()) return;
if (interaction.isChatInputCommand()){
const commandFile = client.commands.get(interaction.commandName);

View File

@ -1,7 +1,7 @@
import Discord from 'discord.js';
import TClient from '../client';
export default {
async run(client:TClient, invite: Discord.Invite){
run(client:TClient, invite: Discord.Invite){
client.invites.delete(invite.code)
}
}

View File

@ -10,9 +10,7 @@ export default {
delete client.repeatedMessages[message.author.id]
}
const Whitelist = [
// Arrary of channel ids for automod to be disabled in
]
const Whitelist = [] // Array of channel ids for automod to be disabled in (Disables bannedWords and advertisement, mind you.)
if (await client.bannedWords._content.findOne({_id:msgarr}) && !message.member.roles.cache.has(client.config.mainServer.roles.dcmod) && message.guildId == client.config.mainServer.id && !Whitelist.includes(message.channelId) && client.config.botSwitches.automod){
automodded = true;
@ -45,6 +43,7 @@ export default {
client.repeatedMessages[message.author.id].data.set(message.createdTimestamp, {cont: 0, ch: message.channelId});
}
}
if (message.content.toLowerCase().includes('discord.gg/') && !message.member.roles.cache.has(client.config.mainServer.roles.dcmod) && message.guildId == client.config.mainServer.id && !Whitelist.includes(message.channelId)) {
automodded = true;
const threshold = 60000;

View File

@ -1,7 +1,7 @@
import Discord from 'discord.js';
import TClient from '../client';
export default {
async run(client:TClient, msg:Discord.Message){
run(client:TClient, msg:Discord.Message){
if (!client.config.botSwitches.logs) return;
const channel = client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel;
const disabledChannels = [ '548032776830582794', '541677709487505408']

View File

@ -1,10 +1,14 @@
import Discord from 'discord.js';
import TClient from '../client';
export default {
async run(client:TClient, messages:Discord.Collection<string, Discord.Message<boolean>>){
run(client:TClient, messages:Discord.Collection<string, Discord.Message<boolean>>){
if (!client.config.botSwitches.logs) return;
if (client.config.mainServer.id != '468835415093411861') return;
const channel = client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel;
channel.send({embeds: [new client.embed().setColor(client.config.embedColorRed).setTimestamp().setTitle(`${messages.size} messages were purged`).setDescription(`\`\`\`${messages.map((msgs)=>`${msgs.member?.displayName}: ${msgs.content}`).reverse().join('\n').slice(0,3900)}\`\`\``).addFields({name: 'Channel', value: `<#${messages.first().channel.id}>`})]})
channel.send({embeds: [new client.embed().setColor(client.config.embedColorRed).setTimestamp().setTitle(`${messages.size} messages were purged`)
.setDescription(`\`\`\`${messages.map((msgs)=>`${msgs.member?.displayName}: ${msgs.content}`).reverse().join('\n').slice(0,3900)}\`\`\``).addFields(
{name: 'Channel', value: `<#${messages.first().channel.id}>`}
)]
})
}
}

View File

@ -8,6 +8,6 @@ export default {
const msgarr = newMsg.content.toLowerCase().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}\n\`\`\`\nNew content:\n\`\`\`\n${newMsg.content}\`\`\`\nChannel: <#${oldMsg.channelId}>`)], components: [new ActionRowBuilder<ButtonBuilder>().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 ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setStyle(5).setURL(`${oldMsg.url}`).setLabel('Jump to message'))]});
}
}

View File

@ -20,6 +20,7 @@ client.on('ready', async()=>{
console.log(`${client.user.tag} has logged into Discord API`);
console.log(client.config.botSwitches, 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')}\`\`\``);
console.timeEnd('Startup')
})
// Handle errors
@ -116,9 +117,7 @@ setInterval(async()=>{
{name: 'Slot Usage', value: `${slotSystem}`, inline: true},
{name: 'Timescale', value: `${timeScale}`, inline: true}
);
FSdss.data.slots.players.filter((x)=>x.isUsed !== false).forEach(player=>{
Players.push(`**${player.name} ${player.isAdmin ? '| admin' : ''}**\nFarming for ${(Math.floor(player.uptime/60))} hr & ${('' + (player.uptime % 60)).slice(-2)} min`)
})
FSdss.data.slots.players.filter((x)=>x.isUsed !== false).forEach(player=>Players.push(`**${player.name} ${player.isAdmin ? '| admin' : ''}**\nFarming for ${(Math.floor(player.uptime/60))} hr & ${('' + (player.uptime % 60)).slice(-2)} min`))
embed.setDescription(`${FSdss.data.slots.used == 0 ? '*No players online*' : Players.join('\n\n')}`).setTitle(FSdss.data.server.name).setColor(client.config.embedColor)
embed.setAuthor({name: `${FSdss.data.slots.used}/${FSdss.data.slots.capacity}`});
msg.edit({content: 'This embed updates every minute.', embeds: [embed1, embed]})
@ -148,9 +147,7 @@ setInterval(async()=>{
if (!dailyMsgs.some((x:Array<number>)=>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<number>)=>x[0] === formattedDate - 1);
if (total < yesterday){ // messages went down.
total = yesterday
}
if (total < yesterday) total = yesterday // messages went down.
dailyMsgs.push([formattedDate, total]);
fs.writeFileSync(__dirname + '/database/dailyMsgs.json', JSON.stringify(dailyMsgs))
console.log(client.logTime(), `Pushed [${formattedDate}, ${total}] to dailyMsgs`);