From 86764942d9e6a8c72e56db34f7c788507bb67139 Mon Sep 17 00:00:00 2001 From: Ale Date: Sun, 20 Aug 2023 20:44:16 +0200 Subject: [PATCH] first commit --- .gitignore | 7 +++++++ package.json | 21 +++++++++++++++++++++ src/commands/help.ts | 9 +++++++++ src/commands/help.ts~ | 3 +++ src/index.ts | 20 ++++++++++++++++++++ src/index.ts~ | 18 ++++++++++++++++++ src/repositories/CharacterRepo.ts | 15 +++++++++++++++ src/services/CharacterService.ts | 13 +++++++++++++ src/utils/commandHandler.ts | 23 +++++++++++++++++++++++ src/utils/commandHandler.ts~ | 9 +++++++++ tsconfig.json | 14 ++++++++++++++ 11 files changed, 152 insertions(+) create mode 100644 .gitignore create mode 100644 package.json create mode 100644 src/commands/help.ts create mode 100644 src/commands/help.ts~ create mode 100644 src/index.ts create mode 100644 src/index.ts~ create mode 100644 src/repositories/CharacterRepo.ts create mode 100644 src/services/CharacterService.ts create mode 100644 src/utils/commandHandler.ts create mode 100644 src/utils/commandHandler.ts~ create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39cdef8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +node_modules +build +npm-debug.log +.nyc +.env +.DS_Store +config.json \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..615a272 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "cakebot-revolt", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "@types/sqlite3": "^3.1.8", + "typescript": "^5.1.3", + "typescript-language-server": "^3.3.2" + }, + "dependencies": { + "revolt.js": "^7.0.0-beta.7", + "shlex": "^2.1.2", + "sqlite3": "^5.1.6" + } +} diff --git a/src/commands/help.ts b/src/commands/help.ts new file mode 100644 index 0000000..05153c5 --- /dev/null +++ b/src/commands/help.ts @@ -0,0 +1,9 @@ +export function returnHelpText() { + return "# Howdy user, welcome to pluralcake\n" + + "pluralcake is a bot that allows you to send messages as your Alters, with a custom profile picture, tag and nickname. \n" + + "It's pretty much a work in progress, and doesn't allow you to edit or delete messages, and to send pictures." + + "The currently available commands are : \n" + + "- list | allows you to see your currently available alters.\n" + + "- create <'name of the alter'> <'your alter s tag'>| Allows you to create your Alters\n" + + "- avatar <'Alter's name'> <'picture url'> | Allows you to edit your alter's profile picture" +} diff --git a/src/commands/help.ts~ b/src/commands/help.ts~ new file mode 100644 index 0000000..7ffa94b --- /dev/null +++ b/src/commands/help.ts~ @@ -0,0 +1,3 @@ +export function returnHelpText() { + return "gum" +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..b232baa --- /dev/null +++ b/src/index.ts @@ -0,0 +1,20 @@ +import { Client, Message } from "revolt.js"; +import { commandHandler } from "./utils/commandHandler" +import config from "../config.json" +const client : Client = new Client(); + + +client.on("ready", async () => { + console.info(`Gummed in as ${client.user.username}!`) + client.user.edit({status : {text: config.prefix + "help for the help menu"}}) +}); + +client.on("messageCreate", async (message: Message) => { + if (message.author.bot) {} + else { + if (message.content.startsWith(config.prefix)){commandHandler(message, config.prefix)} + else {} + } +}); + +client.loginBot(config.botKey); diff --git a/src/index.ts~ b/src/index.ts~ new file mode 100644 index 0000000..bf421ed --- /dev/null +++ b/src/index.ts~ @@ -0,0 +1,18 @@ +import { Client, Message } from "revolt.js"; +import { commandHandler } from "./utils/commandHandler" +import config from "../config.json" +const client : Client = new Client(); + + +client.on("ready", async () => + console.info(`Gummed in as ${client.user.username}!`) +); + +client.on("messageCreate", async (message: Message) => { + if (message.author.bot) {} + else { + if (message.content.startsWith(config.prefix)){commandHandler(message, config.prefix)} + } +}); + +client.loginBot(config.botKey); diff --git a/src/repositories/CharacterRepo.ts b/src/repositories/CharacterRepo.ts new file mode 100644 index 0000000..75c9d2f --- /dev/null +++ b/src/repositories/CharacterRepo.ts @@ -0,0 +1,15 @@ +import { Database } from 'sqlite3'; +export class CharacterRepo { + db : Database + constructor() { + this.db = new Database('db.sqlite'); + } + + getAllCharacters(){ + return this.db.get( + 'SELECT * FROM CHARACTERS', + res => console.log(res) + ) + } + +} diff --git a/src/services/CharacterService.ts b/src/services/CharacterService.ts new file mode 100644 index 0000000..5140e20 --- /dev/null +++ b/src/services/CharacterService.ts @@ -0,0 +1,13 @@ +import { CharacterRepo } from "repositories/CharacterRepo"; + +class CharacterService { + repo : CharacterRepo; + + constructor() { + this.repo = new CharacterRepo(); + } + + public getCharacter() : any{ + return this.repo.getAllCharacters(); + } +} \ No newline at end of file diff --git a/src/utils/commandHandler.ts b/src/utils/commandHandler.ts new file mode 100644 index 0000000..0d91210 --- /dev/null +++ b/src/utils/commandHandler.ts @@ -0,0 +1,23 @@ +import { Message } from "revolt.js" +import { returnHelpText } from "../commands/help" +import { split } from "shlex" + +export async function commandHandler(message : Message, prefix : String) { + let args : String[] = split(message.content); + args.shift() + const command = args[0] + + switch(command) { + case "help" : { + message.reply(returnHelpText()); + break; + } + case "list" : { + message.reply("not yet implemented") + break; + } + case "create" : { + message.reply("not yet implemented") + } + } +} diff --git a/src/utils/commandHandler.ts~ b/src/utils/commandHandler.ts~ new file mode 100644 index 0000000..fdd5713 --- /dev/null +++ b/src/utils/commandHandler.ts~ @@ -0,0 +1,9 @@ +import { Message } from "revolt.js" + +export function commandHandler(message : Message) { + switch(message.content) { + case "help" : { + } + + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..3f3bf8d --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "module": "commonjs", + "esModuleInterop": true, + "resolveJsonModule" : true, + "target": "es6", + "moduleResolution": "node", + "sourceMap": true, + "outDir": "dist", + "baseUrl": "./src" + }, + "lib": ["es2015"] + } +