Skip to content

Commit

Permalink
feat: base of new gil package (#248)
Browse files Browse the repository at this point in the history
* feat: start base of new gil

* feat: base of logging adapters

* feat: init'ing the different managers and an example bot

* feat: some listener stuff

* chore: error msgs for bad inputs

* feat: default listeners

* feat: load listeners and connect to gapi

* feat: add message processing logic

* feat: database adapater

* feat: command handling & arg parsing

* feat: mongo adapter

* feat: working test example

* feat: help example command
  • Loading branch information
zaida04 authored Mar 27, 2024
1 parent 3daf20d commit fcb37c4
Show file tree
Hide file tree
Showing 52 changed files with 1,055 additions and 1,236 deletions.
Binary file modified bun.lockb
Binary file not shown.
11 changes: 11 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[install]

# whether to install optionalDependencies
optional = true

# whether to install devDependencies
dev = true

# whether to install peerDependencies
peer = true

34 changes: 34 additions & 0 deletions packages/gil/__tests__/bot_mongo/commands/Help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Command, CommandExecuteContext, GilClient } from "../../../lib";

export default class Help extends Command {
public constructor(client: GilClient) {
super(client, {
name: "help",
description: "Shows this help message.",
aliases: ["h"],
args: [
{
name: "command",
optional: true,
type: "string",
},
],
});
}

public async execute(ctx: CommandExecuteContext<{ command: string }>) {
const { command } = ctx.args;

if (command) {
const getCommand = this.gil.commands.getCommand(command);
if (!getCommand) {
return ctx.message.reply("Command not found.");
}

return ctx.message.reply(`Help for ${getCommand.options.name}`);
}

const allCommands = this.gil.commands.commands.map((command) => command.options.name);
return ctx.message.reply(`All commands: ${allCommands.join(", ")}`);
}
}
12 changes: 12 additions & 0 deletions packages/gil/__tests__/bot_mongo/commands/Ping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Command } from "../../../lib";

export default class Ping extends Command {
options = {
name: "ping",
description: "Tests the bot.",
};

public async execute() {
return "Pong!";
}
}
21 changes: 21 additions & 0 deletions packages/gil/__tests__/bot_mongo/db/Server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import mongoose, { Schema, Document } from "mongoose";

// This is for typescript
export interface IServer extends Document {
server_id: string;
prefix: string;
premium_level: string;
staff_roles: string[];
}

// This is for mongodb to know what we are storing
const ServerSchema: Schema = new Schema({
server_id: { type: String, required: true },
prefix: { type: String, required: false },
premium_level: { type: String, required: false, default: null },
staff_roles: { type: Array, required: false, default: [] },
});

const Server = mongoose.model<IServer>("Server", ServerSchema);

export default Server;
15 changes: 15 additions & 0 deletions packages/gil/__tests__/bot_mongo/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'
services:
mongo:
image: mongo:4.2.5
ports:
- '27017:27017'
environment:
MONGO_INITDB_ROOT_USERNAME: guildedjs
MONGO_INITDB_ROOT_PASSWORD: testpass
MONGO_INITDB_DATABASE: guildedjs
volumes:
- mongo-vol:/data/db

volumes:
mongo-vol:
28 changes: 28 additions & 0 deletions packages/gil/__tests__/bot_mongo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { join } from "path";
import "dotenv/config";
import { GilClient } from "../../lib/GilClient";
import { MongoAdapter } from "../../lib/adapters/db/MongoAdapter";

import mongoose from "mongoose";
import Server from "./db/Server";

mongoose.connect("mongodb://guildedjs:testpass@localhost:27017/", {
connectTimeoutMS: 5000,
retryWrites: true,
retryReads: true,
waitQueueTimeoutMS: 5000,
socketTimeoutMS: 5000,
});

const YokiBot = new GilClient({
token: process.env.TOKEN!,
commandDirectory: join(__dirname, "commands"),
listenerDirectory: join(__dirname, "listeners"),
databaseAdapter: new MongoAdapter({
serverModel: Server,
serverIdKey: "server_id",
serverStaffRolesKey: "staff_roles",
}),
});

YokiBot.start();
Loading

0 comments on commit fcb37c4

Please sign in to comment.