commit
7ad3f34d8c
14 changed files with 37 additions and 33 deletions
|
@ -8,10 +8,11 @@ export const options: IEventOptions = {
|
||||||
type: "on",
|
type: "on",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Execute the function
|
||||||
export const execute = async (guild: Guild) => {
|
export const execute = async (guild: Guild) => {
|
||||||
const { client } = guild;
|
const { client } = guild;
|
||||||
|
|
||||||
await updatePresence(client);
|
updatePresence(client);
|
||||||
|
|
||||||
// Create guildMember object
|
// Create guildMember object
|
||||||
const createGuildMember = await prisma.guildMember.upsert({
|
const createGuildMember = await prisma.guildMember.upsert({
|
||||||
|
|
|
@ -9,10 +9,11 @@ export const options: IEventOptions = {
|
||||||
type: "on",
|
type: "on",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Execute the function
|
||||||
export const execute = async (guild: Guild) => {
|
export const execute = async (guild: Guild) => {
|
||||||
const { client } = guild;
|
const { client } = guild;
|
||||||
|
|
||||||
await updatePresence(client);
|
updatePresence(client);
|
||||||
|
|
||||||
// Delete guildMember objects
|
// Delete guildMember objects
|
||||||
const deleteGuildMembers = prisma.guildMember.deleteMany({
|
const deleteGuildMembers = prisma.guildMember.deleteMany({
|
||||||
|
|
|
@ -11,6 +11,7 @@ export const options: IEventOptions = {
|
||||||
type: "on",
|
type: "on",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Execute the function
|
||||||
export const execute = async (member: GuildMember) => {
|
export const execute = async (member: GuildMember) => {
|
||||||
const { client, user, guild } = member;
|
const { client, user, guild } = member;
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ export const execute = async (member: GuildMember) => {
|
||||||
|
|
||||||
await audits.execute(member);
|
await audits.execute(member);
|
||||||
await joinMessage.execute(member);
|
await joinMessage.execute(member);
|
||||||
await updatePresence(client);
|
updatePresence(client);
|
||||||
|
|
||||||
// Create guildMember object
|
// Create guildMember object
|
||||||
const createGuildMember = await prisma.guildMember.upsert({
|
const createGuildMember = await prisma.guildMember.upsert({
|
||||||
|
|
|
@ -11,6 +11,7 @@ export const options: IEventOptions = {
|
||||||
type: "on",
|
type: "on",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Execute the function
|
||||||
export const execute = async (member: GuildMember) => {
|
export const execute = async (member: GuildMember) => {
|
||||||
const { client, user, guild } = member;
|
const { client, user, guild } = member;
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ export const execute = async (member: GuildMember) => {
|
||||||
|
|
||||||
await audits.execute(member);
|
await audits.execute(member);
|
||||||
await leaveMessage.execute(member);
|
await leaveMessage.execute(member);
|
||||||
await updatePresence(client);
|
updatePresence(client);
|
||||||
|
|
||||||
// Delete guildMember object
|
// Delete guildMember object
|
||||||
const deleteGuildMember = await prisma.guildMember.deleteMany({
|
const deleteGuildMember = await prisma.guildMember.deleteMany({
|
||||||
|
|
|
@ -11,10 +11,11 @@ export const options: IEventOptions = {
|
||||||
type: "once",
|
type: "once",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Execute the event
|
||||||
export const execute = async (client: Client) => {
|
export const execute = async (client: Client) => {
|
||||||
logger.info("Discord's API client is ready!");
|
logger.info("Discord's API client is ready!");
|
||||||
|
|
||||||
await updatePresence(client);
|
updatePresence(client);
|
||||||
await devMode(client);
|
await devMode(client);
|
||||||
await deployCommands(client);
|
await deployCommands(client);
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,7 @@ import addSeconds from "../../helpers/addSeconds";
|
||||||
import logger from "../../middlewares/logger";
|
import logger from "../../middlewares/logger";
|
||||||
import prisma from "../database";
|
import prisma from "../database";
|
||||||
|
|
||||||
|
// Command cooldown
|
||||||
export const command = async (i: CommandInteraction, cooldown: number) => {
|
export const command = async (i: CommandInteraction, cooldown: number) => {
|
||||||
const { guild, user, commandId } = i;
|
const { guild, user, commandId } = i;
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ export const command = async (i: CommandInteraction, cooldown: number) => {
|
||||||
// If user is not on timeout
|
// If user is not on timeout
|
||||||
if (hasTimeout) {
|
if (hasTimeout) {
|
||||||
const { userId, timeoutId, createdAt } = hasTimeout;
|
const { userId, timeoutId, createdAt } = hasTimeout;
|
||||||
const overDue = (await addSeconds(cooldown, createdAt)) < new Date();
|
const overDue = addSeconds(cooldown, createdAt) < new Date();
|
||||||
|
|
||||||
if (!overDue) {
|
if (!overDue) {
|
||||||
const diff = Math.round(
|
const diff = Math.round(
|
||||||
|
@ -94,6 +95,7 @@ export const command = async (i: CommandInteraction, cooldown: number) => {
|
||||||
logger.silly(createCooldown);
|
logger.silly(createCooldown);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Button cooldown
|
||||||
export const button = async (i: ButtonInteraction, cooldown: number) => {
|
export const button = async (i: ButtonInteraction, cooldown: number) => {
|
||||||
const { guild, user, customId } = i;
|
const { guild, user, customId } = i;
|
||||||
|
|
||||||
|
@ -115,7 +117,7 @@ export const button = async (i: ButtonInteraction, cooldown: number) => {
|
||||||
// If user is not on timeout
|
// If user is not on timeout
|
||||||
if (hasTimeout) {
|
if (hasTimeout) {
|
||||||
const { userId, timeoutId, createdAt } = hasTimeout;
|
const { userId, timeoutId, createdAt } = hasTimeout;
|
||||||
const overDue = (await addSeconds(cooldown, createdAt)) < new Date();
|
const overDue = addSeconds(cooldown, createdAt) < new Date();
|
||||||
|
|
||||||
if (!overDue) {
|
if (!overDue) {
|
||||||
const diff = Math.round(
|
const diff = Math.round(
|
||||||
|
@ -184,6 +186,7 @@ export const button = async (i: ButtonInteraction, cooldown: number) => {
|
||||||
logger.silly(createCooldown);
|
logger.silly(createCooldown);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Message cooldown
|
||||||
export const message = async (msg: Message, cooldown: number, id: string) => {
|
export const message = async (msg: Message, cooldown: number, id: string) => {
|
||||||
const { guild, member } = msg;
|
const { guild, member } = msg;
|
||||||
|
|
||||||
|
@ -206,7 +209,7 @@ export const message = async (msg: Message, cooldown: number, id: string) => {
|
||||||
// If user is not on timeout
|
// If user is not on timeout
|
||||||
if (hasTimeout) {
|
if (hasTimeout) {
|
||||||
const { userId, timeoutId, createdAt } = hasTimeout;
|
const { userId, timeoutId, createdAt } = hasTimeout;
|
||||||
const overDue = (await addSeconds(cooldown, createdAt)) < new Date();
|
const overDue = addSeconds(cooldown, createdAt) < new Date();
|
||||||
|
|
||||||
if (!overDue) {
|
if (!overDue) {
|
||||||
const diff = Math.round(
|
const diff = Math.round(
|
||||||
|
|
|
@ -13,34 +13,28 @@ export default async (client: Client) => {
|
||||||
logger.info("Gathering command list");
|
logger.info("Gathering command list");
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
client.commands.map(async (commandData: ICommand) => {
|
client.commands.map((commandData: ICommand) => {
|
||||||
commandList.push(commandData.builder.toJSON());
|
commandList.push(commandData.builder.toJSON());
|
||||||
|
|
||||||
logger.verbose(`${commandData.builder.name} pushed to list`);
|
logger.verbose(`${commandData.builder.name} pushed to list`);
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.then(async () => {
|
.then(() => {
|
||||||
logger.info(`Finished gathering command list.`);
|
logger.info(`Finished gathering command list.`);
|
||||||
})
|
})
|
||||||
.catch(async (error) => {
|
.catch((error) => {
|
||||||
throw new Error(`Could not gather command list: ${error}`);
|
throw new Error(`Could not gather command list: ${error}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
await client.application?.commands
|
await client.application?.commands
|
||||||
.set(commandList, process.env.DISCORD_GUILD_ID)
|
.set(commandList, process.env.DISCORD_GUILD_ID)
|
||||||
.then(async () => {
|
.then(() => {
|
||||||
logger.info(`Finished updating command list.`);
|
logger.info(`Finished updating command list.`);
|
||||||
})
|
|
||||||
.catch(async (error) => {
|
|
||||||
logger.error(`${error}`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== "production") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
await client.application?.commands
|
await client.application?.commands
|
||||||
.set(commandList)
|
.set(commandList)
|
||||||
.then(async () => logger.info(`Finished updating guild command list.`))
|
.then(() => logger.info(`Finished updating guild command list.`));
|
||||||
.catch(async (error) => {
|
|
||||||
logger.error(`${error}`);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,9 +3,9 @@ import logger from "../../middlewares/logger";
|
||||||
|
|
||||||
export default async (client: Client) => {
|
export default async (client: Client) => {
|
||||||
if (process.env.NODE_ENV !== "production") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
return client?.application?.commands
|
await client?.application?.commands
|
||||||
?.set([], process.env.DISCORD_GUILD_ID)
|
?.set([], process.env.DISCORD_GUILD_ID)
|
||||||
.then(async () => {
|
.then(() => {
|
||||||
return logger.verbose(`Development mode is disabled.`);
|
return logger.verbose(`Development mode is disabled.`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { ActivityType, Client } from "discord.js";
|
||||||
import logger from "../../middlewares/logger";
|
import logger from "../../middlewares/logger";
|
||||||
|
|
||||||
// Function
|
// Function
|
||||||
export default async (client: Client) => {
|
export default (client: Client) => {
|
||||||
if (!client?.user) throw new Error("Client's user is undefined.");
|
if (!client?.user) throw new Error("Client's user is undefined.");
|
||||||
const { guilds } = client;
|
const { guilds } = client;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export default async (seconds: number, date: Date) => {
|
export default (seconds: number, date: Date) => {
|
||||||
date.setSeconds(date.getSeconds() + seconds);
|
date.setSeconds(date.getSeconds() + seconds);
|
||||||
return date;
|
return date;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,5 +2,6 @@ import fs from "fs";
|
||||||
const fsPromises = fs.promises;
|
const fsPromises = fs.promises;
|
||||||
|
|
||||||
export default async (path: string) => {
|
export default async (path: string) => {
|
||||||
return fsPromises.readdir(path);
|
const result = await fsPromises.readdir(path);
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
12
src/index.ts
12
src/index.ts
|
@ -1,8 +1,8 @@
|
||||||
import { Client, Collection, GatewayIntentBits } from "discord.js"; // discord.js
|
import { Client, Collection, GatewayIntentBits } from "discord.js"; // discord.js
|
||||||
import "dotenv/config";
|
import "dotenv/config";
|
||||||
import * as command from "./handlers/command";
|
import { register as commandRegister } from "./handlers/command";
|
||||||
import * as event from "./handlers/event";
|
import { register as eventRegister } from "./handlers/event";
|
||||||
import * as schedule from "./handlers/schedule";
|
import { start as scheduleStart } from "./handlers/schedule";
|
||||||
|
|
||||||
// Main process that starts all other sub processes
|
// Main process that starts all other sub processes
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
|
@ -19,9 +19,9 @@ const main = async () => {
|
||||||
// Create command collection
|
// Create command collection
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
|
|
||||||
await schedule.start(client);
|
await scheduleStart(client);
|
||||||
await event.register(client);
|
await eventRegister(client);
|
||||||
await command.register(client);
|
await commandRegister(client);
|
||||||
|
|
||||||
// Authorize with Discord's API
|
// Authorize with Discord's API
|
||||||
await client.login(process.env.DISCORD_TOKEN);
|
await client.login(process.env.DISCORD_TOKEN);
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
// Dependencies
|
// Dependencies
|
||||||
import { Client } from "discord.js";
|
import { Client } from "discord.js";
|
||||||
|
|
||||||
import * as roles from "./modules/roles";
|
import { execute as RolesExecute } from "./modules/roles";
|
||||||
|
|
||||||
export const options = {
|
export const options = {
|
||||||
schedule: "*/5 * * * *", // https://crontab.guru/
|
schedule: "*/5 * * * *", // https://crontab.guru/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Execute the function
|
||||||
export const execute = async (client: Client) => {
|
export const execute = async (client: Client) => {
|
||||||
await roles.execute(client);
|
await RolesExecute(client);
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,7 +16,7 @@ export const execute = async () => {
|
||||||
for await (const timeout of getCooldown) {
|
for await (const timeout of getCooldown) {
|
||||||
const { guildId, userId, timeoutId, cooldown, createdAt } = timeout;
|
const { guildId, userId, timeoutId, cooldown, createdAt } = timeout;
|
||||||
|
|
||||||
const overDue = (await addSeconds(cooldown, createdAt)) < new Date();
|
const overDue = addSeconds(cooldown, createdAt) < new Date();
|
||||||
|
|
||||||
if (overDue) {
|
if (overDue) {
|
||||||
logger.info(timeout);
|
logger.info(timeout);
|
||||||
|
|
Loading…
Add table
Reference in a new issue