Files
Yumi/src/discord/Invite.ts
T

51 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-06-06 14:59:53 +07:00
import { Message, CommandInteraction, Interaction } from 'discord.js';
2022-06-07 03:08:27 +07:00
import { I18n } from 'i18n';
2022-03-03 20:56:49 +07:00
2022-06-06 14:59:53 +07:00
import Environment from '../providers/Environment';
import DiscordProvider from '../providers/Discord';
import Users from '../services/Users';
2022-06-07 03:08:27 +07:00
import Locale from '../services/Locale';
2022-06-06 14:59:53 +07:00
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from '../utils/DiscordMessage';
2021-09-18 05:19:40 -07:00
const EMBEDS = {
2022-06-07 03:08:27 +07:00
INVITE_INFO: (data: HybridInteractionMessage, locale: I18n) => {
const user = data.getUser();
2021-09-18 05:19:40 -07:00
let message;
2022-06-07 03:08:27 +07:00
if (!Environment.get().PRIVATE_BOT || user != null && Users.isDeveloper(user.id))
2022-06-27 20:28:01 +07:00
message = locale.__('invite.info', { BOT_NAME: DiscordProvider.client.user!.username, LINK: `https://discord.com/api/oauth2/authorize?client_id=${DiscordProvider.client.user?.id}&permissions=0&scope=bot%20applications.commands`});
2022-06-06 14:59:53 +07:00
2021-09-18 05:19:40 -07:00
return makeInfoEmbed({
title: `Invite`,
2022-06-27 20:28:01 +07:00
description: message || locale.__('invite.private', { BOT_NAME: DiscordProvider.client.user!.username}),
2022-06-07 03:08:27 +07:00
user
2021-09-18 05:19:40 -07:00
});
2021-09-18 05:44:44 -07:00
}
2022-06-06 14:59:53 +07:00
};
2021-09-16 23:55:08 -07:00
2022-03-03 20:56:49 +07:00
export default class Invite extends DiscordModule {
2022-06-06 14:59:53 +07:00
public id: string = 'Discord_Invite';
public commands = ['invite'];
public commandInteractionName = 'invite';
2022-03-03 20:56:49 +07:00
async GuildOnModuleCommand(args: any, message: Message) {
await this.run(new HybridInteractionMessage(message), args);
2021-09-16 23:55:08 -07:00
}
2022-06-06 14:59:53 +07:00
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
2022-03-03 20:56:49 +07:00
await this.run(new HybridInteractionMessage(interaction), interaction.options);
2021-09-16 23:55:08 -07:00
}
2022-03-03 20:56:49 +07:00
async run(data: HybridInteractionMessage, args: any) {
2022-06-07 03:08:27 +07:00
const guild = data.getGuild();
if (!guild) return;
const locale = await Locale.getGuildLocale(guild.id);
2022-06-06 14:59:53 +07:00
return await sendHybridInteractionMessageResponse(data, {
2022-06-07 03:08:27 +07:00
embeds: [EMBEDS.INVITE_INFO(data, locale)]
2022-06-06 14:59:53 +07:00
});
2021-09-16 23:55:08 -07:00
}
2022-06-06 14:59:53 +07:00
}