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 { ExcludeEnum, PresenceStatusData } from "discord.js"; |
import { ExcludeEnum, PresenceStatusData } from "discord.js"; |
21 |
import { ActivityTypes } from "discord.js/typings/enums"; |
import { ActivityTypes } from "discord.js/typings/enums"; |
|
import DiscordClient from "../client/Client"; |
|
22 |
import Service from "../utils/structures/Service"; |
import Service from "../utils/structures/Service"; |
23 |
import { random } from "../utils/util"; |
import { random } from "../utils/util"; |
24 |
|
|
25 |
export default class RandomStatus extends Service { |
export default class RandomStatus extends Service { |
26 |
async update(name?: string, type?: ExcludeEnum<typeof ActivityTypes, 'CUSTOM'>, status?: PresenceStatusData) { |
async update(status?: PresenceStatusData) { |
27 |
status ??= random(['dnd', 'idle', 'online'] as PresenceStatusData[]); |
status ??= random(['dnd', 'idle', 'online'] as PresenceStatusData[]); |
28 |
console.log(status); |
console.log(status); |
29 |
|
|
30 |
await this.client.user?.setActivity({ |
await this.client.user?.setActivity({ |
31 |
type: type ?? 'WATCHING', |
type: this.client.config.props.status?.type ?? 'WATCHING', |
32 |
name: name ?? 'over the server' |
name: this.client.config.props.status?.name ?? 'over the server' |
33 |
}); |
}); |
34 |
|
|
35 |
await this.client.user?.setStatus(status!); |
await this.client.user?.setStatus(status!); |
36 |
} |
} |
37 |
|
|
38 |
|
async config(name?: string, type?: ExcludeEnum<typeof ActivityTypes, 'CUSTOM'>) { |
39 |
|
this.client.config.props.status ??= {}; |
40 |
|
this.client.config.props.status.type = type ?? 'WATCHING'; |
41 |
|
this.client.config.props.status.name = name ?? 'over the server'; |
42 |
|
this.client.config.write(); |
43 |
|
} |
44 |
} |
} |