1 |
rakinar2 |
577 |
/** |
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 { formatDistanceToNowStrict } from "date-fns"; |
21 |
|
|
import { Message, CacheType, CommandInteraction, GuildPreview } from "discord.js"; |
22 |
|
|
import Client from "../../client/Client"; |
23 |
|
|
import MessageEmbed from "../../client/MessageEmbed"; |
24 |
|
|
import CommandOptions from "../../types/CommandOptions"; |
25 |
|
|
import InteractionOptions from "../../types/InteractionOptions"; |
26 |
|
|
import { emoji } from "../../utils/Emoji"; |
27 |
|
|
import BaseCommand from "../../utils/structures/BaseCommand"; |
28 |
|
|
|
29 |
|
|
export default class GuildLookupCommand extends BaseCommand { |
30 |
|
|
constructor() { |
31 |
|
|
super("guildlookup", "information", ["glookup", "guild"]); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
async run(client: Client, message: CommandInteraction<CacheType> | Message<boolean>, options: CommandOptions | InteractionOptions): Promise<void> { |
35 |
|
|
if (!options.isInteraction && options.args[0] === undefined) { |
36 |
|
|
await message.reply(`${emoji('error')} You must provide the guild/server ID to lookup.`); |
37 |
|
|
return; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
const inputID = options.isInteraction ? options.options.getString("guild_id")! : options.args[0]; |
41 |
|
|
let guild: GuildPreview | undefined; |
42 |
|
|
|
43 |
|
|
try { |
44 |
|
|
guild = await client.fetchGuildPreview(inputID); |
45 |
|
|
|
46 |
|
|
if (!guild) { |
47 |
|
|
guild = undefined; |
48 |
|
|
} |
49 |
|
|
} |
50 |
|
|
catch (e) { |
51 |
|
|
console.log(e); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
if (!guild) { |
55 |
|
|
await message.reply(`${emoji('error')} No guild/server was found with that ID or the guild isn't a public server.`); |
56 |
|
|
return; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
await message.reply({ |
60 |
|
|
embeds: [ |
61 |
|
|
new MessageEmbed({ |
62 |
|
|
author: { |
63 |
|
|
name: guild.name, |
64 |
|
|
iconURL: guild.iconURL() ?? undefined |
65 |
|
|
}, |
66 |
|
|
description: guild.description ?? '*No description available*', |
67 |
|
|
fields: [ |
68 |
|
|
{ |
69 |
|
|
name: "Approximate Member Count", |
70 |
|
|
value: guild.approximateMemberCount + '', |
71 |
|
|
inline: true |
72 |
|
|
}, |
73 |
|
|
{ |
74 |
|
|
name: "Approximate Presence Count", |
75 |
|
|
value: guild.approximatePresenceCount + '', |
76 |
|
|
inline: true |
77 |
|
|
}, |
78 |
|
|
{ |
79 |
|
|
name: "Created", |
80 |
|
|
value: `${guild.createdAt.toLocaleString()} (${formatDistanceToNowStrict(guild.createdAt, { addSuffix: true })})`, |
81 |
|
|
}, |
82 |
|
|
], |
83 |
|
|
thumbnail: guild.splashURL() ? { |
84 |
|
|
url: guild.splashURL()! |
85 |
|
|
} : undefined, |
86 |
|
|
footer: { |
87 |
|
|
text: `${guild.id}` |
88 |
|
|
} |
89 |
|
|
}) |
90 |
|
|
.setTimestamp() |
91 |
|
|
] |
92 |
|
|
}); |
93 |
|
|
} |
94 |
|
|
} |