rmtrollbot 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +19 -2
  2. package/index.mts +31 -2
  3. package/package.json +5 -5
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # Reversed Meow TrollBot
1
+ # ![Reversed Meow TrollBot](https://upload.wikimedia.org/wikipedia/commons/thumb/6/6b/Windows_93_logo.svg/250px-Windows_93_logo.svg.png)
2
2
  [![Package Quality](https://packagequality.com/badge/rmtrollbot.png)](https://packagequality.com/#?package=rmtrollbot)![NPM (prod) Dependency Version](https://img.shields.io/npm/dependency-version/rmtrollbot/%40rmtrollbot%2Floader)![NPM (prod) Dependency Version](https://img.shields.io/npm/dependency-version/rmtrollbot/%40rmtrollbot%2Ftypes)![NPM Downloads](https://img.shields.io/npm/dy/rmtrollbot?logo=npm&color=blue)[NPM Dependency Tree](https://npm.anvaka.com/#/view/2d/rmtrollbot)
3
3
  # About
4
- A package making the producing of rmtrollbox bots easier.<br>
4
+ A package making the producing of [rmtrollbox](https://trollbox.fun) bots easier.<br>
5
5
  To start a bot, you must start a new TrollBot element.
6
6
  ```ts
7
7
  let bot = new TrollBot("clanker", "gray")
@@ -83,6 +83,20 @@ UH OH!!! UPDATE OVERFLOW!!!!<br>
83
83
  now, it uses [`@rmtrollbot/types`](https://www.npmjs.com/package/@rmtrollbot/types) instead of [`rmtrollbot-types`](https://www.npmjs.com/package/rmtrollbot-types), since rmtrollbot-types is deprecated.
84
84
  ## New for v4.0.0!
85
85
  rmtrollbot now uses [`yocto-spinner`](https://www.npmjs.com/package/yocto-spinner) instead of [`ora`](https://www.npmjs.com/package/ora), since ora installs more dependencies than yocto-spinner, and i don't want that.
86
+ ### New for v4.1.0!
87
+ Now, the `emit()` function has changed mechanics.
88
+ ```ts
89
+ bot.emit("delet") /* Acts normally like socket.emit() */
90
+
91
+ bot.emit("message", "hi!") /* Acts like socket.send() */
92
+ ```
93
+ And there is now a `Trollbot.of()` function.
94
+ ```ts
95
+ const bot = new Trollbot("clanker", "gray")
96
+ // is the same as...
97
+ const bot = TrollBot.of("clanker", "gray")
98
+ ```
99
+ Also there is new documentation! (more soon though...)
86
100
  # Extensions
87
101
  [`rmtrollbot-decode`](https://www.npmjs.com/package/rmtrollbot-decode?activeTab=readme): Decoder for rmtrollbot<br>
88
102
  [`rmtrollbot-ping`](https://www.npmjs.com/package/rmtrollbot-ping): Ping example
@@ -110,6 +124,9 @@ To install this package by Bun, run the following:
110
124
  bun add rmtrollbot
111
125
  ```
112
126
  # vs. trollbox-bot
127
+ ## From v3.2.2
113
128
  ![Comparison between trollbox-bot and rmtrollbot](https://iili.io/BgZPC0P.png)
129
+ ## From v4.0.0
130
+ ![Comparison between trollbox-bot and rmtrollbot](https://iili.io/B4sJKdJ.png)
114
131
  # Bots using this package
115
132
  None have been recorded, but please use this package
package/index.mts CHANGED
@@ -2,6 +2,9 @@ import { init } from "@rmtrollbot/loader";
2
2
  import yocto from "yocto-spinner"
3
3
  import { message, user, userchangenick, userupdate, rmtbID } from "@rmtrollbot/types"
4
4
 
5
+ /**
6
+ * The TrollBot instance.
7
+ */
5
8
  export class TrollBot {
6
9
  protected name: string;
7
10
  protected readonly ogname: string;
@@ -10,6 +13,12 @@ export class TrollBot {
10
13
  protected tag: string;
11
14
  protected readonly ogtag: string;
12
15
  protected socket = init()
16
+ /**
17
+ * Constructor for the TrollBot instance.
18
+ * @param name The name of the bot.
19
+ * @param color The color of the bot.
20
+ * @param tag (Defaults to "bot") The tag for the bot.
21
+ */
13
22
  constructor(name: string, color: string, tag: string = "bot") {
14
23
  this.name = name
15
24
  this.ogname = name
@@ -33,12 +42,25 @@ export class TrollBot {
33
42
  protected rejoin() {
34
43
  this.socket.emit("user joined", this.name, this.color, this.tag, "")
35
44
  }
45
+ /**
46
+ * Sends a message
47
+ * @param args The message
48
+ */
36
49
  send(...args: string[]) {
37
50
  this.socket.send(...args)
38
51
  }
52
+ /**
53
+ * Executes a callback when a message is sent.
54
+ * @param callback Callback when a message is sent.
55
+ */
39
56
  onMessage(callback: (data: message) => void) {
40
57
  this.socket.on("message", callback)
41
58
  }
59
+ /**
60
+ * Executes a callback when a user does a join/leave action.
61
+ * @param event The action.
62
+ * @param callback Callback when the user does a join/leave action.
63
+ */
42
64
  onUser(event: "join" | "leave", callback: (data: user) => void) {
43
65
  this.socket.on((event == "join" ? "user joined" : "user left"), callback)
44
66
  }
@@ -48,8 +70,12 @@ export class TrollBot {
48
70
  onUserUpdate(callback: (data: { [ P: string ]: userupdate }) => void) {
49
71
  this.socket.on("update users", callback)
50
72
  }
51
- emit<Ev extends string>(ev: Ev, ...args: any[]) {
52
- this.socket.emit(ev, ...args)
73
+ emit<Ev extends string , Args>(ev: Ev, ...args: Args extends any[] ? Args : Args[]) {
74
+ if (ev == "message"){
75
+ this.socket.send(...args)
76
+ } else {
77
+ this.socket.emit(ev, ...args)
78
+ }
53
79
  }
54
80
  disconnect() {
55
81
  this.socket.disconnect()
@@ -95,4 +121,7 @@ export class TrollBot {
95
121
  editByID(id: rmtbID, newt: string) {
96
122
  this.socket.emit("edit_ownid", id, newt)
97
123
  }
124
+ static of(name: string, color: string, tag: string = "bot"){
125
+ return new TrollBot(name, color, tag)
126
+ }
98
127
  }
package/package.json CHANGED
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "name": "rmtrollbot",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "A package making the producing of rmtrollbox bots easier.",
5
5
  "main": "index.mts",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
6
  "keywords": [
10
7
  "bot",
11
8
  "chat",
@@ -20,5 +17,8 @@
20
17
  "@rmtrollbot/loader": "^1.0.0",
21
18
  "@rmtrollbot/types": "^1.0.0",
22
19
  "yocto-spinner": "^1.1.0"
20
+ },
21
+ "scripts": {
22
+ "test": "echo \"Error: no test specified\" && exit 1"
23
23
  }
24
- }
24
+ }