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

Make them one-liner.

This commit is contained in:
AnxietyisReal 2024-01-16 22:28:03 +11:00
parent d0d65c2986
commit f72c17746a
6 changed files with 21 additions and 65 deletions

View File

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

View File

@ -48,13 +48,7 @@ export class ProhibitedWordsSvc {
throw new Error(`Failed to insert words into Postgres database: ${err.message}`) throw new Error(`Failed to insert words into Postgres database: ${err.message}`)
} }
} }
async getAllWords() { getAllWords = async()=>await this.model.findAll();
return 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}})
async insertWord(word:string) {
return await this.model.create({word: word})
}
async removeWord(word:string) {
return await this.model.destroy({where: {word: word}})
}
} }

View File

@ -82,15 +82,9 @@ export class PunishmentsSvc {
const findCase = this.findCase(caseId); const findCase = this.findCase(caseId);
if (findCase) return this.model.update({reason: reason}, {where: {case_id: caseId}}); if (findCase) return this.model.update({reason: reason}, {where: {case_id: caseId}});
} }
async findCase(caseId:number) { findCase =(caseId:number)=>this.model.findOne({where: {case_id: caseId}});
return this.model.findOne({where: {case_id: caseId}}); findByCancels =(caseId:number)=>this.model.findOne({where: {cancels: caseId}})
} getAllCases =()=>this.model.findAll();
async findByCancels(caseId:number) {
return this.model.findOne({where: {cancels: caseId}})
}
async getAllCases() {
return this.model.findAll();
}
async generateCaseId() { async generateCaseId() {
const result = await this.model.findAll(); const result = await this.model.findAll();
return Math.max(...result.map((x:Punishment)=>x.case_id), 0) + 1; return Math.max(...result.map((x:Punishment)=>x.case_id), 0) + 1;
@ -107,7 +101,7 @@ export class PunishmentsSvc {
async findInCache():Promise<any> { async findInCache():Promise<any> {
const cacheKey = 'punishments'; const cacheKey = 'punishments';
const cachedResult = await CacheServer.get(cacheKey, true); const cachedResult = await CacheServer.get(cacheKey, true);
let result; let result:any;
if (cachedResult) result = cachedResult; if (cachedResult) result = cachedResult;
else { else {
result = await this.model.findAll(); result = await this.model.findAll();
@ -164,13 +158,7 @@ export class PunishmentsSvc {
const durText = millisecondTime ? ` for ${Formatters.timeFormat(millisecondTime, 4, {longNames: true, commas: true})}` : ''; const durText = millisecondTime ? ` for ${Formatters.timeFormat(millisecondTime, 4, {longNames: true, commas: true})}` : '';
if (time) embed.addFields({name: 'Duration', value: durText}); if (time) embed.addFields({name: 'Duration', value: durText});
if (guildUser) { 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'}));
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 (['ban', 'softban'].includes(type)) { if (['ban', 'softban'].includes(type)) {
const alreadyBanned = await guild.bans.fetch(user.id).catch(()=>null); // 172800 seconds is 48 hours, just for future reference 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(); this.model.sync();
} }
async fetchById(id:number) { fetchById = async(id:number)=>await this.model.findByPk(id);
return 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'})
async updateStatus(id:number, status:string) { delete =(id:number)=>this.model.destroy({where: {id: id}});
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}});
}
} }

View File

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

View File

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