1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-10 12:42:44 +01:00

Bot update

This commit is contained in:
Madeline 2022-07-22 22:30:38 +10:00
parent 96c8c854ca
commit ce224e200b
11 changed files with 766 additions and 516 deletions

View File

@ -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"
}
]
}

15
slowcord/bot/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"configurations": [
{
"name": "Slowcord Bot",
"program": "${workspaceFolder}/build/index.js",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "node",
"preLaunchTask": "npm: build"
}
]
}

File diff suppressed because it is too large Load Diff

View File

@ -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"
}
}
}

View File

@ -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,

View File

@ -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;
};
};

View File

@ -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;

View File

@ -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);
(async () => {
await initDatabase();
await client.login(process.env.TOKEN);
})();

View File

@ -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. */

View File

@ -1,11 +1,11 @@
{
"name": "slowcord",
"name": "slowcord-login",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "slowcord",
"name": "slowcord-login",
"version": "1.0.0",
"license": "AGPL-3.0-only",
"dependencies": {