diff --git a/slowcord/.vscode/launch.json b/slowcord/.vscode/launch.json deleted file mode 100644 index 6b41b246..00000000 --- a/slowcord/.vscode/launch.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "configurations": [ - { - "name": "ts-node", - "type": "node", - "request": "launch", - "args": [ - "${relativeFile}" - ], - "runtimeArgs": [ - "-r", - "ts-node/register" - ], - "cwd": "${workspaceRoot}", - "protocol": "inspector", - "internalConsoleOptions": "openOnSessionStart" - } - - ] -} \ No newline at end of file diff --git a/slowcord/bot/.vscode/launch.json b/slowcord/bot/.vscode/launch.json new file mode 100644 index 00000000..92765e22 --- /dev/null +++ b/slowcord/bot/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + "configurations": [ + { + "name": "Slowcord Bot", + "program": "${workspaceFolder}/build/index.js", + "request": "launch", + "skipFiles": [ + "/**" + ], + "type": "node", + "preLaunchTask": "npm: build" + } + + ] +} \ No newline at end of file diff --git a/slowcord/.vscode/tasks.json b/slowcord/bot/.vscode/tasks.json similarity index 100% rename from slowcord/.vscode/tasks.json rename to slowcord/bot/.vscode/tasks.json diff --git a/slowcord/bot/package-lock.json b/slowcord/bot/package-lock.json index 4a31bd61..0d72daab 100644 Binary files a/slowcord/bot/package-lock.json and b/slowcord/bot/package-lock.json differ diff --git a/slowcord/bot/package.json b/slowcord/bot/package.json index 00f674d5..847cef09 100644 --- a/slowcord/bot/package.json +++ b/slowcord/bot/package.json @@ -10,8 +10,9 @@ "author": "", "license": "ISC", "dependencies": { + "@fosscord/util": "file:../../util", "fosscord-gopnik": "^1.0.0", + "mysql": "^2.18.1", "typescript": "^4.7.4" - }, - "type": "module" -} \ No newline at end of file + } +} 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 => { +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 diff --git a/slowcord/bot/tsconfig.json b/slowcord/bot/tsconfig.json index 08c1fe6a..05bfc5c7 100644 --- a/slowcord/bot/tsconfig.json +++ b/slowcord/bot/tsconfig.json @@ -11,10 +11,10 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + "target": "ES6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "lib": ["ES2021"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ - // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ @@ -24,7 +24,7 @@ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ /* Modules */ - "module": "ES2022", /* Specify what module code is generated. */ + "module": "CommonJS", /* Specify what module code is generated. */ // "rootDir": "./", /* Specify the root folder within your source files. */ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ @@ -45,7 +45,7 @@ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ // "declarationMap": true, /* Create sourcemaps for d.ts files. */ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + "sourceMap": true, /* Create source map files for emitted JavaScript files. */ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ "outDir": "./build", /* Specify an output folder for all emitted files. */ // "removeComments": true, /* Disable emitting comments. */ @@ -79,7 +79,7 @@ // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + "strictPropertyInitialization": false, /* Check for class properties that are declared but not set in the constructor. */ // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ diff --git a/slowcord/login/package-lock.json b/slowcord/login/package-lock.json index 05d385a3..82eac102 100644 Binary files a/slowcord/login/package-lock.json and b/slowcord/login/package-lock.json differ