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