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:
parent
d0d65c2986
commit
f72c17746a
@ -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}});
|
||||
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!
|
||||
}
|
||||
}
|
||||
|
@ -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}})
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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}});
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user