forked from engineering/crv2
misc fixes
parent
373cb814c3
commit
7ea009714b
|
@ -117,7 +117,7 @@ export default class Whois extends DiscordInteractionCommand {
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'offline':
|
case 'offline':
|
||||||
embed.addFields({ name: 'Status', value: 'offline', inline: true });
|
embed.addFields({ name: 'Status', value: 'Offline', inline: true });
|
||||||
break;
|
break;
|
||||||
case 'invisible':
|
case 'invisible':
|
||||||
embed.addFields({ name: 'Status', value: 'invisible', inline: true });
|
embed.addFields({ name: 'Status', value: 'invisible', inline: true });
|
||||||
|
|
135
index.ts
135
index.ts
|
@ -1,77 +1,88 @@
|
||||||
import { Client, GatewayIntentBits, Partials, REST, Routes } from "discord.js";
|
import { Client, GatewayIntentBits, Partials, REST, Routes } from 'discord.js';
|
||||||
import { discordBotToken, discordClientID } from "./config.json"
|
import { discordBotToken, discordClientID, MongoDbUrl } from './config.json';
|
||||||
import Collection from "./util/Collection";
|
import Collection from './util/Collection';
|
||||||
import DiscordInteractionCommand from "./util/DiscordInteractionCommand";
|
import DiscordInteractionCommand from './util/DiscordInteractionCommand';
|
||||||
import DiscordEvent from "./util/DiscordEvent";
|
import DiscordEvent from './util/DiscordEvent';
|
||||||
import * as DiscordInteractionCommandsIndex from "./discord/commands";
|
import * as DiscordInteractionCommandsIndex from './discord/commands';
|
||||||
import * as DiscordEventsIndex from "./discord/events";
|
import * as DiscordEventsIndex from './discord/events';
|
||||||
import mongoose from "mongoose";
|
import mongoose from 'mongoose';
|
||||||
|
|
||||||
export const DiscordInteractionCommands: Collection<DiscordInteractionCommand> = new Collection();
|
export const DiscordInteractionCommands: Collection<DiscordInteractionCommand> =
|
||||||
|
new Collection();
|
||||||
export const DiscordEvents: Collection<DiscordEvent> = new Collection();
|
export const DiscordEvents: Collection<DiscordEvent> = new Collection();
|
||||||
|
|
||||||
// Instantiates a new Discord client
|
// Instantiates a new Discord client
|
||||||
const discordClient = new Client({
|
const discordClient = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
GatewayIntentBits.DirectMessages,
|
GatewayIntentBits.DirectMessages,
|
||||||
GatewayIntentBits.GuildIntegrations,
|
GatewayIntentBits.GuildIntegrations,
|
||||||
GatewayIntentBits.GuildPresences,
|
GatewayIntentBits.GuildPresences,
|
||||||
GatewayIntentBits.GuildMessages,
|
GatewayIntentBits.GuildMessages,
|
||||||
GatewayIntentBits.Guilds,
|
GatewayIntentBits.Guilds,
|
||||||
GatewayIntentBits.GuildInvites,
|
GatewayIntentBits.GuildInvites,
|
||||||
GatewayIntentBits.GuildModeration,
|
GatewayIntentBits.GuildModeration,
|
||||||
],
|
],
|
||||||
partials: [ Partials.GuildMember, Partials.Message, Partials.User, Partials.Channel, ],
|
partials: [
|
||||||
|
Partials.GuildMember,
|
||||||
|
Partials.Message,
|
||||||
|
Partials.User,
|
||||||
|
Partials.Channel,
|
||||||
|
],
|
||||||
});
|
});
|
||||||
const discordREST = new REST().setToken(discordBotToken);
|
const discordREST = new REST().setToken(discordBotToken);
|
||||||
// const stripeClient = new Stripe(stripeToken, { typescript: true });
|
// const stripeClient = new Stripe(stripeToken, { typescript: true });
|
||||||
|
|
||||||
export async function main() {
|
export async function main() {
|
||||||
// Connect to the databases
|
// Connect to the databases
|
||||||
try {
|
try {
|
||||||
mongoose.connection.once("open", () => {
|
//@ts-ignore
|
||||||
console.info("[Info - Database] Connected to MongoDB");
|
mongoose.connection.once('open', () => {
|
||||||
})
|
console.info('[Info - Database] Connected to MongoDB');
|
||||||
// TODO: Fetch the MongoDB URI from the config file
|
});
|
||||||
await mongoose.connect("mongodb://localhost:27017/crra-main", {});
|
// TODO: Fetch the MongoDB URI from the config file
|
||||||
} catch (error) {
|
await mongoose.connect(MongoDbUrl, {});
|
||||||
console.error(`[Error - Database] Failed to connect to MongoDB: ${error}`);
|
} catch (error) {
|
||||||
process.exit(1);
|
console.error(`[Error - Database] Failed to connect to MongoDB: ${error}`);
|
||||||
}
|
process.exit(1);
|
||||||
// Load Discord interaction commands
|
}
|
||||||
for (const Command of Object.values(DiscordInteractionCommandsIndex)) {
|
// Load Discord interaction commands
|
||||||
const instance = new Command();
|
for (const Command of Object.values(DiscordInteractionCommandsIndex)) {
|
||||||
DiscordInteractionCommands.add(instance.name, instance);
|
const instance = new Command();
|
||||||
console.info(`[Info - Discord] Loaded interaction command: ${instance.name}`);
|
DiscordInteractionCommands.add(instance.name, instance);
|
||||||
}
|
console.info(
|
||||||
// Load Discord events
|
`[Info - Discord] Loaded interaction command: ${instance.name}`
|
||||||
for (const Event of Object.values(DiscordEventsIndex)) {
|
);
|
||||||
const instance = new Event(discordClient);
|
}
|
||||||
DiscordEvents.add(instance.name, instance);
|
// Load Discord events
|
||||||
discordClient.on(instance.name, instance.execute);
|
for (const Event of Object.values(DiscordEventsIndex)) {
|
||||||
console.info(`[Info - Discord] Loaded event: ${instance.name}`);
|
const instance = new Event(discordClient);
|
||||||
}
|
DiscordEvents.add(instance.name, instance);
|
||||||
await discordClient.login(discordBotToken);
|
discordClient.on(instance.name, instance.execute);
|
||||||
|
console.info(`[Info - Discord] Loaded event: ${instance.name}`);
|
||||||
|
}
|
||||||
|
await discordClient.login(discordBotToken);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(`Started refreshing ${DiscordInteractionCommands.size} application (/) commands.`);
|
console.log(
|
||||||
const interactionCommandsData = [];
|
`Started refreshing ${DiscordInteractionCommands.size} application (/) commands.`
|
||||||
for (const command of DiscordInteractionCommands.values()) {
|
);
|
||||||
interactionCommandsData.push(command.builder.toJSON());
|
const interactionCommandsData = [];
|
||||||
}
|
for (const command of DiscordInteractionCommands.values()) {
|
||||||
|
interactionCommandsData.push(command.builder.toJSON());
|
||||||
// The put method is used to fully refresh all commands in the guild with the current set
|
|
||||||
const data = await discordREST.put(
|
|
||||||
Routes.applicationCommands(discordClientID),
|
|
||||||
{ body: interactionCommandsData },
|
|
||||||
);
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
console.log(`Successfully reloaded ${data?.length} application (/) commands.`);
|
|
||||||
} catch (error) {
|
|
||||||
// And of course, make sure you catch and log any errors!
|
|
||||||
console.error(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The put method is used to fully refresh all commands in the guild with the current set
|
||||||
|
const data = await discordREST.put(
|
||||||
|
Routes.applicationCommands(discordClientID),
|
||||||
|
{ body: interactionCommandsData }
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`Successfully reloaded ${interactionCommandsData?.length} application (/) commands.`
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
// And of course, make sure you catch and log any errors!
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
Loading…
Reference in New Issue