diff --git a/slowcord/bot/src/Bot.ts b/slowcord/bot/src/Bot.ts
index a89102e6..4b684ea9 100644
--- a/slowcord/bot/src/Bot.ts
+++ b/slowcord/bot/src/Bot.ts
@@ -22,13 +22,12 @@ export default class Bot {
type: "WATCHING",
}]
});
-
};
- onMessageCreate = (msg: Message) => {
+ onMessageCreate = async (msg: Message) => {
const prefix = process.env.PREFIX as string;
- if (msg.content.indexOf(prefix) === -1) return;
if (msg.author.bot) return;
+ if (msg.content && msg.content.indexOf(prefix) === -1) return;
const content = msg.content.slice(prefix.length).split(" ");
const cmd = content.shift();
@@ -38,7 +37,7 @@ export default class Bot {
const command = this.commands[cmd];
if (!command) return;
- command.exec({
+ await command.exec({
user: msg.author,
member: msg.member,
guild: msg.guild,
diff --git a/slowcord/bot/src/commands/index.ts b/slowcord/bot/src/commands/index.ts
index ef2d2a22..d3b39e0f 100644
--- a/slowcord/bot/src/commands/index.ts
+++ b/slowcord/bot/src/commands/index.ts
@@ -14,20 +14,24 @@ export type Command = {
exec: (ctx: CommandContext) => any;
};
-const walk = async (path: string): Promise<Command[]> => {
+const walk = async (path: string) => {
const files = fs.readdirSync(path);
- const out: Command[] = [];
+ const out = [];
for (var file of files) {
- if (file.indexOf("index") !== -1) continue;
-
- var imported = await import(`${path}/${file}`);
+ if (fs.statSync(`${path}/${file}`).isDirectory()) continue;
+ if (file.indexOf("index") !== -1)
+ continue;
+ if (file.indexOf(".js") !== file.length - 3) continue;
+ var imported = (await import(`./${file}`)).default;
+ out.push(imported);
}
-
return out;
};
export const getCommands = async () => {
- const map: { [key: string]: Command; } = {};
- (await walk("./build/commands")).forEach((val) => map[val.name] = val);
+ const map: { [key: string]: Command } = {};
+ for (var cmd of await walk("./build/commands")) {
+ map[cmd.name] = cmd;
+ }
return map;
-};
\ No newline at end of file
+};
diff --git a/slowcord/bot/src/commands/instance.ts b/slowcord/bot/src/commands/instance.ts
index 7fcfaef4..d1b08cef 100644
--- a/slowcord/bot/src/commands/instance.ts
+++ b/slowcord/bot/src/commands/instance.ts
@@ -1,8 +1,35 @@
import { Command } from "./index.js";
+import { User, Guild, Message } from "@fosscord/util";
+
+const cache: { [key: string]: number; } = {
+ users: 0,
+ guilds: 0,
+ messages: 0,
+ lastChecked: 0,
+};
export default {
name: "instance",
- exec: ({ message }) => {
- message.reply("Test");
+ exec: async ({ message }) => {
+ if (Date.now() > cache.lastChecked + parseInt(process.env.CACHE_TTL as string)) {
+ cache.users = await User.count();
+ cache.guilds = await Guild.count();
+ cache.messages = await Message.count();
+ cache.lastChecked = Date.now();
+ }
+
+ return message.reply({
+ embeds: [{
+ title: "Instance Stats",
+ footer: {
+ text: `Last checked: ${Math.floor((Date.now() - cache.lastChecked) / (1000 * 60))} minutes ago`,
+ },
+ fields: [
+ { inline: true, name: "Total Users", value: cache.users.toString() },
+ { inline: true, name: "Total Guilds", value: cache.guilds.toString() },
+ { inline: true, name: "Total Messages", value: cache.messages.toString() },
+ ]
+ }]
+ });
}
} as Command;
\ No newline at end of file
diff --git a/slowcord/bot/src/index.ts b/slowcord/bot/src/index.ts
index 2113b3a8..ae69111b 100644
--- a/slowcord/bot/src/index.ts
+++ b/slowcord/bot/src/index.ts
@@ -1,6 +1,7 @@
import "dotenv/config";
import Fosscord from "fosscord-gopnik";
import Bot from "./Bot.js"; // huh?
+import { initDatabase } from "@fosscord/util";
const client = new Fosscord.Client({
intents: ["GUILD_MESSAGES"],
@@ -17,4 +18,7 @@ const bot = new Bot(client);
client.on("ready", bot.onReady);
client.on("messageCreate", bot.onMessageCreate);
-client.login(process.env.TOKEN);
\ No newline at end of file
+(async () => {
+ await initDatabase();
+ await client.login(process.env.TOKEN);
+})();
\ No newline at end of file
|