37 |
AFK.find().then(models => this.list = models).catch(console.error); |
AFK.find().then(models => this.list = models).catch(console.error); |
38 |
} |
} |
39 |
|
|
40 |
findUsers(ids: string[], guild: string) { |
findUsers(ids: string[]) { |
41 |
return this.list.filter(afk => ids.includes(afk.user) && afk.guild_id === guild); |
return this.list.filter(afk => ids.includes(afk.user)); |
42 |
} |
} |
43 |
|
|
44 |
async removeUser(id: string, guild: string) { |
async removeUser(id: string) { |
45 |
let index = 0; |
let index = 0; |
46 |
|
|
47 |
for await (const afk of this.list) { |
for await (const afk of this.list) { |
48 |
if (afk.user === id && afk.guild_id === guild) { |
if (afk.user === id) { |
49 |
await afk.delete(); |
await afk.delete(); |
50 |
this.list.splice(index, 1); |
this.list.splice(index, 1); |
51 |
} |
} |
55 |
} |
} |
56 |
|
|
57 |
async toggle(message: Message | CommandInteraction, enable: boolean = false, status?: string) { |
async toggle(message: Message | CommandInteraction, enable: boolean = false, status?: string) { |
58 |
const afk = this.findUsers([message.member!.user.id], message.guild!.id); |
const afk = this.findUsers([message.member!.user.id]); |
59 |
|
|
60 |
if (afk.length > 0) { |
if (afk.length > 0) { |
61 |
const mentions = afk[0].get("mentions")! as Array<MentionSchema>; |
const mentions = afk[0].get("mentions")! as Array<MentionSchema>; |
84 |
count++; |
count++; |
85 |
} |
} |
86 |
|
|
87 |
await this.client.afkEngine.removeUser(message.member!.user.id, message.guild!.id); |
await this.client.afkEngine.removeUser(message.member!.user.id); |
88 |
|
|
89 |
await message.reply({ |
await message.reply({ |
90 |
embeds: [ |
embeds: [ |
117 |
if (msg.author.bot) |
if (msg.author.bot) |
118 |
return; |
return; |
119 |
|
|
120 |
const selfAFK = this.findUsers([msg.author.id], msg.guild!.id); |
const selfAFK = this.findUsers([msg.author.id]); |
121 |
|
|
122 |
if (selfAFK.length > 0) { |
if (selfAFK.length > 0) { |
123 |
this.toggle(msg, false); |
this.toggle(msg, false); |
126 |
const mention = msg.mentions.members?.first(); |
const mention = msg.mentions.members?.first(); |
127 |
|
|
128 |
if (mention) { |
if (mention) { |
129 |
const afkRecords: Array<IAFK> = this.findUsers([...msg.mentions.members!.keys()].slice(0, 3), msg.guild!.id).filter(afk => afk.user !== msg.author.id); |
const afkRecords: Array<IAFK> = this.findUsers([...msg.mentions.members!.keys()].slice(0, 3)).filter(afk => afk.user !== msg.author.id); |
130 |
|
|
131 |
if (!afkRecords || afkRecords.length < 1) { |
if (!afkRecords || afkRecords.length < 1) { |
132 |
return; |
return; |