/[sudobot]/branches/4.x/src/services/Utilities.ts
ViewVC logotype

Contents of /branches/4.x/src/services/Utilities.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 3158 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 /**
2 * This file is part of SudoBot.
3 *
4 * Copyright (C) 2021-2022 OSN Inc.
5 *
6 * SudoBot is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * SudoBot is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 import { userMention } from "@discordjs/builders";
21 import { Collection, Message } from "discord.js";
22 import DiscordClient from "../client/Client";
23 import StaffAway, { IStaffAway } from "../models/StaffAway";
24 import { emoji } from "../utils/Emoji";
25 import Service from "../utils/structures/Service";
26
27 export default class Utilities extends Service {
28 typingInterval: NodeJS.Timer | null = null;
29 typingTimeOut: NodeJS.Timeout | null = null;
30 lastDeletedMessage?: Message;
31 staffAwayList: IStaffAway[] = [];
32
33 constructor(client: DiscordClient) {
34 super(client);
35
36 StaffAway.find({ enabled: true }).then(list => {
37 this.staffAwayList = list;
38 }).catch(console.error);
39 }
40
41 findStaffAway(guild: string, id: string, del = false) {
42 let i = 0;
43
44 for (const entry of this.staffAwayList) {
45 if (entry.user === id && entry.guild_id === guild) {
46 if (del) {
47 this.staffAwayList.splice(i, 1);
48 }
49
50 return entry;
51 }
52
53 i++;
54 }
55
56 return null;
57 }
58
59 async checkStaffAway(message: Message) {
60 if (!message.author.bot &&
61 this.client.config.props[message.guildId!].staffchannel_group &&
62 message.channel.type === 'GUILD_TEXT' &&
63 message.channel.parent?.id &&
64 message.channel.parent?.id === this.client.config.props[message.guildId!].staffchannel_group &&
65 message.member?.roles.cache.has(this.client.config.props[message.guildId!].mod_role)) {
66 const user = message.mentions.repliedUser ?? message.mentions.users.first();
67
68 const entry = user ? this.findStaffAway(message.guildId!, user.id) : null;
69 const selfentry = this.findStaffAway(message.guildId!, message.author.id);
70
71 if (selfentry) {
72 this.client.utils.findStaffAway(message.guildId!, message.author.id, true);
73 await selfentry.delete();
74 await message.reply(`${emoji('check')} Welcome back, we've removed your away status.`);
75 }
76 else if (entry) {
77 await message.reply({
78 content: `${userMention(entry.user)} has taken a break from moderating.`,
79 allowedMentions: {
80 users: []
81 }
82 });
83 }
84 }
85 }
86 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26