mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-05 10:22:31 +01:00
bot stuff idk
This commit is contained in:
parent
a9a74ae67a
commit
c0877a4aee
22681
package-lock.json
generated
Normal file
22681
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
slowcord/.vscode/launch.json
vendored
20
slowcord/.vscode/launch.json
vendored
@ -1,14 +1,20 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Program",
|
||||
"program": "${workspaceFolder}/build/index.js",
|
||||
"request": "launch",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"name": "ts-node",
|
||||
"type": "node",
|
||||
"preLaunchTask": "tsc: build - tsconfig.json"
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": [
|
||||
"-r",
|
||||
"ts-node/register"
|
||||
],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
|
||||
]
|
||||
}
|
@ -12,5 +12,6 @@
|
||||
"dependencies": {
|
||||
"fosscord-gopnik": "^1.0.0",
|
||||
"typescript": "^4.7.4"
|
||||
}
|
||||
},
|
||||
"type": "module"
|
||||
}
|
@ -1,14 +1,19 @@
|
||||
import { Message } from "discord.js";
|
||||
import { Client } from "fosscord-gopnik/build/lib"; // huh? oh well. some bugs in my lib Ig
|
||||
|
||||
import { Command, getCommands } from "./commands/index.js";
|
||||
|
||||
export default class Bot {
|
||||
client: Client;
|
||||
commands: { [key: string]: Command; } = {};
|
||||
|
||||
constructor(client: Client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
onReady = () => {
|
||||
onReady = async () => {
|
||||
this.commands = await getCommands();
|
||||
|
||||
console.log(`Logged in as ${this.client.user!.tag}`);
|
||||
|
||||
this.client.user!.setPresence({
|
||||
@ -16,10 +21,29 @@ export default class Bot {
|
||||
name: "EVERYTHING",
|
||||
type: "WATCHING",
|
||||
}]
|
||||
})
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
onMessageCreate = (msg: Message) => {
|
||||
|
||||
const prefix = process.env.PREFIX as string;
|
||||
if (msg.content.indexOf(prefix) === -1) return;
|
||||
if (msg.author.bot) return;
|
||||
|
||||
const content = msg.content.slice(prefix.length).split(" ");
|
||||
const cmd = content.shift();
|
||||
if (!cmd) return;
|
||||
const args = content;
|
||||
|
||||
const command = this.commands[cmd];
|
||||
if (!command) return;
|
||||
|
||||
command.exec({
|
||||
user: msg.author,
|
||||
member: msg.member,
|
||||
guild: msg.guild,
|
||||
message: msg,
|
||||
args: args,
|
||||
});
|
||||
};
|
||||
}
|
33
slowcord/bot/src/commands/index.ts
Normal file
33
slowcord/bot/src/commands/index.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Message, GuildMember, Guild, User } from "discord.js";
|
||||
import fs from "fs";
|
||||
|
||||
export type CommandContext = {
|
||||
user: User,
|
||||
guild: Guild | null,
|
||||
member: GuildMember | null,
|
||||
message: Message,
|
||||
args: string[],
|
||||
};
|
||||
|
||||
export type Command = {
|
||||
name: string;
|
||||
exec: (ctx: CommandContext) => any;
|
||||
};
|
||||
|
||||
const walk = async (path: string): Promise<Command[]> => {
|
||||
const files = fs.readdirSync(path);
|
||||
const out: Command[] = [];
|
||||
for (var file of files) {
|
||||
if (file.indexOf("index") !== -1) continue;
|
||||
|
||||
var imported = await import(`${path}/${file}`);
|
||||
}
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
export const getCommands = async () => {
|
||||
const map: { [key: string]: Command; } = {};
|
||||
(await walk("./build/commands")).forEach((val) => map[val.name] = val);
|
||||
return map;
|
||||
};
|
8
slowcord/bot/src/commands/instance.ts
Normal file
8
slowcord/bot/src/commands/instance.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Command } from "./index.js";
|
||||
|
||||
export default {
|
||||
name: "instance",
|
||||
exec: ({ message }) => {
|
||||
message.reply("Test");
|
||||
}
|
||||
} as Command;
|
@ -1,6 +1,6 @@
|
||||
import "dotenv/config";
|
||||
import Fosscord from "fosscord-gopnik";
|
||||
import Bot from "./Bot";
|
||||
import Bot from "./Bot.js"; // huh?
|
||||
|
||||
const client = new Fosscord.Client({
|
||||
intents: ["GUILD_MESSAGES"],
|
||||
@ -15,7 +15,6 @@ const client = new Fosscord.Client({
|
||||
const bot = new Bot(client);
|
||||
|
||||
client.on("ready", bot.onReady);
|
||||
|
||||
client.on("messageCreate", bot.onMessageCreate);
|
||||
|
||||
client.login(process.env.TOKEN);
|
@ -11,7 +11,7 @@
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
"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. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
||||
@ -24,9 +24,9 @@
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
|
||||
/* Modules */
|
||||
"module": "commonjs", /* Specify what module code is generated. */
|
||||
"module": "ES2022", /* 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. */
|
||||
"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. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
|
2044
slowcord/login/package-lock.json
generated
2044
slowcord/login/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -22,7 +22,8 @@
|
||||
"cookie-parser": "^1.4.6",
|
||||
"dotenv": "^16.0.1",
|
||||
"express": "^4.18.1",
|
||||
"node-fetch": "^3.2.6"
|
||||
"node-fetch": "^3.2.6",
|
||||
"sqlite3": "^5.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cookie-parser": "^1.4.3",
|
||||
|
Loading…
Reference in New Issue
Block a user