diff --git a/i18n/bot/en.json b/i18n/bot/en.json index d0197d6c..a07fbf3c 100644 --- a/i18n/bot/en.json +++ b/i18n/bot/en.json @@ -1164,7 +1164,8 @@ "args": { "channel": "The channel that you want to lock down." } - } + }, + "noSuitingRoleFound": "No suitable role found to start a lockdown!" } }, "JOIN_LEAVE_EMBEDS_IS_PREMIUM": "Using an embed as your join/leave message is a premium feature. Premium does not seem to be active on this server. Please contact us to learn more about how to purchase premium.", diff --git a/src/framework/services/Scheduler.ts b/src/framework/services/Scheduler.ts index 066291d3..51ff5b18 100644 --- a/src/framework/services/Scheduler.ts +++ b/src/framework/services/Scheduler.ts @@ -7,6 +7,9 @@ import { ScheduledAction, ScheduledActionType } from '../models/ScheduledAction' import { IMService } from './Service'; +const SEND_MESSAGES = 0x00000800; +const NOT_SEND_MESSAGES = 0x7ffff7ff; + export class SchedulerService extends IMService { private scheduledActionTimers: Map = new Map(); private scheduledActionFunctions: { @@ -68,7 +71,7 @@ export class SchedulerService extends IMService { }); } }; - console.log(`Scheduling timer in ${millisUntilAction} for ${action.id}`); + console.log(`Scheduling timer in ${chalk.blue(millisUntilAction)} for action ${chalk.blue(action.id)}`); const timer = setTimeout(func, millisUntilAction); this.scheduledActionTimers.set(action.id, timer); } @@ -86,7 +89,7 @@ export class SchedulerService extends IMService { private async scheduleScheduledActions() { let actions = await this.client.db.getScheduledActionsForGuilds(this.client.guilds.map((g) => g.id)); actions = actions.filter((a) => a.date !== null); - console.log(`Scheduling ${chalk.blue(actions.length)} actions from db`); + console.log(`Scheduling ${chalk.blue(actions.length)} actions from DB`); actions.forEach((action) => this.createTimer(action)); } @@ -109,7 +112,33 @@ export class SchedulerService extends IMService { await member.removeRole(roleId, 'Timed unmute'); } - private async unlock(guild: Guild, { channelId, roleId }: { channelId: string; roleId: string }) { + private async unlock( + guild: Guild, + { channelId, roleId, wasAllowed }: { channelId: string; roleId: string; wasAllowed: boolean } + ) { console.log('SCHEDULED TASK: UNLOCK', guild.id, channelId, roleId); + + let channel = guild.channels.get(channelId); + if (!channel) { + await guild.getRESTChannels(); + channel = guild.channels.get(channelId); + } + if (!channel) { + console.error('SCHEDULED TASK: UNLOCK: COULD NOT FIND CHANNEL', channelId); + return; + } + + const override = channel.permissionOverwrites.get(roleId); + const newAllow = wasAllowed ? SEND_MESSAGES : 0; + + // tslint:disable: no-bitwise + await this.client.editChannelPermission( + channelId, + roleId, + override ? override.allow | newAllow : newAllow, + override ? override.deny & NOT_SEND_MESSAGES : 0, + 'role', + 'Channel lockdown' + ); } } diff --git a/src/moderation/commands/mod/lockdown.ts b/src/moderation/commands/mod/lockdown.ts index f580f1bd..e7078cd8 100644 --- a/src/moderation/commands/mod/lockdown.ts +++ b/src/moderation/commands/mod/lockdown.ts @@ -1,5 +1,5 @@ import { Channel, Message, PermissionOverwrite, Role, TextChannel } from 'eris'; -import { Duration } from 'moment'; +import moment, { Duration } from 'moment'; import { IMClient } from '../../../client'; import { Command, Context } from '../../../framework/commands/Command'; @@ -100,6 +100,8 @@ export default class extends Command { return; } + // We always add a scheduled actions so that we know what to restore on unlock + // But if the user didn't specify a timeout then we set it to null so they must do it manually await this.client.scheduler.addScheduledAction( guild.id, ScheduledActionType.unlock, @@ -108,7 +110,7 @@ export default class extends Command { roleId: lowestRole.id, wasAllowed: !!(lowestOverride.allow & SEND_MESSAGES) }, - null, + timeout ? moment().add(timeout).toDate() : null, 'Unlock from timed `!lockdown` command' ); diff --git a/src/moderation/commands/mod/mute.ts b/src/moderation/commands/mod/mute.ts index f00209bf..0be4f99d 100644 --- a/src/moderation/commands/mod/mute.ts +++ b/src/moderation/commands/mod/mute.ts @@ -94,7 +94,7 @@ export default class extends Command { guild.id, ScheduledActionType.unmute, { memberId: targetMember.id, roleId: mutedRole }, - moment().locale(settings.lang).add(duration).toDate(), + moment().add(duration).toDate(), 'Unmute from timed `!mute` command' ); }