Skip to content

Commit

Permalink
Add train command, (without test)
Browse files Browse the repository at this point in the history
  • Loading branch information
leomotors committed Apr 20, 2022
1 parent e0513da commit 5b84210
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 163 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Publish Release

on:
push:
branches:
- main
tags:
- "*.*"

jobs:
main:
Expand All @@ -20,5 +20,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TITLE: "Salim Bot {VERSION}"
VERSION_MUST_INCREASE: true
RELEASE_ON_KEYWORD: ${{ github.event.head_commit.message }}
ALWAYS_GENERATE_NOTES: true
TAG: ${{ github.ref }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Notable Changes for Salim Bot will be noted here!

## [4.0.1120] - 2022-04-20

- Add Slash Command: train

## [4.0.1112-revision.116] - 2022-03-28

- Bump Cocoa Discord Utils to 1.4.1 which fixes fatal issues
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ Salim Bot that is currently running of my friends server and is most active bot

## ⚙️ Under the Hood

Version 3 and later of Salim Bot is implemented by Salim Bot Framework, Available as *s-bot-framework* on [npm](https://www.npmjs.com/package/s-bot-framework)
The Salim Bot *since April 2021* has long history, of course it has big technical debt.

Version 4 is released without fixing any legacy code (because they
are pain to do so) but add Slash Command powered by [Cocoa Discord Utils](https://github.com/Leomotors/cocoa-discord-utils)!!!
Each major version (except 3->4) is a rewrite

Currently, since version 3 Salim Bot is implemented by Salim Bot Framework, Available as *s-bot-framework* on [npm](https://www.npmjs.com/package/s-bot-framework)

Version 4 includes Cocoa Discord Utils which take care of all Slash Commands
working with *legacy code* underneath, Just like what Windows 11 is.

## 🛣️ Previous Version: Legacy Salim Bot

Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "salim-bot",
"version": "4.0.1112-revision.116",
"version": "4.0.1120",
"description": "This bot is Salim. Whenever you trigger it, It become mad.",
"type": "module",
"main": "dist/bot.js",
Expand All @@ -24,21 +24,21 @@
"devDependencies": {
"@leomotors/scripts": "^3.1.0",
"@trivago/prettier-plugin-sort-imports": "^3.2.0",
"@types/node": "^17.0.23",
"@types/node": "^17.0.25",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"eslint": "^8.12.0",
"prettier": "^2.6.1",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"eslint": "^8.13.0",
"prettier": "^2.6.2",
"typescript": "^4.6.3"
},
"dependencies": {
"@discordjs/opus": "^0.7.0",
"chalk": "^5.0.1",
"cocoa-discord-utils": "^1.4.1",
"cocoa-discord-utils": "^1.4.2",
"discord.js": "^13.6.0",
"libsodium-wrappers": "^0.7.10",
"s-bot-framework": "^1.0.402",
"uuid": "^8.3.2"
}
}
}
2 changes: 1 addition & 1 deletion src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import QuizCog from "./commands/quiz";
import Salim from "./commands/salim";
import { style } from "./commands/styles";

// * NOTE: Legacy Part
// ! WARNING: LEGACY CODE

// * Salim Bot: Bot that is running in my group's server 24/7
// * Great Example for S-Bot Framework
Expand Down
42 changes: 42 additions & 0 deletions src/commands/salim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { CocoaVersion } from "cocoa-discord-utils/meta";
import { CogSlashClass, SlashCommand } from "cocoa-discord-utils/slash/class";
import {
AutoBuilder,
CocoaOption,
Ephemeral,
getEphemeral,
getStatusFields,
} from "cocoa-discord-utils/template";

import { CommandInteraction } from "discord.js";

import chalk from "chalk";
import fs from "fs/promises";
import { FrameWorkVersion } from "s-bot-framework";

import { style } from "./styles";
Expand Down Expand Up @@ -36,4 +39,43 @@ export default class Salim extends CogSlashClass {

await ctx.reply({ embeds: [emb], ephemeral });
}

@SlashCommand(
AutoBuilder("Add quote เข้าคลัง").addStringOption(
CocoaOption("quote", "quote คุ ณ ภ า พ ที่ต้องการนำเข้าคลัง")
)
)
async train(ctx: CommandInteraction) {
await ctx.deferReply();

const quote = ctx.options.getString("quote", true);

let morequotes = {} as { วาทกรรมสลิ่ม: string[] };
try {
morequotes = JSON.parse(
(await fs.readFile("data/morequotes.json")).toString()
);
} catch (e) {
console.log(chalk.yellow("[INFO] morequotes is initialized"));
morequotes = { วาทกรรมสลิ่ม: [] };
}

if (morequotes.วาทกรรมสลิ่ม.includes(quote)) {
await ctx.followUp(
"ซ้ำครับ หัดใช้สมองบ้างสิครับ ทำตัวเป็นสามกีบไปได้"
);
return;
}

morequotes.วาทกรรมสลิ่ม.push(quote);

await fs.writeFile(
"data/morequotes.json",
JSON.stringify(morequotes, null, 4)
);

await ctx.followUp(
"กระผมน้อนสลิ่มจะจดจำแล้วนำไปใช้ครับ ทั้งนี้กรุณาฝากเรียนไปที่เจ้าของบอทให้รีโหลดด้วย"
);
}
}
Loading

0 comments on commit 5b84210

Please sign in to comment.