Fix DS restrictions

This commit is contained in:
MSWS
2023-04-12 15:30:52 -07:00
parent edfb9928d5
commit efa90e9591
9 changed files with 48 additions and 30 deletions

View File

@@ -50,15 +50,15 @@
100
],
"tierRequirements": {
"create": "SILVER",
"join": "NONE",
"rename": "GOLD",
"lock": "PLATINUM",
"create": "Silver",
"join": "None",
"rename": "Gold",
"lock": "Platinum",
"list": {
"WHITELIST": "SILVER",
"BLACKLIST": "SILVER",
"MUTE": "GOLD",
"GAG": "PLATINUM"
"WHITELIST": "Silver",
"BLACKLIST": "Silver",
"MUTE": "Gold",
"GAG": "Platinum"
}
}
},

View File

@@ -1 +1 @@
{"voice-channels":{"219601562048135168":{"size":0,"hidden":false,"whitelist":[],"blacklist":[],"muted":[],"gagged":[],"mode":"Public","user":"219601562048135168","channelName":"Col Kid Only","id":"1095828256747425832"}}}
{"voice-channels":{"219601562048135168":{"size":99,"hidden":true,"whitelist":[],"blacklist":[],"muted":[],"gagged":[],"mode":"Public","user":"219601562048135168","channelName":"My Cool Channel!","id":"1095838069820772483"}}}

View File

@@ -55,7 +55,7 @@ export class Bot implements DSBot {
this.log(Severity.ERROR, `I ran into an API error: ${error.name}\n${error.message}\n${error.stack}`);
});
process.on("unhandledRejection", (error, p) => {
process.on("unhandledRejection", (error) => {
console.error(error);
this.log(Severity.ERROR, `I ran into a process error: ${(error as any).stack}`);
});

View File

@@ -42,10 +42,7 @@ export const Lang = {
UNKNOWN: "Unknown list type. Please contact a developer.",
CLEARED: (list?: ListType) => ({ content: `Cleared the ${Lang.LISTS.ASNOUN(list)}` })
},
DS: {
MINIMUM_TIER: (tier: DSTier) => ({ content: `You must be a ${tier} to use this command/feature.`, ephemeral: true }),
FOOBAR: ""
},
DS: { MINIMUM_TIER: (tier: DSTier) => ({ content: `You must be a ${tier} Dedicated Supporter to use this command/feature.`, ephemeral: true }) },
VOICE: {
NO_CHANNEL: (user?: User | string) =>
({ content: `${user ? (Lang.USER(user) + " does") : "You do"} not have a voice channel.` }),

View File

@@ -4,6 +4,7 @@ import { Module } from "../api/Module";
import { GuildedConfigEntry } from "../api/data/Config";
import { PermissionBuilder, PermissionsManager } from "./PermissionsManager";
import { Severity } from "../data/configs/Logs";
import { Lang } from "../api/Lang";
export class DSVoice extends Module {
name = "DSVoice";
@@ -48,11 +49,24 @@ export class DSVoice extends Module {
if (!config || !config.enabled)
return;
if (newState.channelId === oldState.channelId)
if (newState.channelId === oldState.channelId || !newState.member)
return;
if (newState.channelId && newState.channelId === config.joinChannel)
const maul = this.main.maul;
const tier = (await maul?.getPlayer(newState.member.id))?.dsInfo?.tier ?? 0;
if (newState.channelId && newState.channelId === config.joinChannel) {
const minTier = Object.values(DSTier).indexOf(config.tierRequirements.create);
if (minTier > tier) {
newState.member.send(Lang.DS.MINIMUM_TIER(config.tierRequirements.create)).catch(() =>
newState.channel?.send(`${newState.member?.toString()},
you must be a ${config.tierRequirements.create} Dedicated Supporter to create VCs.`)
);
newState.setChannel(null);
return;
}
this.createNewChannel(newState);
}
if (oldState.channelId && oldState.member) {
const guildConfig = this.data[oldState.guild.id];
@@ -264,11 +278,11 @@ export interface DSVoiceConfigEntry {
}
export enum DSTier {
NONE = 0,
SILVER,
GOLD,
PLATINUM,
ROYAL
NONE = "None",
SILVER = "Silver",
GOLD = "Gold",
PLATINUM = "Platinum",
ROYAL = "Royal"
}
export class VoiceChannelConfig implements GuildedConfigEntry<Record<string, VoiceChannelEntry>> {

View File

@@ -1,7 +1,7 @@
import { CommandInteraction, SlashCommandSubcommandBuilder } from "discord.js";
import { SubCommand } from "../../../api/data/Command";
import { DSBot } from "../../../api/DSBot";
import { DSVoice, VoiceChannelMode } from "../../DSVoice";
import { DSTier, DSVoice, VoiceChannelMode } from "../../DSVoice";
import { Lang } from "../../../api/Lang";
export class HideCommand extends SubCommand {
@@ -32,7 +32,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)) {
if (Object.values(DSTier).indexOf(requiredTier) > (maulInfo?.dsInfo?.tier ?? 0)) {
interaction.reply(Lang.DS.MINIMUM_TIER(requiredTier));
return false;
}

View File

@@ -1,7 +1,7 @@
import { CommandInteraction, EmbedBuilder, SlashCommandSubcommandBuilder } from "discord.js";
import { SubCommand } from "../../../api/data/Command";
import { DSBot } from "../../../api/DSBot";
import { DSVoice, VoiceChannelEntry } from "../../DSVoice";
import { DSTier, DSVoice, VoiceChannelEntry } from "../../DSVoice";
import { Lang } from "../../../api/Lang";
export class InfoCommand extends SubCommand {
@@ -43,11 +43,11 @@ export class InfoCommand extends SubCommand {
return false;
}
interaction.reply({ embeds: [this.generateEmbed(data, target.username)] });
interaction.reply({ embeds: [await this.generateEmbed(data, target.username)] });
return true;
}
generateEmbed(data: VoiceChannelEntry, name?: string) {
async generateEmbed(data: VoiceChannelEntry, name?: string): Promise<EmbedBuilder> {
const embed = new EmbedBuilder()
.setTitle(`${name ?? data.user}'${(name ?? data.user).toLowerCase().endsWith("s") ? "" : "s"} DS Voice Channel`);
let description = "";
@@ -76,6 +76,13 @@ export class InfoCommand extends SubCommand {
{ name: "Size", value: `${data.size}`, inline: true }
]);
const maul = this.main.maul;
if (!maul)
return embed;
const info = await maul.getPlayer(data.user);
if (!info)
return embed;
embed.addFields([{ name: "Tier", value: Object.values(DSTier)[info.dsInfo?.tier ?? 0] }]);
return embed;
}

View File

@@ -1,7 +1,7 @@
import { CommandInteraction, SlashCommandSubcommandBuilder } from "discord.js";
import { SubCommand } from "../../../api/data/Command";
import { DSBot } from "../../../api/DSBot";
import { DSVoice } from "../../DSVoice";
import { DSTier, DSVoice } from "../../DSVoice";
import { Lang } from "../../../api/Lang";
export class RenameCommand extends SubCommand {
@@ -35,7 +35,7 @@ export class RenameCommand extends SubCommand {
const maulInfo = await this.main.maul?.getPlayer(interaction.user.id);
const requiredTier = dsVoice.configs[interaction.guildId].value.tierRequirements.rename;
if (requiredTier > (maulInfo?.dsInfo?.tier ?? 0)) {
if (Object.values(DSTier).indexOf(requiredTier) > (maulInfo?.dsInfo?.tier ?? 0)) {
interaction.reply(Lang.DS.MINIMUM_TIER(requiredTier));
return false;
}

View File

@@ -1,7 +1,7 @@
import { CommandInteraction, SlashCommandSubcommandBuilder } from "discord.js";
import { SubCommand } from "../../../api/data/Command";
import { DSBot } from "../../../api/DSBot";
import { DSVoice } from "../../DSVoice";
import { DSTier, DSVoice } from "../../DSVoice";
import { Lang } from "../../../api/Lang";
export class ResizeCommand extends SubCommand {
@@ -43,7 +43,7 @@ export class ResizeCommand extends SubCommand {
const maulInfo = await this.main.maul?.getPlayer(interaction.user.id);
const requiredTier = dsVoice.configs[interaction.guildId].value.tierRequirements.create;
const maxSize = dsVoice.configs[interaction.guildId].value.maxSizes[maulInfo?.dsInfo?.tier ?? 0];
if (requiredTier > (maulInfo?.dsInfo?.tier ?? 0)) {
if (Object.values(DSTier).indexOf(requiredTier) > (maulInfo?.dsInfo?.tier ?? 0)) {
interaction.reply(Lang.DS.MINIMUM_TIER(requiredTier));
return false;
}