Cleanup, remove comments, etc.

This commit is contained in:
MSWS
2023-04-12 12:35:29 -07:00
parent cc0efa7c7b
commit 83c9bae7d6
7 changed files with 13 additions and 76 deletions

View File

@@ -1 +1 @@
{"voice-channels":{"219601562048135168":{"size":0,"hidden":false,"whitelist":["161928064614400001"],"blacklist":[],"muted":[],"gagged":[],"mode":"Public","user":"219601562048135168","channelName":"MSWS' Channel","id":"1095580583712800798"}}}
{"voice-channels":{"219601562048135168":{"size":0,"hidden":false,"whitelist":[],"blacklist":[],"muted":["265749200468180992"],"gagged":["228251456162103306"],"mode":"Public","user":"219601562048135168","channelName":"Asdf","id":"1095748688921493614"}}}

View File

@@ -5,6 +5,7 @@ export const Lang = {
GUILD_ONLY: { content: "This command must be used in a guild.", ephemeral: true },
NO_PERMISSIONS: { content: "You do not have permission to use this command.", ephemeral: true },
COMMAND_DISABLED: { content: "This command is disabled.", ephemeral: true },
UNKNOWN_COMMAND: {content: "Unknown command. Please contact a developer." },
LISTS: {
USER_ALREADY_IN_LIST: (user: User, type?: ListType) =>
({ content: `${user.toString()} is already on the ${Lang.LISTS.ASNOUN(type)}.`, ephemeral: true }),
@@ -51,7 +52,8 @@ export const Lang = {
RENAMED: (name: string) => (`Renamed channel to \`${name}\`.`),
MAX_SIZE: (size: number) => ({ content: `You can only resize to a max of ${size}.`, ephemeral: true }),
RESIZED: (size: number) => ({ content: `Resized channel to ${size} slots.`, ephemeral: true }),
HIDDEN_HINT: { content: "Your channel is now public, but still hidden. To make it visible to those who can access it, use `/voice hide`.", ephemeral: true },
HIDDEN_HINT: { content: "Your channel is now public, but still hidden. To change who can see it, use `/voice hide`.", ephemeral: true },
PUBLIC_HINT: { content: "Your channel is now hidden, but still public. To change who can access, use `/voice setmode`.", ephemeral: true },
SET_MODE: (mode: VoiceChannelMode) => ({ content: `Set voice channel to ${mode}.`, ephemeral: true })
},
USER: (user: User | string) => ((user instanceof User) ? user.toString() : `<@${user}>`),

View File

@@ -55,7 +55,6 @@ export class FileConfig implements BotConfig {
if (!entry)
return Promise.reject(`Config entry not found: ${id}`);
console.log(`Setting config value: ${entry.name} = ${JSON.stringify(value)}`);
entry.value = value;
return Promise.resolve();

View File

@@ -152,7 +152,6 @@ export class DSVoice extends Module {
}
async enforcePermissions(channel: VoiceChannelEntry, guild: string) {
console.log(`Enforcing lists for ${channel.id} in ${guild}...`);
if (!channel.id)
return;
const guildChannel =
@@ -169,12 +168,10 @@ export class DSVoice extends Module {
if (!permManager)
throw new Error("No perm manager");
console.log(`Enforcing mode ${channel.mode} for ${channel.id} in ${guild}...`);
const perms = new PermissionBuilder(guildChannel.guild);
const flags: PermissionResolvable[] = ["ViewChannel", "Connect", "Speak", "UseVAD"];
if (!channel.hidden)
flags.push("ViewChannel");
const muted: PermissionResolvable[] = ["Speak"];
const gagged: PermissionResolvable[] = ["SendMessages", "SendMessagesInThreads", "SendTTSMessages"];
const all = PermissionsBitField.All;
switch (channel.mode) {
case VoiceChannelMode.PUBLIC:
@@ -194,7 +191,8 @@ export class DSVoice extends Module {
default:
throw new Error("Invalid mode: " + channel.mode);
}
perms.blockAccess(["Speak", "SendMessages", "SendMessagesInThreads"], ...channel.muted);
perms.blockAccess(muted, ...channel.muted);
perms.blockAccess(gagged, ...channel.gagged);
if (!channel.hidden)
perms.grantAccess(["ViewChannel"], "@everyone");
perms.grantAccess(flags, channel.user, ...leRoles);

View File

@@ -28,66 +28,6 @@ export class PermissionsManager extends Module {
async applyPermissions(perms: OverwriteResolvable[], channel: GuildChannel) {
channel.permissionOverwrites.set(perms);
}
// async grantAccess(channel: GuildChannel | string, flags = new PermissionsBitField("Connect"), ...members: string[]) {
// if (typeof channel === "string") {
// channel = this.main.client.channels.cache.get(channel) as GuildChannel;
// if (!channel)
// throw new Error("Channel not found");
// }
// flags.add("ViewChannel");
// this.processRoleList(channel, members);
// console.log(`Granting ${flags.bitfield} to ${members.join(", ")}`);
// const permWrites: OverwriteData[] = [];
// for (const member of members) {
// if (channel.guild.roles.cache.has(member)) {
// permWrites.push({
// id: member,
// allow: flags,
// type: OverwriteType.Role
// });
// } else {
// permWrites.push({
// id: member,
// allow: flags,
// type: OverwriteType.Member
// });
// }
// }
// await channel.permissionOverwrites.set(permWrites);
// }
// async blockAccess(channel: GuildChannel | string, flags = new PermissionsBitField("Connect"), ...members: string[]) {
// if (typeof channel === "string") {
// channel = this.main.client.channels.cache.get(channel) as GuildChannel;
// if (!channel)
// throw new Error("Channel not found");
// }
// processRoleList(channel.guild, members);
// console.log(`Revoking ${flags.bitfield} to ${members.join(", ")}`);
// const permWrites: OverwriteResolvable[] = [];
// for (const member of members) {
// if (channel.guild.roles.cache.has(member)) {
// permWrites.push({
// id: member,
// deny: flags,
// type: OverwriteType.Role
// });
// } else {
// permWrites.push({
// id: member,
// deny: flags,
// type: OverwriteType.Member
// });
// }
// }
// await channel.permissionOverwrites.set(permWrites);
// }
}
export class PermissionsConfig implements GuildedConfigEntry<PermissionsEntry> {

View File

@@ -8,6 +8,7 @@ import { InfoCommand } from "./voice/InfoCommand";
import { RenameCommand } from "./voice/RenameCommand";
import { ResizeCommand } from "./voice/ResizeCommand";
import { SetModeCommand } from "./voice/SetModeCommand";
import { Lang } from "../../api/Lang";
export class VoiceCommand extends Command {
name = "voice";
@@ -39,14 +40,12 @@ export class VoiceCommand extends Command {
async handleCommand(interaction: CommandInteraction): Promise<boolean> {
if (!(interaction instanceof ChatInputCommandInteraction)) {
interaction.reply({ content: "This command can only be used in a server!", ephemeral: true });
interaction.reply(Lang.GUILD_ONLY);
return false;
}
const sub = this.subCommands.get(interaction.options.getSubcommandGroup(false) ?? interaction.options.getSubcommand(true));
if (!sub) {
interaction.reply({ content: "Unknown sub-command.", ephemeral: true });
interaction.reply(Lang.UNKNOWN_COMMAND);
return false;
}

View File

@@ -33,8 +33,7 @@ export class HideCommand extends SubCommand {
const maulInfo = await this.main.maul?.getPlayer(interaction.user.id);
const requiredTier = dsVoice.configs[interaction.guildId].value.tierRequirements.hide;
if (requiredTier > (maulInfo?.dsInfo?.tier ?? 0)) {
interaction.reply({ content: `You must be tier ${requiredTier} to use this command!`, ephemeral: true });
interaction.reply(Lang.DS.MINIMUM_TIER(requiredTier));
return false;
}
@@ -53,7 +52,7 @@ export class HideCommand extends SubCommand {
dsVoice.updateUserChannel(userData, interaction.guildId);
await interaction.reply({ content: `${userData.hidden ? "Hid" : "Revealed"} channel.`, ephemeral: true });
if (userData.hidden && userData.mode === VoiceChannelMode.PUBLIC)
interaction.followUp({ content: "Your channel is now hidden, but still public. To make it private, use `/voice setmode`.", ephemeral: true });
interaction.followUp(Lang.VOICE.PUBLIC_HINT);
return true;
}