mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-14 03:09:59 +00:00
Fixed wrong folder name on unix systems
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
import { User as PrismaUser, Guild as PrismaGuild } from '@prisma/client';
|
||||
import {
|
||||
Message,
|
||||
Interaction,
|
||||
CommandInteraction,
|
||||
MessageActionRow,
|
||||
MessageButton,
|
||||
ButtonInteraction
|
||||
} from 'discord.js';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
import {
|
||||
makeInfoEmbed,
|
||||
makeErrorEmbed,
|
||||
sendHybridInteractionMessageResponse
|
||||
} from '../../utils/DiscordMessage';
|
||||
|
||||
import DiscordMusicPlayer from '../../providers/DiscordMusicPlayer';
|
||||
import Users from '../../services/Users';
|
||||
import Cache from '../../providers/Cache';
|
||||
|
||||
const EMBEDS = {
|
||||
DEBUG_INFO: (data: HybridInteractionMessage) => {
|
||||
return makeInfoEmbed({
|
||||
title: 'Debug',
|
||||
description: `Test and debug something. **Should not be used on production**`,
|
||||
fields: [
|
||||
{
|
||||
name: 'Available arguments',
|
||||
value: '``InvalidInteraction`` ``CrashMusicPlayer`` ``Crash`` ``ActiveMusicPlayer`` ``MyData`` ``GuildData``'
|
||||
}
|
||||
],
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
INVALID_TEST: (data: HybridInteractionMessage) => {
|
||||
return makeInfoEmbed({
|
||||
title: 'Click button below to test invalid interaction',
|
||||
description: `The interaction will be failed`,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
CRASHING: (data: HybridInteractionMessage) => {
|
||||
return makeInfoEmbed({
|
||||
icon: '💀',
|
||||
title: 'Crashing myself',
|
||||
description: `Sayonara.... cruel world`,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
ACTIVE_MUSIC_PLAYERS: (data: HybridInteractionMessage, totalplayers: Map<any, any>) => {
|
||||
return makeInfoEmbed({
|
||||
icon: '🎵',
|
||||
title: `Total active music players: ${totalplayers.size}`,
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
YOUR_USER_DATA: (data: HybridInteractionMessage, userData?: PrismaUser) => {
|
||||
return makeInfoEmbed({
|
||||
icon: '📃',
|
||||
title: `Your user data`,
|
||||
description: JSON.stringify(userData),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
GUILD_DATA: (data: HybridInteractionMessage, guildData?: PrismaGuild) => {
|
||||
return makeInfoEmbed({
|
||||
icon: '📃',
|
||||
title: `Guild data`,
|
||||
description: JSON.stringify(guildData),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
NOT_DEVELOPER: (data: HybridInteractionMessage) => {
|
||||
return makeErrorEmbed({
|
||||
title: 'Developer only',
|
||||
description: `This command is restricted to the developers only`,
|
||||
user: data.getUser()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default class Debug extends DiscordModule {
|
||||
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);
|
||||
}
|
||||
|
||||
async GuildModuleCommandInteractionCreate(interaction: CommandInteraction) {
|
||||
await this.run(new HybridInteractionMessage(interaction), interaction.options);
|
||||
}
|
||||
|
||||
async GuildButtonInteractionCreate(data: ButtonInteraction) {
|
||||
if (data.customId !== 'dev_make_invalid_interaction') return;
|
||||
|
||||
const hybridData = new HybridInteractionMessage(data);
|
||||
const user = hybridData.getUser();
|
||||
|
||||
if (!user) return;
|
||||
|
||||
if (!Users.isDeveloper(user.id))
|
||||
return await sendHybridInteractionMessageResponse(hybridData, {
|
||||
embeds: [EMBEDS.NOT_DEVELOPER(hybridData)]
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
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 (!Users.isDeveloper(user.id))
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.NOT_DEVELOPER(data)]
|
||||
});
|
||||
|
||||
const funct = {
|
||||
crash: async (data: HybridInteractionMessage) => {
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.CRASHING(data)]
|
||||
});
|
||||
throw new Error('Manually crashed by debug command');
|
||||
},
|
||||
crashMusicPlayer: async (data: HybridInteractionMessage) => {
|
||||
const instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
if (!instance) return;
|
||||
|
||||
instance._fake_error_on_player();
|
||||
},
|
||||
activeMusicPlayer: async (data: HybridInteractionMessage) => {
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [
|
||||
EMBEDS.ACTIVE_MUSIC_PLAYERS(data, DiscordMusicPlayer.GuildQueue)
|
||||
]
|
||||
});
|
||||
},
|
||||
myData: async (data: HybridInteractionMessage) => {
|
||||
const userData = await Cache.getCachedUser(user.id);
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [
|
||||
EMBEDS.YOUR_USER_DATA(data, userData)
|
||||
]
|
||||
});
|
||||
},
|
||||
guildData: async (data: HybridInteractionMessage) => {
|
||||
const guildData = await Cache.getCachedGuild(guild.id);
|
||||
await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [
|
||||
EMBEDS.GUILD_DATA(data, guildData)
|
||||
]
|
||||
});
|
||||
},
|
||||
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)],
|
||||
components: [row]
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
let query;
|
||||
|
||||
if (data.isMessage()) {
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.DEBUG_INFO(data)]
|
||||
});
|
||||
|
||||
query = args[0].toLowerCase();
|
||||
} else if (data.isSlashCommand()) {
|
||||
query = args.getSubcommand();
|
||||
}
|
||||
|
||||
switch (query) {
|
||||
case 'info':
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.DEBUG_INFO(data)]
|
||||
});
|
||||
case 'crash':
|
||||
return await funct.crash(data);
|
||||
case 'invalidinteraction':
|
||||
return await funct.invalidInteraction(data);
|
||||
case 'crashmusicplayer':
|
||||
return await funct.crashMusicPlayer(data);
|
||||
case 'activemusicplayer':
|
||||
return await funct.activeMusicPlayer(data);
|
||||
case 'mydata':
|
||||
return await funct.myData(data);
|
||||
case 'guilddata':
|
||||
return await funct.guildData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,363 @@
|
||||
import { Message, MessageEmbed, Interaction, CommandInteraction, TextChannel } from 'discord.js';
|
||||
import { Promise } from 'bluebird';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
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) => {
|
||||
return makeInfoEmbed({
|
||||
title: 'Service Announcement',
|
||||
description: `This module contains management tool for announcement feed\n The announcement message is located in \`\`configs/ServiceAnnouncement.json\`\``,
|
||||
fields: [
|
||||
{
|
||||
name: 'Available arguments',
|
||||
value: '``reload`` ``previewNews`` ``sendNews`` ``previewMaintenance`` ``sendMaintenance`` ``previewMessage`` ``sendMessage`` ``previewAlert`` ``sendAlert``'
|
||||
}
|
||||
],
|
||||
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
|
||||
});
|
||||
},
|
||||
MAKE_PAYLOAD: (payload: any) => {
|
||||
const user = DiscordProvider.client.user;
|
||||
payload.footer = {
|
||||
text: `${user?.username}`,
|
||||
iconURL: `${user?.displayAvatarURL()}?size=4096`
|
||||
};
|
||||
|
||||
if (!payload.timestamp) payload.timestamp = new Date();
|
||||
|
||||
if (payload.thumbnail?.url === 'bot_avatar')
|
||||
payload.thumbnail.url = `${user?.displayAvatarURL()}?size=4096`;
|
||||
|
||||
if (payload.image?.url === 'bot_avatar')
|
||||
payload.image.url = `${user?.displayAvatarURL()}?size=4096`;
|
||||
|
||||
if (payload.description)
|
||||
payload.description = payload.description.replaceAll('{bot_username}', user?.username);
|
||||
|
||||
return new MessageEmbed(payload);
|
||||
},
|
||||
RELOADED: (data: Message | Interaction) => {
|
||||
return makeSuccessEmbed({
|
||||
title: 'Service Announcement Configuration Reloaded',
|
||||
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
|
||||
});
|
||||
},
|
||||
SENDING_SERVICE_ANNOUNCEMENT: (data: Message | Interaction) => {
|
||||
return makeProcessingEmbed({
|
||||
title: 'Service Announcement',
|
||||
description: `Broadcasting Service Announcement`,
|
||||
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
|
||||
});
|
||||
},
|
||||
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
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
let Announcements = {
|
||||
News: {
|
||||
color: '#FAEDF0',
|
||||
title: '📰 Newsletter',
|
||||
description: 'Some description here',
|
||||
thumbnail: {
|
||||
url: 'bot_avatar'
|
||||
}
|
||||
},
|
||||
Maintenance: {
|
||||
color: '#383b80',
|
||||
title: '🔧 Maintenance',
|
||||
description: 'The bot is going offline for maintenance.',
|
||||
thumbnail: {
|
||||
url: 'bot_avatar'
|
||||
}
|
||||
},
|
||||
Message: {
|
||||
color: '#A1DE93',
|
||||
title: '✉️ Message',
|
||||
description: 'Some description here',
|
||||
thumbnail: {
|
||||
url: 'bot_avatar'
|
||||
}
|
||||
},
|
||||
Alert: {
|
||||
color: '#EC255A',
|
||||
title: '🚨 Alert',
|
||||
description: 'Some description here',
|
||||
thumbnail: {
|
||||
url: 'bot_avatar'
|
||||
}
|
||||
}
|
||||
};
|
||||
export default class ServiceAnnouncement extends DiscordModule {
|
||||
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 jsonData = JSON.parse(rawData.toString());
|
||||
Announcements = jsonData;
|
||||
} catch (err) {
|
||||
Logger.error('Unable to load custom ServiceAnnouncement config: ' + err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async GuildOnModuleCommand(args: any, message: Message) {
|
||||
await this.run(new HybridInteractionMessage(message), args);
|
||||
}
|
||||
|
||||
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())]
|
||||
});
|
||||
|
||||
const channel = data.getChannel();
|
||||
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 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)]
|
||||
});
|
||||
}
|
||||
} else {
|
||||
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())]
|
||||
});
|
||||
},
|
||||
previewNews: async (data: HybridInteractionMessage) => {
|
||||
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)]
|
||||
});
|
||||
},
|
||||
previewMessage: async (data: HybridInteractionMessage) => {
|
||||
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)]
|
||||
});
|
||||
},
|
||||
publishServiceAnnouncement: async (data: HybridInteractionMessage, embed: any) => {
|
||||
const Guilds = await Prisma.client.guild.findMany({});
|
||||
const toSend = new Map();
|
||||
|
||||
let withError = false;
|
||||
|
||||
for (const Guild of Guilds) {
|
||||
if (!Guild.ServiceAnnouncement_Enabled) continue;
|
||||
if (Guild.ServiceAnnouncement_Channel === null) continue;
|
||||
|
||||
let channel = undefined;
|
||||
try {
|
||||
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})`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!channel) continue;
|
||||
toSend.set(Guild, channel);
|
||||
}
|
||||
|
||||
let placeholder: HybridInteractionMessage | undefined;
|
||||
|
||||
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})`
|
||||
);
|
||||
|
||||
reject(err);
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let query;
|
||||
|
||||
if (data.isMessage()) {
|
||||
if (args.length === 0)
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ANNOUNCEMENT_INFO(data.getRaw())]
|
||||
});
|
||||
query = args[0].toLowerCase();
|
||||
} else if (data.isSlashCommand()) {
|
||||
query = args.getSubcommand();
|
||||
}
|
||||
|
||||
switch (query) {
|
||||
case 'info':
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ANNOUNCEMENT_INFO(data.getRaw())]
|
||||
});
|
||||
case 'reload':
|
||||
return await funct.reload(data);
|
||||
case 'previewnews':
|
||||
return await funct.previewNews(data);
|
||||
case 'previewmaintenance':
|
||||
return await funct.previewMaintenance(data);
|
||||
case 'previewmessage':
|
||||
return await funct.previewMessage(data);
|
||||
case 'previewalert':
|
||||
return await funct.previewAlert(data);
|
||||
case 'sendnews':
|
||||
return await funct.publishServiceAnnouncement(data, Announcements.News);
|
||||
case 'sendmaintenance':
|
||||
return await funct.publishServiceAnnouncement(data, Announcements.Maintenance);
|
||||
case 'sendmessage':
|
||||
return await funct.publishServiceAnnouncement(data, Announcements.Message);
|
||||
case 'sendalert':
|
||||
return await funct.publishServiceAnnouncement(data, Announcements.Alert);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user