mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-12-29 05:35:38 -05:00
cring duplicate system
This commit is contained in:
parent
46b3ce2532
commit
d202156ee6
176
src/index.ts
176
src/index.ts
@ -4,7 +4,7 @@ const client = new TClient;
|
|||||||
client.init();
|
client.init();
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import MPDB from './models/MPServer';
|
import MPDB from './models/MPServer';
|
||||||
import { Punishment, punOpt, UserLevels } from './typings/interfaces';
|
import { Punishment, UserLevels } from './typings/interfaces';
|
||||||
|
|
||||||
client.on('ready', async()=>{
|
client.on('ready', async()=>{
|
||||||
client.guilds.cache.forEach(async(e: { members: { fetch: () => any; }; })=>{await e.members.fetch()});
|
client.guilds.cache.forEach(async(e: { members: { fetch: () => any; }; })=>{await e.members.fetch()});
|
||||||
@ -163,177 +163,3 @@ setInterval(async()=>{
|
|||||||
console.log(`\x1b[36m[${client.moment().format('DD/MM/YY HH:mm:ss')}] \x1b[33m`, `Pushed [${formattedDate}, ${total}] to dailyMsgs`)
|
console.log(`\x1b[36m[${client.moment().format('DD/MM/YY HH:mm:ss')}] \x1b[33m`, `Pushed [${formattedDate}, ${total}] to dailyMsgs`)
|
||||||
}
|
}
|
||||||
}, 5000)
|
}, 5000)
|
||||||
|
|
||||||
// Punishments
|
|
||||||
Object.assign(client.punishments,{
|
|
||||||
createId(){
|
|
||||||
return Math.max(...client.punishments._content.map((x:Punishment)=>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: Punishment = {type, id: this.createId(), member: member.id, moderator, time: now};
|
|
||||||
let dm1:any;
|
|
||||||
try {
|
|
||||||
dm1 = await member.send(`You've been banned from ${interaction.guild.name} ${timeInMillis ? `for ${client.formatTime(timeInMillis, 4, {longNames: true, commas: true})}` : 'forever'} for reason \`${reason || 'Reason unspecified'}\` (Case #${banData.id})`)
|
|
||||||
} catch (err) {
|
|
||||||
setTimeout(()=>interaction.channel.send('Failed to DM user.'), 500)
|
|
||||||
}
|
|
||||||
const banResult = await interaction.guild.bans.create(member.id, {reason: `${reason || 'Reason unspecified'} | Case #${banData.id}`}).catch((err: Error)=>err.message);
|
|
||||||
if (typeof banResult === 'string'){
|
|
||||||
dm1.delete();
|
|
||||||
return `Ban was unsuccessful: ${banResult}`;
|
|
||||||
} else {
|
|
||||||
if (timeInMillis){
|
|
||||||
banData.endTime = now + timeInMillis;
|
|
||||||
banData.duration = timeInMillis;
|
|
||||||
}
|
|
||||||
if (reason) banData.reason = reason;
|
|
||||||
client.makeModlogEntry(banData, client);
|
|
||||||
this.addData(banData);
|
|
||||||
this.forceSave();
|
|
||||||
return new client.embed().setColor(client.config.embedColor).setTitle(`Case #${banData.id}: Ban`).setDescription(`${member.tag}\n<@${member.id}>\n(\`${member.id}\`)`).addFields(
|
|
||||||
{name: 'Reason', value: `\`${reason || 'Reason unspecified'}\``},
|
|
||||||
{name: 'Duration', value: `${timeInMillis ? `for ${client.formatTime(timeInMillis, 4, {longNames: true, commas: true})}` : 'forever'}`}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
case 'softban':
|
|
||||||
const guild = member.guild;
|
|
||||||
const softbanData: Punishment = {type, id: this.createId(), member: member.user.id, moderator, time: now};
|
|
||||||
const dm2 = await member.send(`You've been softbanned from ${member.guild.name} for reason \`${reason || 'Reason unspecified'}\` (Case #${softbanData.id})`).catch(err=>setTimeout(()=>interaction.channel.send(`Failed to DM <@${member.user.id}>.`), 500));
|
|
||||||
const softbanResult = await member.ban({deleteMessageSeconds: 345600, reason: `${reason || 'Reason unspecified'} | Case #${softbanData.id}`}).catch((err: Error)=>err.message);
|
|
||||||
if (typeof softbanResult === 'string'){
|
|
||||||
dm2.delete();
|
|
||||||
return `Softban was unsuccessful: ${softbanResult}`;
|
|
||||||
} else {
|
|
||||||
const unbanResult = guild.members.unban(softbanData.member, `${reason || 'Reason unspecified'} | Case #${softbanData.id}`).catch((err: Error)=>err.message);
|
|
||||||
if (typeof unbanResult === 'string'){
|
|
||||||
return `Softban (unban) was unsuccessful: ${softbanResult}`
|
|
||||||
} else {
|
|
||||||
if (reason) softbanData.reason = reason;
|
|
||||||
client.makeModlogEntry(softbanData, client);
|
|
||||||
this.addData(softbanData)
|
|
||||||
this.forceSave();
|
|
||||||
return new client.embed().setColor(client.config.embedColor).setTitle(`Case #${softbanData.id}: Softban`).setDescription(`${member.user.tag}\n<@${member.user.id}>\n(\`${member.user.id}\`)`).addFields(
|
|
||||||
{name: 'Reason', value: `\`${reason || 'Reason unspecified'}\``}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case 'kick':
|
|
||||||
const kickData: Punishment = {type, id: this.createId(), member: member.user.id, moderator, time: now};
|
|
||||||
const dm3 = await member.send(`You've been kicked from ${member.guild.name} for reason \`${reason || 'Reason unspecified'}\` (Case #${kickData.id})`).catch((err:Error)=>setTimeout(()=>interaction.channel.send(`Failed to DM <@${member.user.id}>.`), 500));
|
|
||||||
const kickResult = await member.kick(`${reason || 'Reason unspecified'} | Case #${kickData.id}`).catch((err:Error)=>err.message);
|
|
||||||
if (typeof kickResult === 'string'){
|
|
||||||
dm3.delete();
|
|
||||||
return `Kick was unsuccessful: ${kickResult}`;
|
|
||||||
} else {
|
|
||||||
if (reason) kickData.reason = reason;
|
|
||||||
client.makeModlogEntry(kickData, client);
|
|
||||||
this.addData(kickData);
|
|
||||||
this.forceSave();
|
|
||||||
return new client.embed().setColor(client.config.embedColor).setTitle(`Case #${kickData.id}: Kick`).setDescription(`${member.user.tag}\n<@${member.user.id}>\n(\`${member.user.id}\`)`).addFields(
|
|
||||||
{name: 'Reason', value: `\`${reason || 'Reason unspecified'}\``}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
case 'mute':
|
|
||||||
const muteData: Punishment = {type, id: this.createId(), member: member.user.id, moderator, time: now};
|
|
||||||
let muteResult;
|
|
||||||
const dm4 = await member.send(`You've been muted in ${member.guild.name} ${timeInMillis ? `for ${client.formatTime(timeInMillis, 4, {longNames: true, commas: true})}` : 'forever'} for reason \`${reason || 'Reason unspecified'}\` (Case #${muteData.id})`).catch((err:Error)=>setTimeout(()=>interaction.channel.send('Failed to DM user.'), 500));
|
|
||||||
if (timeInMillis){
|
|
||||||
muteResult = await member.timeout(timeInMillis, `${reason || 'Reason unspecified'} | Case #${muteData.id}`).catch((err: Error)=>err.message);
|
|
||||||
} else {
|
|
||||||
muteResult = await member.timeout(2419200000, `${reason || 'Reason unspecified'} | Case #${muteData.id}`).catch((err: Error)=>err.message);
|
|
||||||
}
|
|
||||||
if (typeof muteResult === 'string') {
|
|
||||||
dm4.delete();
|
|
||||||
return `Mute was unsuccessful: ${muteResult}`;
|
|
||||||
} else {
|
|
||||||
if (timeInMillis){
|
|
||||||
muteData.endTime = now + timeInMillis;
|
|
||||||
muteData.duration = timeInMillis
|
|
||||||
}
|
|
||||||
if (reason) muteData.reason = reason;
|
|
||||||
client.makeModlogEntry(muteData, client);
|
|
||||||
this.addData(muteData);
|
|
||||||
this.forceSave();
|
|
||||||
const embedm = new client.embed().setColor(client.config.embedColor).setTitle(`Case #${muteData.id}: Mute`).setDescription(`${member.user.tag}\n<@${member.user.id}>\n(\`${member.user.id}\`)`).addFields(
|
|
||||||
{name: 'Reason', value: `\`${reason || 'Reason unspecified'}\``},
|
|
||||||
{name: 'Duration', value: `${client.formatTime(timeInMillis, 4, {longNames: true, commas: true})}`}
|
|
||||||
)
|
|
||||||
if (moderator !== '795443537356521502') {return embedm};
|
|
||||||
}
|
|
||||||
case 'warn':
|
|
||||||
const warnData: Punishment = {type, id: this.createId(), member: member.user.id, moderator, time: now};
|
|
||||||
const warnResult = await member.send(`You've been warned in ${member.guild.name} for reason \`${reason || 'Reason unspecified'}\` (Case #${warnData.id})`).catch((err:Error)=>setTimeout(()=>interaction.channel.send(`Failed to DM <@${member.user.id}>.`), 500));
|
|
||||||
if (typeof warnResult === 'string'){
|
|
||||||
return `Warn was unsuccessful: ${warnResult}`;
|
|
||||||
} else {
|
|
||||||
if (reason) warnData.reason = reason;
|
|
||||||
client.makeModlogEntry(warnData, client);
|
|
||||||
this.addData(warnData);
|
|
||||||
this.forceSave();
|
|
||||||
const embedw = new client.embed().setColor(client.config.embedColor).setTitle(`Case #${warnData.id}: Warn`).setDescription(`${member.user.tag}\n<@${member.user.id}>\n(\`${member.user.id}\`)`).addFields(
|
|
||||||
{name: 'Reason', value: `\`${reason || 'Reason unspecified'}\``}
|
|
||||||
)
|
|
||||||
if (moderator !== '795443537356521502') {return embedw};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async removePunishment(caseId: number, moderator: any, reason: string){
|
|
||||||
const now = Date.now();
|
|
||||||
const punishment = this._content.find((x:any)=>x.id === caseId);
|
|
||||||
const id = this.createId();
|
|
||||||
if (!punishment) return 'Punishment not found.';
|
|
||||||
if (['ban', 'mute'].includes(punishment.type)){
|
|
||||||
const guild = client.guilds.cache.get(client.config.mainServer.id) as Discord.Guild;
|
|
||||||
let removePunishmentResult;
|
|
||||||
if(punishment.type === 'ban'){
|
|
||||||
// unban
|
|
||||||
removePunishmentResult = await guild.members.unban(punishment.member, `${reason || 'Reason unspecified'} | Case #${id}`).catch((err: TypeError)=>err.message);
|
|
||||||
}else if (punishment.type === 'mute') {
|
|
||||||
//remove role
|
|
||||||
const member = await guild.members.fetch(punishment.member).catch(err=>undefined);
|
|
||||||
if (member){
|
|
||||||
removePunishmentResult = await member
|
|
||||||
if (typeof removePunishmentResult !== 'string'){
|
|
||||||
member.timeout(null, `${reason || 'Reason unspecified'} | Case #${id}`)
|
|
||||||
removePunishmentResult.send(`You've been unmuted in ${removePunishmentResult.guild.name}.`)
|
|
||||||
removePunishmentResult = removePunishmentResult.user; //removing a role returns a guildmember
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
// user probably left, lets quietly nuke the punishment.
|
|
||||||
const removePunishmentData = {type: `un${punishment.type}`, id, cancels: punishment.id, member: punishment.member, reason, moderator, time: now};
|
|
||||||
this._content[this._content.findIndex(x=>x.id === punishment.id)].expired = true;
|
|
||||||
this.addData(removePunishmentData).forceSave();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (typeof removePunishmentResult === 'string') return `Un${punishment.type} was unsuccessful: ${removePunishmentResult}`;
|
|
||||||
else{
|
|
||||||
const removePunishmentData = {type: `un${punishment.type}`, id, cancels: punishment.id, member: punishment.member, reason, moderator, time: now};
|
|
||||||
client.makeModlogEntry(removePunishmentData, client);
|
|
||||||
this._content[this._content.findIndex(x=>x.id === punishment.id)].expired = true;
|
|
||||||
this.addData(removePunishmentData).forceSave();
|
|
||||||
return `Successfully ${punishment.type === 'ban' ? 'unbanned' : 'unmuted'} **${removePunishmentResult?.tag}** (\`${removePunishmentResult?.id}\`) for reason \`${reason || 'Reason unspecified'}\``;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
const removePunishmentData = {type: 'removeOtherPunishment', id, cancels: punishment.id, member: punishment.member, reason, moderator, time: now};
|
|
||||||
client.makeModlogEntry(removePunishmentData, client);
|
|
||||||
this._content[this._content.findIndex(x=>x.id === punishment.id)].expired = true;
|
|
||||||
this.addData(removePunishmentData).forceSave();
|
|
||||||
return `Successfully removed Case #${punishment.id} (type: ${punishment.type}, user: ${punishment.member}).`;
|
|
||||||
} catch(error: any){
|
|
||||||
return `${punishment.type[0].toUpperCase()+punishment.type.slice(1)} removal was unsuccessful: ${error.message}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
Loading…
Reference in New Issue
Block a user