1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 16:30:58 -05:00

Compare commits

...

4 Commits

Author SHA1 Message Date
AnxietyisReal
137a0ae7b8 Missed a few bits here and there 2024-01-16 22:41:30 +11:00
AnxietyisReal
ab6c6de9c1 Add bold formatting to uptime text 2024-01-16 22:30:23 +11:00
AnxietyisReal
2a7c243c16 Sort the member's punishment history from newest to oldest by time. 2024-01-16 22:28:31 +11:00
AnxietyisReal
f72c17746a Make them one-liner. 2024-01-16 22:28:03 +11:00
14 changed files with 34 additions and 88 deletions

View File

@ -19,7 +19,7 @@ export default class Case {
}
}
static run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
if (!MessageTool.isStaff(interaction.member)) return MessageTool.youNeedRole(interaction, 'dcmod');
if (!MessageTool.isModerator(interaction.member)) return MessageTool.youNeedRole(interaction, 'dcmod');
const caseId = interaction.options.getInteger('id');
({
update: async()=>{
@ -49,14 +49,14 @@ export default class Case {
const user = (interaction.options.getUser('user') as Discord.User);
if (user.bot) return interaction.reply(`**${user.username}**'s punishment history cannot be viewed as they are a bot.`)
const punishments = await client.punishments.getAllCases();
const userPunishmentData = punishments.filter(x=>x.dataValues.member === user.id);
const userPunishment = userPunishmentData.sort((a,b)=>a.dataValues.time-b.dataValues.time).map(punishment=>{
const userPunishmentData = punishments.filter(x=>x.dataValues.member === user.id).sort((a,b)=>b.dataValues.time-a.dataValues.time);
const userPunishment = userPunishmentData.map(punishment=>{
return {
name: `${punishment.dataValues.type[0].toUpperCase()+punishment.dataValues.type.slice(1)} | Case #${punishment.dataValues.case_id}`,
value: `Reason: \`${punishment.dataValues.reason}\`\n${punishment.dataValues.duration ? `Duration: ${Formatters.timeFormat(punishment.dataValues.duration, 3)}\n` : ''}Moderator: ${MessageTool.formatMention(punishment.dataValues.moderator, 'user')}${punishment.dataValues.expired ? `\nOverwritten by Case #${punishments.find(x=>x.dataValues.cancels===punishment.dataValues.case_id)?.case_id}` : ''}${punishment.dataValues.cancels ? `\nOverwrites Case #${punishment.dataValues.cancels}` : ''}`
}
});
if (!punishments || !userPunishment) return interaction.reply(`**${user.username}** has a clean record.`)
if (!userPunishment.length) return interaction.reply(`**${user.username}** has a clean record.`)
const pageNum = interaction.options.getInteger('page') ?? 1;
return interaction.reply({embeds: [new client.embed().setColor(client.config.embedColor).setTitle(`${user.username}'s punishment history`).setDescription(`**ID:** \`${user.id}\``).setFooter({text: `${userPunishment.length} total punishments. Viewing page ${pageNum} out of ${Math.ceil(userPunishment.length/6)}.`}).addFields(userPunishment.slice((pageNum - 1) * 6, pageNum * 6))]});
}

View File

@ -76,7 +76,7 @@ export default class Developer {
else if (stdout.includes('Already up to date')) hammondYouIdiot.edit('Repository is currently up to date.');
else hammondYouIdiot.edit('Running `yarn tsc`...').then(()=>exec('yarn tsc', {windowsHide:true}, (err:Error)=>{
if (err) hammondYouIdiot.edit(`\`\`\`${UsernameHelper(err.message)}\`\`\``);
else if (interaction.options.getBoolean('restart')) hammondYouIdiot.edit(msgBody + `\nUptime: ${Formatters.timeFormat(process.uptime()*1000, 4, {longNames:true, commas:true})}`).then(()=>process.exit(0));
else if (interaction.options.getBoolean('restart')) hammondYouIdiot.edit(msgBody + `\nUptime: **${Formatters.timeFormat(process.uptime()*1000, 4, {longNames:true, commas:true})}**`).then(()=>process.exit(0));
else hammondYouIdiot.edit(msgBody);
}));
});

View File

@ -4,7 +4,7 @@ import HookMgr from '../components/HookManager.js';
import MessageTool from '../helpers/MessageTool.js';
export default class ProhibitedWords {
static async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
if (!MessageTool.isStaff(interaction.member) && !client.config.whitelist.includes(interaction.member.id)) return MessageTool.youNeedRole(interaction, 'admin');
if (!MessageTool.isModerator(interaction.member) && !client.config.whitelist.includes(interaction.member.id)) return MessageTool.youNeedRole(interaction, 'admin');
const word = interaction.options.getString('word');
const wordExists = await client.prohibitedWords.findWord(word);
({

View File

@ -3,7 +3,7 @@ import TClient from '../client.js';
import MessageTool from '../helpers/MessageTool.js';
export default class Purge {
static async run(_client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
if (!MessageTool.isStaff(interaction.member)) return MessageTool.youNeedRole(interaction, 'dcmod');
if (!MessageTool.isModerator(interaction.member)) return MessageTool.youNeedRole(interaction, 'dcmod');
const amount = interaction.options.getInteger('amount') as number;
if (amount > 100) return interaction.reply({content: 'Discord API limits purging up to 100 messages.', ephemeral: true})
const user = interaction.options.getUser('user');

View File

@ -4,7 +4,7 @@ import Logger from '../helpers/Logger.js';
import MessageTool from '../helpers/MessageTool.js';
export default class Unpunish {
static async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
if (!MessageTool.isStaff(interaction.member as Discord.GuildMember)) return MessageTool.youNeedRole(interaction, 'dcmod');
if (!MessageTool.isModerator(interaction.member as Discord.GuildMember)) return MessageTool.youNeedRole(interaction, 'dcmod');
const punishment = await client.punishments.findCase(interaction.options.getInteger('case_id', true));
if (!punishment) return interaction.reply({content: 'Case ID is not found in database.', ephemeral: true});
if (['unban', 'unmute', 'punishmentOverride'].includes(punishment.dataValues.type)) return interaction.reply({content: 'This case ID is immutable. (Informative case)', ephemeral: true});

View File

@ -3,9 +3,7 @@ import TClient from '../client.js';
import Logger from '../helpers/Logger.js';
export default class Automoderator {
private static lockQuery:Set<Discord.Snowflake> = new Set();
static scanMsg(message:Discord.Message) {
return message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b/g, '').split(' ').join('');
}
static scanMsg =(message:Discord.Message)=>message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b/g, '').split(' ').join('');
static async repeatedMessages(client:TClient, message:Discord.Message, thresholdTime:number, thresholdAmount:number, type:string, duration:string, reason:string) {
const now = Date.now();

View File

@ -29,12 +29,8 @@ export default class CacheServer {
if (jsonMode) return await RedisClient.json.set(key, '.', value);
else return await RedisClient.set(key, JSON.stringify(value));
}
public static async expiry(key:any, time:number) {
return await RedisClient.expire(key, time); // NOTE: time is in seconds, not milliseconds -- you know what you did wrong
}
public static async delete(key:any) {
return await RedisClient.del(key);
}
public static expiry = async(key:any, time:number)=>await RedisClient.expire(key, time); // NOTE: time is in seconds, not milliseconds -- you know what you did wrong
public static delete = async(key:any)=>await RedisClient.del(key);
public static init() {
try {
RedisClient.connect();

View File

@ -14,9 +14,7 @@ export default class HookMgr {
this.webhookId = webhookId;
}
protected async channelFetch(client:TClient, channel:ChannelList) {
return await client.channels.fetch(config.dcServer.channels[channel]) as Discord.TextChannel;
}
protected channelFetch = async(client:TClient, channel:ChannelList)=>await client.channels.fetch(config.dcServer.channels[channel]) as Discord.TextChannel;
protected async fetch(client:TClient, channel:ChannelList, webhookId:Discord.Snowflake) {
const hookInstance = await (await this.channelFetch(client, channel)).fetchWebhooks().then(x=>x.find(y=>y.id===webhookId));
if (!hookInstance) throw new Error('[HookManager] Webhook not found.');

View File

@ -30,21 +30,13 @@ export class DailyMsgsSvc {
})
this.model.sync();
}
async nukeDays() {
return await this.model.destroy({truncate: true})
// Drop a nuclear bomb on the table.
}
async fetchDays() {
return await this.model.findAll();
// Fetch every rows from database.
}
nukeDays = async()=>await this.model.destroy({truncate: true});
fetchDays = async()=>await this.model.findAll();
async newDay(formattedDate:number, total:number) {
if (await this.model.findOne({where: {day: formattedDate}})) return console.log('This day already exists!')
return await this.model.create({day: formattedDate, total: total});
// Save previous day's total messages into database when a new day starts.
}
async updateDay(formattedDate:number, total:number) {
return await this.model.update({total: total}, {where: {day: formattedDate}});
// THIS IS FOR DEVELOPMENT PURPOSES ONLY, NOT TO BE USED IN LIVE ENVIRONMENT!
}
updateDay = async(formattedDate:number, total:number)=>await this.model.update({total: total}, {where: {day: formattedDate}});
// THIS IS FOR DEVELOPMENT PURPOSES ONLY, NOT TO BE USED IN LIVE ENVIRONMENT!
}

View File

@ -26,9 +26,7 @@ export class ProhibitedWordsSvc {
})
this.model.sync();
}
async findWord(word:string) {
return await this.model.findByPk(word);
}
findWord = async(word:string)=>await this.model.findByPk(word);
async importWords(file:string) {
const jsonData = await new Promise<string>((resolve, reject)=>{
get(file, res=>{
@ -48,13 +46,7 @@ export class ProhibitedWordsSvc {
throw new Error(`Failed to insert words into Postgres database: ${err.message}`)
}
}
async getAllWords() {
return await this.model.findAll();
}
async insertWord(word:string) {
return await this.model.create({word: word})
}
async removeWord(word:string) {
return await this.model.destroy({where: {word: word}})
}
getAllWords = async()=>await this.model.findAll();
insertWord = async(word:string)=>await this.model.create({word: word});
removeWord = async(word:string)=>await this.model.destroy({where: {word: word}})
}

View File

@ -82,15 +82,9 @@ export class PunishmentsSvc {
const findCase = this.findCase(caseId);
if (findCase) return this.model.update({reason: reason}, {where: {case_id: caseId}});
}
async findCase(caseId:number) {
return this.model.findOne({where: {case_id: caseId}});
}
async findByCancels(caseId:number) {
return this.model.findOne({where: {cancels: caseId}})
}
async getAllCases() {
return this.model.findAll();
}
findCase =(caseId:number)=>this.model.findOne({where: {case_id: caseId}});
findByCancels =(caseId:number)=>this.model.findOne({where: {cancels: caseId}})
getAllCases =()=>this.model.findAll();
async generateCaseId() {
const result = await this.model.findAll();
return Math.max(...result.map((x:Punishment)=>x.case_id), 0) + 1;
@ -107,7 +101,7 @@ export class PunishmentsSvc {
async findInCache():Promise<any> {
const cacheKey = 'punishments';
const cachedResult = await CacheServer.get(cacheKey, true);
let result;
let result:any;
if (cachedResult) result = cachedResult;
else {
result = await this.model.findAll();
@ -164,13 +158,7 @@ export class PunishmentsSvc {
const durText = millisecondTime ? ` for ${Formatters.timeFormat(millisecondTime, 4, {longNames: true, commas: true})}` : '';
if (time) embed.addFields({name: 'Duration', value: durText});
if (guildUser) {
try {
await guildUser.send(`You've been ${this.getPastTense(type)} ${inOrFromBoolean} **${guild.name}**${durText}\n\`${reason}\` (Case #${punishment.case_id})`)
} catch {
embed.setFooter({text: 'Unable to DM a member'})
}
}
if (guildUser) await guildUser.send(`You've been ${this.getPastTense(type)} ${inOrFromBoolean} **${guild.name}**${durText}\n\`${reason}\` (Case #${punishment.case_id})`).catch(()=>embed.setFooter({text: 'Unable to DM a member'}));
if (['ban', 'softban'].includes(type)) {
const alreadyBanned = await guild.bans.fetch(user.id).catch(()=>null); // 172800 seconds is 48 hours, just for future reference

View File

@ -40,16 +40,8 @@ export class SuggestionsSvc {
})
this.model.sync();
}
async fetchById(id:number) {
return await this.model.findByPk(id);
}
async updateStatus(id:number, status:string) {
return await this.model.update({status: status}, {where: {id: id}})
}
async create(userid:string, description:string) {
return this.model.create({userid: userid, suggestion: description, status: 'Pending'})
}
async delete(id:number) {
return this.model.destroy({where: {id: id}});
}
fetchById = async(id:number)=>await this.model.findByPk(id);
updateStatus = async(id:number, status:string)=>await this.model.update({status: status}, {where: {id: id}});
create =(userid:string, description:string)=>this.model.create({userid: userid, suggestion: description, status: 'Pending'})
delete =(id:number)=>this.model.destroy({where: {id: id}});
}

View File

@ -47,15 +47,9 @@ export class UserLevelsSvc {
});
this.model.sync();
}
async fetchEveryone() {
return await this.model.findAll();
}
async fetchUser(userId:string) {
return await this.model.findByPk(userId);
}
async deleteUser(userId:string) {
return await this.model.destroy({where: {id: userId}});
}
fetchEveryone = async()=>await this.model.findAll();
fetchUser = async(userId:string)=>await this.model.findByPk(userId);
deleteUser = async(userId:string)=>await this.model.destroy({where: {id: userId}});
async modifyUser(userId:string, updatedMessages:number) {
await this.model.update({messages: updatedMessages}, {where: {id: userId}});
return (await this.model.findByPk(userId)).dataValues;

View File

@ -34,15 +34,11 @@ export class YouTubeChannelsSvc {
})
this.model.sync();
}
async getChannels() {
return await this.model.findAll();
}
async addChannel(YTChannelID:string, DCChannelID:string, DCRole:string) {
if (await this.model.findOne({where: {ytchannel: YTChannelID}})) return false;
await this.model.create({ytchannel: YTChannelID, dcchannel: DCChannelID, dcrole: DCRole});
return true;
}
async delChannel(YTChannelID:string) {
return await this.model.destroy({where: {ytchannel: YTChannelID}});
}
delChannel = async(YTChannelID:string)=>await this.model.destroy({where: {ytchannel: YTChannelID}});
getChannels = async()=>await this.model.findAll();
}