Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/commands/implementations/mute.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ function mute(input, services) {
);
}
parsedInput.forEach((result) => {
const { userToPunish, parsedDuration } = result;
const { userToPunish, parsedDuration, parsedReason } = result;
const durationStr = formatDuration(moment.duration(parsedDuration, 'seconds'));
const reason = parsedReason === null
? `Muting: ${userToPunish} for ${durationStr}`
: `Muting: ${userToPunish} for ${durationStr}. Reason: ${parsedReason}`;
services.punishmentStream.write(
makeMute(
userToPunish,
parsedDuration,
`Muting: ${userToPunish} for ${formatDuration(moment.duration(parsedDuration, 'seconds'))}`,
),
makeMute(userToPunish, parsedDuration, reason),
);
});
return new CommandOutput(null, null);
}

module.exports = new Command(mute, false, true, /(\d+[HMDSWwhmds])?\s?(\w+)/, null);
module.exports = new Command(mute, false, true, /((?:\d+[HMDSWwhmds])|(?:perm))?\s?(\w+)(?:\s(.*))?/, null);
51 changes: 51 additions & 0 deletions tests/lib/commands/implementations/mute.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const assert = require('assert');
const sinon = require('sinon');
const mute = require('../../../../lib/commands/implementations/mute');

describe('Mute command', () => {
beforeEach(() => {
this.mockServices = {
punishmentStream: {
write: sinon.spy(),
},
};
});

it('mutes a user with duration and no reason', () => {
mute.work('10m TestUser', this.mockServices);
assert(this.mockServices.punishmentStream.write.calledOnce);
const call = this.mockServices.punishmentStream.write.firstCall.args[0];
assert.strictEqual(call.user, 'testuser');
assert.strictEqual(call.duration, 600);
assert.strictEqual(call.type, 'mute');
assert(call.reason.includes('Muting: testuser for'));
assert(!call.reason.includes('Reason:'));
});

it('mutes a user with duration and reason', () => {
mute.work('10m TestUser being annoying', this.mockServices);
assert(this.mockServices.punishmentStream.write.calledOnce);
const call = this.mockServices.punishmentStream.write.firstCall.args[0];
assert.strictEqual(call.user, 'testuser');
assert.strictEqual(call.duration, 600);
assert.strictEqual(call.type, 'mute');
assert(call.reason.includes('Reason: being annoying'));
});

it('mutes a user with default duration when none provided', () => {
mute.work('TestUser', this.mockServices);
assert(this.mockServices.punishmentStream.write.calledOnce);
const call = this.mockServices.punishmentStream.write.firstCall.args[0];
assert.strictEqual(call.user, 'testuser');
assert.strictEqual(call.duration, 600);
assert.strictEqual(call.type, 'mute');
});

it('mutes a user with default duration and reason', () => {
mute.work('TestUser spamming links', this.mockServices);
assert(this.mockServices.punishmentStream.write.calledOnce);
const call = this.mockServices.punishmentStream.write.firstCall.args[0];
assert.strictEqual(call.user, 'testuser');
assert(call.reason.includes('Reason: spamming links'));
});
});
Loading