style(norme/eslint): now edited the husky rules before commiting
This commit is contained in:
parent
439ddab587
commit
1c4c0f5872
16 changed files with 1883 additions and 1845 deletions
104
eslint.config.js
104
eslint.config.js
|
|
@ -1,55 +1,55 @@
|
||||||
import js from "@eslint/js";
|
import js from '@eslint/js';
|
||||||
import ts from "typescript-eslint";
|
import ts from 'typescript-eslint';
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
js.configs.recommended,
|
js.configs.recommended,
|
||||||
...ts.configs.recommended,
|
...ts.configs.recommended,
|
||||||
{
|
{
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
ecmaVersion: "latest",
|
ecmaVersion: 'latest',
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
"arrow-spacing": ["warn", { before: true, after: true }],
|
'arrow-spacing': ['warn', { before: true, after: true }],
|
||||||
"brace-style": ["error", "stroustrup", { allowSingleLine: true }],
|
'brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
|
||||||
"comma-dangle": ["error", "always-multiline"],
|
'comma-dangle': ['error', 'always-multiline'],
|
||||||
"comma-spacing": "error",
|
'comma-spacing': 'error',
|
||||||
"comma-style": "error",
|
'comma-style': 'error',
|
||||||
curly: ["error", "multi-line", "consistent"],
|
curly: ['error', 'multi-line', 'consistent'],
|
||||||
"dot-location": ["error", "property"],
|
'dot-location': ['error', 'property'],
|
||||||
"handle-callback-err": "off",
|
'handle-callback-err': 'off',
|
||||||
indent: ["error", "tab"],
|
indent: ['error', 'tab'],
|
||||||
"keyword-spacing": "error",
|
'keyword-spacing': 'error',
|
||||||
"max-nested-callbacks": ["error", { max: 4 }],
|
'max-nested-callbacks': ['error', { max: 4 }],
|
||||||
"max-statements-per-line": ["error", { max: 2 }],
|
'max-statements-per-line': ['error', { max: 2 }],
|
||||||
"no-console": "off",
|
'no-console': 'off',
|
||||||
"no-empty-function": "error",
|
'no-empty-function': 'error',
|
||||||
"no-floating-decimal": "error",
|
'no-floating-decimal': 'error',
|
||||||
"no-inline-comments": "error",
|
'no-inline-comments': 'error',
|
||||||
"no-lonely-if": "error",
|
'no-lonely-if': 'error',
|
||||||
"no-multi-spaces": "error",
|
'no-multi-spaces': 'error',
|
||||||
"no-multiple-empty-lines": ["error", { max: 2, maxEOF: 1, maxBOF: 0 }],
|
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1, maxBOF: 0 }],
|
||||||
"no-shadow": ["error", { allow: ["err", "resolve", "reject"] }],
|
'no-shadow': ['error', { allow: ['err', 'resolve', 'reject'] }],
|
||||||
"no-trailing-spaces": ["error"],
|
'no-trailing-spaces': ['error'],
|
||||||
"no-var": "error",
|
'no-var': 'error',
|
||||||
"no-undef": "off",
|
'no-undef': 'off',
|
||||||
"object-curly-spacing": ["error", "always"],
|
'object-curly-spacing': ['error', 'always'],
|
||||||
"prefer-const": "error",
|
'prefer-const': 'error',
|
||||||
quotes: ["error", "single"],
|
quotes: ['error', 'single'],
|
||||||
semi: ["error", "always"],
|
semi: ['error', 'always'],
|
||||||
"space-before-blocks": "error",
|
'space-before-blocks': 'error',
|
||||||
"space-before-function-paren": [
|
'space-before-function-paren': [
|
||||||
"error",
|
'error',
|
||||||
{
|
{
|
||||||
anonymous: "never",
|
anonymous: 'never',
|
||||||
named: "never",
|
named: 'never',
|
||||||
asyncArrow: "always",
|
asyncArrow: 'always',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"space-in-parens": "error",
|
'space-in-parens': 'error',
|
||||||
"space-infix-ops": "error",
|
'space-infix-ops': 'error',
|
||||||
"space-unary-ops": "error",
|
'space-unary-ops': 'error',
|
||||||
"spaced-comment": "error",
|
'spaced-comment': 'error',
|
||||||
yoda: "error",
|
yoda: 'error',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,8 @@
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.{ts,js,cts,mts}": [
|
"*": [
|
||||||
"eslint --fix",
|
"eslint --fix"
|
||||||
"prettier --write"
|
|
||||||
],
|
|
||||||
"*.{json,md,yml,yaml}": [
|
|
||||||
"prettier --write"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
|
|
@ -1,93 +1,95 @@
|
||||||
import { prisma } from "../../lib/prisma.ts";
|
import { prisma } from '../../lib/prisma.ts';
|
||||||
import {
|
import {
|
||||||
ActionRowBuilder,
|
ActionRowBuilder,
|
||||||
ChannelType,
|
ChannelType,
|
||||||
PermissionsBitField,
|
PermissionsBitField,
|
||||||
ComponentType,
|
ComponentType,
|
||||||
StringSelectMenuBuilder,
|
StringSelectMenuBuilder,
|
||||||
StringSelectMenuInteraction,
|
StringSelectMenuInteraction,
|
||||||
StringSelectMenuOptionBuilder,
|
StringSelectMenuOptionBuilder,
|
||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
MessageFlags,
|
MessageFlags,
|
||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
} from "discord.js";
|
} from 'discord.js';
|
||||||
import emoji from "../../../assets/emoji.json" assert { type: "json" };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("logs")
|
.setName('logs')
|
||||||
.setDescription("edit the logs configuration")
|
.setDescription('edit the logs configuration')
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("action")
|
.setName('action')
|
||||||
.setDescription("What is the action you to perform")
|
.setDescription('What is the action you to perform')
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.addChoices(
|
.addChoices(
|
||||||
{
|
{
|
||||||
name: "Show",
|
name: 'Show',
|
||||||
value: "logs_show",
|
value: 'logs_show',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Auto-configuration",
|
name: 'Auto-configuration',
|
||||||
value: "logs_auto",
|
value: 'logs_auto',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Configuration",
|
name: 'Configuration',
|
||||||
value: "logs_config",
|
value: 'logs_config',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
async execute(interaction: CommandInteraction) {
|
async execute(interaction: CommandInteraction) {
|
||||||
let guildData: Guild;
|
let guildData: Guild;
|
||||||
try {
|
try {
|
||||||
guildData = await prisma.guild.findUnique({
|
guildData = await prisma.guild.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: interaction.guild.id,
|
id: interaction.guild.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (err) {
|
}
|
||||||
console.error(
|
catch (err) {
|
||||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
console.error(
|
||||||
);
|
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
||||||
await interaction.reply({
|
);
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | Cannot connect to the database`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
let userData: User;
|
}
|
||||||
try {
|
let userData: User;
|
||||||
userData = await prisma.user.findUnique({
|
try {
|
||||||
where: {
|
userData = await prisma.user.findUnique({
|
||||||
id: interaction.user.id,
|
where: {
|
||||||
},
|
id: interaction.user.id,
|
||||||
});
|
},
|
||||||
} catch (err) {
|
});
|
||||||
throw `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`;
|
}
|
||||||
await interaction.reply({
|
catch (err) {
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
throw `\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`;
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.error} | Cannot connect to the database`,
|
||||||
return;
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
const choice: string = interaction.options.getString("action");
|
return;
|
||||||
switch (choice) {
|
}
|
||||||
case "logs_show": {
|
const choice: string = interaction.options.getString('action');
|
||||||
if (!userData.isOwner) {
|
switch (choice) {
|
||||||
await interaction.reply({
|
case 'logs_show': {
|
||||||
content: `${emoji.answer.no} | This command is only for owner`,
|
if (!userData.isOwner) {
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.no} | This command is only for owner`,
|
||||||
return;
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
if (guildData.logEnable) {
|
return;
|
||||||
const logsData: EmbedBuilder = new EmbedBuilder()
|
}
|
||||||
.setTitle(`Logs for ${interaction.guild.name}`)
|
if (guildData.logEnable) {
|
||||||
.setColor(`${guildData.color}`)
|
const logsData: EmbedBuilder = new EmbedBuilder()
|
||||||
.setFooter({
|
.setTitle(`Logs for ${interaction.guild.name}`)
|
||||||
text: guildData.footer,
|
.setColor(`${guildData.color}`)
|
||||||
}).setDescription(`
|
.setFooter({
|
||||||
|
text: guildData.footer,
|
||||||
|
}).setDescription(`
|
||||||
${guildData.logCategory ? `${emoji.answer.yes} | Categories` : `${emoji.answer.no} | Categories`}
|
${guildData.logCategory ? `${emoji.answer.yes} | Categories` : `${emoji.answer.no} | Categories`}
|
||||||
${guildData.logBot ? `${emoji.answer.yes} | Bot` : `${emoji.answer.no} | Bot`}
|
${guildData.logBot ? `${emoji.answer.yes} | Bot` : `${emoji.answer.no} | Bot`}
|
||||||
${guildData.logChannels ? `${emoji.answer.yes} | Channels` : `${emoji.answer.no} | Channels`}
|
${guildData.logChannels ? `${emoji.answer.yes} | Channels` : `${emoji.answer.no} | Channels`}
|
||||||
|
|
@ -97,185 +99,186 @@ export default {
|
||||||
${guildData.logServer ? `${emoji.answer.yes} | Server` : `${emoji.answer.no} | Server`}
|
${guildData.logServer ? `${emoji.answer.yes} | Server` : `${emoji.answer.no} | Server`}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [logsData],
|
embeds: [logsData],
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
await interaction.reply({
|
else {
|
||||||
content: `${emoji.answer.no} | The log is disable on the server`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.no} | The log is disable on the server`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
return;
|
}
|
||||||
}
|
return;
|
||||||
case "logs_auto": {
|
}
|
||||||
if (!userData.isOwner) {
|
case 'logs_auto': {
|
||||||
await interaction.reply({
|
if (!userData.isOwner) {
|
||||||
content: `${emoji.answer.no} | This command is only for owner`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.no} | This command is only for owner`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
if (guildData.logEnable) {
|
}
|
||||||
await interaction.reply({
|
if (guildData.logEnable) {
|
||||||
content: `${emoji.answer.error} | The log is already setup on this server`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | The log is already setup on this server`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const roles = interaction.guild?.roles.cache
|
const roles = interaction.guild?.roles.cache
|
||||||
.filter((role) => !role.managed && role.id !== interaction.guild?.id)
|
.filter((role) => !role.managed && role.id !== interaction.guild?.id)
|
||||||
.sort((a, b) => b.position - a.position);
|
.sort((a, b) => b.position - a.position);
|
||||||
|
|
||||||
const menu = new StringSelectMenuBuilder()
|
const menu = new StringSelectMenuBuilder()
|
||||||
.setCustomId("role_select")
|
.setCustomId('role_select')
|
||||||
.setPlaceholder("Choose the role that will have logs access")
|
.setPlaceholder('Choose the role that will have logs access')
|
||||||
.setMinValues(1)
|
.setMinValues(1)
|
||||||
.setMaxValues(Math.min(roles.size, 25))
|
.setMaxValues(Math.min(roles.size, 25))
|
||||||
.addOptions(
|
.addOptions(
|
||||||
roles.map((role) =>
|
roles.map((role) =>
|
||||||
new StringSelectMenuOptionBuilder()
|
new StringSelectMenuOptionBuilder()
|
||||||
.setLabel(role.name)
|
.setLabel(role.name)
|
||||||
.setValue(role.id),
|
.setValue(role.id),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
const roleSelection =
|
const roleSelection =
|
||||||
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(menu);
|
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(menu);
|
||||||
|
|
||||||
const permSelector: EmbedBuilder = new EmbedBuilder()
|
const permSelector: EmbedBuilder = new EmbedBuilder()
|
||||||
.setTitle("Which role will have access")
|
.setTitle('Which role will have access')
|
||||||
.setColor(`${guildData.color}`)
|
.setColor(`${guildData.color}`)
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: guildData.footer,
|
text: guildData.footer,
|
||||||
});
|
});
|
||||||
|
|
||||||
const msg = await interaction.reply({
|
const msg = await interaction.reply({
|
||||||
embeds: [permSelector],
|
embeds: [permSelector],
|
||||||
components: [roleSelection],
|
components: [roleSelection],
|
||||||
flags: MessageFlags.fetchReply,
|
flags: MessageFlags.fetchReply,
|
||||||
});
|
});
|
||||||
const collector = msg.createMessageComponentCollector({
|
const collector = msg.createMessageComponentCollector({
|
||||||
componentType: ComponentType.StringSelect,
|
componentType: ComponentType.StringSelect,
|
||||||
time: 60_000,
|
time: 60_000,
|
||||||
max: 25,
|
max: 25,
|
||||||
});
|
});
|
||||||
collector.on(
|
collector.on(
|
||||||
"collect",
|
'collect',
|
||||||
async (selectInteraction: StringSelectMenuInteraction) => {
|
async (selectInteraction: StringSelectMenuInteraction) => {
|
||||||
if (selectInteraction.user.id !== interaction.user.id) {
|
if (selectInteraction.user.id !== interaction.user.id) {
|
||||||
selectInteraction.reply({
|
selectInteraction.reply({
|
||||||
content: `${emoji.answer.no} | You cannot use this selector !`,
|
content: `${emoji.answer.no} | You cannot use this selector !`,
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const selectedRoles = selectInteraction.values;
|
const selectedRoles = selectInteraction.values;
|
||||||
const permissionOverwrites = [
|
const permissionOverwrites = [
|
||||||
{
|
{
|
||||||
id: interaction.guild.roles.everyone.id,
|
id: interaction.guild.roles.everyone.id,
|
||||||
deny: [
|
deny: [
|
||||||
PermissionsBitField.Flags.ViewChannel,
|
PermissionsBitField.Flags.ViewChannel,
|
||||||
PermissionsBitField.Flags.SendMessages,
|
PermissionsBitField.Flags.SendMessages,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
...selectedRoles.map((id) => ({
|
...selectedRoles.map((id) => ({
|
||||||
id,
|
id,
|
||||||
allow: [PermissionsBitField.Flags.ViewChannel],
|
allow: [PermissionsBitField.Flags.ViewChannel],
|
||||||
})),
|
})),
|
||||||
];
|
];
|
||||||
|
|
||||||
const category = (await interaction.guild.channels.create({
|
const category = (await interaction.guild.channels.create({
|
||||||
name: "Logs",
|
name: 'Logs',
|
||||||
type: ChannelType.GuildCategory,
|
type: ChannelType.GuildCategory,
|
||||||
permissionOverwrites,
|
permissionOverwrites,
|
||||||
})) as CategoryChannel;
|
})) as CategoryChannel;
|
||||||
|
|
||||||
const logBot = (await interaction.guild.channels.create({
|
const logBot = (await interaction.guild.channels.create({
|
||||||
name: "bot-logs",
|
name: 'bot-logs',
|
||||||
type: ChannelType.GuildText,
|
type: ChannelType.GuildText,
|
||||||
parent: category,
|
parent: category,
|
||||||
permissionOverwrites,
|
permissionOverwrites,
|
||||||
})) as TextChannel;
|
})) as TextChannel;
|
||||||
|
|
||||||
const logChannels = (await interaction.guild.channels.create({
|
const logChannels = (await interaction.guild.channels.create({
|
||||||
name: "channel-logs",
|
name: 'channel-logs',
|
||||||
type: ChannelType.GuildText,
|
type: ChannelType.GuildText,
|
||||||
parent: category,
|
parent: category,
|
||||||
permissionOverwrites,
|
permissionOverwrites,
|
||||||
})) as TextChannel;
|
})) as TextChannel;
|
||||||
|
|
||||||
const logMember = (await interaction.guild.channels.create({
|
const logMember = (await interaction.guild.channels.create({
|
||||||
name: "member-logs",
|
name: 'member-logs',
|
||||||
type: ChannelType.GuildText,
|
type: ChannelType.GuildText,
|
||||||
parent: category,
|
parent: category,
|
||||||
permissionOverwrites,
|
permissionOverwrites,
|
||||||
})) as TextChannel;
|
})) as TextChannel;
|
||||||
|
|
||||||
const logMod = (await interaction.guild.channels.create({
|
const logMod = (await interaction.guild.channels.create({
|
||||||
name: "mod-logs",
|
name: 'mod-logs',
|
||||||
type: ChannelType.GuildText,
|
type: ChannelType.GuildText,
|
||||||
parent: category,
|
parent: category,
|
||||||
permissionOverwrites,
|
permissionOverwrites,
|
||||||
})) as TextChannel;
|
})) as TextChannel;
|
||||||
|
|
||||||
const logMsg = (await interaction.guild.channels.create({
|
const logMsg = (await interaction.guild.channels.create({
|
||||||
name: "message-logs",
|
name: 'message-logs',
|
||||||
type: ChannelType.GuildText,
|
type: ChannelType.GuildText,
|
||||||
parent: category,
|
parent: category,
|
||||||
permissionOverwrites,
|
permissionOverwrites,
|
||||||
})) as TextChannel;
|
})) as TextChannel;
|
||||||
|
|
||||||
const logServer = (await interaction.guild.channels.create({
|
const logServer = (await interaction.guild.channels.create({
|
||||||
name: "server-logs",
|
name: 'server-logs',
|
||||||
type: ChannelType.GuildText,
|
type: ChannelType.GuildText,
|
||||||
parent: category,
|
parent: category,
|
||||||
permissionOverwrites,
|
permissionOverwrites,
|
||||||
})) as TextChannel;
|
})) as TextChannel;
|
||||||
|
|
||||||
await prisma.guild.update({
|
await prisma.guild.update({
|
||||||
where: {
|
where: {
|
||||||
id: interaction.guild.id,
|
id: interaction.guild.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
logEnable: true,
|
logEnable: true,
|
||||||
logCategory: category.id,
|
logCategory: category.id,
|
||||||
logBot: logBot.id,
|
logBot: logBot.id,
|
||||||
logChannels: logChannels.id,
|
logChannels: logChannels.id,
|
||||||
logMember: logMember.id,
|
logMember: logMember.id,
|
||||||
logMod: logMod.id,
|
logMod: logMod.id,
|
||||||
logMsg: logMsg.id,
|
logMsg: logMsg.id,
|
||||||
logServer: logServer.id,
|
logServer: logServer.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const mentionList = selectedRoles
|
const mentionList = selectedRoles
|
||||||
.map((id) => `- <@&${id}>`)
|
.map((id) => `- <@&${id}>`)
|
||||||
.join("\n");
|
.join('\n');
|
||||||
const autoConfig = new EmbedBuilder()
|
const autoConfig = new EmbedBuilder()
|
||||||
.setTitle("The logs category is created")
|
.setTitle('The logs category is created')
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`
|
`
|
||||||
This following roles will have access to the logs.
|
This following roles will have access to the logs.
|
||||||
${mentionList}
|
${mentionList}
|
||||||
`,
|
`,
|
||||||
)
|
)
|
||||||
.setColor(`${guildData.color}`)
|
.setColor(`${guildData.color}`)
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: guildData.footer,
|
text: guildData.footer,
|
||||||
});
|
});
|
||||||
await selectInteraction.update({
|
await selectInteraction.update({
|
||||||
embeds: [autoConfig],
|
embeds: [autoConfig],
|
||||||
components: [],
|
components: [],
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
console.error(`no choice on logs command ${choice}`);
|
console.error(`no choice on logs command ${choice}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,322 +1,326 @@
|
||||||
import { prisma } from "../../lib/prisma.ts";
|
import { prisma } from '../../lib/prisma.ts';
|
||||||
import {
|
import {
|
||||||
ActivityType,
|
ActivityType,
|
||||||
PresenceUpdateStatus,
|
PresenceUpdateStatus,
|
||||||
MessageFlags,
|
MessageFlags,
|
||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
} from "discord.js";
|
} from 'discord.js';
|
||||||
import emoji from "../../../assets/emoji.json" assert { type: "json" };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("set")
|
.setName('set')
|
||||||
.setDescription("edit the default behavour of the bot")
|
.setDescription('edit the default behavour of the bot')
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("color")
|
.setName('color')
|
||||||
.setDescription("Change the default color for the embed")
|
.setDescription('Change the default color for the embed')
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("color")
|
.setName('color')
|
||||||
.setDescription("The new color by default")
|
.setDescription('The new color by default')
|
||||||
.setRequired(true),
|
.setRequired(true),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("footer")
|
.setName('footer')
|
||||||
.setDescription("Change the default footer for the embed")
|
.setDescription('Change the default footer for the embed')
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("text")
|
.setName('text')
|
||||||
.setDescription("The new text by default of the bot")
|
.setDescription('The new text by default of the bot')
|
||||||
.setRequired(true),
|
.setRequired(true),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("pp")
|
.setName('pp')
|
||||||
.setDescription("Change the bot profile picture")
|
.setDescription('Change the bot profile picture')
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("link")
|
.setName('link')
|
||||||
.setDescription("The new link to the new profile picture")
|
.setDescription('The new link to the new profile picture')
|
||||||
.setRequired(true),
|
.setRequired(true),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("status")
|
.setName('status')
|
||||||
.setDescription("Change the status of the bot")
|
.setDescription('Change the status of the bot')
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("status")
|
.setName('status')
|
||||||
.setDescription("The new status used by the bot")
|
.setDescription('The new status used by the bot')
|
||||||
.setRequired(true),
|
.setRequired(true),
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("presence")
|
.setName('presence')
|
||||||
.setDescription("The new presence of the bot")
|
.setDescription('The new presence of the bot')
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.addChoices(
|
.addChoices(
|
||||||
{
|
{
|
||||||
name: "Online",
|
name: 'Online',
|
||||||
value: "online",
|
value: 'online',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Do not disturb",
|
name: 'Do not disturb',
|
||||||
value: "dnd",
|
value: 'dnd',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Idle",
|
name: 'Idle',
|
||||||
value: "idle",
|
value: 'idle',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Invisible",
|
name: 'Invisible',
|
||||||
value: "invisible",
|
value: 'invisible',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("type")
|
.setName('type')
|
||||||
.setDescription("The type of the new activity")
|
.setDescription('The type of the new activity')
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.addChoices(
|
.addChoices(
|
||||||
{
|
{
|
||||||
name: "Playing",
|
name: 'Playing',
|
||||||
value: "play",
|
value: 'play',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Watching",
|
name: 'Watching',
|
||||||
value: "watch",
|
value: 'watch',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Listening",
|
name: 'Listening',
|
||||||
value: "listen",
|
value: 'listen',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Competing",
|
name: 'Competing',
|
||||||
value: "competing",
|
value: 'competing',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Streaming",
|
name: 'Streaming',
|
||||||
value: "stream",
|
value: 'stream',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
async execute(interaction: CommandInteraction) {
|
async execute(interaction: CommandInteraction) {
|
||||||
let userData: User;
|
let userData: User;
|
||||||
try {
|
try {
|
||||||
userData = await prisma.user.findUnique({
|
userData = await prisma.user.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: interaction.user.id,
|
id: interaction.user.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (err) {
|
}
|
||||||
console.error(
|
catch (err) {
|
||||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
console.error(
|
||||||
);
|
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
||||||
await interaction.reply({
|
);
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | Cannot connect to the database`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
const subcommand: string = interaction.options.getSubcommand();
|
}
|
||||||
switch (subcommand) {
|
const subcommand: string = interaction.options.getSubcommand();
|
||||||
case "color": {
|
switch (subcommand) {
|
||||||
if (!userData.isOwner) {
|
case 'color': {
|
||||||
await interaction.reply({
|
if (!userData.isOwner) {
|
||||||
content: `${emoji.answer.no} | This command is only for owner`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.no} | This command is only for owner`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
const newColor: string = interaction.options.getString("color");
|
}
|
||||||
if (!/^#[0-9A-Fa-f]{6}$/.test(newColor)) {
|
const newColor: string = interaction.options.getString('color');
|
||||||
await interaction.reply({
|
if (!/^#[0-9A-Fa-f]{6}$/.test(newColor)) {
|
||||||
content: `${emoji.answer.no} | You have to give a color with the syntax: \`#000000\`.`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.no} | You have to give a color with the syntax: \`#000000\`.`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
await prisma.guild.upsert({
|
}
|
||||||
where: {
|
await prisma.guild.upsert({
|
||||||
id: interaction.guild.id,
|
where: {
|
||||||
},
|
id: interaction.guild.id,
|
||||||
update: {
|
},
|
||||||
color: newColor,
|
update: {
|
||||||
},
|
color: newColor,
|
||||||
create: {
|
},
|
||||||
id: interaction.guild.id,
|
create: {
|
||||||
color: newColor,
|
id: interaction.guild.id,
|
||||||
},
|
color: newColor,
|
||||||
});
|
},
|
||||||
await interaction.reply({
|
});
|
||||||
content: `${emoji.answer.yes} | The default color for embed will be now changed by \`${newColor}\``,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.yes} | The default color for embed will be now changed by \`${newColor}\``,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
case "footer": {
|
}
|
||||||
if (!userData.isOwner) {
|
case 'footer': {
|
||||||
await interaction.reply({
|
if (!userData.isOwner) {
|
||||||
content: `${emoji.answer.no} | This command is only for owner`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.no} | This command is only for owner`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
const newFooter: string = interaction.options.getString("text");
|
}
|
||||||
if (newFooter.length > 2048) {
|
const newFooter: string = interaction.options.getString('text');
|
||||||
await interaction.reply({
|
if (newFooter.length > 2048) {
|
||||||
content: `${emoji.answer.no} | The maximum lenght for the footer is 2048`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.no} | The maximum lenght for the footer is 2048`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
await prisma.guild.upsert({
|
}
|
||||||
where: {
|
await prisma.guild.upsert({
|
||||||
id: interaction.guild.id,
|
where: {
|
||||||
},
|
id: interaction.guild.id,
|
||||||
update: {
|
},
|
||||||
footer: newFooter,
|
update: {
|
||||||
},
|
footer: newFooter,
|
||||||
create: {
|
},
|
||||||
id: interaction.guild.id,
|
create: {
|
||||||
footer: newFooter,
|
id: interaction.guild.id,
|
||||||
},
|
footer: newFooter,
|
||||||
});
|
},
|
||||||
await interaction.reply({
|
});
|
||||||
content: `${emoji.answer.yes} | The default footer for embed will be now changed by \`${newFooter}\`.`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.yes} | The default footer for embed will be now changed by \`${newFooter}\`.`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
case "pp": {
|
}
|
||||||
if (!userData.isBuyer) {
|
case 'pp': {
|
||||||
await interaction.reply({
|
if (!userData.isBuyer) {
|
||||||
content: `${emoji.answer.no} | This command is only for buyer`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.no} | This command is only for buyer`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
const newPicture: string = interaction.options.getString("link");
|
}
|
||||||
try {
|
const newPicture: string = interaction.options.getString('link');
|
||||||
interaction.client.user.setAvatar(newPicture);
|
try {
|
||||||
} catch (err) {
|
interaction.client.user.setAvatar(newPicture);
|
||||||
await interaction.reply({
|
}
|
||||||
content: `${emoji.answer.no} | Error during changing the bot profile picture`,
|
catch (err) {
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.no} | Error during changing the bot profile picture`,
|
||||||
console.error(
|
flags: MessageFlags.Ephemeral,
|
||||||
`\t⚠️ | Cannot change the bot profile picture!\n\t\t(${err}).`,
|
});
|
||||||
);
|
console.error(
|
||||||
}
|
`\t⚠️ | Cannot change the bot profile picture!\n\t\t(${err}).`,
|
||||||
await interaction.reply({
|
);
|
||||||
content: `${emoji.answer.yes} | The picture profile of the bot is now updated.`,
|
}
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.yes} | The picture profile of the bot is now updated.`,
|
||||||
return;
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
case "status": {
|
return;
|
||||||
if (!userData.isBuyer) {
|
}
|
||||||
await interaction.reply({
|
case 'status': {
|
||||||
content: `${emoji.answer.no} | This command is only for buyer`,
|
if (!userData.isBuyer) {
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.no} | This command is only for buyer`,
|
||||||
return;
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
const newStatus: string = interaction.options.getString("status");
|
return;
|
||||||
const tmpType: string = interaction.options.getString("type");
|
}
|
||||||
let newType: ActivityType;
|
const newStatus: string = interaction.options.getString('status');
|
||||||
switch (tmpType) {
|
const tmpType: string = interaction.options.getString('type');
|
||||||
case "play":
|
let newType: ActivityType;
|
||||||
newType = ActivityType.Playing;
|
switch (tmpType) {
|
||||||
break;
|
case 'play':
|
||||||
case "listen":
|
newType = ActivityType.Playing;
|
||||||
newType = ActivityType.Listening;
|
break;
|
||||||
break;
|
case 'listen':
|
||||||
case "watch":
|
newType = ActivityType.Listening;
|
||||||
newType = ActivityType.Watching;
|
break;
|
||||||
break;
|
case 'watch':
|
||||||
case "stream":
|
newType = ActivityType.Watching;
|
||||||
newType = ActivityType.Streaming;
|
break;
|
||||||
break;
|
case 'stream':
|
||||||
case "competing":
|
newType = ActivityType.Streaming;
|
||||||
newType = ActivityType.Competing;
|
break;
|
||||||
break;
|
case 'competing':
|
||||||
}
|
newType = ActivityType.Competing;
|
||||||
const tmpPresence: string = interaction.options.getString("presence");
|
break;
|
||||||
let newPresence: PresenceUpdateStatus;
|
}
|
||||||
switch (tmpPresence) {
|
const tmpPresence: string = interaction.options.getString('presence');
|
||||||
case "online":
|
let newPresence: PresenceUpdateStatus;
|
||||||
newPresence = PresenceUpdateStatus.Online;
|
switch (tmpPresence) {
|
||||||
break;
|
case 'online':
|
||||||
case "idle":
|
newPresence = PresenceUpdateStatus.Online;
|
||||||
newPresence = PresenceUpdateStatus.Idle;
|
break;
|
||||||
break;
|
case 'idle':
|
||||||
case "dnd":
|
newPresence = PresenceUpdateStatus.Idle;
|
||||||
newPresence = PresenceUpdateStatus.DoNotDisturb;
|
break;
|
||||||
break;
|
case 'dnd':
|
||||||
case "invisible":
|
newPresence = PresenceUpdateStatus.DoNotDisturb;
|
||||||
newPresence = PresenceUpdateStatus.Invisible;
|
break;
|
||||||
break;
|
case 'invisible':
|
||||||
}
|
newPresence = PresenceUpdateStatus.Invisible;
|
||||||
try {
|
break;
|
||||||
await prisma.bot.upsert({
|
}
|
||||||
where: {
|
try {
|
||||||
id: 1,
|
await prisma.bot.upsert({
|
||||||
},
|
where: {
|
||||||
update: {
|
id: 1,
|
||||||
status: newStatus,
|
},
|
||||||
type: tmpType,
|
update: {
|
||||||
presence: newPresence,
|
status: newStatus,
|
||||||
},
|
type: tmpType,
|
||||||
create: {
|
presence: newPresence,
|
||||||
id: 1,
|
},
|
||||||
status: newStatus,
|
create: {
|
||||||
type: tmpType,
|
id: 1,
|
||||||
presence: newPresence,
|
status: newStatus,
|
||||||
},
|
type: tmpType,
|
||||||
});
|
presence: newPresence,
|
||||||
if (tmpType === "steam") {
|
},
|
||||||
interaction.client.user.setPresence({
|
});
|
||||||
status: newPresence,
|
if (tmpType === 'steam') {
|
||||||
activities: [
|
interaction.client.user.setPresence({
|
||||||
{
|
status: newPresence,
|
||||||
name: newStatus,
|
activities: [
|
||||||
type: newType,
|
{
|
||||||
url: "https://twitch.tv/EniumRaphael",
|
name: newStatus,
|
||||||
},
|
type: newType,
|
||||||
],
|
url: 'https://twitch.tv/EniumRaphael',
|
||||||
});
|
},
|
||||||
} else {
|
],
|
||||||
interaction.client.user.setPresence({
|
});
|
||||||
status: newPresence,
|
}
|
||||||
activities: [
|
else {
|
||||||
{
|
interaction.client.user.setPresence({
|
||||||
name: newStatus,
|
status: newPresence,
|
||||||
type: newType,
|
activities: [
|
||||||
},
|
{
|
||||||
],
|
name: newStatus,
|
||||||
});
|
type: newType,
|
||||||
}
|
},
|
||||||
} catch (err) {
|
],
|
||||||
await interaction.reply({
|
});
|
||||||
content: `${emoji.answer.no} | Cannot change the status\n\n\t${err}`,
|
}
|
||||||
flags: MessageFlags.Ephemeral,
|
}
|
||||||
});
|
catch (err) {
|
||||||
return;
|
await interaction.reply({
|
||||||
}
|
content: `${emoji.answer.no} | Cannot change the status\n\n\t${err}`,
|
||||||
await interaction.reply({
|
flags: MessageFlags.Ephemeral,
|
||||||
content: `${emoji.answer.yes} | The new activity is now \`${newStatus}\``,
|
});
|
||||||
flags: MessageFlags.Ephemeral,
|
return;
|
||||||
});
|
}
|
||||||
return;
|
await interaction.reply({
|
||||||
}
|
content: `${emoji.answer.yes} | The new activity is now \`${newStatus}\``,
|
||||||
}
|
flags: MessageFlags.Ephemeral,
|
||||||
},
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,247 +1,254 @@
|
||||||
import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from "discord.js";
|
import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from 'discord.js';
|
||||||
import { prisma } from "../../lib/prisma.ts";
|
import { prisma } from '../../lib/prisma.ts';
|
||||||
import emoji from "../../../assets/emoji.json" assert { type: "json" };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("buyer")
|
.setName('buyer')
|
||||||
.setDescription("Interact with the buyers")
|
.setDescription('Interact with the buyers')
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("add")
|
.setName('add')
|
||||||
.setDescription("Add a user on the buyer list")
|
.setDescription('Add a user on the buyer list')
|
||||||
.addUserOption((option) =>
|
.addUserOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("target")
|
.setName('target')
|
||||||
.setDescription("The user who will be added to the list")
|
.setDescription('The user who will be added to the list')
|
||||||
.setRequired(true),
|
.setRequired(true),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("delete")
|
.setName('delete')
|
||||||
.setDescription("Delete a user on the buyer list")
|
.setDescription('Delete a user on the buyer list')
|
||||||
.addUserOption((option) =>
|
.addUserOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("target")
|
.setName('target')
|
||||||
.setDescription("The user who will be deleted to the list")
|
.setDescription('The user who will be deleted to the list')
|
||||||
.setRequired(true),
|
.setRequired(true),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand.setName("list").setDescription("The list of the buyer"),
|
subcommand.setName('list').setDescription('The list of the buyer'),
|
||||||
),
|
),
|
||||||
async execute(interaction: CommandInteraction) {
|
async execute(interaction: CommandInteraction) {
|
||||||
const subcommand = interaction.options.getSubcommand();
|
const subcommand = interaction.options.getSubcommand();
|
||||||
let userData: User;
|
let userData: User;
|
||||||
try {
|
try {
|
||||||
userData = await prisma.user.findUnique({
|
userData = await prisma.user.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: interaction.user.id,
|
id: interaction.user.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (err) {
|
}
|
||||||
console.error(
|
catch (err) {
|
||||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
console.error(
|
||||||
);
|
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
||||||
await interaction.reply({
|
);
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | Cannot connect to the database`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
let guildData: Guild;
|
}
|
||||||
try {
|
let guildData: Guild;
|
||||||
guildData = await prisma.guild.findUnique({
|
try {
|
||||||
where: {
|
guildData = await prisma.guild.findUnique({
|
||||||
id: interaction.guild.id,
|
where: {
|
||||||
},
|
id: interaction.guild.id,
|
||||||
});
|
},
|
||||||
} catch (err) {
|
});
|
||||||
console.error(
|
}
|
||||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
catch (err) {
|
||||||
);
|
console.error(
|
||||||
await interaction.reply({
|
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
);
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.error} | Cannot connect to the database`,
|
||||||
return;
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
const target: GuildMember = interaction.options.getUser("target");
|
return;
|
||||||
switch (subcommand) {
|
}
|
||||||
case "add":
|
const target: GuildMember = interaction.options.getUser('target');
|
||||||
if (!userData.isDev) {
|
switch (subcommand) {
|
||||||
await interaction.reply({
|
case 'add':
|
||||||
content: `${emoji.answer.no} | This command is only for the developper of the bot`,
|
if (!userData.isDev) {
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.no} | This command is only for the developper of the bot`,
|
||||||
return;
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
try {
|
return;
|
||||||
await prisma.bot.update({
|
}
|
||||||
where: {
|
try {
|
||||||
id: 1,
|
await prisma.bot.update({
|
||||||
},
|
where: {
|
||||||
data: {
|
id: 1,
|
||||||
buyers: {
|
},
|
||||||
connect: {
|
data: {
|
||||||
id: target.id,
|
buyers: {
|
||||||
},
|
connect: {
|
||||||
},
|
id: target.id,
|
||||||
owners: {
|
},
|
||||||
connect: {
|
},
|
||||||
id: target.id,
|
owners: {
|
||||||
},
|
connect: {
|
||||||
},
|
id: target.id,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
await prisma.user.upsert({
|
},
|
||||||
where: {
|
});
|
||||||
id: target.id,
|
await prisma.user.upsert({
|
||||||
},
|
where: {
|
||||||
update: {
|
id: target.id,
|
||||||
isBuyer: true,
|
},
|
||||||
isOwner: true,
|
update: {
|
||||||
},
|
isBuyer: true,
|
||||||
create: {
|
isOwner: true,
|
||||||
id: target.id,
|
},
|
||||||
isBuyer: true,
|
create: {
|
||||||
isOwner: true,
|
id: target.id,
|
||||||
},
|
isBuyer: true,
|
||||||
});
|
isOwner: true,
|
||||||
} catch (err) {
|
},
|
||||||
console.error(
|
});
|
||||||
`⚠️ | Error when adding ${target.username} to the buyer list\n\t${err}`,
|
}
|
||||||
);
|
catch (err) {
|
||||||
await interaction.reply({
|
console.error(
|
||||||
content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`,
|
`⚠️ | Error when adding ${target.username} to the buyer list\n\t${err}`,
|
||||||
flags: MessageFlags.Ephemeral,
|
);
|
||||||
});
|
await interaction.reply({
|
||||||
return;
|
content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`,
|
||||||
}
|
flags: MessageFlags.Ephemeral,
|
||||||
await interaction.reply({
|
});
|
||||||
content: `${emoji.answer.yes} | ${target.username} has been added to the buyer list`,
|
return;
|
||||||
flags: MessageFlags.Ephemeral,
|
}
|
||||||
});
|
await interaction.reply({
|
||||||
return;
|
content: `${emoji.answer.yes} | ${target.username} has been added to the buyer list`,
|
||||||
case "delete":
|
flags: MessageFlags.Ephemeral,
|
||||||
if (!userData.isDev) {
|
});
|
||||||
await interaction.reply({
|
return;
|
||||||
content: `${emoji.answer.no} | This command is only for buyer`,
|
case 'delete':
|
||||||
flags: MessageFlags.Ephemeral,
|
if (!userData.isDev) {
|
||||||
});
|
await interaction.reply({
|
||||||
return;
|
content: `${emoji.answer.no} | This command is only for buyer`,
|
||||||
} else if (interaction.user.id === target.id) {
|
flags: MessageFlags.Ephemeral,
|
||||||
await interaction.reply({
|
});
|
||||||
content: `${emoji.answer.no} | You cannot removing yourself from the buyer list`,
|
return;
|
||||||
flags: MessageFlags.Ephemeral,
|
}
|
||||||
});
|
else if (interaction.user.id === target.id) {
|
||||||
return;
|
await interaction.reply({
|
||||||
}
|
content: `${emoji.answer.no} | You cannot removing yourself from the buyer list`,
|
||||||
try {
|
flags: MessageFlags.Ephemeral,
|
||||||
await prisma.bot.update({
|
});
|
||||||
where: {
|
return;
|
||||||
id: 1,
|
}
|
||||||
},
|
try {
|
||||||
data: {
|
await prisma.bot.update({
|
||||||
buyers: {
|
where: {
|
||||||
disconnect: {
|
id: 1,
|
||||||
id: target.id,
|
},
|
||||||
},
|
data: {
|
||||||
},
|
buyers: {
|
||||||
owners: {
|
disconnect: {
|
||||||
disconnect: {
|
id: target.id,
|
||||||
id: target.id,
|
},
|
||||||
},
|
},
|
||||||
},
|
owners: {
|
||||||
},
|
disconnect: {
|
||||||
});
|
id: target.id,
|
||||||
await prisma.user.upsert({
|
},
|
||||||
where: {
|
},
|
||||||
id: target.id,
|
},
|
||||||
},
|
});
|
||||||
update: {
|
await prisma.user.upsert({
|
||||||
isBuyer: false,
|
where: {
|
||||||
isOwner: false,
|
id: target.id,
|
||||||
},
|
},
|
||||||
create: {
|
update: {
|
||||||
id: target.id,
|
isBuyer: false,
|
||||||
isBuyer: false,
|
isOwner: false,
|
||||||
isOwner: false,
|
},
|
||||||
},
|
create: {
|
||||||
});
|
id: target.id,
|
||||||
} catch (err) {
|
isBuyer: false,
|
||||||
console.error(
|
isOwner: false,
|
||||||
`⚠️ | Error when removing ${target.username} to the buyer list\n\t${err}`,
|
},
|
||||||
);
|
});
|
||||||
return;
|
}
|
||||||
}
|
catch (err) {
|
||||||
await interaction.reply({
|
console.error(
|
||||||
content: `${emoji.answer.yes} | ${target.username} has been removing to the buyer list`,
|
`⚠️ | Error when removing ${target.username} to the buyer list\n\t${err}`,
|
||||||
flags: MessageFlags.Ephemeral,
|
);
|
||||||
});
|
return;
|
||||||
return;
|
}
|
||||||
case "list":
|
await interaction.reply({
|
||||||
if (!userData.isBuyer) {
|
content: `${emoji.answer.yes} | ${target.username} has been removing to the buyer list`,
|
||||||
await interaction.reply({
|
flags: MessageFlags.Ephemeral,
|
||||||
content: `${emoji.answer.no} | This command is only for buyer`,
|
});
|
||||||
flags: MessageFlags.Ephemeral,
|
return;
|
||||||
});
|
case 'list':
|
||||||
return;
|
if (!userData.isBuyer) {
|
||||||
}
|
await interaction.reply({
|
||||||
try {
|
content: `${emoji.answer.no} | This command is only for buyer`,
|
||||||
const bot = await prisma.bot.findUnique({
|
flags: MessageFlags.Ephemeral,
|
||||||
where: {
|
});
|
||||||
id: 1,
|
return;
|
||||||
},
|
}
|
||||||
include: {
|
try {
|
||||||
buyers: true,
|
const bot = await prisma.bot.findUnique({
|
||||||
},
|
where: {
|
||||||
});
|
id: 1,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
buyers: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (!bot || bot.buyers.length === 0) {
|
if (!bot || bot.buyers.length === 0) {
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.error} | There is no buyer registered.`,
|
content: `${emoji.answer.error} | There is no buyer registered.`,
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const buyerList = await Promise.all(
|
const buyerList = await Promise.all(
|
||||||
bot.buyers.map(async (buyer) => {
|
bot.buyers.map(async (buyer) => {
|
||||||
try {
|
try {
|
||||||
const user = await interaction.client.users.fetch(buyer.id);
|
const user = await interaction.client.users.fetch(buyer.id);
|
||||||
return `- ${user.username} (\`${user.id}\`)\n`;
|
return `- ${user.username} (\`${user.id}\`)\n`;
|
||||||
} catch (err) {
|
}
|
||||||
console.warn(`⚠️ | ${buyer.id} : ${err}`);
|
catch (err) {
|
||||||
return null;
|
console.warn(`⚠️ | ${buyer.id} : ${err}`);
|
||||||
}
|
return null;
|
||||||
}),
|
}
|
||||||
);
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const toSend: EmbedBuilder = new EmbedBuilder()
|
const toSend: EmbedBuilder = new EmbedBuilder()
|
||||||
.setTitle(`${emoji.badge.buyer} | Buyer list`)
|
.setTitle(`${emoji.badge.buyer} | Buyer list`)
|
||||||
.setColor(guildData.color)
|
.setColor(guildData.color)
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: guildData.footer,
|
text: guildData.footer,
|
||||||
})
|
})
|
||||||
.setDescription(buyerList.filter(Boolean).join(""));
|
.setDescription(buyerList.filter(Boolean).join(''));
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [toSend],
|
embeds: [toSend],
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
}
|
||||||
console.error(
|
catch (err) {
|
||||||
`⚠️ | error when fetching infromation from the database: ${err}`,
|
console.error(
|
||||||
);
|
`⚠️ | error when fetching infromation from the database: ${err}`,
|
||||||
await interaction.reply({
|
);
|
||||||
content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
break;
|
}
|
||||||
return;
|
break;
|
||||||
}
|
return;
|
||||||
},
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,236 +1,243 @@
|
||||||
import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from "discord.js";
|
import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from 'discord.js';
|
||||||
import { prisma } from "../../lib/prisma.ts";
|
import { prisma } from '../../lib/prisma.ts';
|
||||||
import emoji from "../../../assets/emoji.json" assert { type: "json" };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("owner")
|
.setName('owner')
|
||||||
.setDescription("Interact with the owners")
|
.setDescription('Interact with the owners')
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("add")
|
.setName('add')
|
||||||
.setDescription("Add a user on the owner list")
|
.setDescription('Add a user on the owner list')
|
||||||
.addUserOption((option) =>
|
.addUserOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("target")
|
.setName('target')
|
||||||
.setDescription("The user who will be added to the list")
|
.setDescription('The user who will be added to the list')
|
||||||
.setRequired(true),
|
.setRequired(true),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("delete")
|
.setName('delete')
|
||||||
.setDescription("Delete a user on the owner list")
|
.setDescription('Delete a user on the owner list')
|
||||||
.addUserOption((option) =>
|
.addUserOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("target")
|
.setName('target')
|
||||||
.setDescription("The user who will be deleted to the list")
|
.setDescription('The user who will be deleted to the list')
|
||||||
.setRequired(true),
|
.setRequired(true),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand.setName("list").setDescription("The list of the owner"),
|
subcommand.setName('list').setDescription('The list of the owner'),
|
||||||
),
|
),
|
||||||
async execute(interaction: CommandInteraction) {
|
async execute(interaction: CommandInteraction) {
|
||||||
const subcommand = interaction.options.getSubcommand();
|
const subcommand = interaction.options.getSubcommand();
|
||||||
let userData: User;
|
let userData: User;
|
||||||
try {
|
try {
|
||||||
userData = await prisma.user.findUnique({
|
userData = await prisma.user.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: interaction.user.id,
|
id: interaction.user.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (err) {
|
}
|
||||||
console.error(
|
catch (err) {
|
||||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
console.error(
|
||||||
);
|
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
||||||
await interaction.reply({
|
);
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | Cannot connect to the database`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
let guildData: Guild;
|
}
|
||||||
try {
|
let guildData: Guild;
|
||||||
guildData = await prisma.guild.findUnique({
|
try {
|
||||||
where: {
|
guildData = await prisma.guild.findUnique({
|
||||||
id: interaction.guild.id,
|
where: {
|
||||||
},
|
id: interaction.guild.id,
|
||||||
});
|
},
|
||||||
} catch (err) {
|
});
|
||||||
console.error(
|
}
|
||||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
catch (err) {
|
||||||
);
|
console.error(
|
||||||
await interaction.reply({
|
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
);
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.error} | Cannot connect to the database`,
|
||||||
return;
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
const target: GuildMember = interaction.options.getUser("target");
|
return;
|
||||||
switch (subcommand) {
|
}
|
||||||
case "add":
|
const target: GuildMember = interaction.options.getUser('target');
|
||||||
if (!userData.isBuyer) {
|
switch (subcommand) {
|
||||||
await interaction.reply({
|
case 'add':
|
||||||
content: `${emoji.answer.no} | This command is only for buyer`,
|
if (!userData.isBuyer) {
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.no} | This command is only for buyer`,
|
||||||
return;
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
try {
|
return;
|
||||||
await prisma.bot.update({
|
}
|
||||||
where: {
|
try {
|
||||||
id: 1,
|
await prisma.bot.update({
|
||||||
},
|
where: {
|
||||||
data: {
|
id: 1,
|
||||||
owners: {
|
},
|
||||||
connect: {
|
data: {
|
||||||
id: target.id,
|
owners: {
|
||||||
},
|
connect: {
|
||||||
},
|
id: target.id,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
await prisma.user.upsert({
|
},
|
||||||
where: {
|
});
|
||||||
id: target.id,
|
await prisma.user.upsert({
|
||||||
},
|
where: {
|
||||||
update: {
|
id: target.id,
|
||||||
isOwner: true,
|
},
|
||||||
},
|
update: {
|
||||||
create: {
|
isOwner: true,
|
||||||
id: target.id,
|
},
|
||||||
isOwner: true,
|
create: {
|
||||||
},
|
id: target.id,
|
||||||
});
|
isOwner: true,
|
||||||
} catch (err) {
|
},
|
||||||
console.error(
|
});
|
||||||
`⚠️ | Error when adding ${target.username} to the owner list\n\t${err}`,
|
}
|
||||||
);
|
catch (err) {
|
||||||
await interaction.reply({
|
console.error(
|
||||||
content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`,
|
`⚠️ | Error when adding ${target.username} to the owner list\n\t${err}`,
|
||||||
flags: MessageFlags.Ephemeral,
|
);
|
||||||
});
|
await interaction.reply({
|
||||||
return;
|
content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`,
|
||||||
}
|
flags: MessageFlags.Ephemeral,
|
||||||
await interaction.reply({
|
});
|
||||||
content: `${emoji.answer.yes} | ${target.username} has been added to the owner list`,
|
return;
|
||||||
flags: MessageFlags.Ephemeral,
|
}
|
||||||
});
|
await interaction.reply({
|
||||||
return;
|
content: `${emoji.answer.yes} | ${target.username} has been added to the owner list`,
|
||||||
case "delete":
|
flags: MessageFlags.Ephemeral,
|
||||||
if (!userData.isBuyer) {
|
});
|
||||||
await interaction.reply({
|
return;
|
||||||
content: `${emoji.answer.no} | This command is only for buyer`,
|
case 'delete':
|
||||||
flags: MessageFlags.Ephemeral,
|
if (!userData.isBuyer) {
|
||||||
});
|
await interaction.reply({
|
||||||
return;
|
content: `${emoji.answer.no} | This command is only for buyer`,
|
||||||
} else if (interaction.user.id === target.id) {
|
flags: MessageFlags.Ephemeral,
|
||||||
await interaction.reply({
|
});
|
||||||
content: `${emoji.answer.no} | You cannot removing yourself from the owner list`,
|
return;
|
||||||
flags: MessageFlags.Ephemeral,
|
}
|
||||||
});
|
else if (interaction.user.id === target.id) {
|
||||||
return;
|
await interaction.reply({
|
||||||
}
|
content: `${emoji.answer.no} | You cannot removing yourself from the owner list`,
|
||||||
try {
|
flags: MessageFlags.Ephemeral,
|
||||||
await prisma.bot.update({
|
});
|
||||||
where: {
|
return;
|
||||||
id: 1,
|
}
|
||||||
},
|
try {
|
||||||
data: {
|
await prisma.bot.update({
|
||||||
owners: {
|
where: {
|
||||||
disconnect: {
|
id: 1,
|
||||||
id: target.id,
|
},
|
||||||
},
|
data: {
|
||||||
},
|
owners: {
|
||||||
},
|
disconnect: {
|
||||||
});
|
id: target.id,
|
||||||
await prisma.user.upsert({
|
},
|
||||||
where: {
|
},
|
||||||
id: target.id,
|
},
|
||||||
},
|
});
|
||||||
update: {
|
await prisma.user.upsert({
|
||||||
isOwner: false,
|
where: {
|
||||||
},
|
id: target.id,
|
||||||
create: {
|
},
|
||||||
id: target.id,
|
update: {
|
||||||
isOwner: false,
|
isOwner: false,
|
||||||
},
|
},
|
||||||
});
|
create: {
|
||||||
} catch (err) {
|
id: target.id,
|
||||||
console.error(
|
isOwner: false,
|
||||||
`⚠️ | Error when removing ${target.username} to the owner list\n\t${err}`,
|
},
|
||||||
);
|
});
|
||||||
await interaction.reply({
|
}
|
||||||
content: `${emoji.answer.error} | Cannot removing the user from the owner list`,
|
catch (err) {
|
||||||
flags: MessageFlags.Ephemeral,
|
console.error(
|
||||||
});
|
`⚠️ | Error when removing ${target.username} to the owner list\n\t${err}`,
|
||||||
return;
|
);
|
||||||
}
|
await interaction.reply({
|
||||||
await interaction.reply({
|
content: `${emoji.answer.error} | Cannot removing the user from the owner list`,
|
||||||
content: `${emoji.answer.yes} | ${target.username} has been removing to the owner list`,
|
flags: MessageFlags.Ephemeral,
|
||||||
flags: MessageFlags.Ephemeral,
|
});
|
||||||
});
|
return;
|
||||||
return;
|
}
|
||||||
case "list":
|
await interaction.reply({
|
||||||
if (!userData.isOwner) {
|
content: `${emoji.answer.yes} | ${target.username} has been removing to the owner list`,
|
||||||
await interaction.reply({
|
flags: MessageFlags.Ephemeral,
|
||||||
content: `${emoji.answer.no} | This command is only for owner`,
|
});
|
||||||
flags: MessageFlags.Ephemeral,
|
return;
|
||||||
});
|
case 'list':
|
||||||
return;
|
if (!userData.isOwner) {
|
||||||
}
|
await interaction.reply({
|
||||||
try {
|
content: `${emoji.answer.no} | This command is only for owner`,
|
||||||
const bot = await prisma.bot.findUnique({
|
flags: MessageFlags.Ephemeral,
|
||||||
where: {
|
});
|
||||||
id: 1,
|
return;
|
||||||
},
|
}
|
||||||
include: {
|
try {
|
||||||
owners: true,
|
const bot = await prisma.bot.findUnique({
|
||||||
},
|
where: {
|
||||||
});
|
id: 1,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
owners: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (!bot || bot.owners.length === 0) {
|
if (!bot || bot.owners.length === 0) {
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.error} | There is no owner registered.`,
|
content: `${emoji.answer.error} | There is no owner registered.`,
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ownerList = await Promise.all(
|
const ownerList = await Promise.all(
|
||||||
bot.owners.map(async (owner) => {
|
bot.owners.map(async (owner) => {
|
||||||
try {
|
try {
|
||||||
const user = await interaction.client.users.fetch(owner.id);
|
const user = await interaction.client.users.fetch(owner.id);
|
||||||
return `- ${user.username} (\`${user.id}\`)\n`;
|
return `- ${user.username} (\`${user.id}\`)\n`;
|
||||||
} catch (err) {
|
}
|
||||||
console.warn(`⚠️ | ${owner.id} : ${err}`);
|
catch (err) {
|
||||||
return null;
|
console.warn(`⚠️ | ${owner.id} : ${err}`);
|
||||||
}
|
return null;
|
||||||
}),
|
}
|
||||||
);
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const toSend: EmbedBuilder = new EmbedBuilder()
|
const toSend: EmbedBuilder = new EmbedBuilder()
|
||||||
.setTitle(`${emoji.badge.owner} | Owner list`)
|
.setTitle(`${emoji.badge.owner} | Owner list`)
|
||||||
.setColor(guildData.color)
|
.setColor(guildData.color)
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: guildData.footer,
|
text: guildData.footer,
|
||||||
})
|
})
|
||||||
.setDescription(ownerList.filter(Boolean).join(""));
|
.setDescription(ownerList.filter(Boolean).join(''));
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [toSend],
|
embeds: [toSend],
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
}
|
||||||
console.error(
|
catch (err) {
|
||||||
`⚠️ | error when fetching infromation from the database: ${err}`,
|
console.error(
|
||||||
);
|
`⚠️ | error when fetching infromation from the database: ${err}`,
|
||||||
await interaction.reply({
|
);
|
||||||
content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
break;
|
}
|
||||||
return;
|
break;
|
||||||
}
|
return;
|
||||||
},
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,244 +1,251 @@
|
||||||
import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from "discord.js";
|
import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from 'discord.js';
|
||||||
import { prisma } from "../../lib/prisma.ts";
|
import { prisma } from '../../lib/prisma.ts';
|
||||||
import emoji from "../../../assets/emoji.json" assert { type: "json" };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("whitelist")
|
.setName('whitelist')
|
||||||
.setDescription("Interact with the whitelist")
|
.setDescription('Interact with the whitelist')
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("add")
|
.setName('add')
|
||||||
.setDescription("Add a user on the whitelist")
|
.setDescription('Add a user on the whitelist')
|
||||||
.addUserOption((option) =>
|
.addUserOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("target")
|
.setName('target')
|
||||||
.setDescription("The user who will be added to the whitelist")
|
.setDescription('The user who will be added to the whitelist')
|
||||||
.setRequired(true),
|
.setRequired(true),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("delete")
|
.setName('delete')
|
||||||
.setDescription("Delete a user on the whitelist")
|
.setDescription('Delete a user on the whitelist')
|
||||||
.addUserOption((option) =>
|
.addUserOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("target")
|
.setName('target')
|
||||||
.setDescription("The user who will be deleted to the whitelist")
|
.setDescription('The user who will be deleted to the whitelist')
|
||||||
.setRequired(true),
|
.setRequired(true),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand.setName("list").setDescription("Show the whitelist"),
|
subcommand.setName('list').setDescription('Show the whitelist'),
|
||||||
),
|
),
|
||||||
async execute(interaction: CommandInteraction) {
|
async execute(interaction: CommandInteraction) {
|
||||||
const subcommand = interaction.options.getSubcommand();
|
const subcommand = interaction.options.getSubcommand();
|
||||||
let userData: User;
|
let userData: User;
|
||||||
try {
|
try {
|
||||||
userData = await prisma.user.findUnique({
|
userData = await prisma.user.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: interaction.user.id,
|
id: interaction.user.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (err) {
|
}
|
||||||
console.error(
|
catch (err) {
|
||||||
`\t⚠️ | Whitelist => Cannot get the database connection!\n\t\t(${err}).`,
|
console.error(
|
||||||
);
|
`\t⚠️ | Whitelist => Cannot get the database connection!\n\t\t(${err}).`,
|
||||||
await interaction.reply({
|
);
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | Cannot connect to the database`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
let guildData: Guild;
|
}
|
||||||
try {
|
let guildData: Guild;
|
||||||
guildData = await prisma.guild.findUnique({
|
try {
|
||||||
where: {
|
guildData = await prisma.guild.findUnique({
|
||||||
id: interaction.guild.id,
|
where: {
|
||||||
},
|
id: interaction.guild.id,
|
||||||
});
|
},
|
||||||
} catch (err) {
|
});
|
||||||
console.error(
|
}
|
||||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
catch (err) {
|
||||||
);
|
console.error(
|
||||||
await interaction.reply({
|
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
);
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.error} | Cannot connect to the database`,
|
||||||
return;
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
const target: GuildMember = interaction.options.getUser("target");
|
return;
|
||||||
switch (subcommand) {
|
}
|
||||||
case "add":
|
const target: GuildMember = interaction.options.getUser('target');
|
||||||
if (!userData.isOwner) {
|
switch (subcommand) {
|
||||||
await interaction.reply({
|
case 'add':
|
||||||
content: `${emoji.answer.no} | This command is only for owner`,
|
if (!userData.isOwner) {
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.no} | This command is only for owner`,
|
||||||
return;
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
try {
|
return;
|
||||||
await prisma.guildUser.upsert({
|
}
|
||||||
where: {
|
try {
|
||||||
userId_guildId: {
|
await prisma.guildUser.upsert({
|
||||||
userId: target.id,
|
where: {
|
||||||
guildId: interaction.guild.id,
|
userId_guildId: {
|
||||||
},
|
userId: target.id,
|
||||||
},
|
guildId: interaction.guild.id,
|
||||||
update: {
|
},
|
||||||
isWlUser: true,
|
},
|
||||||
},
|
update: {
|
||||||
create: {
|
isWlUser: true,
|
||||||
userId: target.id,
|
},
|
||||||
guildId: interaction.guild.id,
|
create: {
|
||||||
isWlUser: true,
|
userId: target.id,
|
||||||
},
|
guildId: interaction.guild.id,
|
||||||
});
|
isWlUser: true,
|
||||||
await prisma.guild.update({
|
},
|
||||||
where: {
|
});
|
||||||
id: interaction.guild.id,
|
await prisma.guild.update({
|
||||||
},
|
where: {
|
||||||
data: {
|
id: interaction.guild.id,
|
||||||
WlUsers: {
|
},
|
||||||
connect: {
|
data: {
|
||||||
id: target.id,
|
WlUsers: {
|
||||||
},
|
connect: {
|
||||||
},
|
id: target.id,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
} catch (err) {
|
},
|
||||||
console.error(
|
});
|
||||||
`⚠️ | Error when adding ${target.username} to the whitelist\n\t${err}`,
|
}
|
||||||
);
|
catch (err) {
|
||||||
await interaction.reply({
|
console.error(
|
||||||
content: `${emoji.answer.error} | Error when adding ${target.username} to the whitelist`,
|
`⚠️ | Error when adding ${target.username} to the whitelist\n\t${err}`,
|
||||||
flags: MessageFlags.Ephemeral,
|
);
|
||||||
});
|
await interaction.reply({
|
||||||
return;
|
content: `${emoji.answer.error} | Error when adding ${target.username} to the whitelist`,
|
||||||
}
|
flags: MessageFlags.Ephemeral,
|
||||||
await interaction.reply({
|
});
|
||||||
content: `${emoji.answer.yes} | ${target.username} has been added to the whitelist`,
|
return;
|
||||||
flags: MessageFlags.Ephemeral,
|
}
|
||||||
});
|
await interaction.reply({
|
||||||
return;
|
content: `${emoji.answer.yes} | ${target.username} has been added to the whitelist`,
|
||||||
case "delete":
|
flags: MessageFlags.Ephemeral,
|
||||||
if (!userData.isOwner) {
|
});
|
||||||
await interaction.reply({
|
return;
|
||||||
content: `${emoji.answer.no} | This command is only for owner`,
|
case 'delete':
|
||||||
flags: MessageFlags.Ephemeral,
|
if (!userData.isOwner) {
|
||||||
});
|
await interaction.reply({
|
||||||
return;
|
content: `${emoji.answer.no} | This command is only for owner`,
|
||||||
} else if (interaction.user.id === target.id) {
|
flags: MessageFlags.Ephemeral,
|
||||||
await interaction.reply({
|
});
|
||||||
content: `${emoji.answer.no} | You cannot removing yourself from the whitelist`,
|
return;
|
||||||
flags: MessageFlags.Ephemeral,
|
}
|
||||||
});
|
else if (interaction.user.id === target.id) {
|
||||||
return;
|
await interaction.reply({
|
||||||
}
|
content: `${emoji.answer.no} | You cannot removing yourself from the whitelist`,
|
||||||
try {
|
flags: MessageFlags.Ephemeral,
|
||||||
await prisma.guildUser.upsert({
|
});
|
||||||
where: {
|
return;
|
||||||
userId_guildId: {
|
}
|
||||||
userId: target.id,
|
try {
|
||||||
guildId: interaction.guild.id,
|
await prisma.guildUser.upsert({
|
||||||
},
|
where: {
|
||||||
},
|
userId_guildId: {
|
||||||
update: {
|
userId: target.id,
|
||||||
isWlUser: false,
|
guildId: interaction.guild.id,
|
||||||
},
|
},
|
||||||
create: {
|
},
|
||||||
userId: target.id,
|
update: {
|
||||||
guildId: interaction.guild.id,
|
isWlUser: false,
|
||||||
isWlUser: false,
|
},
|
||||||
},
|
create: {
|
||||||
});
|
userId: target.id,
|
||||||
await prisma.guild.update({
|
guildId: interaction.guild.id,
|
||||||
where: {
|
isWlUser: false,
|
||||||
id: interaction.guild.id,
|
},
|
||||||
},
|
});
|
||||||
data: {
|
await prisma.guild.update({
|
||||||
WlUsers: {
|
where: {
|
||||||
disconnect: {
|
id: interaction.guild.id,
|
||||||
id: target.id,
|
},
|
||||||
},
|
data: {
|
||||||
},
|
WlUsers: {
|
||||||
},
|
disconnect: {
|
||||||
});
|
id: target.id,
|
||||||
} catch (err) {
|
},
|
||||||
console.error(
|
},
|
||||||
`⚠️ | Error when removing ${target.username} to the username\n\t${err}`,
|
},
|
||||||
);
|
});
|
||||||
await interaction.reply({
|
}
|
||||||
content: `${emoji.answer.error} | Cannot remove ${target.username} from the whitelist`,
|
catch (err) {
|
||||||
flags: MessageFlags.Ephemeral,
|
console.error(
|
||||||
});
|
`⚠️ | Error when removing ${target.username} to the username\n\t${err}`,
|
||||||
return;
|
);
|
||||||
}
|
await interaction.reply({
|
||||||
await interaction.reply({
|
content: `${emoji.answer.error} | Cannot remove ${target.username} from the whitelist`,
|
||||||
content: `${emoji.answer.yes} | ${target.username} has been removing to the whitelist`,
|
flags: MessageFlags.Ephemeral,
|
||||||
flags: MessageFlags.Ephemeral,
|
});
|
||||||
});
|
return;
|
||||||
return;
|
}
|
||||||
case "list":
|
await interaction.reply({
|
||||||
if (!userData.isOwner) {
|
content: `${emoji.answer.yes} | ${target.username} has been removing to the whitelist`,
|
||||||
await interaction.reply({
|
flags: MessageFlags.Ephemeral,
|
||||||
content: `${emoji.answer.no} | This command is only for owner`,
|
});
|
||||||
flags: MessageFlags.Ephemeral,
|
return;
|
||||||
});
|
case 'list':
|
||||||
return;
|
if (!userData.isOwner) {
|
||||||
}
|
await interaction.reply({
|
||||||
try {
|
content: `${emoji.answer.no} | This command is only for owner`,
|
||||||
const guild = await prisma.guild.findUnique({
|
flags: MessageFlags.Ephemeral,
|
||||||
where: {
|
});
|
||||||
id: interaction.guild.id,
|
return;
|
||||||
},
|
}
|
||||||
include: {
|
try {
|
||||||
WlUsers: true,
|
const guild = await prisma.guild.findUnique({
|
||||||
},
|
where: {
|
||||||
});
|
id: interaction.guild.id,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
WlUsers: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (!guild || guild.WlUsers.length === 0) {
|
if (!guild || guild.WlUsers.length === 0) {
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.error} | There is no whitelisted user.`,
|
content: `${emoji.answer.error} | There is no whitelisted user.`,
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const WlUsers = await Promise.all(
|
const WlUsers = await Promise.all(
|
||||||
guild.WlUsers.map(async (whitelist) => {
|
guild.WlUsers.map(async (whitelist) => {
|
||||||
try {
|
try {
|
||||||
const user = await interaction.client.users.fetch(whitelist.id);
|
const user = await interaction.client.users.fetch(whitelist.id);
|
||||||
return `- ${user.username} (\`${user.id}\`)\n`;
|
return `- ${user.username} (\`${user.id}\`)\n`;
|
||||||
} catch (err) {
|
}
|
||||||
console.warn(`⚠️ | ${whitelist.id} : ${err}`);
|
catch (err) {
|
||||||
return null;
|
console.warn(`⚠️ | ${whitelist.id} : ${err}`);
|
||||||
}
|
return null;
|
||||||
}),
|
}
|
||||||
);
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const toSend: EmbedBuilder = new EmbedBuilder()
|
const toSend: EmbedBuilder = new EmbedBuilder()
|
||||||
.setTitle("🗞️ | Whitelist")
|
.setTitle('🗞️ | Whitelist')
|
||||||
.setColor(guildData.color)
|
.setColor(guildData.color)
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: guildData.footer,
|
text: guildData.footer,
|
||||||
})
|
})
|
||||||
.setDescription(WlUsers.filter(Boolean).join(""));
|
.setDescription(WlUsers.filter(Boolean).join(''));
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [toSend],
|
embeds: [toSend],
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
}
|
||||||
console.error(
|
catch (err) {
|
||||||
`⚠️ | Whitelist => error when fetching infromation from the database: ${err}`,
|
console.error(
|
||||||
);
|
`⚠️ | Whitelist => error when fetching infromation from the database: ${err}`,
|
||||||
await interaction.reply({
|
);
|
||||||
content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
break;
|
}
|
||||||
return;
|
break;
|
||||||
}
|
return;
|
||||||
},
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,68 +1,70 @@
|
||||||
import { MessageFlags, ChannelType, SlashCommandBuilder } from "discord.js";
|
import { MessageFlags, ChannelType, SlashCommandBuilder } from 'discord.js';
|
||||||
import emoji from "../../../assets/emoji.json" assert { type: "json" };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
import { prisma } from "../../lib/prisma.ts";
|
import { prisma } from '../../lib/prisma.ts';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("deletecat")
|
.setName('deletecat')
|
||||||
.setDescription("Delete the categorie given in parameter")
|
.setDescription('Delete the categorie given in parameter')
|
||||||
.addChannelOption((opt) =>
|
.addChannelOption((opt) =>
|
||||||
opt
|
opt
|
||||||
.setName("category")
|
.setName('category')
|
||||||
.setDescription("Choose the categorie you want to delete")
|
.setDescription('Choose the categorie you want to delete')
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.addChannelTypes(ChannelType.GuildCategory),
|
.addChannelTypes(ChannelType.GuildCategory),
|
||||||
),
|
),
|
||||||
async execute(interaction: CommandInteraction) {
|
async execute(interaction: CommandInteraction) {
|
||||||
let userData: User;
|
let userData: User;
|
||||||
try {
|
try {
|
||||||
userData = await prisma.user.findUnique({
|
userData = await prisma.user.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: interaction.user.id,
|
id: interaction.user.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (err) {
|
}
|
||||||
console.error(
|
catch (err) {
|
||||||
`\t⚠️ | Whitelist => Cannot get the database connection!\n\t\t(${err}).`,
|
console.error(
|
||||||
);
|
`\t⚠️ | Whitelist => Cannot get the database connection!\n\t\t(${err}).`,
|
||||||
await interaction.reply({
|
);
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | Cannot connect to the database`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
console.error(`Cannot connect to the database:\n\t${err}`);
|
});
|
||||||
return;
|
console.error(`Cannot connect to the database:\n\t${err}`);
|
||||||
}
|
return;
|
||||||
if (!userData.isOwner) {
|
}
|
||||||
await interaction.reply({
|
if (!userData.isOwner) {
|
||||||
content: `${emoji.answer.no} | This command is only for owner`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.no} | This command is only for owner`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
const category: GuildCategory = interaction.options.getChannel(
|
}
|
||||||
"category",
|
const category: GuildCategory = interaction.options.getChannel(
|
||||||
true,
|
'category',
|
||||||
);
|
true,
|
||||||
try {
|
);
|
||||||
for (const channel of category.children.cache.values()) {
|
try {
|
||||||
await channel.delete(
|
for (const channel of category.children.cache.values()) {
|
||||||
`Delete cat of ${channel.name} (by ${interaction.username})`,
|
await channel.delete(
|
||||||
);
|
`Delete cat of ${channel.name} (by ${interaction.username})`,
|
||||||
}
|
);
|
||||||
await category.delete(
|
}
|
||||||
`Delete cat of ${category.name} (by ${interaction.username})`,
|
await category.delete(
|
||||||
);
|
`Delete cat of ${category.name} (by ${interaction.username})`,
|
||||||
await interaction.reply({
|
);
|
||||||
content: `${emoji.answer.yes} | Suppressed the ${category.name}`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.yes} | Suppressed the ${category.name}`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
} catch (err) {
|
});
|
||||||
await interaction.reply({
|
}
|
||||||
content: `${emoji.answer.error} | Cannot suppress the category's channels`,
|
catch (err) {
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.error} | Cannot suppress the category's channels`,
|
||||||
console.error(`Cannot suppress the category's channel:\n\t${err}`);
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
console.error(`Cannot suppress the category's channel:\n\t${err}`);
|
||||||
},
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,29 @@
|
||||||
import { prisma } from "../../lib/prisma.ts";
|
import { prisma } from '../../lib/prisma.ts';
|
||||||
import {
|
import {
|
||||||
userMention,
|
userMention,
|
||||||
roleMention,
|
roleMention,
|
||||||
MessageFlags,
|
MessageFlags,
|
||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
} from "discord.js";
|
} from 'discord.js';
|
||||||
import emoji from "../../../assets/emoji.json" assert { type: "json" };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
|
|
||||||
function getGuildRoles(guild: Guild): string {
|
function getGuildRoles(guild: Guild): string {
|
||||||
const roles = guild.roles.cache
|
const roles = guild.roles.cache
|
||||||
.filter((role) => role.id !== guild.id)
|
.filter((role) => role.id !== guild.id)
|
||||||
.sort((a, b) => b.position - a.position)
|
.sort((a, b) => b.position - a.position)
|
||||||
.map((role) => roleMention(role.id));
|
.map((role) => roleMention(role.id));
|
||||||
|
|
||||||
return roles.length > 0 ? roles.join(", ") : "No role";
|
return roles.length > 0 ? roles.join(', ') : 'No role';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserRoles(target: GuildMember): string {
|
function getUserRoles(target: GuildMember): string {
|
||||||
const roles = target.roles.cache
|
const roles = target.roles.cache
|
||||||
.filter((role) => role.id !== target.guild.id)
|
.filter((role) => role.id !== target.guild.id)
|
||||||
.sort((a, b) => b.position - a.position)
|
.sort((a, b) => b.position - a.position)
|
||||||
.map((role) => `${roleMention(role.id)}`);
|
.map((role) => `${roleMention(role.id)}`);
|
||||||
|
|
||||||
return roles.length > 0 ? roles.join(", ") : "No role";
|
return roles.length > 0 ? roles.join(', ') : 'No role';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserBadges(userData: {
|
function getUserBadges(userData: {
|
||||||
|
|
@ -32,105 +32,108 @@ function getUserBadges(userData: {
|
||||||
isBuyer?: boolean;
|
isBuyer?: boolean;
|
||||||
isOwner?: boolean;
|
isOwner?: boolean;
|
||||||
}): string {
|
}): string {
|
||||||
const badges: string[] = [];
|
const badges: string[] = [];
|
||||||
|
|
||||||
if (userData.isDev) badges.push(`${emoji.badge.dev}`);
|
if (userData.isDev) badges.push(`${emoji.badge.dev}`);
|
||||||
if (userData.isEnium) badges.push(`${emoji.badge.enium}`);
|
if (userData.isEnium) badges.push(`${emoji.badge.enium}`);
|
||||||
if (userData.isPwn) badges.push(`${emoji.badge.dash}`);
|
if (userData.isPwn) badges.push(`${emoji.badge.dash}`);
|
||||||
if (userData.isBuyer) badges.push(`${emoji.badge.buyer}`);
|
if (userData.isBuyer) badges.push(`${emoji.badge.buyer}`);
|
||||||
if (userData.isOwner) badges.push(`${emoji.badge.owner}`);
|
if (userData.isOwner) badges.push(`${emoji.badge.owner}`);
|
||||||
|
|
||||||
return badges.length > 0 ? badges.join(" ") : "Aucun badge";
|
return badges.length > 0 ? badges.join(' ') : 'Aucun badge';
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("info")
|
.setName('info')
|
||||||
.setDescription(
|
.setDescription(
|
||||||
"Show the infromation of one of these categories (user, server, bot)",
|
'Show the infromation of one of these categories (user, server, bot)',
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("user")
|
.setName('user')
|
||||||
.setDescription("Show the infromation of one user")
|
.setDescription('Show the infromation of one user')
|
||||||
.addUserOption((option) =>
|
.addUserOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("target")
|
.setName('target')
|
||||||
.setDescription("The user to show the infromation"),
|
.setDescription('The user to show the infromation'),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("server")
|
.setName('server')
|
||||||
.setDescription("Show the infromation of the server"),
|
.setDescription('Show the infromation of the server'),
|
||||||
),
|
),
|
||||||
async execute(interaction: CommandInteraction) {
|
async execute(interaction: CommandInteraction) {
|
||||||
let guildData: Guild;
|
let guildData: Guild;
|
||||||
try {
|
try {
|
||||||
guildData = await prisma.guild.findUnique({
|
guildData = await prisma.guild.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: interaction.guild.id,
|
id: interaction.guild.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (err) {
|
}
|
||||||
console.error(
|
catch (err) {
|
||||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
console.error(
|
||||||
);
|
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
||||||
await interaction.reply({
|
);
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | Cannot connect to the database`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
const subcommand: string = interaction.options.getSubcommand();
|
}
|
||||||
switch (subcommand) {
|
const subcommand: string = interaction.options.getSubcommand();
|
||||||
case "user": {
|
switch (subcommand) {
|
||||||
const targetGlobal: GuildMember =
|
case 'user': {
|
||||||
interaction.options.getUser("target") || interaction.user;
|
const targetGlobal: GuildMember =
|
||||||
await targetGlobal.fetch();
|
interaction.options.getUser('target') || interaction.user;
|
||||||
let userData: User;
|
await targetGlobal.fetch();
|
||||||
try {
|
let userData: User;
|
||||||
userData = await prisma.user.findUnique({
|
try {
|
||||||
where: {
|
userData = await prisma.user.findUnique({
|
||||||
id: targetGlobal.id,
|
where: {
|
||||||
},
|
id: targetGlobal.id,
|
||||||
});
|
},
|
||||||
} catch (err) {
|
});
|
||||||
console.error(
|
}
|
||||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
catch (err) {
|
||||||
);
|
console.error(
|
||||||
await interaction.reply({
|
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
);
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.error} | Cannot connect to the database`,
|
||||||
}
|
flags: MessageFlags.Ephemeral,
|
||||||
let targetServer: GuildMember;
|
});
|
||||||
|
}
|
||||||
|
let targetServer: GuildMember;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
targetServer = await interaction.guild.members.fetch(targetGlobal.id);
|
targetServer = await interaction.guild.members.fetch(targetGlobal.id);
|
||||||
} catch (err) {
|
}
|
||||||
console.error(`\t⚠️ | Cannot get the targetServer!\n\t\t(${err}).`);
|
catch (err) {
|
||||||
await interaction.reply({
|
console.error(`\t⚠️ | Cannot get the targetServer!\n\t\t(${err}).`);
|
||||||
content: `${emoji.answer.error} | Cannot get the guild profile of the user`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | Cannot get the guild profile of the user`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
}
|
return;
|
||||||
const userResult: EmbedBuilder = new EmbedBuilder()
|
}
|
||||||
.setTitle(`${targetGlobal.displayName}'s information`)
|
const userResult: EmbedBuilder = new EmbedBuilder()
|
||||||
.setColor(`${guildData.color}`)
|
.setTitle(`${targetGlobal.displayName}'s information`)
|
||||||
.setThumbnail(
|
.setColor(`${guildData.color}`)
|
||||||
`${targetGlobal.displayAvatarURL({ dynamic: true, size: 2048 })}`,
|
.setThumbnail(
|
||||||
)
|
`${targetGlobal.displayAvatarURL({ dynamic: true, size: 2048 })}`,
|
||||||
.setFooter({
|
)
|
||||||
text: guildData.footer,
|
.setFooter({
|
||||||
})
|
text: guildData.footer,
|
||||||
.setImage(
|
})
|
||||||
targetGlobal.bannerURL({
|
.setImage(
|
||||||
size: 2048,
|
targetGlobal.bannerURL({
|
||||||
dynamic: true,
|
size: 2048,
|
||||||
}),
|
dynamic: true,
|
||||||
).setDescription(`
|
}),
|
||||||
|
).setDescription(`
|
||||||
**👤 | Username:**
|
**👤 | Username:**
|
||||||
${targetGlobal.username}
|
${targetGlobal.username}
|
||||||
**🆔 | ID:**
|
**🆔 | ID:**
|
||||||
|
|
@ -146,30 +149,30 @@ export default {
|
||||||
**🛬 | Server Join:**
|
**🛬 | Server Join:**
|
||||||
<t:${parseInt(targetServer.joinedTimestamp / 1000)}:f> (<t:${parseInt(targetServer.joinedTimestamp / 1000)}:R>)
|
<t:${parseInt(targetServer.joinedTimestamp / 1000)}:f> (<t:${parseInt(targetServer.joinedTimestamp / 1000)}:R>)
|
||||||
`);
|
`);
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [userResult],
|
embeds: [userResult],
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "server": {
|
case 'server': {
|
||||||
const guild: Guild = interaction.guild;
|
const guild: Guild = interaction.guild;
|
||||||
const serverResult: EmbedBuilder = new EmbedBuilder()
|
const serverResult: EmbedBuilder = new EmbedBuilder()
|
||||||
.setTitle(`${guild.name} Informations`)
|
.setTitle(`${guild.name} Informations`)
|
||||||
.setColor(guildData.color)
|
.setColor(guildData.color)
|
||||||
.setThumbnail(guild.iconURL({ dynamic: true, size: 2048 }))
|
.setThumbnail(guild.iconURL({ dynamic: true, size: 2048 }))
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: guildData.footer,
|
text: guildData.footer,
|
||||||
})
|
})
|
||||||
.setImage(guild.bannerURL({ dynamic: true, size: 2048 }))
|
.setImage(guild.bannerURL({ dynamic: true, size: 2048 }))
|
||||||
.setDescription(`
|
.setDescription(`
|
||||||
**🆔 | ID:**
|
**🆔 | ID:**
|
||||||
${guild.id}
|
${guild.id}
|
||||||
|
|
||||||
**🖊️ | Description:**
|
**🖊️ | Description:**
|
||||||
${guild.description || "No description given."}
|
${guild.description || 'No description given.'}
|
||||||
**🔗 | VanityLink:**
|
**🔗 | VanityLink:**
|
||||||
${guild.vanityURLCode || "No custom link."}
|
${guild.vanityURLCode || 'No custom link.'}
|
||||||
|
|
||||||
**🆕 | Creation Date:**
|
**🆕 | Creation Date:**
|
||||||
<t:${parseInt(guild.createdTimestamp / 1000)}:R>
|
<t:${parseInt(guild.createdTimestamp / 1000)}:R>
|
||||||
|
|
@ -187,11 +190,11 @@ export default {
|
||||||
There is ${guild.roles.cache.size - 1} on __${guild.name}__
|
There is ${guild.roles.cache.size - 1} on __${guild.name}__
|
||||||
${getGuildRoles(guild)}
|
${getGuildRoles(guild)}
|
||||||
`);
|
`);
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [serverResult],
|
embeds: [serverResult],
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
import { MessageFlags, SlashCommandBuilder } from "discord.js";
|
import { MessageFlags, SlashCommandBuilder } from 'discord.js';
|
||||||
import emoji from "../../../assets/emoji.json" assert { type: "json" };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("ping")
|
.setName('ping')
|
||||||
.setDescription("Show your latency"),
|
.setDescription('Show your latency'),
|
||||||
async execute(interaction: CommandInteraction) {
|
async execute(interaction: CommandInteraction) {
|
||||||
const time: number = Date.now();
|
const time: number = Date.now();
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.loading} | Calculating your ping !`,
|
content: `${emoji.answer.loading} | Calculating your ping !`,
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
});
|
});
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
content: `⏱️ | Response latency: **${Date.now() - time}**ms`,
|
content: `⏱️ | Response latency: **${Date.now() - time}**ms`,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,48 +1,48 @@
|
||||||
import { Events } from "discord.js";
|
import { Events } from 'discord.js';
|
||||||
import { prisma } from "../../lib/prisma.ts";
|
import { prisma } from '../../lib/prisma.ts';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: Events.GuildCreate,
|
name: Events.GuildCreate,
|
||||||
async execute(guild) {
|
async execute(guild) {
|
||||||
await prisma.guild.upsert({
|
await prisma.guild.upsert({
|
||||||
where: {
|
where: {
|
||||||
id: guild.id,
|
id: guild.id,
|
||||||
},
|
},
|
||||||
update: {},
|
update: {},
|
||||||
create: {
|
create: {
|
||||||
id: guild.id,
|
id: guild.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const members = await guild.members.fetch();
|
const members = await guild.members.fetch();
|
||||||
for (const [memberId] of members) {
|
for (const [memberId] of members) {
|
||||||
await prisma.user.upsert({
|
await prisma.user.upsert({
|
||||||
where: {
|
where: {
|
||||||
id: memberId,
|
id: memberId,
|
||||||
},
|
},
|
||||||
update: {},
|
update: {},
|
||||||
create: {
|
create: {
|
||||||
id: memberId,
|
id: memberId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await prisma.guildUser.upsert({
|
await prisma.guildUser.upsert({
|
||||||
where: {
|
where: {
|
||||||
userId_guildId: {
|
userId_guildId: {
|
||||||
userId: memberId,
|
userId: memberId,
|
||||||
guildId: guild.id,
|
guildId: guild.id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
update: {},
|
update: {},
|
||||||
create: {
|
create: {
|
||||||
userId: memberId,
|
userId: memberId,
|
||||||
guildId: guild.id,
|
guildId: guild.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(
|
||||||
`✅ | Guild ${guild.name} synchronisée avec ${members.size} membres.`,
|
`✅ | Guild ${guild.name} synchronisée avec ${members.size} membres.`,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,80 +1,82 @@
|
||||||
import { ActivityType, PresenceUpdateStatus, Events } from "discord.js";
|
import { ActivityType, PresenceUpdateStatus, Events } from 'discord.js';
|
||||||
import { prisma } from "../../lib/prisma.ts";
|
import { prisma } from '../../lib/prisma.ts';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: Events.ClientReady,
|
name: Events.ClientReady,
|
||||||
once: true,
|
once: true,
|
||||||
async execute(client) {
|
async execute(client) {
|
||||||
try {
|
try {
|
||||||
const botData: Bot = await prisma.bot.findUnique({
|
const botData: Bot = await prisma.bot.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: 1,
|
id: 1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const newStatus: string = botData.status;
|
const newStatus: string = botData.status;
|
||||||
const tmpType: string = botData.type;
|
const tmpType: string = botData.type;
|
||||||
let newType: ActivityType;
|
let newType: ActivityType;
|
||||||
switch (tmpType) {
|
switch (tmpType) {
|
||||||
case "play":
|
case 'play':
|
||||||
newType = ActivityType.Playing;
|
newType = ActivityType.Playing;
|
||||||
break;
|
break;
|
||||||
case "listen":
|
case 'listen':
|
||||||
newType = ActivityType.Listening;
|
newType = ActivityType.Listening;
|
||||||
break;
|
break;
|
||||||
case "watch":
|
case 'watch':
|
||||||
newType = ActivityType.Watching;
|
newType = ActivityType.Watching;
|
||||||
break;
|
break;
|
||||||
case "stream":
|
case 'stream':
|
||||||
newType = ActivityType.Streaming;
|
newType = ActivityType.Streaming;
|
||||||
break;
|
break;
|
||||||
case "comptet":
|
case 'comptet':
|
||||||
newType = ActivityType.Competing;
|
newType = ActivityType.Competing;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const tmpPresence: string = botData.presence;
|
const tmpPresence: string = botData.presence;
|
||||||
let newPresence: PresenceUpdateStatus;
|
let newPresence: PresenceUpdateStatus;
|
||||||
switch (tmpPresence) {
|
switch (tmpPresence) {
|
||||||
case "online":
|
case 'online':
|
||||||
newPresence = PresenceUpdateStatus.Online;
|
newPresence = PresenceUpdateStatus.Online;
|
||||||
break;
|
break;
|
||||||
case "idle":
|
case 'idle':
|
||||||
newPresence = PresenceUpdateStatus.Idle;
|
newPresence = PresenceUpdateStatus.Idle;
|
||||||
break;
|
break;
|
||||||
case "dnd":
|
case 'dnd':
|
||||||
newPresence = PresenceUpdateStatus.DoNotDisturb;
|
newPresence = PresenceUpdateStatus.DoNotDisturb;
|
||||||
break;
|
break;
|
||||||
case "invisible":
|
case 'invisible':
|
||||||
newPresence = PresenceUpdateStatus.Invisible;
|
newPresence = PresenceUpdateStatus.Invisible;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (botData.type === "steam") {
|
if (botData.type === 'steam') {
|
||||||
client.user.setPresence({
|
client.user.setPresence({
|
||||||
status: newPresence,
|
status: newPresence,
|
||||||
activities: [
|
activities: [
|
||||||
{
|
{
|
||||||
name: newStatus,
|
name: newStatus,
|
||||||
type: newType,
|
type: newType,
|
||||||
url: "https://twich.tv/EniumRaphael",
|
url: 'https://twich.tv/EniumRaphael',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
client.user.setPresence({
|
else {
|
||||||
status: newPresence,
|
client.user.setPresence({
|
||||||
activities: [
|
status: newPresence,
|
||||||
{
|
activities: [
|
||||||
name: newStatus,
|
{
|
||||||
type: newType,
|
name: newStatus,
|
||||||
},
|
type: newType,
|
||||||
],
|
},
|
||||||
});
|
],
|
||||||
}
|
});
|
||||||
} catch (err) {
|
}
|
||||||
console.error(
|
}
|
||||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
catch (err) {
|
||||||
);
|
console.error(
|
||||||
return;
|
`\t⚠️ | Cannot get the database connection!\n\t\t(${err}).`,
|
||||||
}
|
);
|
||||||
console.log(`✅ | ${client.user.username} is now running under TTS bot`);
|
return;
|
||||||
},
|
}
|
||||||
|
console.log(`✅ | ${client.user.username} is now running under TTS bot`);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,38 @@
|
||||||
import { Events, MessageFlags } from "discord.js";
|
import { Events, MessageFlags } from 'discord.js';
|
||||||
import emoji from "../../../assets/emoji.json" assert { type: "json" };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: Events.InteractionCreate,
|
name: Events.InteractionCreate,
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
if (!interaction.isChatInputCommand()) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
const command = interaction.client.commands.get(interaction.commandName);
|
const command = interaction.client.commands.get(interaction.commandName);
|
||||||
if (!command) {
|
if (!command) {
|
||||||
console.error(`⚠️ | Can't execute ${interaction.commandName}`);
|
console.error(`⚠️ | Can't execute ${interaction.commandName}`);
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.error} | Cannot execute the command ${interaction.commandName}`,
|
content: `${emoji.answer.error} | Cannot execute the command ${interaction.commandName}`,
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await command.execute(interaction);
|
await command.execute(interaction);
|
||||||
} catch (error) {
|
}
|
||||||
console.error(
|
catch (error) {
|
||||||
`⚠️ | Error when occured this command ${interaction.commandName}\n\t${error}`,
|
console.error(
|
||||||
);
|
`⚠️ | Error when occured this command ${interaction.commandName}\n\t${error}`,
|
||||||
if (interaction.replied || interaction.deferred) {
|
);
|
||||||
await interaction.followUp({
|
if (interaction.replied || interaction.deferred) {
|
||||||
content: `${emoji.answer.error} | ${interaction.commandName} seems have a problem, thanks report that to the support (After Print)`,
|
await interaction.followUp({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.error} | ${interaction.commandName} seems have a problem, thanks report that to the support (After Print)`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
} else {
|
});
|
||||||
await interaction.reply({
|
}
|
||||||
content: `${emoji.answer.error} | ${interaction.commandName} seems have a problem, thanks report that to the support (Before Print)`,
|
else {
|
||||||
flags: MessageFlags.Ephemeral,
|
await interaction.reply({
|
||||||
});
|
content: `${emoji.answer.error} | ${interaction.commandName} seems have a problem, thanks report that to the support (Before Print)`,
|
||||||
}
|
flags: MessageFlags.Ephemeral,
|
||||||
}
|
});
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
209
src/index.ts
209
src/index.ts
|
|
@ -1,129 +1,132 @@
|
||||||
import fs from "node:fs";
|
import fs from 'node:fs';
|
||||||
import path from "node:path";
|
import path from 'node:path';
|
||||||
import "dotenv/config";
|
import 'dotenv/config';
|
||||||
import { Client, Collection, GatewayIntentBits } from "discord.js";
|
import { Client, Collection, GatewayIntentBits } from 'discord.js';
|
||||||
import { PrismaClient } from "@prisma/client";
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
GatewayIntentBits.Guilds,
|
GatewayIntentBits.Guilds,
|
||||||
GatewayIntentBits.GuildMessages,
|
GatewayIntentBits.GuildMessages,
|
||||||
GatewayIntentBits.MessageContent,
|
GatewayIntentBits.MessageContent,
|
||||||
GatewayIntentBits.GuildMembers,
|
GatewayIntentBits.GuildMembers,
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
client.login(process.env.DSC_TOKEN);
|
client.login(process.env.DSC_TOKEN);
|
||||||
|
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
|
|
||||||
const commandFolderPath = path.join(__dirname, "commands");
|
const commandFolderPath = path.join(__dirname, 'commands');
|
||||||
const commandFolders = fs.readdirSync(commandFolderPath);
|
const commandFolders = fs.readdirSync(commandFolderPath);
|
||||||
|
|
||||||
console.log("\n🔍 | Commands search:");
|
console.log('\n🔍 | Commands search:');
|
||||||
for (const folder of commandFolders) {
|
for (const folder of commandFolders) {
|
||||||
const commandsPath = path.join(commandFolderPath, folder);
|
const commandsPath = path.join(commandFolderPath, folder);
|
||||||
const commandFiles = fs
|
const commandFiles = fs
|
||||||
.readdirSync(commandsPath)
|
.readdirSync(commandsPath)
|
||||||
.filter((file) => file.endsWith(".js") || file.endsWith(".ts"));
|
.filter((file) => file.endsWith('.js') || file.endsWith('.ts'));
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
const fullCommandPath = path.join(commandsPath, file);
|
const fullCommandPath = path.join(commandsPath, file);
|
||||||
try {
|
try {
|
||||||
const commandModule = await import(fullCommandPath);
|
const commandModule = await import(fullCommandPath);
|
||||||
const command = commandModule.default || commandModule;
|
const command = commandModule.default || commandModule;
|
||||||
if ("data" in command && "execute" in command) {
|
if ('data' in command && 'execute' in command) {
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
console.log(`\t✅ | ${command.data.name}`);
|
console.log(`\t✅ | ${command.data.name}`);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
}
|
||||||
console.error(`\t⚠️ | Command at ${file}\n\t\t(${err}).`);
|
catch (err) {
|
||||||
}
|
console.error(`\t⚠️ | Command at ${file}\n\t\t(${err}).`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
console.log("\n\n");
|
console.log('\n\n');
|
||||||
|
|
||||||
const eventFolderPath = path.join(__dirname, "events");
|
const eventFolderPath = path.join(__dirname, 'events');
|
||||||
const eventFolders = fs.readdirSync(eventFolderPath);
|
const eventFolders = fs.readdirSync(eventFolderPath);
|
||||||
|
|
||||||
console.log("\n🔍 | Events search:");
|
console.log('\n🔍 | Events search:');
|
||||||
for (const folder of eventFolders) {
|
for (const folder of eventFolders) {
|
||||||
const eventsPath = path.join(eventFolderPath, folder);
|
const eventsPath = path.join(eventFolderPath, folder);
|
||||||
const eventFiles = fs
|
const eventFiles = fs
|
||||||
.readdirSync(eventsPath)
|
.readdirSync(eventsPath)
|
||||||
.filter((file) => file.endsWith(".js") || file.endsWith(".ts"));
|
.filter((file) => file.endsWith('.js') || file.endsWith('.ts'));
|
||||||
for (const file of eventFiles) {
|
for (const file of eventFiles) {
|
||||||
const fullEventPath = path.join(eventsPath, file);
|
const fullEventPath = path.join(eventsPath, file);
|
||||||
try {
|
try {
|
||||||
const eventModule = await import(fullEventPath);
|
const eventModule = await import(fullEventPath);
|
||||||
const event = eventModule.default || eventModule;
|
const event = eventModule.default || eventModule;
|
||||||
if ("name" in event && "execute" in event) {
|
if ('name' in event && 'execute' in event) {
|
||||||
if (event.once) {
|
if (event.once) {
|
||||||
client.once(event.name, (...args) => event.execute(...args));
|
client.once(event.name, (...args) => event.execute(...args));
|
||||||
} else {
|
}
|
||||||
client.on(event.name, (...args) => event.execute(...args));
|
else {
|
||||||
}
|
client.on(event.name, (...args) => event.execute(...args));
|
||||||
console.log(`\t✅ | ${event.name}`);
|
}
|
||||||
}
|
console.log(`\t✅ | ${event.name}`);
|
||||||
} catch (err) {
|
}
|
||||||
console.error(`\t⚠️ | Event at ${file}\n\t\t(${err}).`);
|
}
|
||||||
}
|
catch (err) {
|
||||||
}
|
console.error(`\t⚠️ | Event at ${file}\n\t\t(${err}).`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
console.log("\n\n");
|
console.log('\n\n');
|
||||||
|
|
||||||
client.once("ready", async () => {
|
client.once('ready', async () => {
|
||||||
console.log(`🤖 | Connecté en tant que ${client.user?.tag}`);
|
console.log(`🤖 | Connecté en tant que ${client.user?.tag}`);
|
||||||
|
|
||||||
await prisma.bot.upsert({
|
await prisma.bot.upsert({
|
||||||
where: {
|
where: {
|
||||||
id: 1,
|
id: 1,
|
||||||
},
|
},
|
||||||
update: {},
|
update: {},
|
||||||
create: {},
|
create: {},
|
||||||
});
|
});
|
||||||
for (const [guildId, guild] of client.guilds.cache) {
|
for (const [guildId, guild] of client.guilds.cache) {
|
||||||
await prisma.guild.upsert({
|
await prisma.guild.upsert({
|
||||||
where: {
|
where: {
|
||||||
id: guildId,
|
id: guildId,
|
||||||
},
|
},
|
||||||
update: {},
|
update: {},
|
||||||
create: {
|
create: {
|
||||||
id: guildId,
|
id: guildId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const members = await guild.members.fetch();
|
const members = await guild.members.fetch();
|
||||||
|
|
||||||
for (const [memberId] of members) {
|
for (const [memberId] of members) {
|
||||||
await prisma.user.upsert({
|
await prisma.user.upsert({
|
||||||
where: {
|
where: {
|
||||||
id: memberId,
|
id: memberId,
|
||||||
},
|
},
|
||||||
update: {},
|
update: {},
|
||||||
create: {
|
create: {
|
||||||
id: memberId,
|
id: memberId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await prisma.guildUser.upsert({
|
await prisma.guildUser.upsert({
|
||||||
where: {
|
where: {
|
||||||
userId_guildId: {
|
userId_guildId: {
|
||||||
userId: memberId,
|
userId: memberId,
|
||||||
guildId: guildId,
|
guildId: guildId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
update: {},
|
update: {},
|
||||||
create: {
|
create: {
|
||||||
userId: memberId,
|
userId: memberId,
|
||||||
guildId: guildId,
|
guildId: guildId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`✅ | Guild ${guild.name} synchronisée avec ${members.size} membres.`,
|
`✅ | Guild ${guild.name} synchronisée avec ${members.size} membres.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,52 +1,54 @@
|
||||||
import { REST, Routes } from "discord.js";
|
import { REST, Routes } from 'discord.js';
|
||||||
import { Client, Collection, GatewayIntentBits } from "discord.js";
|
import { Client, Collection, GatewayIntentBits } from 'discord.js';
|
||||||
import "dotenv/config";
|
import 'dotenv/config';
|
||||||
import fs from "node:fs";
|
import fs from 'node:fs';
|
||||||
import path from "node:path";
|
import path from 'node:path';
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [GatewayIntentBits.Guilds],
|
intents: [GatewayIntentBits.Guilds],
|
||||||
});
|
});
|
||||||
|
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
|
|
||||||
const commands = [];
|
const commands = [];
|
||||||
|
|
||||||
const foldersPath = path.join(__dirname, "../commands");
|
const foldersPath = path.join(__dirname, '../commands');
|
||||||
const commandFolders = fs.readdirSync(foldersPath);
|
const commandFolders = fs.readdirSync(foldersPath);
|
||||||
|
|
||||||
for (const folder of commandFolders) {
|
for (const folder of commandFolders) {
|
||||||
const commandsPath = path.join(foldersPath, folder);
|
const commandsPath = path.join(foldersPath, folder);
|
||||||
const commandFiles = fs
|
const commandFiles = fs
|
||||||
.readdirSync(commandsPath)
|
.readdirSync(commandsPath)
|
||||||
.filter((file) => file.endsWith(".ts") || file.endsWith(".js"));
|
.filter((file) => file.endsWith('.ts') || file.endsWith('.js'));
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
const filesPath = path.join(commandsPath, file);
|
const filesPath = path.join(commandsPath, file);
|
||||||
const commandModule = await import(filesPath);
|
const commandModule = await import(filesPath);
|
||||||
const command = commandModule.default || commandModule;
|
const command = commandModule.default || commandModule;
|
||||||
if ("data" in command && "execute" in command) {
|
if ('data' in command && 'execute' in command) {
|
||||||
commands.push(command.data.toJSON());
|
commands.push(command.data.toJSON());
|
||||||
} else {
|
}
|
||||||
console.log(
|
else {
|
||||||
'⚠️ | A Command is missing a required "data" or "execute" property.',
|
console.log(
|
||||||
);
|
'⚠️ | A Command is missing a required "data" or "execute" property.',
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const rest = new REST().setToken(process.env.DSC_TOKEN);
|
const rest = new REST().setToken(process.env.DSC_TOKEN);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
console.log(`🔍 | ${commands.length} commands found.`);
|
console.log(`🔍 | ${commands.length} commands found.`);
|
||||||
const data = await rest.put(
|
const data = await rest.put(
|
||||||
Routes.applicationCommands(process.env.CLIENT_ID),
|
Routes.applicationCommands(process.env.CLIENT_ID),
|
||||||
{
|
{
|
||||||
body: commands,
|
body: commands,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
console.log(`✅ | ${data.length} is now reloaded`);
|
console.log(`✅ | ${data.length} is now reloaded`);
|
||||||
} catch (error) {
|
}
|
||||||
console.error(error);
|
catch (error) {
|
||||||
}
|
console.error(error);
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import { PrismaClient } from "@prisma/client";
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
export const prisma = new PrismaClient();
|
export const prisma = new PrismaClient();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue