v3.0 (#145)
* Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
This commit is contained in:
parent
1168898e57
commit
04a4a6204c
118 changed files with 13966 additions and 4027 deletions
59
src/helpers/SettingsHelper.ts
Normal file
59
src/helpers/SettingsHelper.ts
Normal file
|
@ -0,0 +1,59 @@
|
|||
import DefaultValues from "../constants/DefaultValues";
|
||||
import Server from "../entity/Server";
|
||||
import Setting from "../entity/Setting";
|
||||
|
||||
export default class SettingsHelper {
|
||||
public static async GetSetting(key: string, serverId: string): Promise<string | undefined> {
|
||||
const server = await Server.FetchOneById(Server, serverId, [
|
||||
"Settings"
|
||||
]);
|
||||
|
||||
if (!server) {
|
||||
return DefaultValues.GetValue(key);
|
||||
}
|
||||
|
||||
const setting = server.Settings.filter(x => x.Key == key)[0];
|
||||
|
||||
if (!setting) {
|
||||
return DefaultValues.GetValue(key);
|
||||
}
|
||||
|
||||
return setting.Value;
|
||||
}
|
||||
|
||||
public static async SetSetting(key: string, serverId: string, value: string): Promise<void> {
|
||||
const server = await Server.FetchOneById(Server, serverId, [
|
||||
"Settings"
|
||||
]);
|
||||
|
||||
if (!server) {
|
||||
return;
|
||||
}
|
||||
|
||||
const setting = server.Settings.filter(x => x.Key == key)[0];
|
||||
|
||||
if (setting) {
|
||||
setting.UpdateBasicDetails(key, value);
|
||||
|
||||
await setting.Save(Setting, setting);
|
||||
} else {
|
||||
const newSetting = new Setting(key, value);
|
||||
|
||||
await newSetting.Save(Setting, newSetting);
|
||||
|
||||
server.AddSettingToServer(newSetting);
|
||||
|
||||
await server.Save(Server, server);
|
||||
}
|
||||
}
|
||||
|
||||
public static async GetServerPrefix(serverId: string): Promise<string> {
|
||||
const setting = await this.GetSetting("bot.prefix", serverId);
|
||||
|
||||
if (!setting) {
|
||||
return "v!";
|
||||
}
|
||||
|
||||
return setting;
|
||||
}
|
||||
}
|
38
src/helpers/StringTools.ts
Normal file
38
src/helpers/StringTools.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
export default class StringTools {
|
||||
public static Capitalise(str: string): string {
|
||||
const words = str.split(" ");
|
||||
let result: string[] = [];
|
||||
|
||||
words.forEach(word => {
|
||||
const firstLetter = word.substring(0, 1).toUpperCase();
|
||||
const rest = word.substring(1);
|
||||
|
||||
result.push(firstLetter + rest);
|
||||
});
|
||||
|
||||
return result.join(" ");
|
||||
}
|
||||
|
||||
public static CapitaliseArray(str: string[]): string[] {
|
||||
const res: string[] = [];
|
||||
|
||||
str.forEach(s => {
|
||||
res.push(StringTools.Capitalise(s));
|
||||
});
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static RandomString(length: number) {
|
||||
let result = "";
|
||||
|
||||
const characters = 'abcdefghkmnpqrstuvwxyz23456789';
|
||||
const charactersLength = characters.length;
|
||||
|
||||
for ( var i = 0; i < length; i++ ) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
19
src/helpers/embeds/ErrorEmbed.ts
Normal file
19
src/helpers/embeds/ErrorEmbed.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { MessageEmbed } from "discord.js";
|
||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
||||
|
||||
export default class ErrorEmbed extends MessageEmbed {
|
||||
public context: ICommandContext;
|
||||
|
||||
constructor(context: ICommandContext, message: string) {
|
||||
super();
|
||||
|
||||
super.setColor(0xd52803);
|
||||
super.setDescription(message);
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public SendToCurrentChannel() {
|
||||
this.context.message.channel.send({ embeds: [ this ]});
|
||||
}
|
||||
}
|
72
src/helpers/embeds/EventEmbed.ts
Normal file
72
src/helpers/embeds/EventEmbed.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
import { MessageEmbed, TextChannel, User, Guild } from "discord.js";
|
||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
||||
import SettingsHelper from "../SettingsHelper";
|
||||
|
||||
export default class EventEmbed extends MessageEmbed {
|
||||
public guild: Guild;
|
||||
|
||||
constructor(guild: Guild, title: string) {
|
||||
super();
|
||||
|
||||
super.setColor(0x3050ba);
|
||||
super.setTitle(title);
|
||||
|
||||
this.guild = guild;
|
||||
}
|
||||
|
||||
// Detail methods
|
||||
public AddUser(title: string, user: User, setThumbnail: boolean = false) {
|
||||
this.addField(title, `${user} \`${user.tag}\``, true);
|
||||
|
||||
if (setThumbnail) {
|
||||
this.setThumbnail(user.displayAvatarURL());
|
||||
}
|
||||
}
|
||||
|
||||
public AddReason(message: string) {
|
||||
this.addField("Reason", message || "*none*");
|
||||
}
|
||||
|
||||
// Send methods
|
||||
public SendToChannel(name: string) {
|
||||
const channel = this.guild.channels.cache
|
||||
.find(channel => channel.name == name) as TextChannel;
|
||||
|
||||
if (!channel) {
|
||||
console.error(`Unable to find channel ${name}`);
|
||||
return;
|
||||
}
|
||||
|
||||
channel.send({embeds: [ this ]});
|
||||
}
|
||||
|
||||
public async SendToMessageLogsChannel() {
|
||||
const channelName = await SettingsHelper.GetSetting("channels.logs.message", this.guild.id);
|
||||
|
||||
if (!channelName) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.SendToChannel(channelName);
|
||||
}
|
||||
|
||||
public async SendToMemberLogsChannel() {
|
||||
const channelName = await SettingsHelper.GetSetting("channels.logs.member", this.guild.id);
|
||||
|
||||
if (!channelName) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.SendToChannel(channelName);
|
||||
}
|
||||
|
||||
public async SendToModLogsChannel() {
|
||||
const channelName = await SettingsHelper.GetSetting("channels.logs.mod", this.guild.id);
|
||||
|
||||
if (!channelName) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.SendToChannel(channelName);
|
||||
}
|
||||
}
|
79
src/helpers/embeds/LogEmbed.ts
Normal file
79
src/helpers/embeds/LogEmbed.ts
Normal file
|
@ -0,0 +1,79 @@
|
|||
import { MessageEmbed, TextChannel, User } from "discord.js";
|
||||
import ErrorMessages from "../../constants/ErrorMessages";
|
||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
||||
import SettingsHelper from "../SettingsHelper";
|
||||
import ErrorEmbed from "./ErrorEmbed";
|
||||
|
||||
export default class LogEmbed extends MessageEmbed {
|
||||
public context: ICommandContext;
|
||||
|
||||
constructor(context: ICommandContext, title: string) {
|
||||
super();
|
||||
|
||||
super.setColor(0x3050ba);
|
||||
super.setTitle(title);
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
// Detail methods
|
||||
public AddUser(title: string, user: User, setThumbnail: boolean = false) {
|
||||
this.addField(title, `${user} \`${user.tag}\``, true);
|
||||
|
||||
if (setThumbnail) {
|
||||
this.setThumbnail(user.displayAvatarURL());
|
||||
}
|
||||
}
|
||||
|
||||
public AddReason(message: string) {
|
||||
this.addField("Reason", message || "*none*");
|
||||
}
|
||||
|
||||
// Send methods
|
||||
public SendToCurrentChannel() {
|
||||
this.context.message.channel.send({ embeds: [ this ]});
|
||||
}
|
||||
|
||||
public SendToChannel(name: string) {
|
||||
const channel = this.context.message.guild?.channels.cache
|
||||
.find(channel => channel.name == name) as TextChannel;
|
||||
|
||||
if (!channel) {
|
||||
const errorEmbed = new ErrorEmbed(this.context, ErrorMessages.ChannelNotFound);
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
return;
|
||||
}
|
||||
|
||||
channel.send({ embeds: [ this ]});
|
||||
}
|
||||
|
||||
public async SendToMessageLogsChannel() {
|
||||
const channelName = await SettingsHelper.GetSetting("channels.logs.message", this.context.message.guild?.id!);
|
||||
|
||||
if (!channelName) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.SendToChannel(channelName);
|
||||
}
|
||||
|
||||
public async SendToMemberLogsChannel() {
|
||||
const channelName = await SettingsHelper.GetSetting("channels.logs.member", this.context.message.guild?.id!);
|
||||
|
||||
if (!channelName) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.SendToChannel(channelName);
|
||||
}
|
||||
|
||||
public async SendToModLogsChannel() {
|
||||
const channelName = await SettingsHelper.GetSetting("channels.logs.mod", this.context.message.guild?.id!);
|
||||
|
||||
if (!channelName) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.SendToChannel(channelName);
|
||||
}
|
||||
}
|
26
src/helpers/embeds/PublicEmbed.ts
Normal file
26
src/helpers/embeds/PublicEmbed.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { MessageEmbed } from "discord.js";
|
||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
||||
|
||||
export default class PublicEmbed extends MessageEmbed {
|
||||
public context: ICommandContext;
|
||||
|
||||
constructor(context: ICommandContext, title: string, description: string) {
|
||||
super();
|
||||
|
||||
super.setColor(0x3050ba);
|
||||
super.setTitle(title);
|
||||
super.setDescription(description);
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
// Detail methods
|
||||
public AddReason(message: string) {
|
||||
this.addField("Reason", message || "*none*");
|
||||
}
|
||||
|
||||
// Send methods
|
||||
public SendToCurrentChannel() {
|
||||
this.context.message.channel.send({ embeds: [ this ]});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue