Feature/66 add different commands per server #122

Merged
Vylpes merged 4 commits from feature/66-add-different-commands-per-server into develop 2022-04-09 14:11:06 +01:00
3 changed files with 113 additions and 0 deletions
Showing only changes of commit 5c00601e16 - Show all commits

View file

@ -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();
}
}

View file

@ -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**.`);
}
}

View file

@ -1,4 +1,6 @@
import { CoreClient } from "./client/client"; import { CoreClient } from "./client/client";
// Command Imports
import About from "./commands/about"; import About from "./commands/about";
import Ban from "./commands/ban"; import Ban from "./commands/ban";
import Clear from "./commands/clear"; import Clear from "./commands/clear";
@ -15,6 +17,12 @@ import Rules from "./commands/rules";
import Setup from "./commands/setup"; import Setup from "./commands/setup";
import Unmute from "./commands/unmute"; import Unmute from "./commands/unmute";
import Warn from "./commands/warn"; 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 MemberEvents from "./events/MemberEvents";
import MessageEvents from "./events/MessageEvents"; import MessageEvents from "./events/MessageEvents";
@ -36,6 +44,10 @@ export default class Registry {
client.RegisterCommand("config", new Config()); client.RegisterCommand("config", new Config());
client.RegisterCommand("code", new Code()); client.RegisterCommand("code", new Code());
client.RegisterCommand("disable", new Disable()); 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) { public static RegisterEvents(client: CoreClient) {