From 5c00601e16b001343303f631ea1b5fcea99a6cf0 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 2 Apr 2022 18:34:15 +0100 Subject: [PATCH] Add MankBot server-exclusive commands --- src/commands/501231711271780357/entry.ts | 25 ++++++++ src/commands/501231711271780357/lobby.ts | 76 ++++++++++++++++++++++++ src/registry.ts | 12 ++++ 3 files changed, 113 insertions(+) create mode 100644 src/commands/501231711271780357/entry.ts create mode 100644 src/commands/501231711271780357/lobby.ts diff --git a/src/commands/501231711271780357/entry.ts b/src/commands/501231711271780357/entry.ts new file mode 100644 index 0000000..f70f9d3 --- /dev/null +++ b/src/commands/501231711271780357/entry.ts @@ -0,0 +1,25 @@ +import { ICommandContext } from "../../contracts/ICommandContext"; +import PublicEmbed from "../../helpers/embeds/PublicEmbed"; +import SettingsHelper from "../../helpers/SettingsHelper"; +import { Command } from "../../type/command"; + +export default class Entry extends Command { + constructor() { + super(); + + super._category = "Moderation"; + super._roles = [ + "moderator" + ]; + } + + public override async execute(context: ICommandContext) { + if (!context.message.guild) return; + + const rulesChannelId = await SettingsHelper.GetSetting("channels.rules", context.message.guild.id) || "rules"; + + const embedInfo = new PublicEmbed(context, "", `Welcome to the server! Please make sure to read the rules in the <#${rulesChannelId}> channel and type the code found there in here to proceed to the main part of the server.`); + + embedInfo.SendToCurrentChannel(); + } +} \ No newline at end of file diff --git a/src/commands/501231711271780357/lobby.ts b/src/commands/501231711271780357/lobby.ts new file mode 100644 index 0000000..960d611 --- /dev/null +++ b/src/commands/501231711271780357/lobby.ts @@ -0,0 +1,76 @@ +import { TextChannel } from "discord.js"; +import { SOURCE_MAPPING_PREFIX } from "ts-jest"; +import { ICommandContext } from "../../contracts/ICommandContext"; +import ErrorEmbed from "../../helpers/embeds/ErrorEmbed"; +import SettingsHelper from "../../helpers/SettingsHelper"; +import { Command } from "../../type/command"; + +export default class Lobby extends Command { + constructor() { + super(); + + super._category = "General"; + } + + public override async execute(context: ICommandContext) { + if (!context.message.guild) return; + + const channel = context.message.channel as TextChannel; + const channelName = channel.name; + const channelId = channel.id; + + // TODO: Check if channel is enabled for this + + const timeUsed = await SettingsHelper.GetSetting(`commands.lobby.channel.${channelId}.time`, context.message.guild.id); + + if (!timeUsed) { + await this.RequestLobby(context, channelId, context.message.guild.id); + return; + } + + const timeNow = Date.now(); + const timeCooldown = await SettingsHelper.GetSetting('commands.lobby.cooldown', context.message.guild.id) || "30"; + const timeLength = parseInt(timeCooldown) * 60 * 1000; // x minutes in ms + const timeAgo = timeNow - timeLength; + + // If it was less than x minutes ago + if (parseInt(timeUsed) > timeAgo) { + this.SendOnCooldown(context, timeLength, timeNow, parseInt(timeUsed)); + return; + } + + await this.RequestLobby(context, channelId, context.message.guild.id); + } + + private async RequestLobby(context: ICommandContext, channelId: string, serverId: string) { + const roleId = await SettingsHelper.GetSetting(`commands.lobby.channel.${channelId}.role`, serverId); + + if (!roleId) { + const errorEmbed = new ErrorEmbed(context, "Unable to find the channel's role"); + errorEmbed.setFooter(`commands.lobby.channel.${channelId}.role`); + + errorEmbed.SendToCurrentChannel(); + return; + } + + const gameName = await SettingsHelper.GetSetting(`commands.lobby.channel.${channelId}.game`, serverId); + + if (!gameName) { + const errorEmbed = new ErrorEmbed(context, "Unable to find the channel's game name"); + errorEmbed.setFooter(`commands.lobby.channel.${channelId}.game`); + + errorEmbed.SendToCurrentChannel(); + return; + } + + await SettingsHelper.SetSetting(`commands.lobby.channel.${channelId}.time`, serverId, `${Date.now()}`); + + context.message.channel.send(`${context.message.author} would like to organise a lobby of **${gameName}**! <@&${roleId}>`); + } + + private SendOnCooldown(context: ICommandContext, timeLength: number, timeNow: number, timeUsed: number) { + const timeLeft = Math.ceil((timeLength - (timeNow - timeUsed)) / 1000 / 60); + + context.message.reply(`Requesting a lobby for this game is on cooldown! Please try again in **${timeLeft} minutes**.`); + } +} \ No newline at end of file diff --git a/src/registry.ts b/src/registry.ts index d80fa6c..d7c64e3 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -1,4 +1,6 @@ import { CoreClient } from "./client/client"; + +// Command Imports import About from "./commands/about"; import Ban from "./commands/ban"; import Clear from "./commands/clear"; @@ -15,6 +17,12 @@ import Rules from "./commands/rules"; import Setup from "./commands/setup"; import Unmute from "./commands/unmute"; import Warn from "./commands/warn"; + +// Command Imports: MankBot +import Entry from "./commands/501231711271780357/entry"; +import Lobby from "./commands/501231711271780357/lobby"; + +// Event Imports import MemberEvents from "./events/MemberEvents"; import MessageEvents from "./events/MessageEvents"; @@ -36,6 +44,10 @@ export default class Registry { client.RegisterCommand("config", new Config()); client.RegisterCommand("code", new Code()); client.RegisterCommand("disable", new Disable()); + + // Exclusive Commands: MankBot + client.RegisterCommand("lobby", new Lobby(), "501231711271780357"); + client.RegisterCommand("entry", new Entry(), "501231711271780357"); } public static RegisterEvents(client: CoreClient) {