Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added role restriction actions #469

Merged
merged 3 commits into from
Nov 4, 2019
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
2 changes: 1 addition & 1 deletion database/5.2.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,4 +619,4 @@
* }
*/

export const DEPRECATED = false;
export const DEPRECATED = true;
96 changes: 50 additions & 46 deletions database/5.2.1.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
import { mergeDefault } from '@klasa/utils';
import { CLIENT_OPTIONS } from '../config';
import { Pool } from 'pg';
/*
* import { mergeDefault } from '@klasa/utils';
* import { CLIENT_OPTIONS } from '../config';
* import { Pool } from 'pg';
*
* async function main() {
* const connection = mergeDefault({
* host: 'localhost',
* port: 5432,
* database: 'klasa',
* options: {
* max: 20,
* idleTimeoutMillis: 30000,
* connectionTimeoutMillis: 2000
* }
* }, CLIENT_OPTIONS.providers!.postgres);
* const pgsql = new Pool({
* ...connection.options,
* host: connection.host,
* port: connection.port,
* user: connection.user,
* password: connection.password,
* database: connection.database
* });
* // eslint-disable-next-line @typescript-eslint/unbound-method
* pgsql.on('error', console.error);
* const dbconnection = await pgsql.connect();
* await processQueries(pgsql);
* dbconnection.release();
* await pgsql.end();
* }
*
* async function processQueries(pgsql: Pool) {
* await pgsql.query(`
* ALTER TABLE "users"
* ADD COLUMN IF NOT EXISTS "dark_theme" BOOLEAN DEFAULT FALSE NOT NULL,
* ADD COLUMN IF NOT EXISTS "moderation_dm" BOOLEAN DEFAULT TRUE NOT NULL;
* `);
*
* await pgsql.query(`
* ALTER TABLE "guilds"
* DROP COLUMN IF EXISTS "messages.warnings",
* ADD COLUMN IF NOT EXISTS "messages.moderation-dm" BOOLEAN DEFAULT FALSE NOT NULL,
* ADD COLUMN IF NOT EXISTS "messages.moderator-name-display" BOOLEAN DEFAULT TRUE NOT NULL;
* `);
* }
*
* main().catch(error => console.error(error));
*/

async function main() {
const connection = mergeDefault({
host: 'localhost',
port: 5432,
database: 'klasa',
options: {
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000
}
}, CLIENT_OPTIONS.providers!.postgres);
const pgsql = new Pool({
...connection.options,
host: connection.host,
port: connection.port,
user: connection.user,
password: connection.password,
database: connection.database
});
// eslint-disable-next-line @typescript-eslint/unbound-method
pgsql.on('error', console.error);
const dbconnection = await pgsql.connect();
await processQueries(pgsql);
dbconnection.release();
await pgsql.end();
}

async function processQueries(pgsql: Pool) {
await pgsql.query(/* sql */`
ALTER TABLE "users"
ADD COLUMN IF NOT EXISTS "dark_theme" BOOLEAN DEFAULT FALSE NOT NULL,
ADD COLUMN IF NOT EXISTS "moderation_dm" BOOLEAN DEFAULT TRUE NOT NULL;
`);

await pgsql.query(/* sql */`
ALTER TABLE "guilds"
DROP COLUMN IF EXISTS "messages.warnings",
ADD COLUMN IF NOT EXISTS "messages.moderation-dm" BOOLEAN DEFAULT FALSE NOT NULL,
ADD COLUMN IF NOT EXISTS "messages.moderator-name-display" BOOLEAN DEFAULT TRUE NOT NULL;
`);
}

main().catch(error => console.error(error));
export const DEPRECATED = true;
44 changes: 44 additions & 0 deletions database/5.3.0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { mergeDefault } from '@klasa/utils';
import { CLIENT_OPTIONS } from '../config';
import { Pool } from 'pg';

async function main() {
const connection = mergeDefault({
host: 'localhost',
port: 5432,
database: 'klasa',
options: {
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000
}
}, CLIENT_OPTIONS.providers!.postgres);
const pgsql = new Pool({
...connection.options,
host: connection.host,
port: connection.port,
user: connection.user,
password: connection.password,
database: connection.database
});
// eslint-disable-next-line @typescript-eslint/unbound-method
pgsql.on('error', console.error);
const dbconnection = await pgsql.connect();
await processQueries(pgsql);
dbconnection.release();
await pgsql.end();
}

async function processQueries(pgsql: Pool) {
await pgsql.query(/* sql */`
ALTER TABLE "guilds"
ADD COLUMN IF NOT EXISTS "roles.restricted-reaction" VARCHAR(19),
ADD COLUMN IF NOT EXISTS "roles.restricted-embed" VARCHAR(19),
ADD COLUMN IF NOT EXISTS "roles.restricted-attachment" VARCHAR(19),
ADD COLUMN IF NOT EXISTS "roles.restricted-voice" VARCHAR(19);
`);
}

main().catch(error => console.error(error));

export const DEPRECATED = false;
3 changes: 2 additions & 1 deletion src/commands/Moderation/mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default class extends ModerationCommand {
}

public async inhibit(message: KlasaMessage) {
if (message.guild === null) return true;
// If the command run is not this one (potentially help command) or the guild is null, return with no error.
if (message.command !== this || message.guild === null) return false;
const id = message.guild.settings.get(GuildSettings.Roles.Muted);
const role = (id && message.guild!.roles.get(id)) || null;
if (!role) {
Expand Down
6 changes: 4 additions & 2 deletions src/languages/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3301,7 +3301,11 @@ export default class extends Language {
? '[Action] Applied Voice Restriction.'
: `[Action] Applied Voice Restriction | Reason: ${reason}`,
ACTION_REQUIRED_MEMBER: 'The user does not exist or is not in this server.',
ACTION_SETUP_MUTE_EXISTS: '**Aborting mute role creation**: There is already one that exists.',
ACTION_SETUP_RESTRICTION_EXISTS: '**Aborting restriction role creation**: There is already one that exists.',
ACTION_SETUP_TOO_MANY_ROLES: '**Aborting role creation**: There are 250 roles in this guild, you need to delete one role.',
MUTE_NOT_CONFIGURED: 'The muted role must be configured for this action to happen.',
RESTRICTION_NOT_CONFIGURED: 'The restriction role must be configured for this action to happen',
MUTE_NOT_IN_MEMBER: 'The muted role is not set in the member.',
MUTE_LOW_HIERARCHY: 'I cannot mute a user which higher role hierarchy than me.',
MUTE_CANNOT_MANAGE_ROLES: `I must have **${PERMS.MANAGE_ROLES}** permissions to be able to mute.`,
Expand Down Expand Up @@ -3341,8 +3345,6 @@ export default class extends Language {
SYSTEM_ERROR: 'Something happened!',
SYSTEM_MESSAGE_NOT_FOUND: 'I am sorry, but either you wrote the message ID incorrectly, or it got deleted.',
SYSTEM_NOTENOUGH_PARAMETERS: `I am sorry, but you did not provide enough parameters...`,
SYSTEM_GUILD_MUTECREATE_MUTEEXISTS: '**Aborting mute role creation**: There is already one that exists.',
SYSTEM_GUILD_MUTECREATE_TOOMANYROLES: '**Aborting mute role creation**: There are 250 roles in this guild, you need to delete one role.',
SYSTEM_GUILD_MUTECREATE_APPLYING: (channels, role) => `Applying permissions (\`SEND_MESSAGES\`:\`false\`) for ${channels} to ${role}...`,
SYSTEM_GUILD_MUTECREATE_EXCEPTIONS: denied => denied.length > 1 ? `, with exception of ${denied.join(', ')}.` : '. ',
SYSTEM_GUILD_MUTECREATE_APPLIED: (accepted, exceptions, author, role) => `Permissions applied for ${accepted} channels${exceptions}Dear ${author}, don't forget to tweak the permissions in the channels you want ${role} to send messages.`,
Expand Down
6 changes: 4 additions & 2 deletions src/languages/es-ES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2915,7 +2915,11 @@ export default class extends Language {
? '[Action] Applied Voice Restriction.'
: `[Action] Applied Voice Restriction | Reason: ${reason}`,
ACTION_REQUIRED_MEMBER: 'The user does not exist or is not in this server.',
ACTION_SETUP_MUTE_EXISTS: '**Cancelando la creación del rol de silenciado**: Ya existe un rol de silenciado.',
ACTION_SETUP_RESTRICTION_EXISTS: '**Cancelando la creación del rol de restricción**: Ya existe un rol de restricción.',
ACTION_SETUP_TOO_MANY_ROLES: '**Cancelando la creación del rol**: Hay 250 roles en este servidor, necesitas borrar uno.',
MUTE_NOT_CONFIGURED: 'The muted role must be configured for this action to happen.',
RESTRICTION_NOT_CONFIGURED: 'The restriction role must be configured for this action to happen',
MUTE_NOT_IN_MEMBER: 'The muted role is not set in the member.',
MUTE_LOW_HIERARCHY: 'I cannot mute a user which higher role hierarchy than me.',
MUTE_CANNOT_MANAGE_ROLES: `I must have **${PERMS.MANAGE_ROLES}** permissions to be able to mute.`,
Expand Down Expand Up @@ -2953,8 +2957,6 @@ export default class extends Language {
`${LOADING} Jugando a Piedra, Papel, Tijeras...`
]),
SYSTEM_MESSAGE_NOT_FOUND: 'Lo siento, pero la id del mensaje que escribiste no era correcto, o el mensaje fue borrado.',
SYSTEM_GUILD_MUTECREATE_MUTEEXISTS: '**Cancelando la creación del rol de mute**: Ya existe un rol de mute.',
SYSTEM_GUILD_MUTECREATE_TOOMANYROLES: '**Cancelando la creación del rol de mute**: Hay 250 roles en este servidor, necesitas borrar uno.',
SYSTEM_GUILD_MUTECREATE_APPLYING: (channels, role) => `Aplicando permisos en ${channels} para el rol ${role}...`,
SYSTEM_GUILD_MUTECREATE_EXCEPTIONS: denied => denied.length > 1 ? `, con excepción de los canales ${denied.join(', ')}` : '',
SYSTEM_GUILD_MUTECREATE_APPLIED: (accepted, exceptions, author, role) => `Permisos aplicados para ${accepted} ${accepted === 1 ? 'canal' : 'canales'}${exceptions}. Querido ${author}, puedes modificar los permisos de los canales que quieras para el rol ${role}, por ejemplo si quieres un canal de reclamaciones.`,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/schemas/Guilds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export default Client.defaultGuildSchema
.add('messageReaction', 'String', { min: 17, max: 18, configurable: false })
.add('moderator', 'Role')
.add('muted', 'Role')
.add('restricted-reaction', 'Role')
.add('restricted-embed', 'Role')
.add('restricted-attachment', 'Role')
.add('restricted-voice', 'Role')
.add('public', 'Role', { array: true })
.add('reactions', 'any', { array: true })
.add('removeInitial', 'Boolean')
Expand Down
6 changes: 4 additions & 2 deletions src/lib/types/Languages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,12 @@ export interface LanguageKeys {
ACTION_RESTRICTED_EMBED_REASON: (reason: string | null) => string;
ACTION_RESTRICTED_ATTACHMENT_REASON: (reason: string | null) => string;
ACTION_RESTRICTED_VOICE_REASON: (reason: string | null) => string;
ACTION_SETUP_MUTE_EXISTS: string;
ACTION_SETUP_RESTRICTION_EXISTS: string;
ACTION_SETUP_TOO_MANY_ROLES: string;
ACTION_REQUIRED_MEMBER: string;
MUTE_NOT_CONFIGURED: string;
RESTRICTION_NOT_CONFIGURED: string;
MUTE_NOT_IN_MEMBER: string;
MUTE_LOW_HIERARCHY: string;
MUTE_CANNOT_MANAGE_ROLES: string;
Expand All @@ -1215,8 +1219,6 @@ export interface LanguageKeys {
SYSTEM_NO_RESULTS: string;
SYSTEM_MESSAGE_NOT_FOUND: string;
SYSTEM_NOTENOUGH_PARAMETERS: string;
SYSTEM_GUILD_MUTECREATE_MUTEEXISTS: string;
SYSTEM_GUILD_MUTECREATE_TOOMANYROLES: string;
SYSTEM_GUILD_MUTECREATE_APPLYING: (channels: number, role: string) => string;
SYSTEM_GUILD_MUTECREATE_EXCEPTIONS: (denied: readonly string[]) => string;
SYSTEM_GUILD_MUTECREATE_APPLIED: (accepted: number, exceptions: string, author: string, role: string) => string;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/types/settings/GuildSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export namespace GuildSettings {
export const MessageReaction = T<string>('roles.messageReaction');
export const Moderator = T<string>('roles.moderator');
export const Muted = T<string>('roles.muted');
export const RestrictedReaction = T<string>('roles.restricted-reaction');
export const RestrictedEmbed = T<string>('roles.restricted-embed');
export const RestrictedAttachment = T<string>('roles.restricted-attachment');
export const RestrictedVoice = T<string>('roles.restricted-voice');
export const Public = T<readonly string[]>('roles.public');
export const Reactions = T<readonly RolesReaction[]>('roles.reactions');
export const RemoveInitial = T<boolean>('roles.removeInitial');
Expand Down
8 changes: 8 additions & 0 deletions src/lib/types/settings/raw/RawGuildSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export interface RawGuildSettings {
'roles.messageReaction': string | null;
'roles.moderator': string | null;
'roles.muted': string | null;
'roles.restricted-reaction': string | null;
'roles.restricted-embed': string | null;
'roles.restricted-attachment': string | null;
'roles.restricted-voice': string | null;
'roles.public': string[];
'roles.reactions': object[];
'roles.removeInitial': boolean;
Expand Down Expand Up @@ -141,6 +145,10 @@ export const SQL_TABLE_SCHEMA = /* sql */`
"roles.messageReaction" VARCHAR(19),
"roles.moderator" VARCHAR(19),
"roles.muted" VARCHAR(19),
"roles.restricted-reaction" VARCHAR(19),
"roles.restricted-embed" VARCHAR(19),
"roles.restricted-attachment" VARCHAR(19),
"roles.restricted-voice" VARCHAR(19),
"roles.public" VARCHAR(19)[] DEFAULT ARRAY[]::VARCHAR[] NOT NULL,
"roles.reactions" JSON[] DEFAULT ARRAY[]::JSON[] NOT NULL,
"roles.removeInitial" BOOLEAN DEFAULT FALSE NOT NULL,
Expand Down
Loading