-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: base of new gil package (#248)
* 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
Showing
52 changed files
with
1,055 additions
and
1,236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(", ")}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Oops, something went wrong.