Skip to content

Commit

Permalink
Give admins the ability to mute and unmute the IRC echo
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLVP committed Jun 23, 2020
1 parent 1a11e8b commit 3a481c7
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
3 changes: 3 additions & 0 deletions data/irc_messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@
"reaction-result": "<color:6>*** %s (Id:%d) has won the reaction test in %d seconds!",
"reaction-unscramble": "<color:6>*** First player to unscramble \"%s\" wins %$!",

"mute-echo": "<command:MODE>+m",
"unmute-echo": "<command:MODE>-m",

"merchant": "<color:3>*** The merchant wants to purchase a %{1}s for %{0}$."
}
3 changes: 3 additions & 0 deletions data/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"CRUISE_STOPPED": "{DC143C}Cruise{FFFFFF}: The cruise has stopped, see you next time!",
"CRUISE_USAGE": "@usage {DC143C}Cruise{FFFFFF}: /cruise [start/stop]",

"COMMUNICATION_ADMIN_IRC_MUTE": "%s (Id:%d) has %s unregistered people on IRC.",
"COMMUNICATION_ADMIN_MESSAGE": "{FFFF00}* %s %s (Id:%d): %s",
"COMMUNICATION_ADMIN_SENT": "@success Your message has been sent to the administrators.",
"COMMUNICATION_CALL_CONNECTED": "{DC143C}[Phone]{FFFFFF} * Your conversation with %s has been established. Use {DC143C}/hangup{FFFFFF} to hang up.",
Expand Down Expand Up @@ -100,6 +101,8 @@
"COMMUNICATION_MESSAGE": "{%s}[%d] %s:{FFFFFF} %s",
"COMMUNICATION_ME": "{%s}* %s %s",
"COMMUNICATION_MUTE_BLOCKED": "@error Your message has been blocked because you're muted for another %s.",
"COMMUNICATION_MUTE_IRC_DISABLED": "@success Messages from unregistered people on IRC will be allowed again.",
"COMMUNICATION_MUTE_IRC_ENABLED": "@success Messages from unregistered people on IRC will now be ignored.",
"COMMUNICATION_PM_IRC_RECEIVER": "{FFDC18}PM from %s (IRC): {FFFFFF}%s",
"COMMUNICATION_PM_IRC_SENDER": "{FCF545}* PM to %s (IRC): {FFFFFF}%s",
"COMMUNICATION_PM_ADMIN": "{FF9900}* PM: %s (Id:%d) to %s (Id:%d):{FFFFFF} %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class CommunicationCommands extends Feature {
new CallCommands(this.communication_),
new DirectCommunicationCommands(this.communication_, this.nuwani_, this.playground_),
new IgnoreCommands(this.communication_),
new MuteCommands(this.announce_, this.communication_),
new MuteCommands(this.announce_, this.communication_, this.nuwani_),
];

this.initializeIrcCommands();
Expand Down
39 changes: 38 additions & 1 deletion javascript/features/communication_commands/mute_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ const kMuteMonitorIntervalMs = 1000;
export class MuteCommands {
announce_ = null;
communication_ = null;
nuwani_ = null;

disposed_ = false;
muted_ = new Set();

// Gets the MuteManager from the Communication feature, which we service.
get muteManager() { return this.communication_().muteManager_; }

constructor(announce, communication) {
constructor(announce, communication, nuwani) {
this.announce_ = announce;
this.communication_ = communication;
this.nuwani_ = nuwani;

// /mute [player] [duration=3]
server.commandManager.buildCommand('mute')
Expand All @@ -31,6 +34,12 @@ export class MuteCommands {
{ name: 'duration', type: CommandBuilder.NUMBER_PARAMETER, defaultValue: 3 }])
.build(MuteCommands.prototype.onMuteCommand.bind(this));

// /muteirc [on|off]?
server.commandManager.buildCommand('muteirc')
.restrict(Player.LEVEL_ADMINISTRATOR)
.parameters([{ name: 'on/off', type: CommandBuilder.WORD_PARAMETER, optional: true }])
.build(MuteCommands.prototype.onMuteIrcCommand.bind(this));

// /muted
server.commandManager.buildCommand('muted')
.restrict(Player.LEVEL_ADMINISTRATOR)
Expand Down Expand Up @@ -125,6 +134,34 @@ export class MuteCommands {
player.sendMessage(Message.MUTE_MUTED, targetPlayer.name, targetPlayer.id, proposedText);
}

// /muteirc [on | off]?
//
// Mutes the IRC channel for unregistered people. Useful when someone from IRC is being a troll,
// without having to switch tabs to mIRC or another client.
onMuteIrcCommand(player, command) {
switch (command) {
case 'on':
this.nuwani_().echo('mute-echo');
this.announce_().announceToAdministrators(
Message.COMMUNICATION_ADMIN_IRC_MUTE, player.name, player.id, 'muted');

player.sendMessage(Message.COMMUNICATION_MUTE_IRC_ENABLED);
break;

case 'off':
this.nuwani_().echo('unmute-echo');
this.announce_().announceToAdministrators(
Message.COMMUNICATION_ADMIN_IRC_MUTE, player.name, player.id, 'unmuted');

player.sendMessage(Message.COMMUNICATION_MUTE_IRC_DISABLED);
break;

default:
player.sendMessage(Message.COMMAND_USAGE, '/muteirc [on | off]');
break;
}
}

// /muted
//
// Displays an overview of the currently muted players to |player|, and how much time they have
Expand Down
21 changes: 21 additions & 0 deletions javascript/features/communication_commands/mute_commands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,25 @@ describe('MuteCommands', (it, beforeEach) => {
await server.clock.advance(10 * 1000);
await monitorPromise;
});

it('is able to mute and unmute the IRC channel', async (assert) => {
const nuwani = server.featureManager.loadFeature('nuwani');

assert.isTrue(await russell.issueCommand('/muteirc'));
assert.equal(nuwani.messagesForTesting.length, 0);

assert.isTrue(await russell.issueCommand('/muteirc on'));
assert.equal(nuwani.messagesForTesting.length, 2);
assert.deepEqual(nuwani.messagesForTesting[0], {
tag: 'mute-echo',
params: [],
});

assert.isTrue(await russell.issueCommand('/muteirc off'));
assert.equal(nuwani.messagesForTesting.length, 4);
assert.deepEqual(nuwani.messagesForTesting[2], {
tag: 'unmute-echo',
params: [],
})
});
});

0 comments on commit 3a481c7

Please sign in to comment.