Skip to content

Commit e0397fb

Browse files
committed
refactor: rewrite lockdown
1 parent 9785963 commit e0397fb

File tree

17 files changed

+652
-241
lines changed

17 files changed

+652
-241
lines changed

src/commands/Moderation/lockdown.ts

Lines changed: 332 additions & 85 deletions
Large diffs are not rendered by default.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "lockdown",
3+
"description": "Manage the server's lockdown status",
4+
"actionName": "action",
5+
"actionDescription": "The action to perform",
6+
"channelName": "channel",
7+
"channelDescription": "The channel to lock down",
8+
"durationName": "duration",
9+
"durationDescription": "How long the lockdown should last",
10+
"roleName": "role",
11+
"roleDescription": "The role to use for the lockdown",
12+
"globalName": "global",
13+
"globalDescription": "⚠️ Whether or not to apply the lockdown to the entire server",
14+
"actionLock": "Lock",
15+
"actionUnlock": "Unlock",
16+
"auditLogLockRequestedBy": "Channel locked at request of {{user}}",
17+
"auditLogUnlockRequestedBy": "Channel unlocked at request of {{user}}",
18+
"guildLocked": "{{role}} is already locked down in the server.",
19+
"guildUnlocked": "{{role}} is currently not locked down in the server.",
20+
"successGuild": "Successfully updated the lockdown status for {{role}} in the server.",
21+
"guildUnknownRole": "I somehow could not find the role {{role}}, you can try with other roles.",
22+
"guildLockFailed": "The role {{role}} could not be locked down, please try again later.",
23+
"guildUnlockFailed": "The role {{role}} could not be unlocked, please try again later.",
24+
"successThread": "Successfully updated the lockdown status for the thread {{channel}} in the server.",
25+
"threadLocked": "The thread {{channel}} is already locked.",
26+
"threadUnlocked": "The thread {{channel}} is currently not locked.",
27+
"threadUnmanageable": "I cannot manage the thread {{channel}}, please update my permissions and try again.",
28+
"threadUnknownChannel": "I somehow could not find the thread {{channel}}, you can try with other channels.",
29+
"threadLockFailed": "The thread {{channel}} could not be locked, please try again later.",
30+
"threadUnlockFailed": "The thread {{channel}} could not be unlocked, please try again later.",
31+
"successChannel": "Successfully updated the lockdown status for the channel {{channel}} in the server",
32+
"channelLocked": "The channel {{channel}} is already locked.",
33+
"channelUnlocked": "The channel {{channel}} is currently not locked.",
34+
"channelUnmanageable": "I cannot manage the channel {{channel}}, please update my permissions and try again.",
35+
"channelUnknownChannel": "I somehow could not find the channel {{channel}}, you can try with other channels.",
36+
"channelLockFailed": "The channel {{channel}} could not be locked, please try again later."
37+
}

src/lib/database/entities/ScheduleEntity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class ScheduleEntity extends BaseEntity {
6363
* The stored metadata to send to the Task
6464
*/
6565
@Column('jsonb')
66-
public data!: Record<string, unknown>;
66+
public data!: object;
6767

6868
/**
6969
* Whether or not the entity is running

src/lib/database/settings/structures/Task.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PartialResponseValue } from '#lib/database/entities';
1+
import { ResponseType, type PartialResponseValue } from '#lib/database/entities';
22
import { Piece } from '@sapphire/framework';
33
import type { Awaitable } from '@sapphire/utilities';
44

@@ -8,6 +8,22 @@ export abstract class Task extends Piece {
88
* @param data The data
99
*/
1010
public abstract run(data: unknown): Awaitable<PartialResponseValue | null>;
11+
12+
protected ignore() {
13+
return { type: ResponseType.Ignore } as const;
14+
}
15+
16+
protected finish() {
17+
return { type: ResponseType.Finished } as const;
18+
}
19+
20+
protected delay(value: number) {
21+
return { type: ResponseType.Delay, value } as const;
22+
}
23+
24+
protected update(value: Date) {
25+
return { type: ResponseType.Update, value } as const;
26+
}
1127
}
1228

1329
export namespace Task {

src/lib/i18n/languageKeys/keys/Commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * as Case from '#lib/i18n/languageKeys/keys/commands/Case';
33
export * as Fun from '#lib/i18n/languageKeys/keys/commands/Fun';
44
export * as Games from '#lib/i18n/languageKeys/keys/commands/Games';
55
export * as General from '#lib/i18n/languageKeys/keys/commands/General';
6+
export * as Lockdown from '#lib/i18n/languageKeys/keys/commands/Lockdown';
67
export * as Management from '#lib/i18n/languageKeys/keys/commands/Management';
78
export * as Misc from '#lib/i18n/languageKeys/keys/commands/Misc';
89
export * as Moderation from '#lib/i18n/languageKeys/keys/commands/Moderation';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { FT, T } from '#lib/types';
2+
import type { ChannelMention, RoleMention } from 'discord.js';
3+
4+
// Root
5+
export const Name = T('commands/lockdown:name');
6+
export const Description = T('commands/lockdown:description');
7+
8+
// Options
9+
export const Action = 'commands/lockdown:action';
10+
export const Channel = 'commands/lockdown:channel';
11+
export const Duration = 'commands/lockdown:duration';
12+
export const Role = 'commands/lockdown:role';
13+
export const Global = 'commands/lockdown:global';
14+
15+
// Action choices
16+
export const ActionLock = T('commands/lockdown:actionLock');
17+
export const ActionUnlock = T('commands/lockdown:actionUnlock');
18+
19+
export const AuditLogLockRequestedBy = FT<{ user: string }>('commands/lockdown:auditLogLockRequestedBy');
20+
export const AuditLogUnlockRequestedBy = FT<{ user: string }>('commands/lockdown:auditLogUnlockRequestedBy');
21+
22+
// Guild
23+
export const GuildLocked = FT<{ role: RoleMention }>('commands/lockdown:guildLocked');
24+
export const GuildUnlocked = FT<{ role: RoleMention }>('commands/lockdown:guildUnlocked');
25+
export const SuccessGuild = FT<{ role: RoleMention }>('commands/lockdown:successGuild');
26+
export const GuildUnknownRole = FT<{ role: RoleMention }>('commands/lockdown:guildUnknownRole');
27+
export const GuildLockFailed = FT<{ role: RoleMention }>('commands/lockdown:guildLockFailed');
28+
export const GuildUnlockFailed = FT<{ role: RoleMention }>('commands/lockdown:guildUnlockFailed');
29+
30+
// Thread
31+
export const SuccessThread = FT<{ channel: ChannelMention }>('commands/lockdown:successThread');
32+
export const ThreadLocked = FT<{ channel: ChannelMention }>('commands/lockdown:threadLocked');
33+
export const ThreadUnlocked = FT<{ channel: ChannelMention }>('commands/lockdown:threadUnlocked');
34+
export const ThreadUnmanageable = FT<{ channel: ChannelMention }>('commands/lockdown:threadUnmanageable');
35+
export const ThreadUnknownChannel = FT<{ channel: ChannelMention }>('commands/lockdown:threadUnknownChannel');
36+
export const ThreadLockFailed = FT<{ channel: ChannelMention }>('commands/lockdown:threadLockFailed');
37+
export const ThreadUnlockFailed = FT<{ channel: ChannelMention }>('commands/lockdown:threadUnlockFailed');
38+
39+
// Channel
40+
export const SuccessChannel = FT<{ channel: ChannelMention }>('commands/lockdown:successChannel');
41+
export const ChannelLocked = FT<{ channel: ChannelMention }>('commands/lockdown:channelLocked');
42+
export const ChannelUnlocked = FT<{ channel: ChannelMention }>('commands/lockdown:channelUnlocked');
43+
export const ChannelUnmanageable = FT<{ channel: ChannelMention }>('commands/lockdown:channelUnmanageable');
44+
export const ChannelUnknownChannel = FT<{ channel: ChannelMention }>('commands/lockdown:channelUnknownChannel');
45+
export const ChannelLockFailed = FT<{ channel: ChannelMention }>('commands/lockdown:channelLockFailed');

src/lib/moderation/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from '#lib/moderation/actions/index';
22
export * from '#lib/moderation/managers/index';
33
export * from '#lib/moderation/structures/index';
4+
export * from '#lib/moderation/types';

src/lib/moderation/types.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import type { Snowflake } from 'discord.js';
2+
3+
export type LockdownData = LockdownGuildData | LockdownChannelData | LockdownThreadData;
4+
5+
export enum LockdownType {
6+
Guild,
7+
Channel,
8+
Thread
9+
}
10+
11+
interface BaseLockdownData<T extends LockdownType> {
12+
/**
13+
* The type of lockdown that was applied.
14+
*/
15+
type: T;
16+
17+
/**
18+
* The ID of the guild where the lockdown was applied.
19+
*/
20+
guildId: Snowflake;
21+
22+
/**
23+
* The ID of the user who initiated the lockdown.
24+
*/
25+
userId: Snowflake;
26+
}
27+
28+
export interface LockdownGuildData extends BaseLockdownData<LockdownType.Guild> {
29+
/**
30+
* The ID of the role that was locked down.
31+
*/
32+
roleId: Snowflake;
33+
34+
/**
35+
* The permissions that were applied to the role, as a bitfield.
36+
*/
37+
permissionsApplied: number;
38+
39+
/**
40+
* The original permissions for the role before the lockdown.
41+
*/
42+
permissionsOriginal: number;
43+
}
44+
45+
export interface LockdownChannelData extends BaseLockdownData<LockdownType.Channel> {
46+
/**
47+
* The ID of the channel where the lockdown was applied.
48+
*/
49+
channelId: Snowflake;
50+
51+
/**
52+
* The ID of the role that was locked down in the channel.
53+
*/
54+
roleId: Snowflake;
55+
56+
/**
57+
* The permissions that were applied to the role, as a bitfield.
58+
*/
59+
permissionsApplied: number | null;
60+
61+
/**
62+
* The original allow overrides for the role before the lockdown.
63+
*/
64+
permissionsOriginalAllow: number;
65+
66+
/**
67+
* The original deny overrides for the role before the lockdown.
68+
*/
69+
permissionsOriginalDeny: number;
70+
}
71+
72+
export interface LockdownThreadData extends BaseLockdownData<LockdownType.Thread> {
73+
/**
74+
* The ID of the thread where the lockdown was applied.
75+
*/
76+
channelId: Snowflake;
77+
}

src/lib/structures/managers/LockdownManager.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/lib/structures/managers/ScheduleManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export interface ScheduleManagerAddOptions {
209209
/**
210210
* The data to pass to the Task piece when the ScheduledTask is ready for execution.
211211
*/
212-
data?: Record<string, unknown>;
212+
data?: object;
213213
}
214214

215215
export type TimeResolvable = number | Date | string | Cron;

0 commit comments

Comments
 (0)