diff options
Diffstat (limited to 'src/lib/models')
-rw-r--r-- | src/lib/models/Guild.ts | 27 | ||||
-rw-r--r-- | src/lib/models/StickyRole.ts | 17 |
2 files changed, 42 insertions, 2 deletions
diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts index dfba90c..4640d70 100644 --- a/src/lib/models/Guild.ts +++ b/src/lib/models/Guild.ts @@ -16,6 +16,7 @@ export interface GuildModel { lockdownChannels: Snowflake[]; autoModPhases: string[]; enabledFeatures: string[]; + joinRoles: Snowflake[]; } export interface GuildModelCreationAttributes { @@ -31,6 +32,7 @@ export interface GuildModelCreationAttributes { lockdownChannels?: Snowflake[]; autoModPhases?: string[]; enabledFeatures?: string[]; + joinRoles?: Snowflake[]; } export const guildSettings = { @@ -39,10 +41,12 @@ export const guildSettings = { welcomeChannel: { type: 'channel-array' }, muteRole: { type: 'role' }, punishmentEnding: { type: 'string' }, - lockdownChannels: { type: 'channel-array' } + lockdownChannels: { type: 'channel-array' }, + joinRoles: { type: 'role-array' } }; export const guildFeatures = ['automodEnabled', 'supportThreads', 'stickyRoles']; +export type GuildFeatures = 'automodEnabled' | 'supportThreads' | 'stickyRoles'; const NEVER_USED = 'This should never be executed'; @@ -167,6 +171,16 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i throw new Error(NEVER_USED); } + /** + * The roles to assign to a user if they are not assigned sticky roles + */ + public get joinRoles(): Snowflake[] { + throw new Error(NEVER_USED); + } + public set joinRoles(_: Snowflake[]) { + throw new Error(NEVER_USED); + } + public static initModel(sequelize: Sequelize, client: BushClient): void { Guild.init( { @@ -267,6 +281,17 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i }, allowNull: false, defaultValue: '[]' + }, + joinRoles: { + type: DataTypes.TEXT, + get: function () { + return JSON.parse(this.getDataValue('enabledFeatures') as unknown as string); + }, + set: function (val: string[]) { + return this.setDataValue('enabledFeatures', JSON.stringify(val) as unknown as string[]); + }, + allowNull: false, + defaultValue: '[]' } }, { sequelize: sequelize } diff --git a/src/lib/models/StickyRole.ts b/src/lib/models/StickyRole.ts index b49af80..d304370 100644 --- a/src/lib/models/StickyRole.ts +++ b/src/lib/models/StickyRole.ts @@ -6,11 +6,13 @@ export interface StickyRoleModel { user: Snowflake; guild: Snowflake; roles: Snowflake[]; + nickname: string; } export interface StickyRoleModelCreationAttributes { user: Snowflake; guild: Snowflake; roles: Snowflake[]; + nickname?: string; } const NEVER_USED = 'This should never be executed'; @@ -46,6 +48,16 @@ export class StickyRole extends BaseModel<StickyRoleModel, StickyRoleModelCreati throw new Error(NEVER_USED); } + /** + * The user's previous nickname + */ + public get nickname(): string { + throw new Error(NEVER_USED); + } + public set nickname(_: string) { + throw new Error(NEVER_USED); + } + public static initModel(sequelize: Sequelize): void { StickyRole.init( { @@ -57,7 +69,6 @@ export class StickyRole extends BaseModel<StickyRoleModel, StickyRoleModelCreati type: DataTypes.STRING, allowNull: false }, - roles: { type: DataTypes.STRING, get: function () { @@ -67,6 +78,10 @@ export class StickyRole extends BaseModel<StickyRoleModel, StickyRoleModelCreati return this.setDataValue('roles', JSON.stringify(val) as unknown as Snowflake[]); }, allowNull: true + }, + nickname: { + type: DataTypes.STRING, + allowNull: true } }, { sequelize } |