Skip to content

Commit 3a481c7

Browse files
committed
Give admins the ability to mute and unmute the IRC echo
1 parent 1a11e8b commit 3a481c7

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

data/irc_messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,8 @@
5959
"reaction-result": "<color:6>*** %s (Id:%d) has won the reaction test in %d seconds!",
6060
"reaction-unscramble": "<color:6>*** First player to unscramble \"%s\" wins %$!",
6161

62+
"mute-echo": "<command:MODE>+m",
63+
"unmute-echo": "<command:MODE>-m",
64+
6265
"merchant": "<color:3>*** The merchant wants to purchase a %{1}s for %{0}$."
6366
}

data/messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"CRUISE_STOPPED": "{DC143C}Cruise{FFFFFF}: The cruise has stopped, see you next time!",
7373
"CRUISE_USAGE": "@usage {DC143C}Cruise{FFFFFF}: /cruise [start/stop]",
7474

75+
"COMMUNICATION_ADMIN_IRC_MUTE": "%s (Id:%d) has %s unregistered people on IRC.",
7576
"COMMUNICATION_ADMIN_MESSAGE": "{FFFF00}* %s %s (Id:%d): %s",
7677
"COMMUNICATION_ADMIN_SENT": "@success Your message has been sent to the administrators.",
7778
"COMMUNICATION_CALL_CONNECTED": "{DC143C}[Phone]{FFFFFF} * Your conversation with %s has been established. Use {DC143C}/hangup{FFFFFF} to hang up.",
@@ -100,6 +101,8 @@
100101
"COMMUNICATION_MESSAGE": "{%s}[%d] %s:{FFFFFF} %s",
101102
"COMMUNICATION_ME": "{%s}* %s %s",
102103
"COMMUNICATION_MUTE_BLOCKED": "@error Your message has been blocked because you're muted for another %s.",
104+
"COMMUNICATION_MUTE_IRC_DISABLED": "@success Messages from unregistered people on IRC will be allowed again.",
105+
"COMMUNICATION_MUTE_IRC_ENABLED": "@success Messages from unregistered people on IRC will now be ignored.",
103106
"COMMUNICATION_PM_IRC_RECEIVER": "{FFDC18}PM from %s (IRC): {FFFFFF}%s",
104107
"COMMUNICATION_PM_IRC_SENDER": "{FCF545}* PM to %s (IRC): {FFFFFF}%s",
105108
"COMMUNICATION_PM_ADMIN": "{FF9900}* PM: %s (Id:%d) to %s (Id:%d):{FFFFFF} %s",

javascript/features/communication_commands/communication_commands.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default class CommunicationCommands extends Feature {
6969
new CallCommands(this.communication_),
7070
new DirectCommunicationCommands(this.communication_, this.nuwani_, this.playground_),
7171
new IgnoreCommands(this.communication_),
72-
new MuteCommands(this.announce_, this.communication_),
72+
new MuteCommands(this.announce_, this.communication_, this.nuwani_),
7373
];
7474

7575
this.initializeIrcCommands();

javascript/features/communication_commands/mute_commands.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ const kMuteMonitorIntervalMs = 1000;
1313
export class MuteCommands {
1414
announce_ = null;
1515
communication_ = null;
16+
nuwani_ = null;
17+
1618
disposed_ = false;
1719
muted_ = new Set();
1820

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

22-
constructor(announce, communication) {
24+
constructor(announce, communication, nuwani) {
2325
this.announce_ = announce;
2426
this.communication_ = communication;
27+
this.nuwani_ = nuwani;
2528

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

37+
// /muteirc [on|off]?
38+
server.commandManager.buildCommand('muteirc')
39+
.restrict(Player.LEVEL_ADMINISTRATOR)
40+
.parameters([{ name: 'on/off', type: CommandBuilder.WORD_PARAMETER, optional: true }])
41+
.build(MuteCommands.prototype.onMuteIrcCommand.bind(this));
42+
3443
// /muted
3544
server.commandManager.buildCommand('muted')
3645
.restrict(Player.LEVEL_ADMINISTRATOR)
@@ -125,6 +134,34 @@ export class MuteCommands {
125134
player.sendMessage(Message.MUTE_MUTED, targetPlayer.name, targetPlayer.id, proposedText);
126135
}
127136

137+
// /muteirc [on | off]?
138+
//
139+
// Mutes the IRC channel for unregistered people. Useful when someone from IRC is being a troll,
140+
// without having to switch tabs to mIRC or another client.
141+
onMuteIrcCommand(player, command) {
142+
switch (command) {
143+
case 'on':
144+
this.nuwani_().echo('mute-echo');
145+
this.announce_().announceToAdministrators(
146+
Message.COMMUNICATION_ADMIN_IRC_MUTE, player.name, player.id, 'muted');
147+
148+
player.sendMessage(Message.COMMUNICATION_MUTE_IRC_ENABLED);
149+
break;
150+
151+
case 'off':
152+
this.nuwani_().echo('unmute-echo');
153+
this.announce_().announceToAdministrators(
154+
Message.COMMUNICATION_ADMIN_IRC_MUTE, player.name, player.id, 'unmuted');
155+
156+
player.sendMessage(Message.COMMUNICATION_MUTE_IRC_DISABLED);
157+
break;
158+
159+
default:
160+
player.sendMessage(Message.COMMAND_USAGE, '/muteirc [on | off]');
161+
break;
162+
}
163+
}
164+
128165
// /muted
129166
//
130167
// Displays an overview of the currently muted players to |player|, and how much time they have

javascript/features/communication_commands/mute_commands.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,25 @@ describe('MuteCommands', (it, beforeEach) => {
166166
await server.clock.advance(10 * 1000);
167167
await monitorPromise;
168168
});
169+
170+
it('is able to mute and unmute the IRC channel', async (assert) => {
171+
const nuwani = server.featureManager.loadFeature('nuwani');
172+
173+
assert.isTrue(await russell.issueCommand('/muteirc'));
174+
assert.equal(nuwani.messagesForTesting.length, 0);
175+
176+
assert.isTrue(await russell.issueCommand('/muteirc on'));
177+
assert.equal(nuwani.messagesForTesting.length, 2);
178+
assert.deepEqual(nuwani.messagesForTesting[0], {
179+
tag: 'mute-echo',
180+
params: [],
181+
});
182+
183+
assert.isTrue(await russell.issueCommand('/muteirc off'));
184+
assert.equal(nuwani.messagesForTesting.length, 4);
185+
assert.deepEqual(nuwani.messagesForTesting[2], {
186+
tag: 'unmute-echo',
187+
params: [],
188+
})
189+
});
169190
});

0 commit comments

Comments
 (0)