Skip to content

Commit

Permalink
Merge pull request #473 from gowon-bot/446-better-UI
Browse files Browse the repository at this point in the history
[446] Better UI
  • Loading branch information
abbyfour authored Feb 24, 2024
2 parents 454a75f + 10e0364 commit 3d4e9a3
Show file tree
Hide file tree
Showing 364 changed files with 4,670 additions and 4,471 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To start docker-compose, run `docker-compose up`. Note you will have to download

_You can find the source code for all the commands at [/src/commands](/src/commands)_

There are now too many commands to list in the README, see `!help all` or visit https://gowon.ca/commands for a list of all commands.
There are now too many commands to list in the README, see `!help all` or visit https://gowon.bot/commands for a list of all commands.

## Special Thanks

Expand Down
23 changes: 12 additions & 11 deletions src/commands/Admin/Permissions/BotDisable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { MessageEmbed } from "discord.js";
import {
Permission,
PermissionType,
Expand All @@ -7,6 +6,8 @@ import { CommandNotFoundError } from "../../../errors/errors";
import { code } from "../../../helpers/discord";
import { Variation } from "../../../lib/command/Command";
import { StringArgument } from "../../../lib/context/arguments/argumentTypes/StringArgument";
import { Emoji } from "../../../lib/emoji/Emoji";
import { SuccessEmbed } from "../../../lib/ui/embeds/SuccessEmbed";
import { PermissionsChildCommand } from "./PermissionsChildCommand";

const args = {
Expand Down Expand Up @@ -49,30 +50,30 @@ export class BotDisable extends PermissionsChildCommand<typeof args> {
commandID: command.id,
});

let embed: MessageEmbed;

if (!this.variationWasUsed("botenable")) {
await this.permissionsService.createPermission(
this.ctx,
command,
permission
);

embed = this.newEmbed()
.setAuthor(this.generateEmbedAuthor("Permissions bot disable"))
.setDescription(`Successfully disabled ${code(command.name)} bot-wide`);
const embed = new SuccessEmbed().setDescription(
`Successfully disabled ${code(command.name)} bot-wide`
);

await this.reply(embed);
} else {
await this.permissionsService.destroyPermission(
this.ctx,
command,
permission
);

embed = this.newEmbed()
.setAuthor(this.generateEmbedAuthor("Permissions bot enable"))
.setDescription(`Successfully enabled ${code(command.name)} bot-wide`);
}
const embed = new SuccessEmbed().setDescription(
`${Emoji.checkmark} Successfully enabled ${code(command.name)} bot-wide`
);

await this.send(embed);
await this.reply(embed);
}
}
}
36 changes: 16 additions & 20 deletions src/commands/Admin/Permissions/BotwideUserDisable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { MessageEmbed } from "discord.js";
import {
Permission,
PermissionType,
Expand All @@ -8,7 +7,8 @@ import { bold, code } from "../../../helpers/discord";
import { Variation } from "../../../lib/command/Command";
import { StringArgument } from "../../../lib/context/arguments/argumentTypes/StringArgument";
import { DiscordUserArgument } from "../../../lib/context/arguments/argumentTypes/discord/DiscordUserArgument";
import { displayUserTag } from "../../../lib/views/displays";
import { displayUserTag } from "../../../lib/ui/displays";
import { SuccessEmbed } from "../../../lib/ui/embeds/SuccessEmbed";
import { PermissionsChildCommand } from "./PermissionsChildCommand";

const args = {
Expand Down Expand Up @@ -57,38 +57,34 @@ export class BotwideUserDisable extends PermissionsChildCommand<typeof args> {
entityID: user.id,
});

let embed: MessageEmbed;

if (!this.variationWasUsed("botwideuserenable")) {
await this.permissionsService.createPermission(
this.ctx,
command,
permission
);

embed = this.newEmbed()
.setAuthor(this.generateEmbedAuthor("Permissions user disable"))
.setDescription(
`Successfully disabled ${code(command.name)} for ${bold(
displayUserTag(user)
)} (${user.id}) bot-wide`
);
const embed = new SuccessEmbed().setDescription(
`Successfully disabled ${code(command.name)} for ${bold(
displayUserTag(user)
)} (${user.id}) bot-wide`
);

await this.reply(embed);
} else {
await this.permissionsService.destroyPermission(
this.ctx,
command,
permission
);

embed = this.newEmbed()
.setAuthor(this.generateEmbedAuthor("Permissions enable"))
.setDescription(
`Successfully re-enabled ${code(command.name)} for ${bold(
displayUserTag(user)
)} (${user.id}) bot-wide`
);
}
const embed = new SuccessEmbed().setDescription(
`Successfully re-enabled ${code(command.name)} for ${bold(
displayUserTag(user)
)} (${user.id}) bot-wide`
);

await this.send(embed);
await this.reply(embed);
}
}
}
44 changes: 21 additions & 23 deletions src/commands/Admin/Permissions/ChannelDisable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Channel, MessageEmbed } from "discord.js";
import { Channel } from "discord.js";
import {
Permission,
PermissionType,
Expand All @@ -13,6 +13,8 @@ import { code, mentionChannel } from "../../../helpers/discord";
import { Command, Variation } from "../../../lib/command/Command";
import { StringArgument } from "../../../lib/context/arguments/argumentTypes/StringArgument";
import { ChannelArgument } from "../../../lib/context/arguments/argumentTypes/discord/ChannelArgument";
import { SuccessEmbed } from "../../../lib/ui/embeds/SuccessEmbed";
import { EmbedView } from "../../../lib/ui/views/EmbedView";
import { PermissionsChildCommand } from "./PermissionsChildCommand";

const args = {
Expand Down Expand Up @@ -69,25 +71,25 @@ export class ChannelDisable extends PermissionsChildCommand<typeof args> {
guildID: this.requiredGuild.id,
});

let embed: MessageEmbed;

if (
!this.variationWasUsed("channelenable") &&
!this.extract.didMatch("enable")
) {
embed = await this.handleDisable(command, permission, channel);
const embed = await this.handleDisable(command, permission, channel);

await this.reply(embed);
} else {
embed = await this.handleEnable(command, permission, channel);
}
const embed = await this.handleEnable(command, permission, channel);

await this.send(embed);
await this.reply(embed);
}
}

private async handleDisable(
command: Command,
permission: Permission,
channel: Channel
): Promise<MessageEmbed> {
): Promise<EmbedView> {
let deletedAllow = false;

try {
Expand All @@ -110,20 +112,18 @@ export class ChannelDisable extends PermissionsChildCommand<typeof args> {
}
}

return this.newEmbed()
.setAuthor(this.generateEmbedAuthor("Permissions channel disable"))
.setDescription(
`Successfully ${deletedAllow ? "un-allowed" : "disabled"} ${code(
command.name
)} in ${mentionChannel(channel.id)}`
);
return new SuccessEmbed().setDescription(
`Successfully ${deletedAllow ? "un-allowed" : "disabled"} ${code(
command.name
)} in ${mentionChannel(channel.id)}`
);
}

private async handleEnable(
command: Command,
permission: Permission,
channel: Channel
): Promise<MessageEmbed> {
): Promise<EmbedView> {
let allowed = false;

try {
Expand All @@ -147,12 +147,10 @@ export class ChannelDisable extends PermissionsChildCommand<typeof args> {
}
}

return this.newEmbed()
.setAuthor(this.generateEmbedAuthor("Permissions channel enable"))
.setDescription(
`Successfully ${allowed ? "allowed" : "enabled"} ${code(
command.name
)} in ${mentionChannel(channel.id)}`
);
return new SuccessEmbed().setDescription(
`Successfully ${allowed ? "allowed" : "enabled"} ${code(
command.name
)} in ${mentionChannel(channel.id)}`
);
}
}
22 changes: 11 additions & 11 deletions src/commands/Admin/Permissions/Disable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { MessageEmbed } from "discord.js";
import {
Permission,
PermissionType,
Expand All @@ -12,6 +11,7 @@ import { ChannelArgument } from "../../../lib/context/arguments/argumentTypes/di
import { DiscordRoleArgument } from "../../../lib/context/arguments/argumentTypes/discord/DiscordRoleArgument";
import { DiscordUserArgument } from "../../../lib/context/arguments/argumentTypes/discord/DiscordUserArgument";
import { ArgumentsMap } from "../../../lib/context/arguments/types";
import { SuccessEmbed } from "../../../lib/ui/embeds/SuccessEmbed";
import { ChannelDisable } from "./ChannelDisable";
import { PermissionsChildCommand } from "./PermissionsChildCommand";
import { RoleDisable } from "./RoleDisable";
Expand Down Expand Up @@ -91,30 +91,30 @@ export class Disable extends PermissionsChildCommand<typeof args> {
guildID: this.requiredGuild.id,
});

let embed: MessageEmbed;

if (!this.variationWasUsed("enable")) {
await this.permissionsService.createPermission(
this.ctx,
command,
permission
);

embed = this.newEmbed()
.setAuthor(this.generateEmbedAuthor("Permissions disable"))
.setDescription(`Successfully disabled ${code(command.name)}`);
const embed = new SuccessEmbed().setDescription(
`Successfully disabled ${code(command.name)} for this server`
);

await this.reply(embed);
} else {
await this.permissionsService.destroyPermission(
this.ctx,
command,
permission
);

embed = this.newEmbed()
.setAuthor(this.generateEmbedAuthor("Permissions enable"))
.setDescription(`Successfully enabled ${code(command.name)}`);
}
const embed = new SuccessEmbed().setDescription(
`Successfully re-enabled ${code(command.name)} for this server`
);

await this.send(embed);
await this.reply(embed);
}
}
}
49 changes: 25 additions & 24 deletions src/commands/Admin/Permissions/Help.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HelpEmbed } from "../../../lib/ui/embeds/HelpEmbed";
import { PermissionsChildCommand } from "./PermissionsChildCommand";

export class Help extends PermissionsChildCommand {
Expand All @@ -12,30 +13,30 @@ export class Help extends PermissionsChildCommand {
async run() {
const prefix = this.prefix;

await this.send(
this.newEmbed()
.setAuthor(this.generateEmbedAuthor("Permissions help"))
.addField(
"Disabling commands",
`You can disable a command by running \`${prefix}disable <commandName>\`.\
This will disable for all non-admin users. To enable it again, run \`${prefix}enable <commandName>\`.`
)
.addField(
"Disabling commands for users",
`You can also set permissions on commands for certain users. Run \`${prefix}userdisable <commandName> @user\` to ban a user from running a command. Use \`${prefix}userenable\` to re-enable it.`
)
.addField(
"Disabling commands for roles",
`It also works for roles. Run \`${prefix}roledisable <commandName> @role\` to ban a role from running a command. Use \`${prefix}roleenable\` to re-enable it.`
)
.addField(
"Disabling commands in channels",
`You can restrict users from running commands in certain channels. Run \`${prefix}channeldisable <commandName> #channel\` to ban a command from being run in a channel. Use \`${prefix}channelenable\` to re-enable it.`
)
.addField(
"Admin priveleges",
`All users with \`ADMINISTRATOR\` priveliges in Discord automatically bypass any permissions checks. This means that if you want to only allow administrators to run a command, you can use the disable command. With \`${prefix}setadminrole\`, you can set a role to behave as if users with that role was an administrator.`
)
const embed = new HelpEmbed().setHeader(`Help with permissions`).addFields(
{
name: "Disabling commands",
value: `You can disable a command by running \`${prefix}disable <commandName>\`.\
This will disable for all non-admin users. To enable it again, run \`${prefix}enable <commandName>\`.`,
},
{
name: "Disabling commands for users",
value: `You can also set permissions on commands for certain users. Run \`${prefix}userdisable <commandName> @user\` to ban a user from running a command. Use \`${prefix}userenable\` to re-enable it.`,
},
{
name: "Disabling commands for roles",
value: `It also works for roles. Run \`${prefix}roledisable <commandName> @role\` to ban a role from running a command. Use \`${prefix}roleenable\` to re-enable it.`,
},
{
name: "Disabling commands in channels",
value: `You can restrict users from running commands in certain channels. Run \`${prefix}channeldisable <commandName> #channel\` to ban a command from being run in a channel. Use \`${prefix}channelenable\` to re-enable it.`,
},
{
name: "Admin priveleges",
value: `All users with \`ADMINISTRATOR\` priveliges in Discord automatically bypass any permissions checks. This means that if you want to only allow administrators to run a command, you can use the disable command. With \`${prefix}setadminrole\`, you can set a role to behave as if users with that role was an administrator.`,
}
);

await this.reply(embed);
}
}
14 changes: 7 additions & 7 deletions src/commands/Admin/Permissions/PermissionsParentCommand.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { CommandGroup } from "../../../lib/command/CommandGroup";
import { AdminBaseParentCommand } from "../AdminBaseCommand";
import { UserDisable } from "./UserDisable";
import { Help } from "./Help";
import { View } from "./View";
import { Disable } from "./Disable";
import { ChannelDisable } from "./ChannelDisable";
import { SetAdminRole } from "./SetAdminRole";
import { RoleDisable } from "./RoleDisable";
import { BotDisable } from "./BotDisable";
import { BotwideUserDisable } from "./BotwideUserDisable";
import { ChannelDisable } from "./ChannelDisable";
import { Disable } from "./Disable";
import { Help } from "./Help";
import { RoleDisable } from "./RoleDisable";
import { SetAdminRole } from "./SetAdminRole";
import { SyncGuildPermissions } from "./SyncGuildPermissions";
import { UserDisable } from "./UserDisable";
import { View } from "./View";

export default class PermissionsParentCommand extends AdminBaseParentCommand {
idSeed = "loona vivi";
Expand Down
Loading

0 comments on commit 3d4e9a3

Please sign in to comment.