diff --git a/src/models/dailyMsgs.ts b/src/models/dailyMsgs.ts index 05188d6..23c2493 100644 --- a/src/models/dailyMsgs.ts +++ b/src/models/dailyMsgs.ts @@ -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! } diff --git a/src/models/prohibitedWords.ts b/src/models/prohibitedWords.ts index 7cb6268..67d23e3 100644 --- a/src/models/prohibitedWords.ts +++ b/src/models/prohibitedWords.ts @@ -48,13 +48,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}}) } diff --git a/src/models/punishments.ts b/src/models/punishments.ts index 03ba4b4..2779aeb 100644 --- a/src/models/punishments.ts +++ b/src/models/punishments.ts @@ -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 { 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 diff --git a/src/models/suggestions.ts b/src/models/suggestions.ts index a7b82fb..4fc19ca 100644 --- a/src/models/suggestions.ts +++ b/src/models/suggestions.ts @@ -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}}); } diff --git a/src/models/userLevels.ts b/src/models/userLevels.ts index f065af2..1b5a4ba 100644 --- a/src/models/userLevels.ts +++ b/src/models/userLevels.ts @@ -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; diff --git a/src/models/ytChannels.ts b/src/models/ytChannels.ts index 21add07..dfebd56 100644 --- a/src/models/ytChannels.ts +++ b/src/models/ytChannels.ts @@ -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(); }