From 79a9001adfd25cb372e129fc55f8087d6535b814 Mon Sep 17 00:00:00 2001 From: Mitchdev Date: Sat, 10 Feb 2024 18:34:23 +1300 Subject: [PATCH 1/4] Add args to static output commands. --- lib/commands/implementations/static-output.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/commands/implementations/static-output.js b/lib/commands/implementations/static-output.js index 3d7a2b7..9d6b7b5 100644 --- a/lib/commands/implementations/static-output.js +++ b/lib/commands/implementations/static-output.js @@ -1,7 +1,19 @@ const CommandOutput = require('../command-output'); function staticCommand(staticOutput) { - return () => new CommandOutput(null, staticOutput); + return (input) => { + let output = staticOutput; + const args = input ? input.split(' ') : []; + + output = output.replace(/\{%(\d+)%\}/g, (_, i) => { + if (parseInt(i, 10) && args[parseInt(i, 10) - 1]) { + return args[parseInt(i, 10) - 1]; + } + return ''; + }); + + return new CommandOutput(null, output); + }; } module.exports = staticCommand; From a6b4e8bc4d1c7542a2e932f130e907c02ec8fbaa Mon Sep 17 00:00:00 2001 From: Mitchdev Date: Fri, 16 Feb 2024 03:29:05 +1300 Subject: [PATCH 2/4] Add tests --- .../implementations/addcommand.test.js | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/lib/commands/implementations/addcommand.test.js b/tests/lib/commands/implementations/addcommand.test.js index ff38854..00bd8fc 100644 --- a/tests/lib/commands/implementations/addcommand.test.js +++ b/tests/lib/commands/implementations/addcommand.test.js @@ -4,7 +4,7 @@ const assert = require('assert'); const sinon = require('sinon'); const Command = require('../../../../lib/commands/command-interface'); -describe('AddCommand Test', () => { +describe('AddCommand Tests', () => { beforeEach(function () { this.mockServices = { sql: { @@ -37,5 +37,34 @@ describe('AddCommand Test', () => { }).catch(done); }); + it('adds a command with arguments', function (done) { + const registry = this.mockServices.commandRegistry; + + addCommand.work('!testargs testing {%1%} and {%2%} and {%1%}', this.mockServices).then((output) => { + assert.deepStrictEqual(output, new CommandOutput(null, `Added new command: !testargs`)); + // No args + assert.deepStrictEqual( + registry.registerCommand.getCall(0).args[1].work(''), + new CommandOutput(null, `testing and and `) + ); + // Testing one argument + assert.deepStrictEqual( + registry.registerCommand.getCall(0).args[1].work('one'), + new CommandOutput(null, `testing one and and one`) + ); + // Testing two arguments + assert.deepStrictEqual( + registry.registerCommand.getCall(0).args[1].work('one two'), + new CommandOutput(null, `testing one and two and one`) + ); + // Testing three arguments + assert.deepStrictEqual( + registry.registerCommand.getCall(0).args[1].work('one two three'), + new CommandOutput(null, `testing one and two and one`) + ); + done(); + }).catch(done); + }); + }); From 1292d4ba77755659a24624eddcfaa2f60658a124 Mon Sep 17 00:00:00 2001 From: Mitchdev Date: Fri, 16 Feb 2024 03:29:49 +1300 Subject: [PATCH 3/4] Add arguments to readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a64b0d..6586840 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Durations are in the format of the number, followed by h,m,s or d. | !stalk | {user} (postnumber) | Overrustle logs posts | Yes | !stalk Destiny 5 | | !time | None | Current Steven Time | No | !time | | !schedule !sch | None | Show next upcoming scheduled event, and a link to the schedule calendar. | No | !schedule | -| !addcommand !ac | {command} {text} | Adds a static command that can be called by anyone. | Yes | !addcommand !hello HEY HOWDY THERE PAL HOW YOU DOIN | +| !addcommand !ac | {command} {text} | Adds a static command that can be called by anyone. `{%n%}` can be used in text to get arguments. | Yes | !addcommand !hello HEY HOWDY THERE PAL HOW YOU DOIN {%1%} | | !deletecommand !delcommand !removecommand !dc | {commandToDelete} | Deletes a static command | Yes | !deleteCommand !hello | | !listcommands !lc | None | Lists all static database stored commands | Yes | !listcommands | | !listscheduled !lsc | None | Lists all currently scheduled commands. Youtube and Calendar are always scheduled. | Yes | !lsc | From 60ad8e42ab0739f47fca40f91ee8ec3055adcf98 Mon Sep 17 00:00:00 2001 From: Mitchdev Date: Fri, 16 Feb 2024 03:29:58 +1300 Subject: [PATCH 4/4] fix some readme spacing --- README.md | 72 +++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 6586840..bb70b94 100644 --- a/README.md +++ b/README.md @@ -56,43 +56,43 @@ Durations are in the format of the number, followed by h,m,s or d. (Note on adding commands/scheduled commands for admins, when you add the commands to twitch/dgg, you need to !restart the bot in the other chat to pick these changes up. This will change with a future update.) -| Command | Input | What it does | Requires Admin | Example | -|------------------------------------------------|------------------------------|-----------------------------------------------------------------------------------------|----------------|-----------------------------------------------------| -| !restart | None | Restarts the dgg or Twitch.tv bot. Don't overuse the command, it resets caches. | Yes | !restart | -| !stalk | {user} (postnumber) | Overrustle logs posts | Yes | !stalk Destiny 5 | -| !time | None | Current Steven Time | No | !time | -| !schedule !sch | None | Show next upcoming scheduled event, and a link to the schedule calendar. | No | !schedule | +| Command | Input | What it does | Requires Admin | Example | +|------------------------------------------------|------------------------------|---------------------------------------------------------------------------------------------------|----------------|-----------------------------------------------------------| +| !restart | None | Restarts the dgg or Twitch.tv bot. Don't overuse the command, it resets caches. | Yes | !restart | +| !stalk | {user} (postnumber) | Overrustle logs posts | Yes | !stalk Destiny 5 | +| !time | None | Current Steven Time | No | !time | +| !schedule !sch | None | Show next upcoming scheduled event, and a link to the schedule calendar. | No | !schedule | | !addcommand !ac | {command} {text} | Adds a static command that can be called by anyone. `{%n%}` can be used in text to get arguments. | Yes | !addcommand !hello HEY HOWDY THERE PAL HOW YOU DOIN {%1%} | -| !deletecommand !delcommand !removecommand !dc | {commandToDelete} | Deletes a static command | Yes | !deleteCommand !hello | -| !listcommands !lc | None | Lists all static database stored commands | Yes | !listcommands | -| !listscheduled !lsc | None | Lists all currently scheduled commands. Youtube and Calendar are always scheduled. | Yes | !lsc | -| !mute !mu | (duration) {user} | Mutes a user | Yes | !mute 10m MrMouton | -| !unmute !um !unm | {user} | Unmutes a user | Yes | !unmute MrMouton | -| !ban or !ipban (alias !ip) | (duration) {user} (reason) | Bans a user | Yes | !ban 1024h JAYL For being too cute | -| !voteban !voteipban | (duration) {user} (reason) | Starts a poll in DGG chat, if there's a majority yes the user is banned. | Yes | !voteban 1024h JAYL being too cute | -| !svoteban !svoteipban | (duration) {user} (reason) | SUB WEIGHTED - Same as voteban, but subs votes count for more, increasing with sub tier.| Yes | !voteban 1024h JAYL being too cute | -| !unban | {user} | Unbans a user | Yes | !unban JAYL | -| !nuke | (duration) {phrase or regex} | Mutes anyone using the nuked phrase for 10m by default. | Yes | !nuke 30m KING MOUTON !nuke 30d /[A-Z]+\s?420/ | -| !meganuke | (duration) {phrase or regex} | IPBans anyone using the nuked phrase for 10m by default. | Yes | !nuke 30m KING MOUTON !nuke 30d /[A-Z]+\s?420/ | -| !aegis | None | Removes any nukes that have been fired in the last 10 minutes and unmutes all users muted | Yes | !aegis | -| !aegisSingle !an !unnuke !as | (nukePhrase) | Removes single a Nuke by the phrase that was nuked | Yes | !as KING MOUTON | -| !love | None | Gives you love | No | !love Linusred | -| !addschcmd !asc | (commandToAdd) | Schedules a static command to be sent from the bot every few minutes. | Yes | !asc !hello | -| !deleteschcmd !dsc !unschedule | (commandToDelete) | Deletes a scheduled command so its not longer sent. | Yes | !dsc !hello | -| !song | None | Current song being played on Last.fm | No | !song | -| !lastsong !pastsong !previoussong !earlierSong | None | Previous song before the current one being played on last.fm | No | !lastsong | -| !youtube !yt !lastvideo | None | Last video posted on Destiny's youtube channel | No | !yt | -| !addban !addmute | (duration) {banned phrase} | Adds a banned phrase that will auto mute/ban upon a user posting it. | Yes | !addban 10d HAHA GNOMED !addmute /\bwee(woo)?\b/ | -| !mutelinks !mutelink !linksmute !linkmute | {on,off,all} (duration) | Auto mute linkers. `on` only mutes links that mention the command sender. `all` mutes all links. | Yes | !mutelinks on !mutelinks on 10m !mutelinks all 10m | -| !breakingnews !breaking !bn | {on,off,all} (max link age) | Breaking news mode. `on` only mutes old links (5m by default) that mention the command sender. `all` mutes all old links. | Yes | !breakingnews on 5m | -| !deleteban !dban !deletemute !mute | {banned phrase} | Removes a banned or muted phrase. Works for both. | Yes | !deleteban HAHA GNOMED | -| !live | None | Reports the last time a stream was live, or how long the stream has been going. | No | !live | -| !ud !updateduo !duoupdate | Any text | Updates the !duo command with whatever text you type. | Yes | !ud Lilypichu AYAYA | -| !duo | None | Outputs whatever is current stored using !ud | No | !duo | -| !deaths !death !died | None | Outputs the current death counter | No | !death !died | -| !incdeaths !ideaths !incd !id | None | Adds 1 to the current death counter. Can only be updated once every 15 seconds to prevent 2 people updating | Yes | !id !ideaths !incd | -| !setdeaths !setd !sdeaths | (number to set deaths to)) | Sets the death counter to the value specified | Yes | !setd 50 !sdeaths 100 | -| !gulag | (duration) {user1} (user2) ... (user n) | Voteban between all included users. `random` as a username will select a recent random chatter. | Yes | !gulag 30m derDeidra Dan | +| !deletecommand !delcommand !removecommand !dc | {commandToDelete} | Deletes a static command | Yes | !deleteCommand !hello | +| !listcommands !lc | None | Lists all static database stored commands | Yes | !listcommands | +| !listscheduled !lsc | None | Lists all currently scheduled commands. Youtube and Calendar are always scheduled. | Yes | !lsc | +| !mute !mu | (duration) {user} | Mutes a user | Yes | !mute 10m MrMouton | +| !unmute !um !unm | {user} | Unmutes a user | Yes | !unmute MrMouton | +| !ban or !ipban (alias !ip) | (duration) {user} (reason) | Bans a user | Yes | !ban 1024h JAYL For being too cute | +| !voteban !voteipban | (duration) {user} (reason) | Starts a poll in DGG chat, if there's a majority yes the user is banned. | Yes | !voteban 1024h JAYL being too cute | +| !svoteban !svoteipban | (duration) {user} (reason) | SUB WEIGHTED - Same as voteban, but subs votes count for more, increasing with sub tier. | Yes | !voteban 1024h JAYL being too cute | +| !unban | {user} | Unbans a user | Yes | !unban JAYL | +| !nuke | (duration) {phrase or regex} | Mutes anyone using the nuked phrase for 10m by default. | Yes | !nuke 30m KING MOUTON !nuke 30d /[A-Z]+\s?420/ | +| !meganuke | (duration) {phrase or regex} | IPBans anyone using the nuked phrase for 10m by default. | Yes | !nuke 30m KING MOUTON !nuke 30d /[A-Z]+\s?420/ | +| !aegis | None | Removes any nukes that have been fired in the last 10 minutes and unmutes all users muted | Yes | !aegis | +| !aegisSingle !an !unnuke !as | (nukePhrase) | Removes single a Nuke by the phrase that was nuked | Yes | !as KING MOUTON | +| !love | None | Gives you love | No | !love Linusred | +| !addschcmd !asc | (commandToAdd) | Schedules a static command to be sent from the bot every few minutes. | Yes | !asc !hello | +| !deleteschcmd !dsc !unschedule | (commandToDelete) | Deletes a scheduled command so its not longer sent. | Yes | !dsc !hello | +| !song | None | Current song being played on Last.fm | No | !song | +| !lastsong !pastsong !previoussong !earlierSong | None | Previous song before the current one being played on last.fm | No | !lastsong | +| !youtube !yt !lastvideo | None | Last video posted on Destiny's youtube channel | No | !yt | +| !addban !addmute | (duration) {banned phrase} | Adds a banned phrase that will auto mute/ban upon a user posting it. | Yes | !addban 10d HAHA GNOMED !addmute /\bwee(woo)?\b/ | +| !mutelinks !mutelink !linksmute !linkmute | {on,off,all} (duration) | Auto mute linkers. `on` only mutes links that mention the command sender. `all` mutes all links. | Yes | !mutelinks on !mutelinks on 10m !mutelinks all 10m | +| !breakingnews !breaking !bn | {on,off,all} (max link age) | Breaking news mode. `on` only mutes old links (5m by default) that mention the command sender. `all` mutes all old links. | Yes | !breakingnews on 5m | +| !deleteban !dban !deletemute !mute | {banned phrase} | Removes a banned or muted phrase. Works for both. | Yes | !deleteban HAHA GNOMED | +| !live | None | Reports the last time a stream was live, or how long the stream has been going. | No | !live | +| !ud !updateduo !duoupdate | Any text | Updates the !duo command with whatever text you type. | Yes | !ud Lilypichu AYAYA | +| !duo | None | Outputs whatever is current stored using !ud | No | !duo | +| !deaths !death !died | None | Outputs the current death counter | No | !death !died | +| !incdeaths !ideaths !incd !id | None | Adds 1 to the current death counter. Can only be updated once every 15 seconds to prevent 2 people updating | Yes | !id !ideaths !incd | +| !setdeaths !setd !sdeaths | (number to set deaths to) | Sets the death counter to the value specified | Yes | !setd 50 !sdeaths 100 | +| !gulag | (duration) {user1} (user2) ... (user n) | Voteban between all included users. `random` as a username will select a recent random chatter. | Yes | !gulag 30m derDeidra Dan | ## Todo