mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-14 03:09:59 +00:00
Formatted code and clean up
This commit is contained in:
+16
-18
@@ -1,19 +1,18 @@
|
||||
import DiscordModule from "../utils/DiscordModule";
|
||||
import { Guild } from 'discord.js';
|
||||
|
||||
import { Guild } from "discord.js";
|
||||
import Logger from "../libs/Logger";
|
||||
import Cache from "../providers/Cache";
|
||||
import DiscordProvider from "../providers/Discord";
|
||||
import Prisma from "../providers/Prisma";
|
||||
import DiscordModule from '../utils/DiscordModule';
|
||||
import DiscordProvider from '../providers/Discord';
|
||||
|
||||
import Logger from '../libs/Logger';
|
||||
import Cache from '../providers/Cache';
|
||||
import Prisma from '../providers/Prisma';
|
||||
|
||||
export default class Core extends DiscordModule {
|
||||
|
||||
public id: string = "Discord_Core";
|
||||
public id: string = 'Discord_Core';
|
||||
|
||||
async Ready() {
|
||||
|
||||
let data = [];
|
||||
for(let Guild of DiscordProvider.client.guilds.cache.map(guild => guild)) {
|
||||
for (let Guild of DiscordProvider.client.guilds.cache.map((guild) => guild)) {
|
||||
data.push({ id: Guild.id });
|
||||
}
|
||||
|
||||
@@ -25,20 +24,19 @@ export default class Core extends DiscordModule {
|
||||
await Cache.updateGuildsCache();
|
||||
setInterval(() => {
|
||||
Cache.updateGuildsCache();
|
||||
}, 5 * 60 * 1000)
|
||||
}, 5 * 60 * 1000);
|
||||
|
||||
setInterval(() => {
|
||||
DiscordProvider.client.user!.setActivity("for your heart 💖", {
|
||||
type: "COMPETING"
|
||||
DiscordProvider.client.user!.setActivity('for your heart 💖', {
|
||||
type: 'COMPETING'
|
||||
});
|
||||
}, 5 * 60 * 1000)
|
||||
|
||||
}, 5 * 60 * 1000);
|
||||
|
||||
Logger.info('Core started successfully');
|
||||
|
||||
}
|
||||
|
||||
|
||||
async GuildCreate(guild: Guild) {
|
||||
if(await Prisma.client.guild.findFirst({ where: {id: guild.id} })) return;
|
||||
if (await Prisma.client.guild.findFirst({ where: { id: guild.id } })) return;
|
||||
|
||||
await Prisma.client.guild.create({
|
||||
data: {
|
||||
|
||||
+26
-21
@@ -1,25 +1,29 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||
import { CommandInteraction, Interaction, Message } from 'discord.js';
|
||||
|
||||
import { CommandInteraction, Interaction, Message } from "discord.js";
|
||||
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from "../utils/DiscordMessage";
|
||||
import DiscordProvider from "../providers/Discord";
|
||||
import Cache from "../providers/Cache";
|
||||
import DiscordProvider from '../providers/Discord';
|
||||
import Cache from '../providers/Cache';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from '../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
INFO: async (data: Message | Interaction) => {
|
||||
|
||||
let GuildCache = await Cache.getGuild(data.guildId!);
|
||||
|
||||
// TODO: Better error handling
|
||||
if(typeof GuildCache === 'undefined')
|
||||
throw new Error("Guild not found");
|
||||
if (typeof GuildCache === 'undefined') throw new Error('Guild not found');
|
||||
|
||||
let prefix = GuildCache.prefix || '>';
|
||||
|
||||
let _e = makeInfoEmbed({
|
||||
icon: "💌",
|
||||
icon: '💌',
|
||||
title: `Help - ${DiscordProvider.client.user?.username}`,
|
||||
description: `\u200b\n📰 **Info**\nYumi is currently undergoing complete rewrite, as expected, losing many of her functionality. All of the features will be re-implemented.\n\n🏷️ **Prefix**\nYou can call me using \`\`${prefix.replaceAll('`','`')}\`\`, <@${DiscordProvider.client.user?.id}> or \`\`/slash command\`\`\n\n💻 **Available commands**`,
|
||||
description: `\u200b\n📰 **Info**\nYumi is currently undergoing complete rewrite, as expected, losing many of her functionality. All of the features will be re-implemented.\n\n🏷️ **Prefix**\nYou can call me using \`\`${prefix.replaceAll(
|
||||
'`',
|
||||
'`'
|
||||
)}\`\`, <@${
|
||||
DiscordProvider.client.user?.id
|
||||
}> or \`\`/slash command\`\`\n\n💻 **Available commands**`,
|
||||
fields: [
|
||||
{
|
||||
name: '☕ General',
|
||||
@@ -52,31 +56,32 @@ const EMBEDS = {
|
||||
inline: false
|
||||
}
|
||||
],
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
_e.setThumbnail(`${DiscordProvider.client.user?.displayAvatarURL()}?size=4096`);
|
||||
return _e;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Help extends DiscordModule {
|
||||
|
||||
public id = "Discord_Help";
|
||||
public commands = ["help"];
|
||||
public commandInteractionName = "help";
|
||||
public id = 'Discord_Help';
|
||||
public commands = ['help'];
|
||||
public commandInteractionName = 'help';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
const message = await sendHybridInteractionMessageResponse(data, { embeds: [await EMBEDS.INFO(data.getRaw())] });
|
||||
const message = await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.INFO(data.getRaw())]
|
||||
});
|
||||
|
||||
if(message && data.isMessage())
|
||||
return new HybridInteractionMessage(message).getMessage().react("♥");
|
||||
if (message && data.isMessage())
|
||||
return new HybridInteractionMessage(message).getMessage().react('♥');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||
import { Message, Interaction, CommandInteraction } from 'discord.js';
|
||||
|
||||
import { Message, Interaction, CommandInteraction } from "discord.js";
|
||||
import { makeInfoEmbed, makeErrorEmbed, makeSuccessEmbed, makeProcessingEmbed, sendHybridInteractionMessageResponse } from "../utils/DiscordMessage";
|
||||
import {registerAllGuildsCommands, unregisterAllGuildsCommands} from "../utils/DiscordInteraction";
|
||||
import Users from "../services/Users";
|
||||
import Users from '../services/Users';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import {
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
makeSuccessEmbed,
|
||||
makeProcessingEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../utils/DiscordMessage';
|
||||
import {
|
||||
registerAllGuildsCommands,
|
||||
unregisterAllGuildsCommands
|
||||
} from '../utils/DiscordInteraction';
|
||||
|
||||
const EMBEDS = {
|
||||
INTERACTION_INFO: (data: Message | Interaction) => {
|
||||
@@ -16,105 +26,118 @@ const EMBEDS = {
|
||||
value: '``reloadAll``'
|
||||
}
|
||||
],
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
PROCESSING: (data: Message | Interaction) => {
|
||||
return makeProcessingEmbed({
|
||||
icon: (data instanceof Message) ? undefined : '⌛',
|
||||
icon: data instanceof Message ? undefined : '⌛',
|
||||
title: `Performing actions`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NOT_DEVELOPER: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Developer only',
|
||||
description: `This command is restricted to the developers only`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
RELOADALL_SUCCESS: (data: Message | Interaction) => {
|
||||
return makeSuccessEmbed({
|
||||
title: 'Reloaded all Interaction',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
RELOADALL_ERROR: (data: Message | Interaction, err: any) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: 'An error occurred while trying to reload interaction',
|
||||
description: '```' + err + '```',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
})
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class InteractionManager extends DiscordModule {
|
||||
|
||||
public id = "Discord_InteractionManager";
|
||||
public commands = ["interaction"];
|
||||
public commandInteractionName = "interaction";
|
||||
public id = 'Discord_InteractionManager';
|
||||
public commands = ['interaction'];
|
||||
public commandInteractionName = 'interaction';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const user = data.getUser();
|
||||
if(!user) return;
|
||||
if (!user) return;
|
||||
|
||||
if(!Users.isDeveloper(user.id))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.NOT_DEVELOPER(data.getRaw())] });
|
||||
if (!Users.isDeveloper(user.id))
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NOT_DEVELOPER(data.getRaw())]
|
||||
});
|
||||
|
||||
const funct = {
|
||||
reloadAll: async(data: HybridInteractionMessage) => {
|
||||
reloadAll: async (data: HybridInteractionMessage) => {
|
||||
let placeholder: HybridInteractionMessage | undefined;
|
||||
|
||||
let placeholder: (HybridInteractionMessage | undefined);
|
||||
|
||||
let _placeholder = await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PROCESSING(data.getRaw())] });
|
||||
if (_placeholder)
|
||||
placeholder = new HybridInteractionMessage(_placeholder);
|
||||
let _placeholder = await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PROCESSING(data.getRaw())]
|
||||
});
|
||||
if (_placeholder) placeholder = new HybridInteractionMessage(_placeholder);
|
||||
|
||||
try {
|
||||
await unregisterAllGuildsCommands();
|
||||
await registerAllGuildsCommands();
|
||||
|
||||
if(data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data.getRaw())] });
|
||||
else if(data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.RELOADALL_SUCCESS(data.getRaw())]}, true);
|
||||
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({ embeds: [EMBEDS.RELOADALL_SUCCESS(data.getRaw())] });
|
||||
else if (data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.RELOADALL_SUCCESS(data.getRaw())] },
|
||||
true
|
||||
);
|
||||
} catch (err) {
|
||||
if(data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.RELOADALL_ERROR(data.getRaw(), err)] });
|
||||
else if(data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.RELOADALL_ERROR(data.getRaw(), err)] }, true);
|
||||
}
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({ embeds: [EMBEDS.RELOADALL_ERROR(data.getRaw(), err)] });
|
||||
else if (data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.RELOADALL_ERROR(data.getRaw(), err)] },
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let query;
|
||||
|
||||
if(data.isMessage()) {
|
||||
if(args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INTERACTION_INFO(data.getRaw())] });
|
||||
if (data.isMessage()) {
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.INTERACTION_INFO(data.getRaw())]
|
||||
});
|
||||
|
||||
query = args[0].toLowerCase();
|
||||
}
|
||||
else if(data.isSlashCommand()) {
|
||||
} else if (data.isSlashCommand()) {
|
||||
query = args.getSubcommand();
|
||||
}
|
||||
|
||||
switch(query) {
|
||||
case "info":
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INTERACTION_INFO(data.getRaw())] });
|
||||
case "reloadall":
|
||||
switch (query) {
|
||||
case 'info':
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.INTERACTION_INFO(data.getRaw())]
|
||||
});
|
||||
case 'reloadall':
|
||||
return await funct.reloadAll(data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-18
@@ -1,40 +1,44 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||
import { Message, CommandInteraction, Interaction } from 'discord.js';
|
||||
|
||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from "../utils/DiscordMessage";
|
||||
import DiscordProvider from "../providers/Discord";
|
||||
import Users from "../services/Users"
|
||||
import Environment from "../providers/Environment";
|
||||
import Environment from '../providers/Environment';
|
||||
import DiscordProvider from '../providers/Discord';
|
||||
import Users from '../services/Users';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from '../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
INVITE_INFO: (data: Message | Interaction) => {
|
||||
let message;
|
||||
if(Users.isDeveloper(data.member?.user.id!) || !Environment.get().PRIVATE_BOT)
|
||||
if (Users.isDeveloper(data.member?.user.id!) || !Environment.get().PRIVATE_BOT)
|
||||
message = `[Invite ${DiscordProvider.client.user?.username} to your server!](https://discord.com/api/oauth2/authorize?client_id=${DiscordProvider.client.user?.id}&permissions=0&scope=bot%20applications.commands)`;
|
||||
|
||||
|
||||
return makeInfoEmbed({
|
||||
title: `Invite`,
|
||||
description: message || `${DiscordProvider.client.user?.username}'s invite is currently private. Only the developers can add me to another server`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
description:
|
||||
message ||
|
||||
`${DiscordProvider.client.user?.username}'s invite is currently private. Only the developers can add me to another server`,
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Invite extends DiscordModule {
|
||||
public id: string = 'Discord_Invite';
|
||||
public commands = ['invite'];
|
||||
public commandInteractionName = 'invite';
|
||||
|
||||
public id: string = "Discord_Invite";
|
||||
public commands = ["invite"];
|
||||
public commandInteractionName = "invite";
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.INVITE_INFO(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.INVITE_INFO(data.getRaw())]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+278
-166
@@ -1,47 +1,67 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||
import App from '..';
|
||||
import {
|
||||
GuildChannel,
|
||||
GuildMember,
|
||||
Message,
|
||||
Permissions,
|
||||
TextChannel,
|
||||
MessageActionRow,
|
||||
MessageButton,
|
||||
Interaction,
|
||||
CommandInteraction,
|
||||
Role,
|
||||
ThreadChannel,
|
||||
ButtonInteraction
|
||||
} from 'discord.js';
|
||||
|
||||
import { GuildChannel, GuildMember, Message, Permissions, TextChannel, MessageActionRow, MessageButton, Interaction, CommandInteraction, Role, ThreadChannel, ButtonInteraction } from "discord.js";
|
||||
import App from "..";
|
||||
import { makeSuccessEmbed, makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse, sendMessage } from "../utils/DiscordMessage";
|
||||
import DiscordProvider from "../providers/Discord";
|
||||
import Prisma from "../providers/Prisma";
|
||||
import DiscordProvider from '../providers/Discord';
|
||||
import Prisma from '../providers/Prisma';
|
||||
|
||||
import {
|
||||
makeSuccessEmbed,
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
sendHybridInteractionMessageResponse,
|
||||
sendMessage
|
||||
} from '../utils/DiscordMessage';
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
|
||||
const EMBEDS = {
|
||||
NO_PERMISSION: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'You need ``ADMINISTRATOR`` permission on this guild!',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_PARAMETER: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Missing parameter',
|
||||
description: `You must define membership screening channel and role to enable this feature`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_ROLE_MENTIONED: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'No role mentioned',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_ROLE_FOUND: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Cannot find that role',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_CHANNEL_MENTIONED: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'No channel mentioned',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_CHANNEL_FOUND: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Cannot find that channel',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
MSINFO: (data: Message | Interaction) => {
|
||||
@@ -54,106 +74,120 @@ const EMBEDS = {
|
||||
value: '``setRole`` ``setChannel`` ``createMessage``'
|
||||
}
|
||||
],
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
ALREADY_ENABLED: (data: Message | Interaction) => {
|
||||
return makeInfoEmbed({
|
||||
title: 'Membership Screening is already enabled',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
MESSAGE_CREATED: (data: Message | Interaction) => {
|
||||
return makeSuccessEmbed({
|
||||
title: 'Membership Screening message created',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
ALREADY_DISABLED: (data: Message | Interaction) => {
|
||||
return makeInfoEmbed({
|
||||
title: 'Membership Screening is already disabled',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
ENABLED: (data: Message | Interaction) => {
|
||||
return makeSuccessEmbed({
|
||||
title: 'Enabled Membership Screening',
|
||||
description: `All new member join request will be sent in your defined channel`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
DISABLED: (data: Message | Interaction) => {
|
||||
return makeSuccessEmbed({
|
||||
title: 'Disabled Membership Screening',
|
||||
description: `No longer accepting request, all new member can join directly`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
})
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
MANAGED_ROLE: (data: Message | Interaction, role: Role) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'You cannot use this role',
|
||||
description: '``' + role.name + '``' + ' is managed by external service and cannot be used',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
description:
|
||||
'``' + role.name + '``' + ' is managed by external service and cannot be used',
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
CONFIGURED_ROLE: (data: Message | Interaction, role: Role) => {
|
||||
return makeSuccessEmbed({
|
||||
title: 'Configured Membership Screening Role',
|
||||
description: 'New member will be given a ' + '``' + role.name + '``' + ' role after approval',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
description:
|
||||
'New member will be given a ' + '``' + role.name + '``' + ' role after approval',
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
CONFIGURED_CHANNEL: (data: Message | Interaction, channel: GuildChannel) => {
|
||||
return makeSuccessEmbed({
|
||||
title: 'Configured Membership Screening Channel',
|
||||
description: 'Anyone with ``VIEW_CHANNEL`` permission in ' + '``' + channel.name + '``' + ' can approve or deny request',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
description:
|
||||
'Anyone with ``VIEW_CHANNEL`` permission in ' +
|
||||
'``' +
|
||||
channel.name +
|
||||
'``' +
|
||||
' can approve or deny request',
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
INVALID_CHANNEL: (data: Message | Interaction, channel: GuildChannel) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Invalid channel type, only TextChannel is supported',
|
||||
description: '``' + channel.name + '``' + ' is not a text channel',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
INVALID_CHANNEL_THREAD: (data: Message | Interaction, channel: GuildChannel | ThreadChannel) => {
|
||||
INVALID_CHANNEL_THREAD: (
|
||||
data: Message | Interaction,
|
||||
channel: GuildChannel | ThreadChannel
|
||||
) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Thread channel is not supported',
|
||||
description: '``' + channel.name + '``' + ' is a thread channel. Please use a regular text channel',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
description:
|
||||
'``' +
|
||||
channel.name +
|
||||
'``' +
|
||||
' is a thread channel. Please use a regular text channel',
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
BOT_NO_PERMISSION: (data: Message | Interaction, channel: GuildChannel) => {
|
||||
return makeErrorEmbed({
|
||||
title: `I don't have permission`,
|
||||
description: 'I cannot access/send message in ' + '``' + channel.name + '``',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_LONGER_VALID_ROLE: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'The configured role is no longer valid. Please update the role in configuration',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
})
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
CANNOT_PERFORM_ASSIGN_ROLE: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Cannot grant the role to user, make sure I have permission to do that',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
CANNOT_PERFORM_ASSIGN_KICK: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Cannot kick the user, make sure I have permission to do that',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
})
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
CANNOT_PERFORM_ASSIGN_BAN: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Cannot ban the user, make sure I have permission to do that',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
})
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
CREATE_MESSAGE: () => {
|
||||
return makeInfoEmbed({
|
||||
@@ -161,15 +195,14 @@ const EMBEDS = {
|
||||
title: 'Welcome to this server!',
|
||||
description: `This server have membership screening enabled, **you'll have access to the server when the moderators let you in**.\n\nAlso please make sure that you acknowledged the common rules that everyone should be doing no matter where, Discord ToS (https://discordapp.com/terms)`,
|
||||
user: DiscordProvider.client.user
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class MembershipScreening extends DiscordModule {
|
||||
|
||||
public id = "Discord_MembershipScreening";
|
||||
public commands = ["membershipscreening", "ms"];
|
||||
public commandInteractionName = "membershipscreening";
|
||||
public id = 'Discord_MembershipScreening';
|
||||
public commands = ['membershipscreening', 'ms'];
|
||||
public commandInteractionName = 'membershipscreening';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -180,20 +213,22 @@ export default class MembershipScreening extends DiscordModule {
|
||||
}
|
||||
|
||||
async GuildButtonInteractionCreate(interaction: ButtonInteraction) {
|
||||
|
||||
const hybridData = new HybridInteractionMessage(interaction);
|
||||
const guild = hybridData.getGuild();
|
||||
const user = hybridData.getUser();
|
||||
const channel = hybridData.getChannel();
|
||||
|
||||
if(!guild || !user || !channel) return;
|
||||
if (!guild || !user || !channel) return;
|
||||
|
||||
if (!this.isJsonValid(interaction.customId)) return;
|
||||
const payload = JSON.parse(interaction.customId);
|
||||
|
||||
if (typeof payload.m === 'undefined' ||
|
||||
if (
|
||||
typeof payload.m === 'undefined' ||
|
||||
typeof payload.a === 'undefined' ||
|
||||
payload.m !== 'MembershipScreening') return;
|
||||
payload.m !== 'MembershipScreening'
|
||||
)
|
||||
return;
|
||||
|
||||
const message = await channel.messages.fetch(interaction.message.id);
|
||||
if (!message) return;
|
||||
@@ -204,75 +239,96 @@ export default class MembershipScreening extends DiscordModule {
|
||||
const PrismaGuild = await Prisma.client.guild.findFirst({ where: { id: guild.id } });
|
||||
if (!PrismaGuild) return;
|
||||
|
||||
if (!PrismaGuild.MembershipScreening_Enabled ||
|
||||
if (
|
||||
!PrismaGuild.MembershipScreening_Enabled ||
|
||||
PrismaGuild.MembershipScreening_ApprovalChannel === null ||
|
||||
PrismaGuild.MembershipScreening_GivenRole === null) return;
|
||||
PrismaGuild.MembershipScreening_GivenRole === null
|
||||
)
|
||||
return;
|
||||
|
||||
embed[0].footer = {
|
||||
text: `${interaction.user.username} | v${App.version}`,
|
||||
iconURL: `${interaction.user.displayAvatarURL()}?size=4096`
|
||||
}
|
||||
};
|
||||
|
||||
if (['approve', 'deny', 'ban'].includes(payload.a)) {
|
||||
|
||||
if (!payload.d.requester) return;
|
||||
|
||||
const role = (await guild.roles.fetch()).find(role => role.id === PrismaGuild.MembershipScreening_GivenRole);
|
||||
const requesterMember = (await guild.members.fetch()).find(member => member.id === payload.d.requester);
|
||||
const role = (await guild.roles.fetch()).find(
|
||||
(role) => role.id === PrismaGuild.MembershipScreening_GivenRole
|
||||
);
|
||||
const requesterMember = (await guild.members.fetch()).find(
|
||||
(member) => member.id === payload.d.requester
|
||||
);
|
||||
|
||||
if (!role)
|
||||
return await interaction.reply({ ephemeral: true, embeds: [EMBEDS.NO_LONGER_VALID_ROLE(interaction)] });
|
||||
return await interaction.reply({
|
||||
ephemeral: true,
|
||||
embeds: [EMBEDS.NO_LONGER_VALID_ROLE(interaction)]
|
||||
});
|
||||
|
||||
if (!requesterMember) {
|
||||
embed[0].addField("❌ Invalid", `Unable to find the user. User left already?`);
|
||||
embed[0].addField('❌ Invalid', `Unable to find the user. User left already?`);
|
||||
return await message.edit({ components: [], embeds: embed });
|
||||
}
|
||||
|
||||
if (requesterMember.roles.cache.has(PrismaGuild.MembershipScreening_GivenRole)) {
|
||||
embed[0].addField("✅ Approved", `By: Unknown (User already obtained the role by other means)`);
|
||||
embed[0].addField(
|
||||
'✅ Approved',
|
||||
`By: Unknown (User already obtained the role by other means)`
|
||||
);
|
||||
return await message.edit({ components: [], embeds: embed });
|
||||
}
|
||||
|
||||
if (payload.a === 'approve') {
|
||||
try {
|
||||
await requesterMember.roles.add(role);
|
||||
embed[0].addField("✅ Approved", `By: ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`);
|
||||
embed[0].addField(
|
||||
'✅ Approved',
|
||||
`By: ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`
|
||||
);
|
||||
await message.edit({ components: [], embeds: embed });
|
||||
} catch (err) {
|
||||
return interaction.reply({
|
||||
ephemeral: true,
|
||||
embeds: [EMBEDS.CANNOT_PERFORM_ASSIGN_ROLE(message)]
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
return interaction.reply({ ephemeral: true, embeds: [EMBEDS.CANNOT_PERFORM_ASSIGN_ROLE(message)] });
|
||||
}
|
||||
}
|
||||
|
||||
else if (payload.a === 'deny') {
|
||||
} else if (payload.a === 'deny') {
|
||||
try {
|
||||
await requesterMember.kick();
|
||||
embed[0].addField("❌ Denied", `By: ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`);
|
||||
embed[0].addField(
|
||||
'❌ Denied',
|
||||
`By: ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`
|
||||
);
|
||||
await message.edit({ components: [], embeds: embed });
|
||||
} catch (err) {
|
||||
return interaction.reply({
|
||||
ephemeral: true,
|
||||
embeds: [EMBEDS.CANNOT_PERFORM_ASSIGN_KICK(message)]
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
return interaction.reply({ ephemeral: true, embeds: [EMBEDS.CANNOT_PERFORM_ASSIGN_KICK(message)] });
|
||||
}
|
||||
}
|
||||
|
||||
else if (payload.a === 'ban') {
|
||||
} else if (payload.a === 'ban') {
|
||||
try {
|
||||
await requesterMember.ban({
|
||||
reason: `Membership Screening, action issued by ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`
|
||||
});
|
||||
embed[0].addField("🔪 Banned", `By: ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`);
|
||||
embed[0].addField(
|
||||
'🔪 Banned',
|
||||
`By: ${interaction.user.username}#${interaction.user.discriminator} (${interaction.user.id})`
|
||||
);
|
||||
await message.edit({ components: [], embeds: embed });
|
||||
}
|
||||
catch (err) {
|
||||
return interaction.reply({ ephemeral: true, embeds: [EMBEDS.CANNOT_PERFORM_ASSIGN_BAN(message)] });
|
||||
} catch (err) {
|
||||
return interaction.reply({
|
||||
ephemeral: true,
|
||||
embeds: [EMBEDS.CANNOT_PERFORM_ASSIGN_BAN(message)]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const user = data.getUser();
|
||||
const member = data.getMember();
|
||||
@@ -280,24 +336,32 @@ export default class MembershipScreening extends DiscordModule {
|
||||
|
||||
if (!guild || !user || !member || !channel) return;
|
||||
|
||||
const PrismaGuild = await Prisma.client.guild.findFirst({ where: { id: guild.id } })
|
||||
const PrismaGuild = await Prisma.client.guild.findFirst({ where: { id: guild.id } });
|
||||
if (!PrismaGuild) return;
|
||||
|
||||
|
||||
const funct = {
|
||||
enable: async (data: HybridInteractionMessage) => {
|
||||
if (!PrismaGuild.MembershipScreening_Enabled) {
|
||||
if (
|
||||
PrismaGuild.MembershipScreening_GivenRole === null ||
|
||||
PrismaGuild.MembershipScreening_ApprovalChannel == null
|
||||
)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_PARAMETER(data.getRaw())]
|
||||
});
|
||||
|
||||
if (PrismaGuild.MembershipScreening_GivenRole === null || PrismaGuild.MembershipScreening_ApprovalChannel == null)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PARAMETER(data.getRaw())] });
|
||||
await Prisma.client.guild.update({
|
||||
where: { id: guild.id },
|
||||
data: { MembershipScreening_Enabled: true }
|
||||
});
|
||||
|
||||
await Prisma.client.guild.update({ where: { id: guild.id }, data: { MembershipScreening_Enabled: true } });
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ENABLED(data.getRaw())] });
|
||||
}
|
||||
|
||||
else
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ALREADY_ENABLED(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ENABLED(data.getRaw())]
|
||||
});
|
||||
} else
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ALREADY_ENABLED(data.getRaw())]
|
||||
});
|
||||
},
|
||||
disable: async (data: HybridInteractionMessage) => {
|
||||
if (PrismaGuild.MembershipScreening_Enabled) {
|
||||
@@ -306,111 +370,150 @@ export default class MembershipScreening extends DiscordModule {
|
||||
data: { MembershipScreening_Enabled: false }
|
||||
});
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.DISABLED(data.getRaw())] });
|
||||
}
|
||||
else
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ALREADY_DISABLED(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.DISABLED(data.getRaw())]
|
||||
});
|
||||
} else
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ALREADY_DISABLED(data.getRaw())]
|
||||
});
|
||||
},
|
||||
setRole: async (data: HybridInteractionMessage) => {
|
||||
|
||||
let role: Role | undefined;
|
||||
|
||||
if (data.isMessage()) {
|
||||
let _name: string;
|
||||
if (typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_ROLE_MENTIONED(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_ROLE_MENTIONED(data.getRaw())]
|
||||
});
|
||||
|
||||
let __name = args;
|
||||
__name.shift();
|
||||
_name = __name.join(" ");
|
||||
_name = __name.join(' ');
|
||||
|
||||
role = data.getMessage().mentions.roles.first() || guild.roles.cache.find(role => role.name === _name);
|
||||
}
|
||||
else if (data.isSlashCommand())
|
||||
role = guild.roles.cache.find(role => role.id === data.getSlashCommand().options.getRole('role')?.id);
|
||||
role =
|
||||
data.getMessage().mentions.roles.first() ||
|
||||
guild.roles.cache.find((role) => role.name === _name);
|
||||
} else if (data.isSlashCommand())
|
||||
role = guild.roles.cache.find(
|
||||
(role) => role.id === data.getSlashCommand().options.getRole('role')?.id
|
||||
);
|
||||
|
||||
if (!role)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_ROLE_FOUND(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_ROLE_FOUND(data.getRaw())]
|
||||
});
|
||||
|
||||
if (role.managed)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.MANAGED_ROLE(data.getRaw(), role)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.MANAGED_ROLE(data.getRaw(), role)]
|
||||
});
|
||||
|
||||
await Prisma.client.guild.update({ where: { id: guild.id }, data: { MembershipScreening_GivenRole: role.id } });
|
||||
await Prisma.client.guild.update({
|
||||
where: { id: guild.id },
|
||||
data: { MembershipScreening_GivenRole: role.id }
|
||||
});
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.CONFIGURED_ROLE(data.getRaw(), role)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.CONFIGURED_ROLE(data.getRaw(), role)]
|
||||
});
|
||||
},
|
||||
setChannel: async (data: HybridInteractionMessage) => {
|
||||
|
||||
let mentionChannel;
|
||||
if (data.isMessage()) {
|
||||
if (!args[1])
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_CHANNEL_MENTIONED(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_CHANNEL_MENTIONED(data.getRaw())]
|
||||
});
|
||||
mentionChannel = data.getMessage().mentions.channels.first();
|
||||
}
|
||||
else if (data.isSlashCommand())
|
||||
} else if (data.isSlashCommand())
|
||||
mentionChannel = data.getSlashCommand().options.getChannel('channel');
|
||||
|
||||
if (!mentionChannel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_CHANNEL_FOUND(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_CHANNEL_FOUND(data.getRaw())]
|
||||
});
|
||||
|
||||
let TargetChannel = guild.channels.cache.get(mentionChannel.id);
|
||||
if (!TargetChannel) return;
|
||||
|
||||
if (TargetChannel instanceof ThreadChannel || TargetChannel.isThread())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_CHANNEL_THREAD(data.getRaw(), TargetChannel)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.INVALID_CHANNEL_THREAD(data.getRaw(), TargetChannel)]
|
||||
});
|
||||
|
||||
if (!TargetChannel.isText())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_CHANNEL(data.getRaw(), TargetChannel)] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.INVALID_CHANNEL(data.getRaw(), TargetChannel)]
|
||||
});
|
||||
|
||||
if (!(guild.me!.permissionsIn(TargetChannel).has([Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.VIEW_CHANNEL])))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.BOT_NO_PERMISSION(data.getRaw(), TargetChannel)] });
|
||||
if (
|
||||
!guild
|
||||
.me!.permissionsIn(TargetChannel)
|
||||
.has([Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.VIEW_CHANNEL])
|
||||
)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.BOT_NO_PERMISSION(data.getRaw(), TargetChannel)]
|
||||
});
|
||||
|
||||
await Prisma.client.guild.update({ where: { id: guild.id }, data: { MembershipScreening_ApprovalChannel: mentionChannel.id } });
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.CONFIGURED_CHANNEL(data.getRaw(), TargetChannel)] });
|
||||
await Prisma.client.guild.update({
|
||||
where: { id: guild.id },
|
||||
data: { MembershipScreening_ApprovalChannel: mentionChannel.id }
|
||||
});
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.CONFIGURED_CHANNEL(data.getRaw(), TargetChannel)]
|
||||
});
|
||||
},
|
||||
createMessage: async (data: HybridInteractionMessage) => {
|
||||
if(data.isMessage())
|
||||
return await sendMessage(channel, undefined, { embeds: [EMBEDS.CREATE_MESSAGE()] });
|
||||
else if(data.isSlashCommand()) {
|
||||
await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.MESSAGE_CREATED(data.getRaw())] });
|
||||
return await sendMessage(channel, undefined, { embeds: [EMBEDS.CREATE_MESSAGE()] });
|
||||
if (data.isMessage())
|
||||
return await sendMessage(channel, undefined, {
|
||||
embeds: [EMBEDS.CREATE_MESSAGE()]
|
||||
});
|
||||
else if (data.isSlashCommand()) {
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.MESSAGE_CREATED(data.getRaw())]
|
||||
});
|
||||
return await sendMessage(channel, undefined, {
|
||||
embeds: [EMBEDS.CREATE_MESSAGE()]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let query;
|
||||
|
||||
if (!member.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_PERMISSION(data.getRaw())]
|
||||
});
|
||||
|
||||
if (data.isMessage()) {
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.MSINFO(data.getRaw())] });
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.MSINFO(data.getRaw())]
|
||||
});
|
||||
|
||||
query = args[0].toLowerCase();
|
||||
}
|
||||
else if (data.isSlashCommand())
|
||||
query = args.getSubcommand();
|
||||
} else if (data.isSlashCommand()) query = args.getSubcommand();
|
||||
|
||||
switch (query) {
|
||||
case "enable":
|
||||
case "on":
|
||||
case 'enable':
|
||||
case 'on':
|
||||
return await funct.enable(data);
|
||||
case "disable":
|
||||
case "off":
|
||||
case 'disable':
|
||||
case 'off':
|
||||
return await funct.disable(data);
|
||||
case "setrole":
|
||||
case 'setrole':
|
||||
return await funct.setRole(data);
|
||||
case "setchannel":
|
||||
case 'setchannel':
|
||||
return await funct.setChannel(data);
|
||||
case "createmessage":
|
||||
case 'createmessage':
|
||||
return await funct.createMessage(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async GuildMemberAdd(member: GuildMember) {
|
||||
|
||||
if (member.user.bot) return;
|
||||
|
||||
const Guild = await Prisma.client.guild.findFirst({ where: { id: member.guild.id } });
|
||||
@@ -422,7 +525,9 @@ export default class MembershipScreening extends DiscordModule {
|
||||
|
||||
let channel = undefined;
|
||||
try {
|
||||
channel = await DiscordProvider.client.channels.fetch(Guild.MembershipScreening_ApprovalChannel) as TextChannel;
|
||||
channel = (await DiscordProvider.client.channels.fetch(
|
||||
Guild.MembershipScreening_ApprovalChannel
|
||||
)) as TextChannel;
|
||||
} catch (err) {
|
||||
// TODO: Handle channel not found error
|
||||
return;
|
||||
@@ -434,8 +539,10 @@ export default class MembershipScreening extends DiscordModule {
|
||||
description: `${member.user.username}#${member.user.discriminator} (${member.user.id})`,
|
||||
fields: [
|
||||
{
|
||||
name: "Account Information",
|
||||
value: `Account age: <t:${Math.round(member.user.createdAt.getTime() / 1000)}:R>`
|
||||
name: 'Account Information',
|
||||
value: `Account age: <t:${Math.round(
|
||||
member.user.createdAt.getTime() / 1000
|
||||
)}:R>`
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -445,43 +552,49 @@ export default class MembershipScreening extends DiscordModule {
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setCustomId(JSON.stringify({
|
||||
m: 'MembershipScreening',
|
||||
a: 'approve',
|
||||
d: {
|
||||
requester: member.id
|
||||
}
|
||||
}))
|
||||
.setCustomId(
|
||||
JSON.stringify({
|
||||
m: 'MembershipScreening',
|
||||
a: 'approve',
|
||||
d: {
|
||||
requester: member.id
|
||||
}
|
||||
})
|
||||
)
|
||||
.setEmoji('✅')
|
||||
.setLabel(' Approve')
|
||||
.setStyle('SUCCESS'),
|
||||
.setStyle('SUCCESS')
|
||||
)
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setCustomId(JSON.stringify({
|
||||
m: 'MembershipScreening',
|
||||
a: 'deny',
|
||||
d: {
|
||||
requester: member.id
|
||||
}
|
||||
}))
|
||||
.setCustomId(
|
||||
JSON.stringify({
|
||||
m: 'MembershipScreening',
|
||||
a: 'deny',
|
||||
d: {
|
||||
requester: member.id
|
||||
}
|
||||
})
|
||||
)
|
||||
.setEmoji('⛔')
|
||||
.setLabel(' Deny and kick')
|
||||
.setStyle('DANGER'),
|
||||
.setStyle('DANGER')
|
||||
)
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setCustomId(JSON.stringify({
|
||||
m: 'MembershipScreening',
|
||||
a: 'ban',
|
||||
d: {
|
||||
requester: member.id
|
||||
}
|
||||
}))
|
||||
.setCustomId(
|
||||
JSON.stringify({
|
||||
m: 'MembershipScreening',
|
||||
a: 'ban',
|
||||
d: {
|
||||
requester: member.id
|
||||
}
|
||||
})
|
||||
)
|
||||
.setEmoji('🔪')
|
||||
.setLabel(' Vision Hunt Decree (Ban)')
|
||||
.setStyle('DANGER'),
|
||||
)
|
||||
.setStyle('DANGER')
|
||||
);
|
||||
|
||||
await channel.send({ content: '\u200b', embeds: [embed], components: [row] });
|
||||
}
|
||||
@@ -489,13 +602,12 @@ export default class MembershipScreening extends DiscordModule {
|
||||
private isJsonValid(jsonString: string) {
|
||||
try {
|
||||
let o = JSON.parse(jsonString);
|
||||
if (o && typeof o === "object") {
|
||||
if (o && typeof o === 'object') {
|
||||
return true;
|
||||
//return o;
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
} catch (e) {}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+79
-56
@@ -1,19 +1,23 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||
import { CommandInteraction, Message, Interaction } from 'discord.js';
|
||||
import os from 'os';
|
||||
import NodePing from 'ping';
|
||||
import { Promise } from 'bluebird';
|
||||
|
||||
import { CommandInteraction, Message, Interaction } from "discord.js";
|
||||
import { makeSuccessEmbed, makeProcessingEmbed, sendHybridInteractionMessageResponse } from "../utils/DiscordMessage";
|
||||
import Configuration from '../providers/Configuration';
|
||||
import DiscordProvider from '../providers/Discord';
|
||||
import Environment from '../providers/Environment';
|
||||
|
||||
import DiscordProvider from "../providers/Discord";
|
||||
import NodePing from "ping";
|
||||
import { Promise } from "bluebird";
|
||||
import os from "os";
|
||||
import Environment from "../providers/Environment";
|
||||
import Configuration from "../providers/Configuration";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import {
|
||||
makeSuccessEmbed,
|
||||
makeProcessingEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../utils/DiscordMessage';
|
||||
|
||||
enum MeasureType {
|
||||
Ping = "ping",
|
||||
DiscordHTTPPing = "discordhttp",
|
||||
DiscordWebsocket = "discordwebsocket"
|
||||
Ping = 'ping',
|
||||
DiscordHTTPPing = 'discordhttp',
|
||||
DiscordWebsocket = 'discordwebsocket'
|
||||
}
|
||||
|
||||
const EMBEDS = {
|
||||
@@ -22,23 +26,22 @@ const EMBEDS = {
|
||||
icon: '🌎',
|
||||
title: `Network performance`,
|
||||
description: description,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
PINGING: (data: HybridInteractionMessage) => {
|
||||
return makeProcessingEmbed({
|
||||
icon: data.isMessage() ? undefined : '⌛',
|
||||
title: `Measuring network performance`,
|
||||
user: (data.isInteraction()) ? data.getInteraction().user : data.getMessage().author
|
||||
user: data.isInteraction() ? data.getInteraction().user : data.getMessage().author
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Ping extends DiscordModule {
|
||||
|
||||
public id = "Discord_Ping";
|
||||
public commands = ["ping"];
|
||||
public commandInteractionName = "ping";
|
||||
public id = 'Discord_Ping';
|
||||
public commands = ['ping'];
|
||||
public commandInteractionName = 'ping';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
@@ -49,57 +52,77 @@ export default class Ping extends DiscordModule {
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
let placeholder: (HybridInteractionMessage | undefined);
|
||||
let placeholder: HybridInteractionMessage | undefined;
|
||||
|
||||
let beforeEditDate = Date.now();
|
||||
|
||||
let _placeholder = await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PINGING(data)] });
|
||||
if (_placeholder)
|
||||
placeholder = new HybridInteractionMessage(_placeholder);
|
||||
let _placeholder = await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PINGING(data)]
|
||||
});
|
||||
if (_placeholder) placeholder = new HybridInteractionMessage(_placeholder);
|
||||
|
||||
let afterEditDate = Date.now();
|
||||
|
||||
|
||||
let finalString = [];
|
||||
|
||||
await Promise.map(Configuration.getConfig("Ping"), (entry: any) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let stringCurrent = `${entry.title}`;
|
||||
await Promise.map(
|
||||
Configuration.getConfig('Ping'),
|
||||
(entry: any) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let stringCurrent = `${entry.title}`;
|
||||
|
||||
if (entry.type === MeasureType.Ping) {
|
||||
const res = await NodePing.promise.probe(entry.host!, { min_reply: 4 });
|
||||
if (entry.type === MeasureType.Ping) {
|
||||
const res = await NodePing.promise.probe(entry.host!, { min_reply: 4 });
|
||||
|
||||
if (!res.alive) {
|
||||
stringCurrent += "Failed";
|
||||
return finalString.push(stringCurrent);
|
||||
if (!res.alive) {
|
||||
stringCurrent += 'Failed';
|
||||
return finalString.push(stringCurrent);
|
||||
}
|
||||
|
||||
if (
|
||||
res.avg === 'unknown' ||
|
||||
res.min === 'unknown' ||
|
||||
res.max === 'unknown'
|
||||
) {
|
||||
stringCurrent += 'Failed';
|
||||
return finalString.push(stringCurrent);
|
||||
}
|
||||
|
||||
stringCurrent += `${parseFloat(res.avg).toFixed(1)}ms (${parseFloat(
|
||||
res.min
|
||||
).toFixed(1)}ms - ${parseFloat(res.max).toFixed(1)}ms)`;
|
||||
finalString.push(stringCurrent);
|
||||
} else if (entry.type === MeasureType.DiscordWebsocket) {
|
||||
stringCurrent += `${Math.round(DiscordProvider.client.ws.ping).toFixed(
|
||||
1
|
||||
)}ms`;
|
||||
finalString.push(stringCurrent);
|
||||
} else if (entry.type === MeasureType.DiscordHTTPPing) {
|
||||
stringCurrent += `${Math.abs(afterEditDate - beforeEditDate).toFixed(1)}ms`;
|
||||
finalString.push(stringCurrent);
|
||||
}
|
||||
|
||||
if (res.avg === 'unknown' || res.min === 'unknown' || res.max === 'unknown') {
|
||||
stringCurrent += "Failed";
|
||||
return finalString.push(stringCurrent);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
},
|
||||
{ concurrency: 5 }
|
||||
);
|
||||
|
||||
stringCurrent += `${parseFloat(res.avg).toFixed(1)}ms (${parseFloat(res.min).toFixed(1)}ms - ${parseFloat(res.max).toFixed(1)}ms)`;
|
||||
finalString.push(stringCurrent);
|
||||
} else if (entry.type === MeasureType.DiscordWebsocket) {
|
||||
stringCurrent += `${Math.round(DiscordProvider.client.ws.ping).toFixed(1)}ms`;
|
||||
finalString.push(stringCurrent);
|
||||
} else if (entry.type === MeasureType.DiscordHTTPPing) {
|
||||
stringCurrent += `${Math.abs(afterEditDate - beforeEditDate).toFixed(1)}ms`;
|
||||
finalString.push(stringCurrent);
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
}, { concurrency: 5 });
|
||||
|
||||
finalString.push("");
|
||||
finalString.push("💻 Running on " + `${os.hostname()}${Environment.get().NODE_ENV === "development" ? ' / Development Environment' : ''}`);
|
||||
finalString.push('');
|
||||
finalString.push(
|
||||
'💻 Running on ' +
|
||||
`${os.hostname()}${
|
||||
Environment.get().NODE_ENV === 'development' ? ' / Development Environment' : ''
|
||||
}`
|
||||
);
|
||||
|
||||
if (data.isSlashCommand())
|
||||
return await data.getMessageComponentInteraction().editReply({ embeds: [EMBEDS.PING_INFO(data.getRaw(), finalString.join('\n'))] });
|
||||
return await data
|
||||
.getMessageComponentInteraction()
|
||||
.editReply({ embeds: [EMBEDS.PING_INFO(data.getRaw(), finalString.join('\n'))] });
|
||||
else if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return await placeholder.getMessage().edit({ embeds: [EMBEDS.PING_INFO(data.getRaw(), finalString.join('\n'))] });
|
||||
return await placeholder
|
||||
.getMessage()
|
||||
.edit({ embeds: [EMBEDS.PING_INFO(data.getRaw(), finalString.join('\n'))] });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+53
-35
@@ -1,11 +1,16 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||
import { Message, Permissions, Interaction, CommandInteraction } from 'discord.js';
|
||||
|
||||
import { Message, Permissions, Interaction, CommandInteraction } from "discord.js";
|
||||
import { makeSuccessEmbed, sendHybridInteractionMessageResponse, makeErrorEmbed, makeInfoEmbed } from "../utils/DiscordMessage";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import {
|
||||
makeSuccessEmbed,
|
||||
sendHybridInteractionMessageResponse,
|
||||
makeErrorEmbed,
|
||||
makeInfoEmbed
|
||||
} from '../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
SAY_INFO: (data: Message | Interaction) => {
|
||||
return makeInfoEmbed ({
|
||||
return makeInfoEmbed({
|
||||
title: 'Say',
|
||||
description: `Make me say something!`,
|
||||
fields: [
|
||||
@@ -14,73 +19,86 @@ const EMBEDS = {
|
||||
value: '``Your message``'
|
||||
}
|
||||
],
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_PERMISSION: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: 'You need ``VIEW_CHANNEL, SEND_MESSAGES and MANAGE_CHANNELS`` permission on this guild!',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
SUCCESSFULLY_SAID: (data: Message | Interaction) => {
|
||||
return makeSuccessEmbed ({
|
||||
return makeSuccessEmbed({
|
||||
title: 'Successfully said',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Say extends DiscordModule {
|
||||
|
||||
public id = "Discord_Say";
|
||||
public commands = ["say"];
|
||||
public commandInteractionName = "say";
|
||||
public id = 'Discord_Say';
|
||||
public commands = ['say'];
|
||||
public commandInteractionName = 'say';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
let query;
|
||||
|
||||
if(data.isMessage()) {
|
||||
if (data.isMessage()) {
|
||||
const message = data.getMessage();
|
||||
|
||||
if(!message.member) return;
|
||||
if (!message.member) return;
|
||||
|
||||
if (!message.member.permissions.has([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.MANAGE_CHANNELS]))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data.getRaw())] });
|
||||
if (
|
||||
!message.member.permissions.has([
|
||||
Permissions.FLAGS.VIEW_CHANNEL,
|
||||
Permissions.FLAGS.SEND_MESSAGES,
|
||||
Permissions.FLAGS.MANAGE_CHANNELS
|
||||
])
|
||||
)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_PERMISSION(data.getRaw())]
|
||||
});
|
||||
|
||||
if(args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SAY_INFO(data.getRaw())] });
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SAY_INFO(data.getRaw())]
|
||||
});
|
||||
|
||||
query = args.join(" ");
|
||||
}
|
||||
else if(data.isSlashCommand()) {
|
||||
query = args.join(' ');
|
||||
} else if (data.isSlashCommand()) {
|
||||
const interaction = data.getSlashCommand();
|
||||
if(!data.getGuild()!.members.cache.get(interaction.user.id)?.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data.getRaw())] });
|
||||
if (
|
||||
!data
|
||||
.getGuild()!
|
||||
.members.cache.get(interaction.user.id)
|
||||
?.permissions.has([Permissions.FLAGS.ADMINISTRATOR])
|
||||
)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_PERMISSION(data.getRaw())]
|
||||
});
|
||||
|
||||
query = interaction.options.getString('message');
|
||||
}
|
||||
|
||||
if(data.isSlashCommand() && data.getChannel()) {
|
||||
if (data.isSlashCommand() && data.getChannel()) {
|
||||
await data.getChannel()!.send({ content: query });
|
||||
await data.getMessageComponentInteraction().reply({ ephemeral: true, embeds: [EMBEDS.SUCCESSFULLY_SAID(data.getRaw())] });
|
||||
}
|
||||
else if(data.isMessage()) {
|
||||
await data
|
||||
.getMessageComponentInteraction()
|
||||
.reply({ ephemeral: true, embeds: [EMBEDS.SUCCESSFULLY_SAID(data.getRaw())] });
|
||||
} else if (data.isMessage()) {
|
||||
const message = data.getMessage();
|
||||
if(message.deletable)
|
||||
await message.delete();
|
||||
if (message.deletable) await message.delete();
|
||||
|
||||
await data.getChannel()!.send({ content: query });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+279
-154
@@ -1,10 +1,24 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||
import {
|
||||
Message,
|
||||
Interaction,
|
||||
CommandInteraction,
|
||||
Permissions,
|
||||
ThreadChannel,
|
||||
GuildChannel
|
||||
} from 'discord.js';
|
||||
|
||||
import { Message, Interaction, CommandInteraction, Permissions, ThreadChannel, GuildChannel } from "discord.js";
|
||||
import { makeInfoEmbed, makeErrorEmbed, makeSuccessEmbed, makeProcessingEmbed, sendHybridInteractionMessageResponse } from "../utils/DiscordMessage";
|
||||
import DiscordProvider from "../providers/Discord";
|
||||
import Prisma from "../providers/Prisma";
|
||||
import Cache from "../providers/Cache";
|
||||
import DiscordProvider from '../providers/Discord';
|
||||
import Prisma from '../providers/Prisma';
|
||||
import Cache from '../providers/Cache';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import {
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
makeSuccessEmbed,
|
||||
makeProcessingEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
SETTINGS_INFO: (data: Message | Interaction) => {
|
||||
@@ -17,312 +31,423 @@ const EMBEDS = {
|
||||
value: '``setPrefix`` ``setEnableServiceAnnouncement`` ``setServiceAnnouncementChannel``'
|
||||
}
|
||||
],
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
PROCESSING: (data: HybridInteractionMessage) => {
|
||||
return makeProcessingEmbed({
|
||||
icon: (data.isMessage()) ? undefined : '⌛',
|
||||
icon: data.isMessage() ? undefined : '⌛',
|
||||
title: `Performing actions`,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
NO_PERMISSION: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: 'You need ``ADMINISTRATOR`` permission on this guild!',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_PREFIX_PROVIDED: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: 'No prefix provided',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
SERVICE_ANNOUNCEMENT_INVALID_STATUS: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: 'Invalid status, Use ``true`` or ``false``',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED: async (data: Message | Interaction) => {
|
||||
let GuildCache = await Cache.getGuild(data.guild!.id);
|
||||
|
||||
// TODO: Better error handling
|
||||
if(typeof GuildCache === 'undefined')
|
||||
throw new Error('Guild not found');
|
||||
|
||||
return makeInfoEmbed ({
|
||||
if (typeof GuildCache === 'undefined') throw new Error('Guild not found');
|
||||
|
||||
return makeInfoEmbed({
|
||||
title: 'Service Announcement',
|
||||
description: `Service Announcement is ${GuildCache.ServiceAnnouncement_Enabled ? "**enabled**" : "**disabled**"} on this server`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
description: `Service Announcement is ${
|
||||
GuildCache.ServiceAnnouncement_Enabled ? '**enabled**' : '**disabled**'
|
||||
} on this server`,
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
PREFIX_TOO_LONG: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: 'Prefix too long',
|
||||
description: `I bet you can't even remember that`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
PREFIX_IS_MENTION: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: 'Prefix cannot be mention of me',
|
||||
description: `You can already call me by mentioning me. I got that covered, don't worry`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
PREFIX_UPDATED: (data: Message | Interaction, newPrefix: string) => {
|
||||
return makeSuccessEmbed ({
|
||||
return makeSuccessEmbed({
|
||||
title: 'Prefix Updated',
|
||||
description: `From now onwards, I shall be called by using \`\`${newPrefix}\`\``,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
SERVICE_ANNOUNCEMENT_STATUS_UPDATED: (data: Message | Interaction, newStatus: boolean) => {
|
||||
return makeSuccessEmbed ({
|
||||
title: `Service Announcement is now ${newStatus ? "enabled" : "disabled"}`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
return makeSuccessEmbed({
|
||||
title: `Service Announcement is now ${newStatus ? 'enabled' : 'disabled'}`,
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
SERVICE_ANNOUNCEMENT_STATUS_ALREADY_SET: (data: Message | Interaction, status: boolean) => {
|
||||
return makeInfoEmbed ({
|
||||
title: `Service Announcement is already ${status ? "enabled" : "disabled"}`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
return makeInfoEmbed({
|
||||
title: `Service Announcement is already ${status ? 'enabled' : 'disabled'}`,
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
SERVICE_ANNOUNCEMENT_NO_PARAMETER: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: 'Missing parameter',
|
||||
description: `You must define service announcement channel to enable this feature`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_CHANNEL_MENTIONED: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: 'No channel mentioned',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_CHANNEL_FOUND: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: 'Cannot find that channel',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
INVALID_CHANNEL: (data: Message | Interaction, channel: GuildChannel) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: 'Invalid channel type, only TextChannel is supported',
|
||||
description: '``' + channel.name +'``' + ' is not a text channel',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
description: '``' + channel.name + '``' + ' is not a text channel',
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
INVALID_CHANNEL_THREAD: (data: Message | Interaction, channel: GuildChannel | ThreadChannel) => {
|
||||
return makeErrorEmbed ({
|
||||
INVALID_CHANNEL_THREAD: (
|
||||
data: Message | Interaction,
|
||||
channel: GuildChannel | ThreadChannel
|
||||
) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Thread channel is not supported',
|
||||
description: '``' + channel.name +'``' + ' is a thread channel. Please use a regular text channel',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
description:
|
||||
'``' +
|
||||
channel.name +
|
||||
'``' +
|
||||
' is a thread channel. Please use a regular text channel',
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
BOT_NO_PERMISSION: (data: Message | Interaction, channel: GuildChannel) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: `I don't have permission`,
|
||||
description: 'I cannot access/send message in ' + '``' + channel.name +'``',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
description: 'I cannot access/send message in ' + '``' + channel.name + '``',
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
SERVICE_ANNOUNCEMENT_CONFIGURED_CHANNEL: (data: Message | Interaction, channel: GuildChannel) => {
|
||||
return makeSuccessEmbed ({
|
||||
SERVICE_ANNOUNCEMENT_CONFIGURED_CHANNEL: (
|
||||
data: Message | Interaction,
|
||||
channel: GuildChannel
|
||||
) => {
|
||||
return makeSuccessEmbed({
|
||||
title: 'Configured Service Announcement Channel',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Settings extends DiscordModule {
|
||||
|
||||
public id = "Discord_Settings";
|
||||
public commands = ["settings"];
|
||||
public commandInteractionName = "settings";
|
||||
public id = 'Discord_Settings';
|
||||
public commands = ['settings'];
|
||||
public commandInteractionName = 'settings';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.getGuild()!.id }})
|
||||
if(!Guild) return;
|
||||
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.getGuild()!.id } });
|
||||
if (!Guild) return;
|
||||
|
||||
const funct = {
|
||||
setPrefix: async(data: HybridInteractionMessage) => {
|
||||
|
||||
setPrefix: async (data: HybridInteractionMessage) => {
|
||||
let member = data.getMember();
|
||||
if(!member) return;
|
||||
if (!member) return;
|
||||
|
||||
if (!member.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_PERMISSION(data.getRaw())]
|
||||
});
|
||||
|
||||
let newPrefix: string | null | undefined;
|
||||
if(data.isMessage()) {
|
||||
if (data.isMessage()) {
|
||||
let _name: string;
|
||||
if(typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PREFIX_PROVIDED(data.getRaw())] });
|
||||
if (typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_PREFIX_PROVIDED(data.getRaw())]
|
||||
});
|
||||
|
||||
let __name = args;
|
||||
__name.shift();
|
||||
_name = __name.join(" ");
|
||||
_name = __name.join(' ');
|
||||
newPrefix = _name;
|
||||
}
|
||||
else if(data.isSlashCommand())
|
||||
} else if (data.isSlashCommand())
|
||||
newPrefix = data.getSlashCommand().options.getString('prefix');
|
||||
|
||||
if(!newPrefix)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PREFIX_PROVIDED(data.getRaw())] });
|
||||
if (!newPrefix)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_PREFIX_PROVIDED(data.getRaw())]
|
||||
});
|
||||
|
||||
if(newPrefix.length > 200)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PREFIX_TOO_LONG(data.getRaw())] });
|
||||
if (newPrefix.length > 200)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PREFIX_TOO_LONG(data.getRaw())]
|
||||
});
|
||||
|
||||
if(newPrefix.startsWith(`<@!${DiscordProvider.client.user?.id}>`))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PREFIX_IS_MENTION(data.getRaw())] });
|
||||
if (newPrefix.startsWith(`<@!${DiscordProvider.client.user?.id}>`))
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PREFIX_IS_MENTION(data.getRaw())]
|
||||
});
|
||||
|
||||
let placeholder: (HybridInteractionMessage | undefined);
|
||||
let placeholder: HybridInteractionMessage | undefined;
|
||||
|
||||
let _placeholder = await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PROCESSING(data)] });
|
||||
if (_placeholder)
|
||||
placeholder = new HybridInteractionMessage(_placeholder);
|
||||
let _placeholder = await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PROCESSING(data)]
|
||||
});
|
||||
if (_placeholder) placeholder = new HybridInteractionMessage(_placeholder);
|
||||
|
||||
await Prisma.client.guild.update({ where: { id: data.getGuild()!.id }, data: { prefix: newPrefix }});
|
||||
await Prisma.client.guild.update({
|
||||
where: { id: data.getGuild()!.id },
|
||||
data: { prefix: newPrefix }
|
||||
});
|
||||
Cache.updateGuildCache(data.getGuild()!.id);
|
||||
|
||||
if(data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.PREFIX_UPDATED(data.getRaw(), newPrefix)] });
|
||||
else if(data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PREFIX_UPDATED(data.getRaw(), newPrefix)]}, true);
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({ embeds: [EMBEDS.PREFIX_UPDATED(data.getRaw(), newPrefix)] });
|
||||
else if (data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.PREFIX_UPDATED(data.getRaw(), newPrefix)] },
|
||||
true
|
||||
);
|
||||
},
|
||||
setEnableServiceAnnouncement: async(data: HybridInteractionMessage) => {
|
||||
|
||||
setEnableServiceAnnouncement: async (data: HybridInteractionMessage) => {
|
||||
let member = data.getMember();
|
||||
if(!member) return;
|
||||
if (!member) return;
|
||||
|
||||
if (!member.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_PERMISSION(data.getRaw())]
|
||||
});
|
||||
|
||||
let newStatus: string | null | undefined;
|
||||
if(data.isMessage()) {
|
||||
if (data.isMessage()) {
|
||||
let _name: string;
|
||||
if(typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(data.getRaw())] });
|
||||
if (typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [
|
||||
await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(data.getRaw())
|
||||
]
|
||||
});
|
||||
|
||||
let __name = args;
|
||||
__name.shift();
|
||||
_name = __name.join(" ");
|
||||
_name = __name.join(' ');
|
||||
newStatus = _name;
|
||||
}
|
||||
else if(data.isSlashCommand())
|
||||
} else if (data.isSlashCommand())
|
||||
newStatus = data.getSlashCommand().options.getString('status')!;
|
||||
|
||||
if(!newStatus)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(data.getRaw())] });
|
||||
if (!newStatus)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [
|
||||
await EMBEDS.NO_SERVICE_ANNOUNCEMENT_STATUS_PROVIDED(data.getRaw())
|
||||
]
|
||||
});
|
||||
|
||||
if(!["true", "false", "yes", "no", "y", "n", "enable", "disable"].includes(newStatus.toLowerCase()))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_INVALID_STATUS(data.getRaw())] });
|
||||
if (
|
||||
!['true', 'false', 'yes', 'no', 'y', 'n', 'enable', 'disable'].includes(
|
||||
newStatus.toLowerCase()
|
||||
)
|
||||
)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_INVALID_STATUS(data.getRaw())]
|
||||
});
|
||||
|
||||
await Cache.updateGuildCache(data.getGuild()!.id);
|
||||
let GuildCache = await Cache.getGuild(data.getGuild()!.id);
|
||||
|
||||
const newStatusBool = ["true", "yes", "y", "enable"].includes(newStatus.toLowerCase()) ? true : false;
|
||||
const newStatusBool = ['true', 'yes', 'y', 'enable'].includes(
|
||||
newStatus.toLowerCase()
|
||||
)
|
||||
? true
|
||||
: false;
|
||||
|
||||
if(GuildCache?.ServiceAnnouncement_Enabled === newStatusBool)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_STATUS_ALREADY_SET(data.getRaw(), newStatusBool)] });
|
||||
if (GuildCache?.ServiceAnnouncement_Enabled === newStatusBool)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [
|
||||
EMBEDS.SERVICE_ANNOUNCEMENT_STATUS_ALREADY_SET(
|
||||
data.getRaw(),
|
||||
newStatusBool
|
||||
)
|
||||
]
|
||||
});
|
||||
|
||||
if(GuildCache?.ServiceAnnouncement_Channel === null)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_NO_PARAMETER(data.getRaw())] });
|
||||
if (GuildCache?.ServiceAnnouncement_Channel === null)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_NO_PARAMETER(data.getRaw())]
|
||||
});
|
||||
|
||||
let placeholder = await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PROCESSING(data)] });
|
||||
let placeholder = await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PROCESSING(data)]
|
||||
});
|
||||
|
||||
await Prisma.client.guild.update(
|
||||
{ where: { id: data.getGuild()!.id },
|
||||
data: {
|
||||
await Prisma.client.guild.update({
|
||||
where: { id: data.getGuild()!.id },
|
||||
data: {
|
||||
ServiceAnnouncement_Enabled: newStatusBool
|
||||
}
|
||||
});
|
||||
Cache.updateGuildCache(data.getGuild()!.id);
|
||||
|
||||
if(data.isMessage())
|
||||
return await (placeholder as Message).edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_STATUS_UPDATED(data.getRaw(), newStatusBool)]});
|
||||
else if(data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_STATUS_UPDATED(data.getRaw(), newStatusBool)]}, true);
|
||||
if (data.isMessage())
|
||||
return await (placeholder as Message).edit({
|
||||
embeds: [
|
||||
EMBEDS.SERVICE_ANNOUNCEMENT_STATUS_UPDATED(data.getRaw(), newStatusBool)
|
||||
]
|
||||
});
|
||||
else if (data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{
|
||||
embeds: [
|
||||
EMBEDS.SERVICE_ANNOUNCEMENT_STATUS_UPDATED(
|
||||
data.getRaw(),
|
||||
newStatusBool
|
||||
)
|
||||
]
|
||||
},
|
||||
true
|
||||
);
|
||||
},
|
||||
setServiceAnnouncementChannel: async(data: HybridInteractionMessage) => {
|
||||
|
||||
setServiceAnnouncementChannel: async (data: HybridInteractionMessage) => {
|
||||
let member = data.getMember();
|
||||
if(!member) return;
|
||||
if (!member) return;
|
||||
|
||||
if (!member.permissions.has([Permissions.FLAGS.ADMINISTRATOR]))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_PERMISSION(data.getRaw())] });
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_PERMISSION(data.getRaw())]
|
||||
});
|
||||
|
||||
let channel;
|
||||
if(data.isMessage()) {
|
||||
if(typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_CHANNEL_MENTIONED(data.getRaw())] });
|
||||
if (data.isMessage()) {
|
||||
if (typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_CHANNEL_MENTIONED(data.getRaw())]
|
||||
});
|
||||
channel = data.getMessage().mentions.channels.first();
|
||||
}
|
||||
else if(data.isSlashCommand())
|
||||
} else if (data.isSlashCommand())
|
||||
channel = data.getSlashCommand().options.getChannel('channel');
|
||||
|
||||
if(!channel)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_CHANNEL_FOUND(data.getRaw())] });
|
||||
|
||||
if (!channel)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_CHANNEL_FOUND(data.getRaw())]
|
||||
});
|
||||
|
||||
let TargetChannel = data.getGuild()!.channels.cache.get(channel.id);
|
||||
if(typeof TargetChannel === 'undefined') return;
|
||||
if (typeof TargetChannel === 'undefined') return;
|
||||
|
||||
if(TargetChannel instanceof ThreadChannel || TargetChannel.isThread())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_CHANNEL_THREAD(data.getRaw(), TargetChannel)] });
|
||||
if (TargetChannel instanceof ThreadChannel || TargetChannel.isThread())
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.INVALID_CHANNEL_THREAD(data.getRaw(), TargetChannel)]
|
||||
});
|
||||
|
||||
if(!TargetChannel.isText())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_CHANNEL(data.getRaw(), TargetChannel)] });
|
||||
if (!TargetChannel.isText())
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.INVALID_CHANNEL(data.getRaw(), TargetChannel)]
|
||||
});
|
||||
|
||||
if(!(data.getGuild()!.me?.permissionsIn(TargetChannel).has([Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.VIEW_CHANNEL])))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.BOT_NO_PERMISSION(data.getRaw(), TargetChannel)] });
|
||||
if (
|
||||
!data
|
||||
.getGuild()!
|
||||
.me?.permissionsIn(TargetChannel)
|
||||
.has([Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.VIEW_CHANNEL])
|
||||
)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.BOT_NO_PERMISSION(data.getRaw(), TargetChannel)]
|
||||
});
|
||||
|
||||
let placeholder = await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.PROCESSING(data)] });
|
||||
let placeholder = await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.PROCESSING(data)]
|
||||
});
|
||||
|
||||
await Prisma.client.guild.update({ where: {id: data.getGuild()!.id }, data: { ServiceAnnouncement_Channel: channel.id }});
|
||||
await Prisma.client.guild.update({
|
||||
where: { id: data.getGuild()!.id },
|
||||
data: { ServiceAnnouncement_Channel: channel.id }
|
||||
});
|
||||
|
||||
if(data.isMessage())
|
||||
return await (placeholder as Message).edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_CONFIGURED_CHANNEL(data.getRaw(), TargetChannel)]});
|
||||
else if(data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_CONFIGURED_CHANNEL(data.getRaw(), TargetChannel)]}, true);
|
||||
if (data.isMessage())
|
||||
return await (placeholder as Message).edit({
|
||||
embeds: [
|
||||
EMBEDS.SERVICE_ANNOUNCEMENT_CONFIGURED_CHANNEL(
|
||||
data.getRaw(),
|
||||
TargetChannel
|
||||
)
|
||||
]
|
||||
});
|
||||
else if (data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{
|
||||
embeds: [
|
||||
EMBEDS.SERVICE_ANNOUNCEMENT_CONFIGURED_CHANNEL(
|
||||
data.getRaw(),
|
||||
TargetChannel
|
||||
)
|
||||
]
|
||||
},
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let query;
|
||||
|
||||
if(data.isMessage()) {
|
||||
if(args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SETTINGS_INFO(data.getRaw())] });
|
||||
|
||||
if (data.isMessage()) {
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SETTINGS_INFO(data.getRaw())]
|
||||
});
|
||||
|
||||
query = args[0].toLowerCase();
|
||||
}
|
||||
else if(data.isSlashCommand()) {
|
||||
} else if (data.isSlashCommand()) {
|
||||
query = args.getSubcommand();
|
||||
}
|
||||
|
||||
switch(query) {
|
||||
case "info":
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SETTINGS_INFO(data.getRaw())] });
|
||||
case "setprefix":
|
||||
switch (query) {
|
||||
case 'info':
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SETTINGS_INFO(data.getRaw())]
|
||||
});
|
||||
case 'setprefix':
|
||||
return await funct.setPrefix(data);
|
||||
case "setenableserviceannouncement":
|
||||
case 'setenableserviceannouncement':
|
||||
return await funct.setEnableServiceAnnouncement(data);
|
||||
case "setserviceannouncementchannel":
|
||||
case 'setserviceannouncementchannel':
|
||||
return await funct.setServiceAnnouncementChannel(data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+27
-19
@@ -1,14 +1,13 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||
import { Message, CommandInteraction, Interaction } from 'discord.js';
|
||||
import os from 'os-utils';
|
||||
|
||||
import { Message, CommandInteraction, Interaction } from "discord.js";
|
||||
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from "../utils/DiscordMessage";
|
||||
import DiscordProvider from "../providers/Discord";
|
||||
import os from "os-utils";
|
||||
import DiscordProvider from '../providers/Discord';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import { sendHybridInteractionMessageResponse, makeInfoEmbed } from '../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
STATS_INFO: (data: Message | Interaction) => {
|
||||
let message;
|
||||
|
||||
return makeInfoEmbed({
|
||||
title: `Stats`,
|
||||
icon: '📊',
|
||||
@@ -16,35 +15,44 @@ const EMBEDS = {
|
||||
fields: [
|
||||
{
|
||||
name: '🌐 Users',
|
||||
value: `${DiscordProvider.client.guilds.cache.size} servers\n${DiscordProvider.client.guilds.cache.map((g) => g.memberCount).reduce((a, c) => a + c)} users`,
|
||||
value: `${
|
||||
DiscordProvider.client.guilds.cache.size
|
||||
} servers\n${DiscordProvider.client.guilds.cache
|
||||
.map((g) => g.memberCount)
|
||||
.reduce((a, c) => a + c)} users`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: '🟢 Uptime since',
|
||||
value: `System: <t:${(Math.round(new Date().getTime() / 1000)) - Math.round(os.sysUptime())}:R>\nProcess: <t:${(Math.round(new Date().getTime() / 1000)) - Math.round(os.processUptime())}:R>`,
|
||||
value: `System: <t:${
|
||||
Math.round(new Date().getTime() / 1000) - Math.round(os.sysUptime())
|
||||
}:R>\nProcess: <t:${
|
||||
Math.round(new Date().getTime() / 1000) - Math.round(os.processUptime())
|
||||
}:R>`,
|
||||
inline: true
|
||||
}
|
||||
],
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Stats extends DiscordModule {
|
||||
|
||||
public id = "Discord_Stats";
|
||||
public commands = ["stats"];
|
||||
public commandInteractionName = "stats";
|
||||
|
||||
public id = 'Discord_Stats';
|
||||
public commands = ['stats'];
|
||||
public commandInteractionName = 'stats';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds:[EMBEDS.STATS_INFO(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.STATS_INFO(data.getRaw())]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+97
-70
@@ -1,12 +1,16 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||
import { Message, Interaction, CommandInteraction } from 'discord.js';
|
||||
import { getColorFromURL } from 'color-thief-node';
|
||||
|
||||
import { Message, Interaction, CommandInteraction } from "discord.js";
|
||||
import { sendHybridInteractionMessageResponse, makeErrorEmbed, makeInfoEmbed } from "../utils/DiscordMessage";
|
||||
import { getColorFromURL } from "color-thief-node";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import {
|
||||
sendHybridInteractionMessageResponse,
|
||||
makeErrorEmbed,
|
||||
makeInfoEmbed
|
||||
} from '../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
SAY_INFO: (data: Message | Interaction) => {
|
||||
return makeInfoEmbed ({
|
||||
return makeInfoEmbed({
|
||||
title: 'User Info',
|
||||
description: `View info on discord user`,
|
||||
fields: [
|
||||
@@ -15,75 +19,75 @@ const EMBEDS = {
|
||||
value: '``Discord user mention or id``'
|
||||
}
|
||||
],
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
USER_NOT_FOUND: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: 'That user cannot be found!',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class UserInfo extends DiscordModule {
|
||||
|
||||
public id = "Discord_UserInfo";
|
||||
public commands = ["userinfo"];
|
||||
public commandInteractionName = "userinfo";
|
||||
public id = 'Discord_UserInfo';
|
||||
public commands = ['userinfo'];
|
||||
public commandInteractionName = 'userinfo';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
let query;
|
||||
|
||||
if(data.isMessage()) {
|
||||
if(args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SAY_INFO(data.getRaw())] });
|
||||
if (data.isMessage()) {
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.SAY_INFO(data.getRaw())]
|
||||
});
|
||||
|
||||
if(typeof data.getMessage().mentions.users.first() !== 'undefined')
|
||||
if (typeof data.getMessage().mentions.users.first() !== 'undefined')
|
||||
query = data.getMessage().mentions.users.first()?.id;
|
||||
else
|
||||
query = args[0];
|
||||
}
|
||||
else if(data.isSlashCommand())
|
||||
else query = args[0];
|
||||
} else if (data.isSlashCommand())
|
||||
query = data.getSlashCommand().options.getUser('user')?.id;
|
||||
|
||||
// Find the user want to look up
|
||||
let TargetMember = (await data.getGuild()!.members.fetch()).get(query);
|
||||
if(!TargetMember) return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.USER_NOT_FOUND(data.getRaw())] });
|
||||
if (!TargetMember)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.USER_NOT_FOUND(data.getRaw())]
|
||||
});
|
||||
|
||||
|
||||
if(data.isSlashCommand())
|
||||
await data.getMessageComponentInteraction().deferReply();
|
||||
if (data.isSlashCommand()) await data.getMessageComponentInteraction().deferReply();
|
||||
|
||||
let readableStatus: string;
|
||||
|
||||
switch(TargetMember.presence?.status) {
|
||||
case "online":
|
||||
readableStatus = "🟢 Online";
|
||||
|
||||
switch (TargetMember.presence?.status) {
|
||||
case 'online':
|
||||
readableStatus = '🟢 Online';
|
||||
break;
|
||||
case "idle":
|
||||
readableStatus = "🌙 Idle";
|
||||
case 'idle':
|
||||
readableStatus = '🌙 Idle';
|
||||
break;
|
||||
case "dnd":
|
||||
readableStatus = "⛔ Do not disturb";
|
||||
case 'dnd':
|
||||
readableStatus = '⛔ Do not disturb';
|
||||
break;
|
||||
case "offline":
|
||||
readableStatus = "⚫ Offline";
|
||||
case 'offline':
|
||||
readableStatus = '⚫ Offline';
|
||||
break;
|
||||
default:
|
||||
readableStatus = "❓ Unknown";
|
||||
readableStatus = '❓ Unknown';
|
||||
break;
|
||||
}
|
||||
|
||||
const embed = makeInfoEmbed ({
|
||||
const embed = makeInfoEmbed({
|
||||
icon: '',
|
||||
title: `${TargetMember.user.tag}`,
|
||||
fields: [
|
||||
@@ -95,49 +99,73 @@ export default class UserInfo extends DiscordModule {
|
||||
user: data.getUser()
|
||||
});
|
||||
|
||||
if(TargetMember.presence?.activities)
|
||||
for(let activity of TargetMember.presence?.activities) {
|
||||
if(activity.type === "CUSTOM")
|
||||
embed.addField( `✨ ${activity.name}`, `${!activity.emoji ? '' : `${activity.emoji?.identifier.startsWith('%') ? activity.emoji?.name : '<' + activity.emoji?.identifier + '>'}`} ${activity.state === null ? '' : activity.state}
|
||||
\u200b`, true);
|
||||
if (TargetMember.presence?.activities)
|
||||
for (let activity of TargetMember.presence?.activities) {
|
||||
if (activity.type === 'CUSTOM')
|
||||
embed.addField(
|
||||
`✨ ${activity.name}`,
|
||||
`${
|
||||
!activity.emoji
|
||||
? ''
|
||||
: `${
|
||||
activity.emoji?.identifier.startsWith('%')
|
||||
? activity.emoji?.name
|
||||
: '<' + activity.emoji?.identifier + '>'
|
||||
}`
|
||||
} ${activity.state === null ? '' : activity.state}
|
||||
\u200b`,
|
||||
true
|
||||
);
|
||||
else {
|
||||
let emoji = "";
|
||||
switch(activity.type) {
|
||||
case "PLAYING":
|
||||
emoji = "🕹 ";
|
||||
let emoji = '';
|
||||
switch (activity.type) {
|
||||
case 'PLAYING':
|
||||
emoji = '🕹 ';
|
||||
break;
|
||||
case "STREAMING":
|
||||
emoji = "🔴 ";
|
||||
case 'STREAMING':
|
||||
emoji = '🔴 ';
|
||||
break;
|
||||
case "LISTENING":
|
||||
emoji = "🎵 ";
|
||||
case 'LISTENING':
|
||||
emoji = '🎵 ';
|
||||
break;
|
||||
case "WATCHING":
|
||||
emoji = "📺 ";
|
||||
case 'WATCHING':
|
||||
emoji = '📺 ';
|
||||
break;
|
||||
case "COMPETING":
|
||||
emoji = "🌠 ";
|
||||
case 'COMPETING':
|
||||
emoji = '🌠 ';
|
||||
break;
|
||||
}
|
||||
embed.addField( `${emoji}${activity.type.toLowerCase().charAt(0).toUpperCase() + activity.type.toLowerCase().slice(1)} ${activity.name}`,
|
||||
`${activity.details === null ? '' : activity.details}
|
||||
embed.addField(
|
||||
`${emoji}${
|
||||
activity.type.toLowerCase().charAt(0).toUpperCase() +
|
||||
activity.type.toLowerCase().slice(1)
|
||||
} ${activity.name}`,
|
||||
`${activity.details === null ? '' : activity.details}
|
||||
${activity.state === null ? '' : activity.state}
|
||||
Since <t:${Math.round(new Date(activity.createdAt).getTime() / 1000)}:R>
|
||||
\u200b`, true);
|
||||
\u200b`,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
embed.addField(`📰 Information on this guild`, `${
|
||||
(TargetMember.joinedAt === null) ? 'Cannot determine joined date' : `Joined <t:${Math.round(TargetMember.joinedAt.getTime() / 1000)}:R>`}
|
||||
${(TargetMember.id === data.getGuild()!.ownerId) ? 'Owner of this guild 👑' : ''}
|
||||
`);
|
||||
|
||||
try {
|
||||
const colorthief = await getColorFromURL(TargetMember.user.displayAvatarURL().replace('.webp', '.jpg'));
|
||||
embed.setColor(colorthief);
|
||||
} catch (err) {
|
||||
embed.addField(
|
||||
`📰 Information on this guild`,
|
||||
`${
|
||||
TargetMember.joinedAt === null
|
||||
? 'Cannot determine joined date'
|
||||
: `Joined <t:${Math.round(TargetMember.joinedAt.getTime() / 1000)}:R>`
|
||||
}
|
||||
${TargetMember.id === data.getGuild()!.ownerId ? 'Owner of this guild 👑' : ''}
|
||||
`
|
||||
);
|
||||
|
||||
}
|
||||
try {
|
||||
const colorthief = await getColorFromURL(
|
||||
TargetMember.user.displayAvatarURL().replace('.webp', '.jpg')
|
||||
);
|
||||
embed.setColor(colorthief);
|
||||
} catch (err) {}
|
||||
|
||||
embed.setThumbnail(TargetMember.user.displayAvatarURL());
|
||||
embed.setAuthor({
|
||||
@@ -146,6 +174,5 @@ export default class UserInfo extends DiscordModule {
|
||||
});
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [embed] });
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import {
|
||||
Message,
|
||||
Interaction,
|
||||
CommandInteraction,
|
||||
MessageActionRow,
|
||||
MessageButton,
|
||||
ButtonInteraction
|
||||
} from 'discord.js';
|
||||
|
||||
import { Message, Interaction, CommandInteraction, MessageActionRow, MessageButton, ButtonInteraction } from "discord.js";
|
||||
import { makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse, sendMessageOrInteractionResponse } from "../../utils/DiscordMessage";
|
||||
import DiscordProvider from "../../providers/Discord";
|
||||
import DiscordMusicPlayer from "../../providers/DiscordMusicPlayer";
|
||||
import Users from "../../services/Users";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import {
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../../utils/DiscordMessage';
|
||||
|
||||
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
|
||||
import Users from '../../services/Users';
|
||||
|
||||
const EMBEDS = {
|
||||
DEBUG_INFO: (data: Message | Interaction) => {
|
||||
@@ -17,14 +28,14 @@ const EMBEDS = {
|
||||
value: '``invalidInteraction`` ``crashMusicPlayer`` ``crash`` ``activemusicplayer``'
|
||||
}
|
||||
],
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
INVALID_TEST: (data: Message | Interaction) => {
|
||||
return makeInfoEmbed({
|
||||
title: 'Click button below to test invalid interaction',
|
||||
description: `The interaction will be failed`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
CRASHING: (data: Message | Interaction) => {
|
||||
@@ -32,31 +43,30 @@ const EMBEDS = {
|
||||
icon: '💀',
|
||||
title: 'Crashing myself',
|
||||
description: `Sayonara.... cruel world`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
ACTIVE_MUSIC_PLAYERS: (data: Message | Interaction, totalplayers: Map<any, any>) => {
|
||||
return makeInfoEmbed({
|
||||
icon: '🎵',
|
||||
title: `Total active music players: ${totalplayers.size}`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NOT_DEVELOPER: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Developer only',
|
||||
description: `This command is restricted to the developers only`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class Debug extends DiscordModule {
|
||||
public id = 'Discord_Developer_Debug';
|
||||
public commands = ['debug', 'dbg'];
|
||||
public commandInteractionName = 'debug';
|
||||
|
||||
public id = "Discord_Developer_Debug";
|
||||
public commands = ["debug", "dbg"];
|
||||
public commandInteractionName = "debug";
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
@@ -66,84 +76,100 @@ export default class Debug extends DiscordModule {
|
||||
}
|
||||
|
||||
async GuildButtonInteractionCreate(data: ButtonInteraction) {
|
||||
if(data.customId !== "dev_make_invalid_interaction") return;
|
||||
if (data.customId !== 'dev_make_invalid_interaction') return;
|
||||
|
||||
const hybridData = new HybridInteractionMessage(data);
|
||||
const user = hybridData.getUser();
|
||||
|
||||
if(!user) return;
|
||||
if (!user) return;
|
||||
|
||||
if (!Users.isDeveloper(user.id))
|
||||
return await sendHybridInteractionMessageResponse(hybridData, { embeds: [EMBEDS.NOT_DEVELOPER(hybridData.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(hybridData, {
|
||||
embeds: [EMBEDS.NOT_DEVELOPER(hybridData.getRaw())]
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
await sendHybridInteractionMessageResponse(hybridData, { content: 'dev_make_invalid_interaction' });
|
||||
}, 7 * 1000)
|
||||
await sendHybridInteractionMessageResponse(hybridData, {
|
||||
content: 'dev_make_invalid_interaction'
|
||||
});
|
||||
}, 7 * 1000);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const guild = data.getGuild();
|
||||
const user = data.getUser();
|
||||
const channel = data.getChannel();
|
||||
|
||||
if(!guild || !user || !channel) return;
|
||||
|
||||
if (!guild || !user || !channel) return;
|
||||
|
||||
if (!Users.isDeveloper(user.id))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOT_DEVELOPER(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NOT_DEVELOPER(data.getRaw())]
|
||||
});
|
||||
|
||||
const funct = {
|
||||
crash: async (data: HybridInteractionMessage) => {
|
||||
await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.CRASHING(data.getRaw())] });
|
||||
throw new Error("Manually crashed by debug command");
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.CRASHING(data.getRaw())]
|
||||
});
|
||||
throw new Error('Manually crashed by debug command');
|
||||
},
|
||||
crashMusicPlayer: async (data: HybridInteractionMessage) => {
|
||||
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
if(!instance) return;
|
||||
if (!instance) return;
|
||||
|
||||
instance._fake_error_on_player();
|
||||
},
|
||||
activeMusicPlayer: async (data: HybridInteractionMessage) => {
|
||||
await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ACTIVE_MUSIC_PLAYERS(data.getRaw(), DiscordMusicPlayer.GuildQueue)] });
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [
|
||||
EMBEDS.ACTIVE_MUSIC_PLAYERS(data.getRaw(), DiscordMusicPlayer.GuildQueue)
|
||||
]
|
||||
});
|
||||
},
|
||||
invalidInteraction: async (data: HybridInteractionMessage) => {
|
||||
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setEmoji('😥')
|
||||
.setLabel(' Make invalid interaction (Wait 7 seconds, check error in console or logs)')
|
||||
.setCustomId('dev_make_invalid_interaction')
|
||||
.setStyle('PRIMARY'),
|
||||
)
|
||||
await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_TEST(data.getRaw())], components: [row] });
|
||||
const row = new MessageActionRow().addComponents(
|
||||
new MessageButton()
|
||||
.setEmoji('😥')
|
||||
.setLabel(
|
||||
' Make invalid interaction (Wait 7 seconds, check error in console or logs)'
|
||||
)
|
||||
.setCustomId('dev_make_invalid_interaction')
|
||||
.setStyle('PRIMARY')
|
||||
);
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.INVALID_TEST(data.getRaw())],
|
||||
components: [row]
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let query;
|
||||
|
||||
if (data.isMessage()) {
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.DEBUG_INFO(data.getRaw())] });
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.DEBUG_INFO(data.getRaw())]
|
||||
});
|
||||
|
||||
query = args[0].toLowerCase();
|
||||
}
|
||||
else if (data.isSlashCommand()) {
|
||||
} else if (data.isSlashCommand()) {
|
||||
query = args.getSubcommand();
|
||||
}
|
||||
|
||||
switch (query) {
|
||||
case "info":
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.DEBUG_INFO(data.getRaw())] });
|
||||
case "crash":
|
||||
case 'info':
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.DEBUG_INFO(data.getRaw())]
|
||||
});
|
||||
case 'crash':
|
||||
return await funct.crash(data);
|
||||
case "invalidinteraction":
|
||||
case 'invalidinteraction':
|
||||
return await funct.invalidInteraction(data);
|
||||
case "crashmusicplayer":
|
||||
case 'crashmusicplayer':
|
||||
return await funct.crashMusicPlayer(data);
|
||||
case "activemusicplayer":
|
||||
case 'activemusicplayer':
|
||||
return await funct.activeMusicPlayer(data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../../utils/DiscordModule";
|
||||
import { Message, MessageEmbed, Interaction, CommandInteraction, TextChannel } from 'discord.js';
|
||||
import { Promise } from 'bluebird';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { Message, MessageEmbed, Interaction, CommandInteraction, TextChannel } from "discord.js";
|
||||
import { makeInfoEmbed, makeErrorEmbed, makeSuccessEmbed, makeProcessingEmbed, makeWarningEmbed, sendHybridInteractionMessageResponse, sendMessage } from "../../utils/DiscordMessage";
|
||||
import DiscordProvider from "../../providers/Discord";
|
||||
import Prisma from "../../providers/Prisma";
|
||||
import Users from "../../services/Users";
|
||||
import { Guild } from '@prisma/client';
|
||||
|
||||
import { Promise } from "bluebird";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import Logger from "../../libs/Logger";
|
||||
import { Guild } from "@prisma/client";
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import {
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
makeSuccessEmbed,
|
||||
makeProcessingEmbed,
|
||||
makeWarningEmbed,
|
||||
sendHybridInteractionMessageResponse,
|
||||
sendMessage
|
||||
} from '../../utils/DiscordMessage';
|
||||
|
||||
import Logger from '../../libs/Logger';
|
||||
import DiscordProvider from '../../providers/Discord';
|
||||
import Prisma from '../../providers/Prisma';
|
||||
import Users from '../../services/Users';
|
||||
|
||||
const EMBEDS = {
|
||||
ANNOUNCEMENT_INFO: (data: Message | Interaction) => {
|
||||
@@ -23,14 +32,14 @@ const EMBEDS = {
|
||||
value: '``reload`` ``previewNews`` ``sendNews`` ``previewMaintenance`` ``sendMaintenance`` ``previewMessage`` ``sendMessage`` ``previewAlert`` ``sendAlert``'
|
||||
}
|
||||
],
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NOT_DEVELOPER: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Developer only',
|
||||
description: `This command is restricted to the developers only`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
MAKE_PAYLOAD: (payload: any) => {
|
||||
@@ -38,10 +47,9 @@ const EMBEDS = {
|
||||
payload.footer = {
|
||||
text: `${user?.username}`,
|
||||
iconURL: `${user?.displayAvatarURL()}?size=4096`
|
||||
}
|
||||
};
|
||||
|
||||
if (!payload.timestamp)
|
||||
payload.timestamp = new Date();
|
||||
if (!payload.timestamp) payload.timestamp = new Date();
|
||||
|
||||
if (payload.thumbnail?.url === 'bot_avatar')
|
||||
payload.thumbnail.url = `${user?.displayAvatarURL()}?size=4096`;
|
||||
@@ -50,95 +58,95 @@ const EMBEDS = {
|
||||
payload.image.url = `${user?.displayAvatarURL()}?size=4096`;
|
||||
|
||||
if (payload.description)
|
||||
payload.description = payload.description.replaceAll('{bot_username}', user?.username)
|
||||
payload.description = payload.description.replaceAll('{bot_username}', user?.username);
|
||||
|
||||
return new MessageEmbed(payload)
|
||||
return new MessageEmbed(payload);
|
||||
},
|
||||
RELOADED: (data: Message | Interaction) => {
|
||||
return makeSuccessEmbed({
|
||||
title: 'Service Announcement Configuration Reloaded',
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
RELOAD_ERROR: (data: Message | Interaction, error: string) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Unable to reload Service Announcement Configuration',
|
||||
description: `\`\`\`${error}\`\`\``,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
SENDING_SERVICE_ANNOUNCEMENT: (data: Message | Interaction) => {
|
||||
return makeProcessingEmbed({
|
||||
title: 'Service Announcement',
|
||||
description: `Broadcasting Service Announcement`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
SERVICE_ANNOUNCEMENT_SENT: (data: Message | Interaction) => {
|
||||
return makeSuccessEmbed({
|
||||
title: 'Service Announcement',
|
||||
description: `Broadcasted Service Announcement`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS: (data: Message | Interaction) => {
|
||||
return makeWarningEmbed({
|
||||
title: 'Service Announcement',
|
||||
description: `Broadcasted Service Announcement with errors, check console for more info`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let Announcements = {
|
||||
News: {
|
||||
color: "#FAEDF0",
|
||||
color: '#FAEDF0',
|
||||
title: '📰 Newsletter',
|
||||
description: 'Some description here',
|
||||
thumbnail: {
|
||||
url: 'bot_avatar',
|
||||
url: 'bot_avatar'
|
||||
}
|
||||
},
|
||||
Maintenance: {
|
||||
color: "#383b80",
|
||||
color: '#383b80',
|
||||
title: '🔧 Maintenance',
|
||||
description: 'The bot is going offline for maintenance.',
|
||||
thumbnail: {
|
||||
url: 'bot_avatar',
|
||||
url: 'bot_avatar'
|
||||
}
|
||||
},
|
||||
Message: {
|
||||
color: "#A1DE93",
|
||||
color: '#A1DE93',
|
||||
title: '✉️ Message',
|
||||
description: 'Some description here',
|
||||
thumbnail: {
|
||||
url: 'bot_avatar',
|
||||
url: 'bot_avatar'
|
||||
}
|
||||
},
|
||||
Alert: {
|
||||
color: "#EC255A",
|
||||
color: '#EC255A',
|
||||
title: '🚨 Alert',
|
||||
description: 'Some description here',
|
||||
thumbnail: {
|
||||
url: 'bot_avatar',
|
||||
url: 'bot_avatar'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
export default class ServiceAnnouncement extends DiscordModule {
|
||||
|
||||
public id = "Discord_Developer_ServiceAnnouncement";
|
||||
public commands = ["serviceannouncement"];
|
||||
public commandInteractionName = "serviceannouncement";
|
||||
public id = 'Discord_Developer_ServiceAnnouncement';
|
||||
public commands = ['serviceannouncement'];
|
||||
public commandInteractionName = 'serviceannouncement';
|
||||
|
||||
async Init() {
|
||||
if (fs.existsSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'))) {
|
||||
try {
|
||||
const rawData = fs.readFileSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'));
|
||||
const rawData = fs.readFileSync(
|
||||
path.join(process.cwd(), 'configs/ServiceAnnouncement.json')
|
||||
);
|
||||
const jsonData = JSON.parse(rawData.toString());
|
||||
Announcements = jsonData;
|
||||
} catch (err) {
|
||||
Logger.error("Unable to load custom ServiceAnnouncement config: " + err);
|
||||
Logger.error('Unable to load custom ServiceAnnouncement config: ' + err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,47 +155,65 @@ export default class ServiceAnnouncement extends DiscordModule {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
if (!Users.isDeveloper(data.getUser()!.id))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NOT_DEVELOPER(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NOT_DEVELOPER(data.getRaw())]
|
||||
});
|
||||
|
||||
const channel = data.getChannel();
|
||||
if(!channel) return;
|
||||
if (!channel) return;
|
||||
|
||||
const funct = {
|
||||
reload: async (data: HybridInteractionMessage) => {
|
||||
|
||||
if (fs.existsSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'))) {
|
||||
try {
|
||||
const rawData = fs.readFileSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'));
|
||||
const rawData = fs.readFileSync(
|
||||
path.join(process.cwd(), 'configs/ServiceAnnouncement.json')
|
||||
);
|
||||
const jsonData = JSON.parse(rawData.toString());
|
||||
Announcements = jsonData;
|
||||
} catch (err: any) {
|
||||
Logger.error("Unable to load custom ServiceAnnouncement config: " + err);
|
||||
return await sendMessage(channel, undefined, { embeds: [EMBEDS.RELOAD_ERROR(data.getRaw(), err)] });
|
||||
Logger.error('Unable to load custom ServiceAnnouncement config: ' + err);
|
||||
return await sendMessage(channel, undefined, {
|
||||
embeds: [EMBEDS.RELOAD_ERROR(data.getRaw(), err)]
|
||||
});
|
||||
}
|
||||
} else {
|
||||
fs.writeFileSync(path.join(process.cwd(), 'configs/ServiceAnnouncement.json'), JSON.stringify(Announcements, null, 4), 'utf8');
|
||||
fs.writeFileSync(
|
||||
path.join(process.cwd(), 'configs/ServiceAnnouncement.json'),
|
||||
JSON.stringify(Announcements, null, 4),
|
||||
'utf8'
|
||||
);
|
||||
}
|
||||
|
||||
return await sendMessage(channel, undefined, { embeds: [EMBEDS.RELOADED(data.getRaw())] });
|
||||
return await sendMessage(channel, undefined, {
|
||||
embeds: [EMBEDS.RELOADED(data.getRaw())]
|
||||
});
|
||||
},
|
||||
previewNews: async (data: HybridInteractionMessage) => {
|
||||
return await sendMessage(channel, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(Announcements.News)] });
|
||||
return await sendMessage(channel, undefined, {
|
||||
embeds: [EMBEDS.MAKE_PAYLOAD(Announcements.News)]
|
||||
});
|
||||
},
|
||||
previewMaintenance: async (data: HybridInteractionMessage) => {
|
||||
return await sendMessage(channel, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(Announcements.Maintenance)] });
|
||||
return await sendMessage(channel, undefined, {
|
||||
embeds: [EMBEDS.MAKE_PAYLOAD(Announcements.Maintenance)]
|
||||
});
|
||||
},
|
||||
previewMessage: async (data: HybridInteractionMessage) => {
|
||||
return await sendMessage(channel, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(Announcements.Message)] });
|
||||
return await sendMessage(channel, undefined, {
|
||||
embeds: [EMBEDS.MAKE_PAYLOAD(Announcements.Message)]
|
||||
});
|
||||
},
|
||||
previewAlert: async (data: HybridInteractionMessage) => {
|
||||
return await sendMessage(channel, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(Announcements.Alert)] });
|
||||
return await sendMessage(channel, undefined, {
|
||||
embeds: [EMBEDS.MAKE_PAYLOAD(Announcements.Alert)]
|
||||
});
|
||||
},
|
||||
publishServiceAnnouncement: async (data: HybridInteractionMessage, embed: any) => {
|
||||
const Guilds = await Prisma.client.guild.findMany({});
|
||||
@@ -201,11 +227,15 @@ export default class ServiceAnnouncement extends DiscordModule {
|
||||
|
||||
let channel = undefined;
|
||||
try {
|
||||
channel = await DiscordProvider.client.channels.fetch(Guild.ServiceAnnouncement_Channel) as TextChannel;
|
||||
channel = (await DiscordProvider.client.channels.fetch(
|
||||
Guild.ServiceAnnouncement_Channel
|
||||
)) as TextChannel;
|
||||
} catch (err) {
|
||||
withError = true;
|
||||
const guildObject = DiscordProvider.client.guilds.cache.get(Guild.id);
|
||||
Logger.warn(`Unable to find channel for Service Announcement to ${guildObject?.name} (${Guild.id}) (Channel ID: ${Guild.ServiceAnnouncement_Channel})`);
|
||||
Logger.warn(
|
||||
`Unable to find channel for Service Announcement to ${guildObject?.name} (${Guild.id}) (Channel ID: ${Guild.ServiceAnnouncement_Channel})`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -213,83 +243,121 @@ export default class ServiceAnnouncement extends DiscordModule {
|
||||
toSend.set(Guild, channel);
|
||||
}
|
||||
|
||||
let placeholder: (HybridInteractionMessage | undefined);
|
||||
let placeholder: HybridInteractionMessage | undefined;
|
||||
|
||||
let _placeholder = await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SENDING_SERVICE_ANNOUNCEMENT(data.getRaw())] }, true);
|
||||
if (_placeholder)
|
||||
placeholder = new HybridInteractionMessage(_placeholder);
|
||||
let _placeholder = await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.SENDING_SERVICE_ANNOUNCEMENT(data.getRaw())] },
|
||||
true
|
||||
);
|
||||
if (_placeholder) placeholder = new HybridInteractionMessage(_placeholder);
|
||||
|
||||
await Promise.map(toSend, element => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let Guild: Guild = element[0];
|
||||
let Channel: TextChannel = element[1];
|
||||
try {
|
||||
const guildObject = DiscordProvider.client.guilds.cache.get(Guild.id);
|
||||
if (!guildObject)
|
||||
throw new Error('Guild not found');
|
||||
Logger.info(`Sending Service Announcement to ${guildObject?.name} (${guildObject.id}) #${Channel.name} (${Channel.id})`);
|
||||
await sendMessage(Channel, undefined, { embeds: [EMBEDS.MAKE_PAYLOAD(embed)] })
|
||||
} catch (err) {
|
||||
withError = true;
|
||||
const guildObject = DiscordProvider.client.guilds.cache.get(Guild.id);
|
||||
if (guildObject)
|
||||
Logger.info(`Unable to send Service Announcement to ${guildObject?.name} (${guildObject.id}) #${Channel.name} (${Channel.id})`);
|
||||
await Promise.map(
|
||||
toSend,
|
||||
(element) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let Guild: Guild = element[0];
|
||||
let Channel: TextChannel = element[1];
|
||||
try {
|
||||
const guildObject = DiscordProvider.client.guilds.cache.get(
|
||||
Guild.id
|
||||
);
|
||||
if (!guildObject) throw new Error('Guild not found');
|
||||
Logger.info(
|
||||
`Sending Service Announcement to ${guildObject?.name} (${guildObject.id}) #${Channel.name} (${Channel.id})`
|
||||
);
|
||||
await sendMessage(Channel, undefined, {
|
||||
embeds: [EMBEDS.MAKE_PAYLOAD(embed)]
|
||||
});
|
||||
} catch (err) {
|
||||
withError = true;
|
||||
const guildObject = DiscordProvider.client.guilds.cache.get(
|
||||
Guild.id
|
||||
);
|
||||
if (guildObject)
|
||||
Logger.info(
|
||||
`Unable to send Service Announcement to ${guildObject?.name} (${guildObject.id}) #${Channel.name} (${Channel.id})`
|
||||
);
|
||||
|
||||
reject(err);
|
||||
}
|
||||
reject(err);
|
||||
}
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
resolve();
|
||||
});
|
||||
}, { concurrency: 2 });
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
resolve();
|
||||
});
|
||||
},
|
||||
{ concurrency: 2 }
|
||||
);
|
||||
|
||||
if (withError) {
|
||||
if(data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data.getRaw())] });
|
||||
else if(data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data.getRaw())] }, true);
|
||||
}
|
||||
else {
|
||||
if(data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder.getMessage().edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data.getRaw())] });
|
||||
else if(data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data.getRaw())] }, true);
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({
|
||||
embeds: [
|
||||
EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data.getRaw())
|
||||
]
|
||||
});
|
||||
else if (data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{
|
||||
embeds: [
|
||||
EMBEDS.SERVICE_ANNOUNCEMENT_SENT_WITH_ERRORS(data.getRaw())
|
||||
]
|
||||
},
|
||||
true
|
||||
);
|
||||
} else {
|
||||
if (data && data.isMessage() && placeholder && placeholder.isMessage())
|
||||
return placeholder
|
||||
.getMessage()
|
||||
.edit({ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data.getRaw())] });
|
||||
else if (data.isSlashCommand())
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.SERVICE_ANNOUNCEMENT_SENT(data.getRaw())] },
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let query;
|
||||
|
||||
if (data.isMessage()) {
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ANNOUNCEMENT_INFO(data.getRaw())] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ANNOUNCEMENT_INFO(data.getRaw())]
|
||||
});
|
||||
query = args[0].toLowerCase();
|
||||
}
|
||||
else if (data.isSlashCommand()) {
|
||||
} else if (data.isSlashCommand()) {
|
||||
query = args.getSubcommand();
|
||||
}
|
||||
|
||||
switch (query) {
|
||||
case "info":
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.ANNOUNCEMENT_INFO(data.getRaw())] });
|
||||
case "reload":
|
||||
case 'info':
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ANNOUNCEMENT_INFO(data.getRaw())]
|
||||
});
|
||||
case 'reload':
|
||||
return await funct.reload(data);
|
||||
case "previewnews":
|
||||
case 'previewnews':
|
||||
return await funct.previewNews(data);
|
||||
case "previewmaintenance":
|
||||
case 'previewmaintenance':
|
||||
return await funct.previewMaintenance(data);
|
||||
case "previewmessage":
|
||||
case 'previewmessage':
|
||||
return await funct.previewMessage(data);
|
||||
case "previewalert":
|
||||
case 'previewalert':
|
||||
return await funct.previewAlert(data);
|
||||
case "sendnews":
|
||||
case 'sendnews':
|
||||
return await funct.publishServiceAnnouncement(data, Announcements.News);
|
||||
case "sendmaintenance":
|
||||
case 'sendmaintenance':
|
||||
return await funct.publishServiceAnnouncement(data, Announcements.Maintenance);
|
||||
case "sendmessage":
|
||||
case 'sendmessage':
|
||||
return await funct.publishServiceAnnouncement(data, Announcements.Message);
|
||||
case "sendalert":
|
||||
case 'sendalert':
|
||||
return await funct.publishServiceAnnouncement(data, Announcements.Alert);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+239
-162
@@ -1,16 +1,27 @@
|
||||
import DiscordModule, { HybridInteractionMessage } from "../utils/DiscordModule";
|
||||
|
||||
import { Message, MessageActionRow, MessageButton, Interaction, CommandInteraction } from "discord.js";
|
||||
import { makeInfoEmbed, makeErrorEmbed, sendHybridInteractionMessageResponse } from "../utils/DiscordMessage";
|
||||
import Prisma from "../providers/Prisma";
|
||||
import osuAPI from "../providers/osuAPI";
|
||||
import { countryCodeEmoji } from "country-code-emoji";
|
||||
import countryLookup from "country-code-lookup";
|
||||
import {
|
||||
Message,
|
||||
MessageActionRow,
|
||||
MessageButton,
|
||||
Interaction,
|
||||
CommandInteraction
|
||||
} from 'discord.js';
|
||||
import validator from 'validator';
|
||||
import countryLookup from 'country-code-lookup';
|
||||
import { countryCodeEmoji } from 'country-code-emoji';
|
||||
|
||||
import Prisma from '../providers/Prisma';
|
||||
import osuAPI from '../providers/osuAPI';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule';
|
||||
import {
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../utils/DiscordMessage';
|
||||
|
||||
const EMBEDS = {
|
||||
osu_INFO:(data: Message | Interaction) => {
|
||||
return makeInfoEmbed ({
|
||||
osu_INFO: (data: Message | Interaction) => {
|
||||
return makeInfoEmbed({
|
||||
title: 'osu!',
|
||||
description: `[osu!](https://osu.ppy.sh/home) is a free-to-play rhythm game primarily developed, published, and created by Dean "peppy" Herbert`,
|
||||
fields: [
|
||||
@@ -23,172 +34,211 @@ const EMBEDS = {
|
||||
value: '``user``'
|
||||
}
|
||||
],
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_USER_FOUND: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: `That user doesn't exists on osu!`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_USER_MENTIONED: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: `No osu! username or user id provided`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
INVALID_USER_MENTIONED: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: `Not a valid osu username or id`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
INVALID_BEATMAP_ID_MENTIONED: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: `Not a valid osu beatmap id`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_BEATMAP_FOUND: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: `That beatmap doesn't exists on osu!`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
},
|
||||
NO_BEATMAP_MENTIONED: (data: Message | Interaction) => {
|
||||
return makeErrorEmbed ({
|
||||
return makeErrorEmbed({
|
||||
title: `No osu! beatmap id provided`,
|
||||
user: (data instanceof Interaction) ? data.user : data.author
|
||||
user: data instanceof Interaction ? data.user : data.author
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default class osu extends DiscordModule {
|
||||
|
||||
public id = "Discord_osu";
|
||||
public commands = ["osu"];
|
||||
public commandInteractionName = "osu";
|
||||
public id = 'Discord_osu';
|
||||
public commands = ['osu'];
|
||||
public commandInteractionName = 'osu';
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async run(data: HybridInteractionMessage, args: any) {
|
||||
|
||||
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.getGuild()!.id }})
|
||||
if(!Guild) return;
|
||||
|
||||
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.getGuild()!.id } });
|
||||
if (!Guild) return;
|
||||
|
||||
const funct = {
|
||||
user: async(data: HybridInteractionMessage) => {
|
||||
|
||||
user: async (data: HybridInteractionMessage) => {
|
||||
let user;
|
||||
if(data.isMessage()) {
|
||||
if(typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_USER_MENTIONED(data.getRaw())] });
|
||||
if (data.isMessage()) {
|
||||
if (typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_USER_MENTIONED(data.getRaw())]
|
||||
});
|
||||
const [removed, ...newArgs] = args;
|
||||
user = newArgs.join(" ");
|
||||
}
|
||||
else if(data.isSlashCommand())
|
||||
user = newArgs.join(' ');
|
||||
} else if (data.isSlashCommand())
|
||||
user = data.getSlashCommand().options.getString('user');
|
||||
|
||||
|
||||
if(!validator.isNumeric(user) && !this.validate_osu_username(user))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_USER_MENTIONED(data.getRaw())] });
|
||||
if (!validator.isNumeric(user) && !this.validate_osu_username(user))
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.INVALID_USER_MENTIONED(data.getRaw())]
|
||||
});
|
||||
|
||||
let result = await osuAPI.client.getUser({ u: user });
|
||||
|
||||
if(result instanceof Array && result.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_USER_FOUND(data.getRaw())] });
|
||||
if (result instanceof Array && result.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_USER_FOUND(data.getRaw())]
|
||||
});
|
||||
|
||||
if(data.isSlashCommand()) {
|
||||
if (data.isSlashCommand()) {
|
||||
await data.getSlashCommand().deferReply();
|
||||
}
|
||||
|
||||
const level = {
|
||||
number: (Math.round((result.level + Number.EPSILON) * 100) / 100).toFixed(2).split('.')[0],
|
||||
progression: (Math.round((result.level + Number.EPSILON) * 100) / 100).toFixed(2).split('.')[1]
|
||||
}
|
||||
const embed = makeInfoEmbed ({
|
||||
number: (Math.round((result.level + Number.EPSILON) * 100) / 100)
|
||||
.toFixed(2)
|
||||
.split('.')[0],
|
||||
progression: (Math.round((result.level + Number.EPSILON) * 100) / 100)
|
||||
.toFixed(2)
|
||||
.split('.')[1]
|
||||
};
|
||||
const embed = makeInfoEmbed({
|
||||
icon: '',
|
||||
title: `${countryCodeEmoji(result.country)} ${result.name}`,
|
||||
//description: `${member.user.username}#${member.user.discriminator} (${member.user.id})`,
|
||||
fields: [
|
||||
{
|
||||
name: `🏆 Level **${level.number}** (${level.progression}% progress to the next level)`,
|
||||
value: `Play Count **${this.numberWithCommas(result.counts.plays)}**, totaling in **${this.numberWithCommas(parseFloat(((Math.round(((result.secondsPlayed / (60 * 60)) + Number.EPSILON) * 100) / 100).toFixed(2))))} ${result.secondsPlayed < 60 ? 'hour' : 'hours'}** of songs played
|
||||
\u200b`,
|
||||
value: `Play Count **${this.numberWithCommas(
|
||||
result.counts.plays
|
||||
)}**, totaling in **${this.numberWithCommas(
|
||||
parseFloat(
|
||||
(
|
||||
Math.round(
|
||||
(result.secondsPlayed / (60 * 60) + Number.EPSILON) *
|
||||
100
|
||||
) / 100
|
||||
).toFixed(2)
|
||||
)
|
||||
)} ${result.secondsPlayed < 60 ? 'hour' : 'hours'}** of songs played
|
||||
\u200b`
|
||||
},
|
||||
{
|
||||
name: "🌎 World Ranking",
|
||||
name: '🌎 World Ranking',
|
||||
value: `**#${this.numberWithCommas(result.pp.rank)}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: `${countryCodeEmoji(result.country)} Country Ranking`,
|
||||
value: `**#${this.numberWithCommas(result.pp.countryRank)}** ${countryLookup.byInternet(result.country)!.country}`,
|
||||
value: `**#${this.numberWithCommas(result.pp.countryRank)}** ${
|
||||
countryLookup.byInternet(result.country)!.country
|
||||
}`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "🎀 Total Score",
|
||||
name: '🎀 Total Score',
|
||||
value: `**${this.numberWithCommas(result.scores.total)}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "✨ PP",
|
||||
name: '✨ PP',
|
||||
value: `**${this.numberWithCommas(result.pp.raw)}pp**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "⭕ Hit Accuracy",
|
||||
name: '⭕ Hit Accuracy',
|
||||
value: `**${result.accuracyFormatted}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "🌠 Ranked Score",
|
||||
name: '🌠 Ranked Score',
|
||||
value: `**${this.numberWithCommas(result.scores.ranked)}**
|
||||
\u200b`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "🥇 SSH",
|
||||
name: '🥇 SSH',
|
||||
value: `**${this.numberWithCommas(result.counts.SSH)}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "🥇 SH",
|
||||
name: '🥇 SH',
|
||||
value: `**${this.numberWithCommas(result.counts.SH)}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "🥇 SS",
|
||||
name: '🥇 SS',
|
||||
value: `**${this.numberWithCommas(result.counts.SS)}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "🥈 S",
|
||||
name: '🥈 S',
|
||||
value: `**${this.numberWithCommas(result.counts.S)}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "🥉 A",
|
||||
name: '🥉 A',
|
||||
value: `**${this.numberWithCommas(result.counts.A)}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "🏅 > A / Total plays",
|
||||
value: `**${this.numberWithCommas(result.counts.SSH + result.counts.SH + result.counts.SS + result.counts.S + result.counts.A)}** (${(Math.round((((result.counts.SSH + result.counts.SH + result.counts.SS + result.counts.S + result.counts.A) / (result.counts.plays == 0 ? 1 : result.counts.plays)) + Number.EPSILON) * 10000) / 10000).toFixed(4)})
|
||||
name: '🏅 > A / Total plays',
|
||||
value: `**${this.numberWithCommas(
|
||||
result.counts.SSH +
|
||||
result.counts.SH +
|
||||
result.counts.SS +
|
||||
result.counts.S +
|
||||
result.counts.A
|
||||
)}** (${(
|
||||
Math.round(
|
||||
((result.counts.SSH +
|
||||
result.counts.SH +
|
||||
result.counts.SS +
|
||||
result.counts.S +
|
||||
result.counts.A) /
|
||||
(result.counts.plays == 0 ? 1 : result.counts.plays) +
|
||||
Number.EPSILON) *
|
||||
10000
|
||||
) / 10000
|
||||
).toFixed(4)})
|
||||
\u200b`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: `❤ Account Information`,
|
||||
value: `Joined: <t:${Math.round(new Date(result.raw_joinDate).getTime() / 1000)}:R>, <t:${Math.round(new Date(result.raw_joinDate).getTime() / 1000)}:f>`
|
||||
}//,
|
||||
value: `Joined: <t:${Math.round(
|
||||
new Date(result.raw_joinDate).getTime() / 1000
|
||||
)}:R>, <t:${Math.round(
|
||||
new Date(result.raw_joinDate).getTime() / 1000
|
||||
)}:f>`
|
||||
} //,
|
||||
/*{
|
||||
name: `💌 Recent Events (Coming soon)`,
|
||||
value: `*How about we explore the area ahead of us later?*`
|
||||
@@ -199,106 +249,114 @@ export default class osu extends DiscordModule {
|
||||
embed.setAuthor({
|
||||
name: `${result.name}'s osu profile`,
|
||||
url: `https://osu.ppy.sh/users/${result.id}`,
|
||||
iconURL: 'https://upload.wikimedia.org/wikipedia/commons/e/e3/Osulogo.png'
|
||||
iconURL: 'https://upload.wikimedia.org/wikipedia/commons/e/e3/Osulogo.png'
|
||||
});
|
||||
|
||||
// TODO: Fix for ppl with no image
|
||||
embed.setThumbnail(`https://a.ppy.sh/${result.id}` || 'https://osu.ppy.sh/images/layout/avatar-guest.png');
|
||||
embed.setThumbnail(
|
||||
`https://a.ppy.sh/${result.id}` ||
|
||||
'https://osu.ppy.sh/images/layout/avatar-guest.png'
|
||||
);
|
||||
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
const row = new MessageActionRow().addComponents(
|
||||
new MessageButton()
|
||||
.setEmoji('🔗')
|
||||
.setLabel(' Open Profile')
|
||||
.setURL(`https://osu.ppy.sh/users/${result.id}`)
|
||||
.setStyle('LINK'),
|
||||
)
|
||||
.setStyle('LINK')
|
||||
);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [embed], components: [row] });
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [embed],
|
||||
components: [row]
|
||||
});
|
||||
},
|
||||
beatmap: async(data: HybridInteractionMessage) => {
|
||||
|
||||
beatmap: async (data: HybridInteractionMessage) => {
|
||||
let beatmap;
|
||||
if(data.isMessage()) {
|
||||
if(typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_BEATMAP_MENTIONED(data.getRaw())] });
|
||||
if (data.isMessage()) {
|
||||
if (typeof args[1] === 'undefined')
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_BEATMAP_MENTIONED(data.getRaw())]
|
||||
});
|
||||
const [removed, ...newArgs] = args;
|
||||
beatmap = newArgs.join(" ");
|
||||
}
|
||||
else if(data.isSlashCommand())
|
||||
beatmap = newArgs.join(' ');
|
||||
} else if (data.isSlashCommand())
|
||||
beatmap = data.getSlashCommand().options.getString('beatmap');
|
||||
|
||||
|
||||
if(!validator.isNumeric(beatmap))
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.INVALID_BEATMAP_ID_MENTIONED(data.getRaw())] });
|
||||
if (!validator.isNumeric(beatmap))
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.INVALID_BEATMAP_ID_MENTIONED(data.getRaw())]
|
||||
});
|
||||
|
||||
let result = await osuAPI.client.getBeatmaps({ b: beatmap });
|
||||
|
||||
if(result instanceof Array && result.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.NO_BEATMAP_FOUND(data.getRaw())] });
|
||||
if (result instanceof Array && result.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NO_BEATMAP_FOUND(data.getRaw())]
|
||||
});
|
||||
|
||||
if(data.isSlashCommand())
|
||||
await data.getSlashCommand().deferReply();
|
||||
if (data.isSlashCommand()) await data.getSlashCommand().deferReply();
|
||||
|
||||
const bm_result = result[0];
|
||||
|
||||
let url_mode = "#osu";
|
||||
let statusEmoji = "⚪";
|
||||
|
||||
let url_mode = '#osu';
|
||||
let statusEmoji = '⚪';
|
||||
let mode: unknown = bm_result.mode;
|
||||
let status: unknown = bm_result.approvalStatus;
|
||||
|
||||
if((mode as String) === "Taiko")
|
||||
url_mode = "#taiko";
|
||||
else if((mode as String) === "Catch the Beat")
|
||||
url_mode = "#fruits";
|
||||
else if((mode as String) === "Mania")
|
||||
url_mode = "#mania";
|
||||
if ((mode as String) === 'Taiko') url_mode = '#taiko';
|
||||
else if ((mode as String) === 'Catch the Beat') url_mode = '#fruits';
|
||||
else if ((mode as String) === 'Mania') url_mode = '#mania';
|
||||
|
||||
if((status as String) === "Ranked")
|
||||
statusEmoji = "🏆";
|
||||
else if((status as String) === "Loved")
|
||||
statusEmoji = "❤";
|
||||
else if((status as String) === "Qualified")
|
||||
statusEmoji = "✅";
|
||||
else if((status as String) === "WIP")
|
||||
statusEmoji = "🛠";
|
||||
else if((status as String) === "Pending")
|
||||
statusEmoji = "⌛";
|
||||
else if((status as String) === "Graveyard")
|
||||
statusEmoji = "💀";
|
||||
if ((status as String) === 'Ranked') statusEmoji = '🏆';
|
||||
else if ((status as String) === 'Loved') statusEmoji = '❤';
|
||||
else if ((status as String) === 'Qualified') statusEmoji = '✅';
|
||||
else if ((status as String) === 'WIP') statusEmoji = '🛠';
|
||||
else if ((status as String) === 'Pending') statusEmoji = '⌛';
|
||||
else if ((status as String) === 'Graveyard') statusEmoji = '💀';
|
||||
|
||||
const embed2 = makeInfoEmbed ({
|
||||
const embed2 = makeInfoEmbed({
|
||||
icon: '',
|
||||
title: `${bm_result.title} - ${bm_result.artist}`,
|
||||
fields: [
|
||||
{
|
||||
name: `Difficulty **[${bm_result.version}]**`,
|
||||
value: `Mapper [${bm_result.creator}](${encodeURI('https://osu.ppy.sh/u/'+ bm_result.creator)})
|
||||
value: `Mapper [${bm_result.creator}](${encodeURI(
|
||||
'https://osu.ppy.sh/u/' + bm_result.creator
|
||||
)})
|
||||
Rating **${bm_result.rating.toFixed(2)}/10**
|
||||
\u200b`,
|
||||
\u200b`
|
||||
},
|
||||
{
|
||||
name: "⭐ Star Difficulty",
|
||||
value: `**${(Math.round((bm_result.difficulty.rating + Number.EPSILON) * 100) / 100).toFixed(2)}**`,
|
||||
name: '⭐ Star Difficulty',
|
||||
value: `**${(
|
||||
Math.round((bm_result.difficulty.rating + Number.EPSILON) * 100) /
|
||||
100
|
||||
).toFixed(2)}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: `⌛ Length`,
|
||||
value: `**${(Math.round(((bm_result.length.total / 60) + Number.EPSILON) * 100) / 100).toFixed(2).replace('.', ':')}**`,
|
||||
value: `**${(
|
||||
Math.round((bm_result.length.total / 60 + Number.EPSILON) * 100) /
|
||||
100
|
||||
)
|
||||
.toFixed(2)
|
||||
.replace('.', ':')}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "🏓 Combo",
|
||||
name: '🏓 Combo',
|
||||
value: `**${this.numberWithCommas(bm_result.maxCombo)}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "🕹 Mode",
|
||||
name: '🕹 Mode',
|
||||
value: `**${mode}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "🎵 BPM",
|
||||
name: '🎵 BPM',
|
||||
value: `**${bm_result.bpm}**`,
|
||||
inline: true
|
||||
},
|
||||
@@ -309,17 +367,17 @@ export default class osu extends DiscordModule {
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "⭕ Circle",
|
||||
name: '⭕ Circle',
|
||||
value: `**${bm_result.objects.normal}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "💨 Slider",
|
||||
name: '💨 Slider',
|
||||
value: `**${bm_result.objects.slider}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "💫 Spinner",
|
||||
name: '💫 Spinner',
|
||||
value: `**${bm_result.objects.spinner}**
|
||||
\u200b`,
|
||||
inline: true
|
||||
@@ -328,30 +386,42 @@ export default class osu extends DiscordModule {
|
||||
name: `🎶 Track Information`,
|
||||
value: `Language: **${bm_result.language}**
|
||||
Genre: **${bm_result.genre}**
|
||||
Submission Date: <t:${Math.round(new Date(bm_result.raw_submitDate).getTime() / 1000)}:R>, <t:${Math.round(new Date(bm_result.raw_submitDate).getTime() / 1000)}:f>
|
||||
Last updated: <t:${Math.round(new Date(bm_result.raw_lastUpdate).getTime() / 1000)}:R>, <t:${Math.round(new Date(bm_result.raw_lastUpdate).getTime() / 1000)}:f>
|
||||
Approved: <t:${Math.round(new Date(bm_result.raw_approvedDate).getTime() / 1000)}:R>, <t:${Math.round(new Date(bm_result.raw_approvedDate).getTime() / 1000)}:f>
|
||||
\u200b`,
|
||||
Submission Date: <t:${Math.round(
|
||||
new Date(bm_result.raw_submitDate).getTime() / 1000
|
||||
)}:R>, <t:${Math.round(
|
||||
new Date(bm_result.raw_submitDate).getTime() / 1000
|
||||
)}:f>
|
||||
Last updated: <t:${Math.round(
|
||||
new Date(bm_result.raw_lastUpdate).getTime() / 1000
|
||||
)}:R>, <t:${Math.round(
|
||||
new Date(bm_result.raw_lastUpdate).getTime() / 1000
|
||||
)}:f>
|
||||
Approved: <t:${Math.round(
|
||||
new Date(bm_result.raw_approvedDate).getTime() / 1000
|
||||
)}:R>, <t:${Math.round(
|
||||
new Date(bm_result.raw_approvedDate).getTime() / 1000
|
||||
)}:f>
|
||||
\u200b`
|
||||
},
|
||||
{
|
||||
name: "▶ Plays",
|
||||
name: '▶ Plays',
|
||||
value: `**${this.numberWithCommas(bm_result.counts.plays)}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "🏁 Passes",
|
||||
name: '🏁 Passes',
|
||||
value: `**${this.numberWithCommas(bm_result.counts.passes)}**`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "♥ Favorites",
|
||||
name: '♥ Favorites',
|
||||
value: `**${this.numberWithCommas(bm_result.counts.favorites)}**
|
||||
\u200b`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: `📌 Tags`,
|
||||
value: `\`\`${bm_result.tags.join(" ")}\`\``,
|
||||
value: `\`\`${bm_result.tags.join(' ')}\`\``
|
||||
}
|
||||
],
|
||||
user: data.getUser()
|
||||
@@ -362,70 +432,78 @@ export default class osu extends DiscordModule {
|
||||
url: `https://osu.ppy.sh/beatmapsets/${bm_result.beatmapSetId}${url_mode}/${bm_result.id}`,
|
||||
iconURL: `https://upload.wikimedia.org/wikipedia/commons/e/e3/Osulogo.png`
|
||||
});
|
||||
embed2.setImage(`https://assets.ppy.sh/beatmaps/${bm_result.beatmapSetId}/covers/cover.jpg`);
|
||||
|
||||
embed2.setImage(
|
||||
`https://assets.ppy.sh/beatmaps/${bm_result.beatmapSetId}/covers/cover.jpg`
|
||||
);
|
||||
|
||||
const row = new MessageActionRow();
|
||||
if(bm_result.hasDownload)
|
||||
if (bm_result.hasDownload)
|
||||
row.addComponents(
|
||||
new MessageButton()
|
||||
.setEmoji('🌎')
|
||||
.setLabel(' Download (Beatconnect)')
|
||||
.setURL(`https://beatconnect.io/b/${bm_result.beatmapSetId}/`)
|
||||
.setStyle('LINK'),
|
||||
)
|
||||
.setStyle('LINK')
|
||||
);
|
||||
row.addComponents(
|
||||
new MessageButton()
|
||||
.setEmoji('🔗')
|
||||
.setLabel(' Open listing')
|
||||
.setURL(`https://osu.ppy.sh/beatmapsets/${bm_result.beatmapSetId}${url_mode}/${bm_result.id}`)
|
||||
.setStyle('LINK'),
|
||||
)
|
||||
.setURL(
|
||||
`https://osu.ppy.sh/beatmapsets/${bm_result.beatmapSetId}${url_mode}/${bm_result.id}`
|
||||
)
|
||||
.setStyle('LINK')
|
||||
);
|
||||
row.addComponents(
|
||||
new MessageButton()
|
||||
.setEmoji('💬')
|
||||
.setLabel(' Open discussion')
|
||||
.setURL(`https://osu.ppy.sh/beatmapsets/${bm_result.beatmapSetId}/discussion`)
|
||||
.setStyle('LINK'),
|
||||
)
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [embed2], components: [row] });
|
||||
.setURL(
|
||||
`https://osu.ppy.sh/beatmapsets/${bm_result.beatmapSetId}/discussion`
|
||||
)
|
||||
.setStyle('LINK')
|
||||
);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [embed2],
|
||||
components: [row]
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let query;
|
||||
|
||||
if(data.isMessage()) {
|
||||
if(args.length === 0) {
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.osu_INFO(data.getRaw())] });
|
||||
if (data.isMessage()) {
|
||||
if (args.length === 0) {
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.osu_INFO(data.getRaw())]
|
||||
});
|
||||
}
|
||||
query = args[0].toLowerCase();
|
||||
}
|
||||
else if(data.isSlashCommand()) {
|
||||
} else if (data.isSlashCommand()) {
|
||||
query = args.getSubcommand();
|
||||
}
|
||||
|
||||
switch(query) {
|
||||
case "user":
|
||||
case "u":
|
||||
switch (query) {
|
||||
case 'user':
|
||||
case 'u':
|
||||
return await funct.user(data);
|
||||
case "beatmap":
|
||||
case "b":
|
||||
case 'beatmap':
|
||||
case 'b':
|
||||
return await funct.beatmap(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private numberWithCommas(x: Number) {
|
||||
try {
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
} catch(err) {
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
} catch (err) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
// Criteria from https://github.com/ppy/osu-web/blob/9de00a0b874c56893d98261d558d78d76259d81b/app/Libraries/UsernameValidation.php
|
||||
private validate_osu_username(username: string) {
|
||||
|
||||
//username_no_spaces
|
||||
if (username.startsWith(' ') || username.endsWith(' ')) return false;
|
||||
|
||||
@@ -436,12 +514,11 @@ export default class osu extends DiscordModule {
|
||||
if (username.length > 15) return false;
|
||||
|
||||
//username_invalid_characters
|
||||
if (username.includes(' ') || !(/^[A-Za-z0-9-\[\]_ ]+$/.test(username))) return false;
|
||||
if (username.includes(' ') || !/^[A-Za-z0-9-\[\]_ ]+$/.test(username)) return false;
|
||||
|
||||
//username_no_space_userscore_mix
|
||||
if (username.includes('_') && username.includes(' ')) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user