Skip to content

Commit d0160ac

Browse files
committed
refactor: rewrite lockdown
1 parent 3c790b6 commit d0160ac

File tree

17 files changed

+652
-241
lines changed

17 files changed

+652
-241
lines changed

Diff for: src/commands/Moderation/lockdown.ts

+332-85
Large diffs are not rendered by default.

Diff for: src/languages/en-US/commands/lockdown.json

+37
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+
}

Diff for: src/lib/database/entities/ScheduleEntity.ts

+1-1
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

Diff for: src/lib/database/settings/structures/Task.ts

+17-1
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 {

Diff for: src/lib/i18n/languageKeys/keys/Commands.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * as Case from '#lib/i18n/languageKeys/keys/commands/Case';
44
export * as Fun from '#lib/i18n/languageKeys/keys/commands/Fun';
55
export * as Games from '#lib/i18n/languageKeys/keys/commands/Games';
66
export * as General from '#lib/i18n/languageKeys/keys/commands/General';
7+
export * as Lockdown from '#lib/i18n/languageKeys/keys/commands/Lockdown';
78
export * as Management from '#lib/i18n/languageKeys/keys/commands/Management';
89
export * as Misc from '#lib/i18n/languageKeys/keys/commands/Misc';
910
export * as Moderation from '#lib/i18n/languageKeys/keys/commands/Moderation';

Diff for: src/lib/i18n/languageKeys/keys/commands/Lockdown.ts

+45
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');

Diff for: src/lib/moderation/index.ts

+1
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';

Diff for: src/lib/moderation/types.ts

+77
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+
}

Diff for: src/lib/structures/managers/LockdownManager.ts

-73
This file was deleted.

Diff for: src/lib/structures/managers/ScheduleManager.ts

+1-1
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;

Diff for: src/lib/structures/managers/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
export * from '#lib/structures/managers/LockdownManager';
21
export * from '#lib/structures/managers/ScheduleManager';

Diff for: src/lib/util/Security/GuildSecurity.ts

-21
This file was deleted.

Diff for: src/lib/util/Timers.ts

-34
This file was deleted.

Diff for: src/lib/util/functions/guild.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { LoggerManager, ModerationManager, StickyRoleManager } from '#lib/moderation/managers';
2-
import { GuildSecurity } from '#utils/Security/GuildSecurity';
32
import { container } from '@sapphire/framework';
43
import type { Guild, GuildResolvable } from 'discord.js';
54

65
interface GuildUtilities {
76
readonly logger: LoggerManager;
87
readonly moderation: ModerationManager;
9-
readonly security: GuildSecurity;
108
readonly stickyRoles: StickyRoleManager;
119
}
1210

@@ -20,7 +18,6 @@ export function getGuildUtilities(resolvable: GuildResolvable): GuildUtilities {
2018
const entry: GuildUtilities = {
2119
logger: new LoggerManager(guild),
2220
moderation: new ModerationManager(guild),
23-
security: new GuildSecurity(guild),
2421
stickyRoles: new StickyRoleManager(guild)
2522
};
2623
cache.set(guild, entry);
@@ -30,7 +27,6 @@ export function getGuildUtilities(resolvable: GuildResolvable): GuildUtilities {
3027

3128
export const getLogger = getProperty('logger');
3229
export const getModeration = getProperty('moderation');
33-
export const getSecurity = getProperty('security');
3430
export const getStickyRoles = getProperty('stickyRoles');
3531

3632
function getProperty<K extends keyof GuildUtilities>(property: K) {

Diff for: src/lib/util/functions/pieces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Piece } from '@sapphire/framework';
22
import { bgBlue, bgRed } from 'colorette';
33

44
export function getLogPrefix(piece: Piece | string) {
5-
return bgBlue(piece instanceof Piece ? `[ ${piece.store.name} => ${piece.name} ]` : `[ ${piece} ]`);
5+
return bgBlue(piece instanceof Piece ? `[ ${piece.name} ]` : `[ ${piece} ]`);
66
}
77

88
export function getCodeStyle(code: string | number) {

0 commit comments

Comments
 (0)