/[sudobot]/trunk/src/services/AFKEngine.ts
ViewVC logotype

Diff of /trunk/src/services/AFKEngine.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 304 by rakin, Mon Jul 29 17:29:27 2024 UTC revision 327 by rakin, Mon Jul 29 17:29:33 2024 UTC
# Line 2  import { formatDistanceToNowStrict } fro Line 2  import { formatDistanceToNowStrict } fro
2  import { CommandInteraction, GuildMember, Message, User, Util } from "discord.js";  import { CommandInteraction, GuildMember, Message, User, Util } from "discord.js";
3  import DiscordClient from "../client/Client";  import DiscordClient from "../client/Client";
4  import MessageEmbed from "../client/MessageEmbed";  import MessageEmbed from "../client/MessageEmbed";
5  import AFKCommand from "../commands/utils/AFKCommand";  import AFK, { IAFK } from "../models/AFK";
 import AFK from "../models/AFK";  
6  import Service from "../utils/structures/Service";  import Service from "../utils/structures/Service";
7    
8  export interface MentionSchema {  export interface MentionSchema {
# Line 12  export interface MentionSchema { Line 11  export interface MentionSchema {
11  }  }
12    
13  export default class AFKEngine extends Service {  export default class AFKEngine extends Service {
14      list: AFK[] = [];      list: IAFK[] = [];
15    
16      constructor(client: DiscordClient) {      constructor(client: DiscordClient) {
17          super(client);          super(client);
18          AFK.findAll().then(models => this.list = models).catch(console.error);          AFK.find().then(models => this.list = models).catch(console.error);
19      }      }
20    
21      findUsers(ids: string[], guild: string) {      findUsers(ids: string[], guild: string) {
22          return this.list.filter(afk => ids.includes(afk.get("user") as string) && afk.get("guild_id") as string === guild);          return this.list.filter(afk => ids.includes(afk.user) && afk.guild_id === guild);
23      }      }
24    
25      async removeUser(id: string, guild: string) {      async removeUser(id: string, guild: string) {
26          let index = 0;          let index = 0;
27    
28          for await (const afk of this.list) {          for await (const afk of this.list) {
29              if (afk.get('user') === id && afk.get("guild_id") === guild) {              if (afk.user === id && afk.guild_id === guild) {
30                  await afk.destroy();                  await afk.delete();
31                  this.list.splice(index, 1);                  this.list.splice(index, 1);
32              }              }
33    
# Line 81  export default class AFKEngine extends S Line 80  export default class AFKEngine extends S
80                  user: message.member!.user.id,                  user: message.member!.user.id,
81                  guild_id: message.guild!.id,                  guild_id: message.guild!.id,
82                  mentions: [],                  mentions: [],
83                  reason: status ?? undefined                  reason: status ?? undefined,
84                    createdAt: new Date()
85              }));              }));
86    
87              await message.reply({              await message.reply({
# Line 107  export default class AFKEngine extends S Line 107  export default class AFKEngine extends S
107          const mention = msg.mentions.members?.first();          const mention = msg.mentions.members?.first();
108    
109          if (mention) {          if (mention) {
110              const afkRecords: AFK[] = this.findUsers([...msg.mentions.members!.keys()].slice(0, 3), msg.guild!.id);              const afkRecords: Array<IAFK> = this.findUsers([...msg.mentions.members!.keys()].slice(0, 3), msg.guild!.id).filter(afk => afk.user !== msg.author.id);
111    
112              if (!afkRecords || afkRecords.length < 1) {              if (!afkRecords || afkRecords.length < 1) {
113                  return;                  return;
114              }              }
115    
116              for (const record of afkRecords) {              for (const record of afkRecords) {
117                  const mentions = record.get("mentions") as MentionSchema[];                  const mentions = record.mentions as MentionSchema[];
118    
119                  mentions.push({                  mentions.push({
120                      date: Date.now(),                      date: Date.now(),

Legend:
Removed from v.304  
changed lines
  Added in v.327

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26