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

Add command to remove admin role permissions #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,30 @@ const slashCommands: SlashCommandsType = {
},
text: 'Sets a non-admin server role that can use commands like /track, /remove, and more',
admin: true
},
removerole: {
execute: async (interaction) => {
const guild = getInteractionGuild(interaction);
if (state.hasPrivilegedRole(guild.id)) {
const role = state.getPrivilegedRole(guild.id);
await pgStorageClient.deletePrivilegedRole(guild.id);
state.clearPrivilegedRole(guild.id);
await interaction.reply({
content: `${role} can no longer use admin commands.`,
ephemeral: true
});
return true;
} else {
await interaction.reply({
content: 'No privileged role has been set.',
ephemeral: true
});
return false;
}

},
text: 'Removes permission from server role to use admin commands like /track, /remove, and more',
admin: true
}
};

Expand Down
4 changes: 4 additions & 0 deletions src/pg-storage-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ export default class PGStorageClient {
await this.client.query('INSERT INTO privileged_roles VALUES ($1, $2) ON CONFLICT (guild_id) DO UPDATE SET role_id = EXCLUDED.role_id;', [guildId, roleId]);
}

async deletePrivilegedRole(guildId: Snowflake): Promise<void> {
await this.client.query('DELETE FROM privileged_roles WHERE guild_id = $1;', [guildId]);
}

// TODO: Update this to make the return type better. Idk what it should actually be... Maybe a list?
async fetchDailyAnalyticsForLabel(label: DailyAnalyticsLabel): Promise<Record<string, number>> {
const result: Record<string, number> = {};
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type MiscPropertyName = 'timestamp' | 'disabled' | 'auditCounters' | type

export type BuiltSlashCommand = SlashCommandBuilder | Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;

export type SlashCommandName = 'help' | 'ping' | 'info' | 'track' | 'remove' | 'clear' | 'list' | 'check' | 'channel' | 'kc' | 'details' | 'role';
export type SlashCommandName = 'help' | 'ping' | 'info' | 'track' | 'remove' | 'clear' | 'list' | 'check' | 'channel' | 'kc' | 'details' | 'role' | 'removerole';

export type HiddenCommandName = 'help' | 'log' | 'thumbnail' | 'thumbnail99' | 'spoof' | 'spoofverbose' | 'admin' | 'kill' | 'enable' | 'rollback' | 'removeglobal' | 'logger' | 'player' | 'refresh' | 'guildnotify';

Expand Down