Compare commits

..

No commits in common. "main" and "v2.1.3" have entirely different histories.
main ... v2.1.3

160 changed files with 3312 additions and 20797 deletions

View file

@ -1,11 +0,0 @@
node_modules/
tests/
coverage/
.github/
.gitlab/
.env.template
.gitlab-ci.yml
jest.config.js
jest.setup.js
README.md

View file

@ -1,72 +0,0 @@
---
kind: pipeline
name: deployment
steps:
- name: deploy
image: appleboy/drone-ssh
settings:
host: 192.168.1.115
username: vylpes
password:
from_secret: ssh_password
port: 22
script:
- sh /home/vylpes/scripts/vylbot/deploy_prod.sh
trigger:
event:
- tag
---
kind: pipeline
name: staging
steps:
- name: stage
image: appleboy/drone-ssh
settings:
host: 192.168.1.115
username: vylpes
password:
from_secret: ssh_password
port: 22
script:
- sh /home/vylpes/scripts/vylbot/deploy_stage.sh
trigger:
branch:
- develop
event:
- push
---
kind: pipeline
name: integration
steps:
- name: build
image: node
commands:
- yarn install --frozen-lockfile
- yarn build
# - name: test
# image: node
# commands:
# - yarn install --frozen-lockfile
# - yarn test
trigger:
branch:
- main
- develop
- hotfix/*
- feature/*
- renovate/*
event:
- push
- pull_request

View file

@ -1,26 +0,0 @@
# Security Warning! Do not commit this file to any VCS!
# This is a local file to speed up development process,
# so you don't have to change your environment variables.
#
# This is not applied to `.env.template`!
# Template files must be committed to the VCS, but must not contain
# any secret values.
BOT_TOKEN=
BOT_VER=3.2.1
BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816
BOT_CLIENTID=682942374040961060
ABOUT_FUNDING=https://ko-fi.com/vylpes
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app
CACHE_INTERVAL=1800000 # 30 minutes
DB_HOST=127.0.0.1
DB_PORT=3101
DB_NAME=vylbot
DB_AUTH_USER=dev
DB_AUTH_PASS=dev
DB_SYNC=true
DB_LOGGING=true

49
.eslintrc Normal file
View file

@ -0,0 +1,49 @@
{
"parserOptions": {
"ecmaVersion": 6
},
"extends": [
"eslint:recommended"
],
"rules": {
"camelcase": "error",
"brace-style": [
"error",
"1tbs"
],
"comma-dangle": [
"error",
"never"
],
"comma-spacing": [
"error",
{
"before": false,
"after": true
}
],
"comma-style": [
"error",
"last"
],
"arrow-body-style": [
"error",
"as-needed"
],
"arrow-parens": [
"error",
"as-needed"
],
"arrow-spacing": "error",
"no-var": "error",
"prefer-template": "error",
"prefer-const": "error"
},
"globals": {
"exports": "writable",
"module": "writable",
"require": "writable",
"process": "writable",
"console": "writable"
}
}

View file

@ -1,67 +0,0 @@
name: Deploy To Production
on:
push:
branches:
- main
jobs:
build:
environment: prod
runs-on: node
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 18.x
- run: npm ci
- run: npm run build
- run: npm test
- name: "Copy files over to location"
run: cp -r . ${{ secrets.PROD_REPO_PATH }}
deploy:
environment: prod
needs: build
runs-on: node
steps:
- uses: https://github.com/appleboy/ssh-action@v1.0.0
env:
DB_NAME: ${{ secrets.PROD_DB_NAME }}
DB_AUTH_USER: ${{ secrets.PROD_DB_AUTH_USER }}
DB_AUTH_PASS: ${{ secrets.PROD_DB_AUTH_PASS }}
DB_HOST: ${{ secrets.PROD_DB_HOST }}
DB_PORT: ${{ secrets.PROD_DB_PORT }}
DB_ROOT_HOST: ${{ secrets.PROD_DB_ROOT_HOST }}
DB_SYNC: ${{ secrets.PROD_DB_SYNC }}
DB_LOGGING: ${{ secrets.PROD_DB_LOGGING }}
DB_DATA_LOCATION: ${{ secrets.PROD_DB_DATA_LOCATION }}
SERVER_PATH: ${{ secrets.PROD_SSH_SERVER_PATH }}
BOT_TOKEN: ${{ secrets.PROD_BOT_TOKEN }}
BOT_VER: ${{ vars.PROD_BOT_VER }}
BOT_AUTHOR: ${{ vars.PROD_BOT_AUTHOR }}
BOT_OWNERID: ${{ vars.PROD_BOT_OWNERID }}
BOT_CLIENTID: ${{ vars.PROD_BOT_CLIENTID }}
ABOUT_FUNDING: ${{ vars.PROD_ABOUT_FUNDING }}
ABOUT_REPO: ${{ vars.PROD_ABOUT_REPO }}
CACHE_INTERVAL: ${{ vars.PROD_CACHE_INTERVAL }}
with:
host: ${{ secrets.PROD_SSH_HOST }}
username: ${{ secrets.PROD_SSH_USER }}
key: ${{ secrets.PROD_SSH_KEY }}
port: ${{ secrets.PROD_SSH_PORT }}
envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO,CACHE_INTERVAL
script: |
source .sshrc \
&& cd /home/vylpes/apps/vylbot/vylbot_prod \
&& docker compose down \
&& (pm2 stop vylbot_prod || true) \
&& (pm2 delete vylbot_prod || true) \
&& docker compose up -d \
&& sleep 10 \
&& npm run db:up \
&& pm2 start --name vylbot_prod dist/vylbot.js

View file

@ -1,67 +0,0 @@
name: Deploy To Stage
on:
push:
branches:
- develop
jobs:
build:
environment: prod
runs-on: node
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 18.x
- run: npm ci
- run: npm run build
- run: npm test
- name: "Copy files over to location"
run: cp -r . ${{ secrets.STAGE_REPO_PATH }}
deploy:
environment: prod
needs: build
runs-on: node
steps:
- uses: https://github.com/appleboy/ssh-action@v1.0.0
env:
DB_NAME: ${{ secrets.STAGE_DB_NAME }}
DB_AUTH_USER: ${{ secrets.STAGE_DB_AUTH_USER }}
DB_AUTH_PASS: ${{ secrets.STAGE_DB_AUTH_PASS }}
DB_HOST: ${{ secrets.STAGE_DB_HOST }}
DB_PORT: ${{ secrets.STAGE_DB_PORT }}
DB_ROOT_HOST: ${{ secrets.STAGE_DB_ROOT_HOST }}
DB_SYNC: ${{ secrets.STAGE_DB_SYNC }}
DB_LOGGING: ${{ secrets.STAGE_DB_LOGGING }}
DB_DATA_LOCATION: ${{ secrets.STAGE_DB_DATA_LOCATION }}
SERVER_PATH: ${{ secrets.STAGE_SSH_SERVER_PATH }}
BOT_TOKEN: ${{ secrets.STAGE_BOT_TOKEN }}
BOT_VER: ${{ vars.STAGE_BOT_VER }}
BOT_AUTHOR: ${{ vars.STAGE_BOT_AUTHOR }}
BOT_OWNERID: ${{ vars.STAGE_BOT_OWNERID }}
BOT_CLIENTID: ${{ vars.STAGE_BOT_CLIENTID }}
ABOUT_FUNDING: ${{ vars.STAGE_ABOUT_FUNDING }}
ABOUT_REPO: ${{ vars.STAGE_ABOUT_REPO }}
CACHE_INTERVAL: ${{ vars.STAGE_CACHE_INTERVAL }}
with:
host: ${{ secrets.STAGE_SSH_HOST }}
username: ${{ secrets.STAGE_SSH_USER }}
key: ${{ secrets.STAGE_SSH_KEY }}
port: ${{ secrets.STAGE_SSH_PORT }}
envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO,CACHE_INTERVAL
script: |
source .sshrc \
&& cd /home/vylpes/apps/vylbot/vylbot_stage \
&& docker compose down \
&& (pm2 stop vylbot_stage || true) \
&& (pm2 delete vylbot_stage || true) \
&& docker compose up -d \
&& sleep 10 \
&& npm run db:up \
&& pm2 start --name vylbot_stage dist/vylbot.js

View file

@ -1,24 +0,0 @@
name: Test
on:
push:
branches:
- feature/*
- hotfix/*
- renovate/*
jobs:
build:
environment: stage
runs-on: node
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 18.x
- run: npm ci
- run: npm run build
- run: npm test

View file

@ -1,18 +0,0 @@
Epic: \
Story Points:
---
*No description*
## Acceptance Criteria
*No acceptance criteria*
## Subtasks
*No subtasks*
## Notes
*No notes*

4
.gitignore vendored
View file

@ -103,6 +103,4 @@ dist
# TernJS port file # TernJS port file
.tern-port .tern-port
config.json config.json
.DS_Store
ormconfig.json

0
.gitlab/.gitkeep Normal file
View file

View file

View file

@ -8,14 +8,14 @@ Fixes # (issue)
Please delete options that are not relevant. Please delete options that are not relevant.
- [ ] Bug fix (non-breaking change which fixes an issue) - Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality) - New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update - This change requires a documentation update
# How Has This Been Tested? # How Has This Been Tested?
Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
# Checklist # Checklist
@ -24,6 +24,6 @@ Please describe the tests that you ran to verify the changes. Provide instructio
- [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation - [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings - [ ] My changes generate no new warnings
- [ ] I have added tests that provide my fix is effective or that my feature works - [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes - [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules - [ ] Any dependant changes have been merged and published in downstream modules

21
LICENSE
View file

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2023 Vylpes
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,6 +1,6 @@
# VylBot App # VylBot App
Discord bot for Vylpes' Den Discord Server. Discord bot for Vylpes' Den Discord Server. Based on [VylBot Core](https://github.com/getgravitysoft/vylbot-core).
## Installation ## Installation
@ -8,48 +8,16 @@ Download the latest version from the [releases page](https://github.com/Vylpes/v
Copy the config template file and fill in the strings. Copy the config template file and fill in the strings.
## Requirements
- NodeJS v16
- Yarn
## Usage ## Usage
Install the dependencies and build the app: Implement the client using something like:
```bash ```js
yarn install const vylbot = require('vylbot-core');
yarn build const config = require('./config.json');
const client = new vylbot.client(config);
client.start();
``` ```
Setup the database (Recommended to use the docker-compose file) See the `docs` folder for more information on how to use vylbot-core
```bash
docker-compose up -d
```
Copy and edit the settings files
```bash
cp .env.template .env
# Edit the .env file
cp ormconfig.json.template ormconfig.json
# Edit the ormconfig.json file
```
> **NOTE:** Make sure you do *not* check in these files! These contain sensitive information and should be treated as private.
Start the bot
```bash
yarn start
```
Alternatively, you can start the bot in development mode using:
```bash
yarn start --dev
```
> Dev mode ensures that the default prefix is different to the production mode, in case you have both running in the same server.

45
commands/about.js Normal file
View file

@ -0,0 +1,45 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class about extends command {
constructor() {
// Set execute method, description, and category
super("about");
super.description = "About the bot";
super.category = "General";
// Set required configs in the config.about json string.
// description: The bot description
// version: The bot version
// author: Bot author
// date: Date of build
super.requiredConfigs = "description";
super.requiredConfigs = "version";
super.requiredConfigs = "core-ver";
super.requiredConfigs = "author";
super.requiredConfigs = "date";
}
// The execution method
about(context) {
// Create an embed containing data about the bot
const embed = new MessageEmbed()
.setTitle("About")
.setColor(embedColor)
.setDescription(context.client.config.about.description)
.addField("Version", context.client.config.about.version, true)
.addField("VylBot Core", context.client.config.about['core-ver'], true)
.addField("Author", context.client.config.about.author)
.addField("Date", context.client.config.about.date);
// Send embed to the channel the command was sent in
context.message.channel.send(embed);
}
}
// Set the about class to be exported
module.exports = about;

93
commands/ban.js Normal file
View file

@ -0,0 +1,93 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class ban extends command {
constructor() {
// Set execution method, description, category, and usage
super("ban");
super.description = "Bans the mentioned user with an optional reason";
super.category = "Moderation";
super.usage = "<@user> [reason]";
// Set required configs in the config.ban json string
super.requiredConfigs = "modrole";
super.requiredCofigs = "logchannel";
}
// Command execution method
ban(context) {
// If the user has the modrole (set in config.ban.modrole)
if (context.message.guild.roles.cache.find(role => role.name == context.client.config.ban.modrole)) {
// Gets the user pinged in the command
const user = context.message.mentions.users.first();
// If the user pinged is a valid user
if (user) {
// Get the guild member object from the pinged user
const member = context.message.guild.member(user);
// If the member object exists, i.e. if they are in the server
if (member) {
// Get the arguments and remove what isn't the reason
const reasonArgs = context.arguments;
reasonArgs.splice(0, 1);
// Join the array into a string
const reason = reasonArgs.join(" ");
// If the guild is available to work with
if (context.message.guild.available) {
// If the bot client is able to ban the member
if (member.bannable) {
// The Message Embed which goes into the bot log
const embedLog = new MessageEmbed()
.setTitle("Member Banned")
.setColor(embedColor)
.addField("User", `${user} \`${user.tag}\``, true)
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
.addField("Reason", reason || "*none*")
.setThumbnail(user.displayAvatarURL);
// The Message Embed which goes into the public channel the message was sent in
const embedPublic = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${user} has been banned`);
// Ban the member and send the embeds into the appropriate channel, then delete the initial message
member.ban({ reason: reason }).then(() => {
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.ban.logchannel).send(embedLog);
context.message.channel.send(embedPublic);
context.message.delete();
}).catch(err => { // If the bot couldn't ban the member, say so and log the error to the console
errorEmbed(context, "An error occurred");
console.log(err);
});
}
}
} else { // If the member object doesn't exist
errorEmbed(context, "User is not in this server");
}
} else { // If the user object doesn't exist
errorEmbed(context, "User does not exist");
}
} else { // If the user doesn't have the mod role
errorEmbed(context, `You require the \`${context.client.config.ban.modrole}\` role to run this command`);
}
}
}
// Post an error embed
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = ban;

36
commands/bunny.js Normal file
View file

@ -0,0 +1,36 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const { randomBunny } = require('random-bunny');
// Command variables
const embedColor = "0x3050ba";
// Command class
class bunny extends command {
constructor() {
// Set run method, description, and category
super("bunny");
super.description = "Gives you a random bunny";
super.category = "Fun";
}
// Run method
bunny(context) {
// Get a random post from r/Rabbits
randomBunny('rabbits', 'hot', (res) => {
// Create an embed containing the random image
const embed = new MessageEmbed()
.setColor(embedColor)
.setTitle(res.title)
.setImage(res.url)
.setURL("https://reddit.com" + res.permalink)
.setFooter(`r/Rabbits · ${res.ups} upvotes`);
// Send the embed
context.message.channel.send(embed);
});
}
}
module.exports = bunny;

58
commands/clear.js Normal file
View file

@ -0,0 +1,58 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class clear extends command {
constructor() {
// Set execute method, description, category, and usage
super("clear");
super.description = "Bulk deletes the chat for up to 100 messages";
super.category = "Moderation";
super.usage = "<amount>";
// Set required configs in the config.clear json string
super.requiredConfigs = "modrole";
super.requiredConfigs = "logchannel";
}
// Execute method
clear(context) {
// If the user has the config.clear.modrole role
if (context.message.member.roles.cache.find(role => role.name == context.client.config.clear.modrole)) {
// If the command specifies a number between 1 and 100
if (context.arguments.length > 0 && context.arguments[0] > 0 && context.arguments[0] < 101) {
// Attempt to bulk delete the amount of messages specified as an argument
context.message.channel.bulkDelete(context.arguments[0]).then(() => {
// Public embed
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${context.arguments[0]} messages were removed`);
// Send the embed into the channel the command was sent in
context.message.channel.send(embed);
}).catch(err => { // If the bot couldn't bulk delete
errorEmbed(context, "An error has occurred");
console.log(err);
});
} else { // If the user didn't give a number valid (between 1 and 100)
errorEmbed(context, "Please specify an amount between 1 and 100");
}
} else { // If the user doesn't have the mod role
errorEmbed(context, `This command requires the \`${context.client.config.clear.modrole}\` role to run`);
}
}
}
// Function to send an error embed
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = clear;

25
commands/eval.js Normal file
View file

@ -0,0 +1,25 @@
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
class evaluate extends command {
constructor() {
super("evaluate");
super.description = "Evaluates an expression";
super.category = "Administration";
super.requiredConfigs = "ownerid";
}
evaluate(context) {
if (context.message.author.id == context.client.config.eval.ownerid) {
const result = eval(context.arguments.join(" "));
const embed = new MessageEmbed()
.setDescription(result)
.setColor(0x3050ba);
context.message.channel.send(embed);
}
}
}
module.exports = evaluate;

150
commands/help.js Normal file
View file

@ -0,0 +1,150 @@
// Required Components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const { readdirSync } = require('fs');
const embedColor = "0x3050ba";
// Command Class
class help extends command {
constructor() {
// Set the execute method, description, category, and example usage
super("help");
super.description = "Gives a list of commands available in the bot";
super.category = "General";
super.usage = "[command]";
}
// Execute method
help(context) {
// Get the list of command folders the bot has been setup to check
const commandFolders = context.client.config.commands;
// Empty arrays for commands
// allCommands: Will contain objects of all commands with their related info
// categories: Will contain strings of all the categories the commands are set to, unique
const allCommands = [];
const categories = [];
// Loop through all the command folders set
// i = folder index
for (let i = 0; i < commandFolders.length; i++) {
// The current folder the bot is looking through
const folder = commandFolders[i];
// Read the directory of the current folder
const contents = readdirSync(`${process.cwd()}/${folder}`);
// Loop through the contents of the folder
// j = file index in folder i
for (let j = 0; j < contents.length; j++) {
// Get command in the current folder to read
const file = require(`${process.cwd()}/${folder}/${contents[j]}`);
// Initialise the command
const obj = new file();
// Data object containing the command information
const data = {
"name": contents[j].replace(".js", ""),
"description": obj.description,
"category": obj.category,
"usage": obj.usage,
"roles": obj.roles
};
// Push the command data to the allCommands Array
allCommands.push(data);
}
}
// Loop through all the commands discovered by the previous loop
for (let i = 0; i < allCommands.length; i++) {
// Get the current command category name, otherwise "none"
const category = allCommands[i].category || "none";
// If the command isn't already set, set it.
// This will then make the categories array be an array of all categories which have been used but only one of each.
if (!categories.includes(category)) categories.push(category);
}
// If an command name has been passed as an argument
// If so, send information about that command
// If not, send the help embed of all commands
if (context.arguments[0]) {
sendCommand(context, allCommands, context.arguments[0]);
} else {
sendAll(context, categories, allCommands);
}
}
}
// Send embed of all commands
// context: The command context json string
// categories: The array of categories found
// allCommands: The array of the commands found
function sendAll(context, categories, allCommands) {
// Embed to be sent
const embed = new MessageEmbed()
.setColor(embedColor)
.setTitle("Commands");
// Loop through each command
for (let i = 0; i < categories.length; i++) {
// The category name of the current one to check
const category = categories[i];
// Empty Array for the next loop to filter out the current category
const commandsFilter = [];
// Loop through allCommands
// If the command is set to the current category being checked, add it to the filter array
for (let j = 0; j < allCommands.length; j++) {
if (allCommands[j].category == category) commandsFilter.push(`\`${allCommands[j].name}\``);
}
// Add a field to the embed which contains the category name and all the commands in that category
embed.addField(category, commandsFilter.join(", "));
}
// Send the embed
context.message.channel.send(embed);
}
// Send information about a specific command
// context: The command context json string
// allCommands: The array of categories found
// name: The command name to check
function sendCommand(context, allCommands, name) {
let command = {};
// Loop through all commands, if the command name is the same as the one we're looking for, select it
for (let i = 0; i < allCommands.length; i++) {
if (allCommands[i].name == name) command = allCommands[i];
}
// If a matching command has been found
if (command.name) {
// Create an embed containing the related information of the command
// The title is the command name but sets the first letter to be capitalised
// If a set of information isn't set, set it to say "none"
const embed = new MessageEmbed()
.setColor(embedColor)
.setTitle(command.name[0].toUpperCase() + command.name.substring(1))
.setDescription(command.description || "*none*")
.addField("Category", command.category || "*none*", true)
.addField("Usage", command.usage || "*none*", true)
.addField("Required Roles", command.roles.join(", ") || "*none*");
// Send the embed
context.message.channel.send(embed);
} else { // If no command has been found, then send an embed which says this
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription("Command does not exist");
context.message.channel.send(embed);
}
}
module.exports = help;

93
commands/kick.js Normal file
View file

@ -0,0 +1,93 @@
// Required Components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class kick extends command {
constructor() {
// Sets the command's run method, description, category, and usage
super("kick");
super.description = "Kicks the mentioned user with an optional reason";
super.category = "Moderation";
super.usage = "<@user> [reason]";
// Sets the required configs for the command
super.requiredConfigs = "modrole";
super.requiredConfigs = "logchannel";
}
// The command's run method
kick(context) {
// Checks if the user has the mod role, set in the config json string
if (context.message.member.roles.cache.find(role => role.name == context.client.config.kick.modrole)) {
// Gets the first user pinged in the command
const user = context.message.mentions.users.first();
// If a user was pinged
if (user) {
// Gets the guild member object of the pinged user
const member = context.message.guild.member(user);
// If the member object exists, i.e if the user is in the server
if (member) {
// Gets the part of the argument array which holds the reason
const reasonArgs = context.arguments;
reasonArgs.splice(0, 1);
// Joins the reason into a string
const reason = reasonArgs.join(" ");
// If the server is available
if (context.message.guild.available) {
// If the bot client can kick the mentioned member
if (member.kickable) {
// The embed to go into the bot log
const embedLog = new MessageEmbed()
.setTitle("Member Kicked")
.setColor(embedColor)
.addField("User", `${user} \`${user.tag}\``, true)
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
.addField("Reason", reason || "*none*")
.setThumbnail(user.displayAvatarURL);
// The embed to go into channel the command was sent in
const embedPublic = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${user} has been kicked`);
// Attemtp to kick the user, if successful send the embeds, if unsuccessful notify the chat and log the error
member.kick({ reason: reason }).then(() => {
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.kick.logchannel).send(embedLog);
context.message.channel.send(embedPublic);
context.message.delete();
}).catch(err => {
errorEmbed(context, "An error has occurred");
console.log(err);
});
} else { // If the user isn't kickable
errorEmbed(context, "I am unable to kick this user");
}
}
} else { // If the member object is invalid
errorEmbed(context, "Please specify a valid user");
}
} else { // If the user object is invalid
errorEmbed(context, "Please specify a valid user");
}
}
}
}
// Function to post an embed in case of an error
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = kick;

98
commands/mute.js Normal file
View file

@ -0,0 +1,98 @@
// Required Components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class mute extends command {
constructor() {
// Set the command's run method, description, category, and usage
super("mute");
super.description = "Mutes the mentioned user with an optional reason";
super.category = "Moderation";
super.usage = "<@user> [reason]";
// Set the required configs for the command
super.requiredConfigs = "modrole";
super.requiredConfigs = "logchannel";
super.requiredConfigs = "muterole";
}
// The command's run method
mute(context) {
// Check if the user has the mod role
if (context.message.member.roles.cache.find(role => role.name == context.client.config.mute.modrole)) {
// Get the user first pinged in the message
const user = context.message.mentions.users.first();
// If the user object exists
if (user) {
// Get the guild member object of the mentioned user
const member = context.message.guild.member(user);
// If the member object exists, i.e. if the user is in the server
if (member) {
// Get the part of the arguments array which contains the reason
const reasonArgs = context.arguments;
reasonArgs.splice(0, 1);
// Join the reason into a string
const reason = reasonArgs.join(" ");
// If the server is available
if (context.message.guild.available) {
// If the bot client can manage the user's roles
if (member.manageable) {
// The embed to go into the bot log
const embedLog = new MessageEmbed()
.setTitle("Member Muted")
.setColor(embedColor)
.addField("User", `${user} \`${user.tag}\``, true)
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
.addField("Reason", reason || "*none*")
.setThumbnail(user.displayAvatarURL);
// The embed to go into the channel the command was sent in
const embedPublic = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${user} has been muted`)
.addField("Reason", reason || "*none*");
// Get the 'Muted' role
const mutedRole = context.message.guild.roles.cache.find(role => role.name == context.client.config.mute.muterole);
// Attempt to mute the user, if successful send the embeds, if not log the error
member.roles.add(mutedRole, reason).then(() => {
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.mute.logchannel).send(embedLog);
context.message.channel.send(embedPublic);
context.message.delete();
}).catch(err => {
errorEmbed(context, "An error occurred");
console.log(err);
});
} else { // If the bot can't manage the user
errorEmbed(context, "I am unable to mute this user");
}
}
} else { // If the member object doesn't exist
errorEmbed(context, "Please specify a valid user");
}
} else { // If the user object doesn't exist
errorEmbed(context, "Please specify a valid user");
}
}
}
}
// Send an embed when an error occurs
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = mute;

60
commands/partner.js Normal file
View file

@ -0,0 +1,60 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const { existsSync, readFileSync } = require('fs');
// Command Variables
const embedColor = "0x3050ba";
// Command class
class partner extends command {
constructor() {
// Set the command's run method, description, and category
super("partner");
super.description = "Generates the embeds for the partner from the partners.json file";
super.category = "Admin";
// Require in the config the name of the admin role and the rules file name
super.requiredConfigs = "adminrole";
super.requiredConfigs = "partnersfile";
}
// Run method
partner(context) {
if (context.message.member.roles.cache.find(role => role.name == context.client.config.partner.adminrole)) {
if (existsSync(context.client.config.partner.partnersfile)) {
const partnerJson = JSON.parse(readFileSync(context.client.config.partner.partnersfile));
for (const i in partnerJson) {
const serverName = partnerJson[i].name;
const serverInvite = partnerJson[i].invite;
const serverDescription = partnerJson[i].description;
const serverIcon = partnerJson[i].icon;
const embed = new MessageEmbed()
.setColor(embedColor)
.setTitle(serverName)
.setDescription(serverDescription)
.setURL(serverInvite)
.setThumbnail(serverIcon);
context.message.channel.send(embed);
}
} else {
const errorEmbed = new MessageEmbed()
.setColor(embedColor)
.setDescription('File does not exist');
context.message.channel.send(errorEmbed);
}
} else {
const errorEmbed = new MessageEmbed()
.setColor(embedColor)
.setDescription('You do not have permission to run this command');
context.message.channel.send(errorEmbed);
}
}
}
module.exports = partner;

150
commands/poll.js Normal file
View file

@ -0,0 +1,150 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const emojiRegex = require('emoji-regex/RGI_Emoji');
// Command variables
const embedColor = "0x3050ba";
// Command class
class poll extends command {
constructor() {
// Set the command's run method, description, category, and example usage
super("poll");
super.description = "Generates a poll with reaction numbers";
super.category = "General";
super.usage = "<title>;<option 1>;<option 2>...";
}
// Run method
poll(context) {
// Get the command's arguments, and split them by a semicolon rather than a space
// This allows the variables to be able to use spaces in them
let args = context.arguments;
const argsJoined = args.join(' ');
args = argsJoined.split(';');
// If the argument has 3 or more arguments and less than 11 arguments
// This allows the title and 2-9 options
if (args.length >= 3 && args.length < 11) {
// Set the title to the first argument
const title = args[0];
let optionString = "";
// Array used to get the numbers as their words
// arrayOfNumbers[n] = "n written in full words"
const arrayOfNumbers = [
':zero:',
':one:',
':two:',
':three:',
':four:',
':five:',
':six:',
':seven:',
':eight:',
':nine:'
];
// Array containing the numbers as their emoji
const reactionEmojis = ["0⃣", "1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣"];
// Loop through all the arguments after the title
// Add them to the optionString, with their index turned into a number emoji
// Example: :one: Option 1
for (let i = 1; i < args.length; i++) {
// If the option contains an emoji, replace the emoji with it
const regex = emojiRegex();
const match = regex.exec(args[i]);
if (match) {
const emoji = match[0];
reactionEmojis[i] = emoji;
arrayOfNumbers[i] = '';
}
optionString += `${arrayOfNumbers[i]} ${args[i]}\n`;
}
// Create the embed with the title at the top of the description with the options below
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(`**${title}**\n\n${optionString}`);
// Send the embed and then react with the numbers for users to react with,
// the bot will determine how many to react with for the amount of options inputted
context.message.channel.send(embed).then(message => {
if (args.length == 2) {
message.react(reactionEmojis[1]);
} else if (args.length == 3) {
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]));
} else if (args.length == 4) {
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]));
} else if (args.length == 5) {
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]))
.then(() => message.react(reactionEmojis[4]));
} else if (args.length == 6) {
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]))
.then(() => message.react(reactionEmojis[4]))
.then(() => message.react(reactionEmojis[5]));
} else if (args.length == 7) {
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]))
.then(() => message.react(reactionEmojis[4]))
.then(() => message.react(reactionEmojis[5]))
.then(() => message.react(reactionEmojis[6]));
} else if (args.length == 8) {
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]))
.then(() => message.react(reactionEmojis[4]))
.then(() => message.react(reactionEmojis[5]))
.then(() => message.react(reactionEmojis[6]))
.then(() => message.react(reactionEmojis[7]));
} else if (args.length == 9) {
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]))
.then(() => message.react(reactionEmojis[4]))
.then(() => message.react(reactionEmojis[5]))
.then(() => message.react(reactionEmojis[6]))
.then(() => message.react(reactionEmojis[7]))
.then(() => message.react(reactionEmojis[8]));
} else if (args.length == 10) {
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]))
.then(() => message.react(reactionEmojis[4]))
.then(() => message.react(reactionEmojis[5]))
.then(() => message.react(reactionEmojis[6]))
.then(() => message.react(reactionEmojis[7]))
.then(() => message.react(reactionEmojis[8]))
.then(() => message.react(reactionEmojis[9]));
}
}).catch(console.error);
// Delete the message
context.message.delete();
} else if (args.length >= 11) { // If the user inputted more than 9 options
const errorEmbed = new MessageEmbed()
.setDescription("The poll command can only accept up to 9 options");
context.message.channel.send(errorEmbed);
} else { // If the user didn't give enough data
const errorEmbed = new MessageEmbed()
.setDescription("Please use the correct usage: <title>;<option 1>;<option 2>... (separate options with semicolons)");
context.message.channel.send(errorEmbed);
}
}
}
module.exports = poll;

105
commands/role.js Normal file
View file

@ -0,0 +1,105 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
// Command variables
const embedColor = "0x3050ba";
// Command class
class role extends command {
constructor() {
// Set the command's run method, description, category, and example usage
super("role");
super.description = "Toggles a role for the user to gain/remove";
super.category = "General";
super.usage = "[name]";
// Require in the config the 'assignable roles' array
super.requiredConfigs = "assignable";
}
// Run method
role(context) {
// Get the array containing the assignable roles
const roles = context.client.config.role.assignable;
let requestedRole = "";
// If the arguments specifys a specific role
if (context.arguments.length > 0) {
// Loop through all the assignable roles and check against the first parameter
// Save the role name if they match, i.e. the role can be assignable
for (let i = 0; i < roles.length; i++) {
if (roles[i].toLowerCase() == context.arguments[0].toLowerCase()) {
requestedRole = roles[i];
}
}
// If a matching assignable role was found
if (requestedRole != "") {
// Get the role object from the server with the role name
const role = context.message.guild.roles.cache.find(r => r.name == requestedRole);
// If the user already has the role, remove the role from them and send an embed
// Otherwise, add the role and send an embed
if (context.message.member.roles.cache.find(r => r.name == requestedRole)) {
context.message.member.roles.remove(role).then(() => {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(`Removed role: ${requestedRole}`);
context.message.channel.send(embed);
}).catch(err => {
console.error(err);
const errorEmbed = new MessageEmbed()
.setColor(embedColor)
.setDescription("An error occured. Please check logs");
context.message.channel.send(errorEmbed);
});
} else { // If the user doesn't have the role
context.message.member.roles.add(role).then(() => {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(`Gave role: ${requestedRole}`);
context.message.channel.send(embed);
}).catch(err => {
console.error(err);
const errorEmbed = new MessageEmbed()
.setColor(embedColor)
.setDescription("An error occured. Please check logs");
context.message.channel.send(errorEmbed);
});
}
} else { // If the role can't be found, send an error embed
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription("This role does not exist, see assignable roles with the role command (no arguments)");
context.message.channel.send(embed);
}
} else { // If no role was specified, Send a list of the roles you can assign
// The start of the embed text
let rolesString = `Do ${context.client.config.prefix}role <role> to get the role!\n`;
// Loop through all the roles, and add them to the embed text
for (let i = 0; i < roles.length; i++) {
rolesString += `${roles[i]}\n`;
}
// Create an embed containing the text
const embed = new MessageEmbed()
.setTitle("Roles")
.setColor(embedColor)
.setDescription(rolesString);
// Send the embed
context.message.channel.send(embed);
}
}
}
module.exports = role;

75
commands/rules.js Normal file
View file

@ -0,0 +1,75 @@
// Required Components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const { existsSync, readFileSync } = require('fs');
// Command variables
const embedColor = "0x3050ba";
// Command class
class rules extends command {
constructor() {
// Set the command's run method, description, and category
super("rules");
super.description = "Generates the rules embeds from the rules.txt file";
super.category = "Admin";
// Require in the config the name of the admin role and the rules file name
super.requiredConfigs = "adminrole";
super.requiredConfigs = "rulesfile";
}
// Run method
rules(context) {
// If the user is an Admin (has the admin role)
if (context.message.member.roles.cache.find(role => role.name == context.client.config.rules.adminrole)) {
// If the rulesfile exists
if (existsSync(context.client.config.rules.rulesfile)) {
// Get the contents of the rules file, and split it by "> "
// Each embed in the rules is set by the "> " syntax
let rulesText = readFileSync(context.client.config.rules.rulesfile).toString();
rulesText = rulesText.split("> ");
// Loop through each embed to be sent
for (let i = 0; i < rulesText.length; i++) {
// If the first line after "> " has a "#", create and embed with an image of the url specified after
if (rulesText[i].charAt(0) == '#') {
const embed = new MessageEmbed()
.setColor(embedColor)
.setImage(rulesText[i].substring(1));
context.message.channel.send(embed);
} else { // If the file doesn't have a "#" at the start
// Split the embed into different lines, set the first line as the title, and the rest as the description
const rulesLines = rulesText[i].split("\n");
const rulesTitle = rulesLines[0];
const rulesDescription = rulesLines.slice(1).join("\n");
// Create the embed with the specified information above
const embed = new MessageEmbed()
.setTitle(rulesTitle)
.setColor(embedColor)
.setDescription(rulesDescription);
// Send the embed
context.message.channel.send(embed);
}
}
} else { // If the rules file doesn't exist
const errorEmbed = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${context.client.config.rules.rulesfile} doesn't exist`);
context.message.channel.send(errorEmbed);
}
} else { // If the user doesn't have the Admin role
const errorEmbed = new MessageEmbed()
.setColor(embedColor)
.setDescription("You do not have permission to run this command");
context.message.channel.send(errorEmbed);
}
}
}
module.exports = rules;

98
commands/unmute.js Normal file
View file

@ -0,0 +1,98 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class unmute extends command {
constructor() {
// Set run method, description, category, usage
super("unmute");
super.description = "Unmutes the mentioned user with an optional reason";
super.category = "Moderation";
super.usage = "<@user> [reason]";
// Set required configs
super.requiredConfigs = "modrole";
super.requiredConfigs = "logchannel";
super.requiredConfigs = "muterole";
}
// The command's run method
unmute(context) {
// Check if the user has the mod role
if (context.message.member.roles.cache.find(role => role.name == context.client.config.mute.modrole)) {
// Get the user first pinged in the message
const user = context.message.mentions.users.first();
// If the user object exists
if (user) {
// Get the guild member object from the pinged user
const member = context.message.guild.member(user);
// If the member object exists, i.e. if the user is in the server
if (member) {
// Get the part of the argument array which contains the reason
const reasonArgs = context.arguments;
reasonArgs.splice(0, 1);
// Join the array into a string
const reason = reasonArgs.join(" ");
// If the server is available
if (context.message.guild.available) {
// If the bot client can manage the user
if (member.manageable) {
// The embed to go into the bot log
const embedLog = new MessageEmbed()
.setColor(embedColor)
.setTitle("Member Unmuted")
.addField("User", `${user} \`${user.tag}\``, true)
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
.addField("Reason", reason || "*none*")
.setThumbnail(user.displayAvatarURL);
// The embed to go into the channel the command was sent in
const embedPublic = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${user} has been unmuted`)
.addField("Reason", reason || "*none*");
// Get the muted role
const mutedRole = context.message.guild.roles.cache.find(role => role.name == context.client.config.unmute.muterole);
// Attempt to remove the role from the user, and then send the embeds. If unsuccessful log the error
member.roles.remove(mutedRole, reason).then(() => {
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.unmute.logchannel).send(embedLog);
context.message.channel.send(embedPublic);
context.message.delete();
}).catch(err => {
errorEmbed(context, "An error occurred");
console.log(err);
});
} else { // If the bot can't manage the user
errorEmbed(context, "I am unable to unmute this user");
}
}
} else { // If the member object doesn't exist
errorEmbed(context, "Please specify a valid user");
}
} else { // If the user object doesn't exist
errorEmbed(context, "Please specify a valid user");
}
}
}
}
// Send an embed in case of an error
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = unmute;

86
commands/warn.js Normal file
View file

@ -0,0 +1,86 @@
// Required Components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class warn extends command {
constructor() {
// Set the run method, description, category, and usage
super("warn");
super.description = "Warns the mentioned user with an optional reason";
super.category = "Moderation";
super.usage = "<@user> [reason]";
// Set the required configs
super.requiredConfigs = "modrole";
super.requiredConfigs = "logchannel";
}
// The command's run method
warn(context) {
// If the user has the mod role
if (context.message.member.roles.cache.find(role => role.name == context.client.config.warn.modrole)) {
// Get the user first pinged in the message
const user = context.message.mentions.users.first();
// If the user object exists
if (user) {
// Get the guild member object from the user
const member = context.message.guild.member(user);
// If the member object exists. i.e. if the user is in the server
if (member) {
// Get the part of the argument array which the reason is in
const reasonArgs = context.arguments;
reasonArgs.splice(0, 1);
// Join the array into a string
const reason = reasonArgs.join(" ");
// If the server is available
if (context.message.guild.available) {
// The embed to go into the bot log
const embedLog = new MessageEmbed()
.setColor(embedColor)
.setTitle("Member Warned")
.addField("User", `${user} \`${user.tag}\``, true)
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
.addField("Reason", reason || "*none*")
.setThumbnail(user.displayAvatarURL);
// The embed to go into the channel the command was sent in
const embedPublic = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${user} has been warned`)
.addField("Reason", reason || "*none*");
// Send the embeds
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.warn.logchannel).send(embedLog);
context.message.channel.send(embedPublic);
context.message.delete();
}
} else { // If the member objest doesn't exist
errorEmbed(context, "Please specify a valid user");
}
} else { // If the user object doesn't exist
errorEmbed(context, "Please specify a valid user");
}
} else { // If the user isn't mod
errorEmbed(context, "You do not have permission to run this command");
}
}
}
// Send an embed in case of an error
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = warn;

61
config.template.json Normal file
View file

@ -0,0 +1,61 @@
{
"token": "",
"prefix": "v!",
"commands": [
"commands"
],
"events": [
"events"
],
"about": {
"description": "Discord Bot for Vylpes' Den",
"version": "2.1.3",
"core-ver": "1.0.4",
"author": "Vylpes",
"date": "22-Jan-22"
},
"ban": {
"modrole": "Moderator",
"logchannel": "mod-logs"
},
"clear": {
"modrole": "Moderator",
"logchannel": "mod-logs"
},
"eval": {
"ownerid": "147392775707426816"
},
"kick": {
"modrole": "Moderator",
"logchannel": "mod-logs"
},
"mute": {
"modrole": "Moderator",
"logchannel": "mod-logs",
"muterole": "Muted"
},
"partner": {
"adminrole": "Admin",
"partnersfile": "data/partner/partner.json"
},
"rules": {
"adminrole": "Admin",
"rulesfile": "data/rules/rules.txt"
},
"unmute": {
"modrole": "Moderator",
"logchannel": "mod-logs",
"muterole": "Muted"
},
"warn": {
"modrole": "Moderator",
"logchannel": "mod-logs"
},
"role": {
"assignable": [
"Notify",
"VotePings",
"ProjectUpdates"
]
}
}

14
data/partner/partner.json Normal file
View file

@ -0,0 +1,14 @@
[
{
"name": "Cuzethstan",
"description": "Cuzeth Server. Yes.",
"invite": "http://discord.gg/uhEFNw7",
"icon": "https://cdn.discordapp.com/icons/720177983016665251/a_e4250e57b26559c6609dfe562774ee27.gif"
},
{
"name": "Boblin",
"description": "Official server of the... Boblin?\n- Multiple Topics\n- Lots of Very Active Members",
"invite": "https://discord.gg/Td4uzVu",
"icon": "https://cdn.discordapp.com/attachments/464708407010787328/487824441846267907/image0.png"
}
]

View file

@ -1,86 +0,0 @@
[
{
"image": "https://i.imgur.com/bjH1gza.png"
},
{
"title": "Vylpes' Den",
"description": [
"Welcome to Vylpes' Den! Make sure to say hi!",
"Invite link: https://go.vylpes.xyz/A6HcA"
]
},
{
"title": "Discord TOS",
"description": [
"All servers are required to follow the Discord Terms of Service. This includes minimum age requirements (13+). If the moderation team discover a breach of TOS we are required by discord to ban. Make sure you know them!",
"https://discord.com/terms"
]
},
{
"title": "Rules",
"description": [
"**English Only**",
"In order for everyone to understand each other we would like to ask everyone to speak in English only.",
"",
"**No NSFW or Obscene Content**",
"This includes text, images, or links featuring nudity, sex, hard violence, or other graphically disturbing content.",
"",
"**Treat Everyone with Respect**",
"Absolutely no harassment, witch hunting, sexism, racism, or hate speech will be tolerated.",
"",
"**No spam or self promotion**",
"Outside of #self-promo. This includes DMing fellow members.",
"",
"**Keep Politics to #general**",
"And make sure it doesn't become too heated. Debate don't argue.",
"",
"**Drama From Other Servers**",
"Please don't bring up drama from other servers, keep that to DMs",
"",
"**Bot Abuse**",
"Don't abuse the bots or you will be blocked from using them",
"",
"**Event Spoilers**",
"Contents of events and keynotes, such as the Nintendo Direct, must be spoken about in events, this rule applies for up to 24 hours after the event ends. Even though we will only enforce talking there for a set time, please be considerate of those who haven't watched the event yet."
]
},
{
"title": "Moderators Discretion",
"description": [
"Don't argue with a mod's decision. A moderator's choice is final. If you have an issue with a member of the mod team DM me (Vylpes#0001)."
]
},
{
"title": "Supporters",
"description": [
"If you are a Twitch Subscriber or a Patreon Member and have linked your profiles to your discord account you will get exclusive access to the Vylpes Plus channels, including early access to videos!"
]
},
{
"title": "Self-Assignable Roles",
"description": [
"If you want to assign yourself roles, go to #bot-stuff and type v!role <role>. The current roles you can get are:",
"Notify: Get pinged when a new stream or video releases.",
"VotePings: Get pinged when I start a new poll",
"ProjectUpdates: Get pinged when I update my projects as well as new for them"
]
},
{
"title": "VylBot",
"description": [
"This server uses a bot made by me, VylBot, to help moderate the server.",
"For more information on it, see the GitHub repositories:",
"https://gitea.vylpes.xyz/rabbitlabs/vylbot-app"
]
},
{
"title": "Links",
"description": [
"YouTube: https://www.youtube.com/@vylpes",
"Patreon: https://www.patreon.com/vylpes",
"Twitch: https://www.twitch.tv/vylpes_",
"Twitter: https://twitter.com/vylpes"
],
"footer": "Last updated 20/06/2023"
}
]

View file

@ -1,12 +0,0 @@
[
{
"title": "Welcome to Mankalor's Discord Server!",
"description": [
"*You must follow Discord's TOS, including the rule where", "you must be 13 years or older.",
"If moderators know you're under 13, we will have to ban you!*",
"",
"You need to input a code in *#entry* which is somewhere in this message before you can start chatting, so read the server rules and info below.",
"If you still don't see the other channels after writing this code, message a moderator. For any issues with this bot, message <@147392775707426816>."
]
}
]

View file

@ -1,70 +0,0 @@
[
{
"title": "Welcome to Mankalor's Discord Server!",
"description": [
"*You must follow Discord's TOS, including the rule where", "you must be 13 years or older.",
"If moderators know you're under 13, we will have to ban you!*",
"",
"You need to input a code in *#entry* which is somewhere in this message before you can start chatting, so read the server rules and info below.",
"If you still don't see the other channels after writing this code, message a moderator. For any issues with this bot, message <@147392775707426816>."
]
},
{
"title": "Server Rules",
"description": [
"1. We allow most things in *#general-off-topic*, but if it pertains to a topic that has a channel, post it in the correct chat.",
"",
"2. No spamming, except in *#bot-craziness* and *#spam* ",
" 2a. Those 'Hacker Warning!!! Copy Paste this to all servers!' messages and other copypastas are considered spam.",
"",
"3. Do not insult or harass anyone for race, religion, gender, gaming skills, social skills, etc.",
" 3a. Some people may be new to Discord or a game. Politely educate, don't belittle.",
"",
"4. Absolutely no NSFW content on this server. (Porn, Rule 34, etc.)",
"",
"5. Swearing is allowed, but certain words such as racial/homophobic/disability slurs or sex terms will still be filtered out. Bypassing this will result in punishment.",
" 5a. Swearing past the point of typical rager is still not allowed.",
" 5b. If you're unsure if a word is allowed, then don't use it.",
"",
"6. Avoid unnecessarily & excessively @ mentioning anyone, even in *#bot-craziness* and *#spam*",
"",
"7. Advertising your own content (videos, channels, servers, etc.) should only go in *#self-promo*",
"",
"8. Do not bring up drama from other places here, keep that to DMs.",
"",
"9. Keep it serious in the venting chats, don't joke around.",
" 9a. To access the vent channels, assign yourself the role from *#self-assign-roles*",
"",
"10. Do not ask to become a moderator.",
"",
"11. Please don't join to ask about how to download hacks, where to find them, etc. Requests will be ignored and if you continue to ask you will be muted.",
" 11a. Watch Mankalor's video on it here: https://www.youtube.com/watch?v=wps_4DBlEyM"
]
},
{
"description": [
"1. You can assign yourself a game role in *#self-assign-roles*. When you want to setup a lobby type m!lobby into the game's channel.",
" 1a. Do not ping a role excessively in a short time. The command's cooldown is 20 minutes.",
" 1b. Only use the ping to set up lobbies. Not for advertising, pointless announcements, etc.",
" 1c. Only give yourself a role if you don't mind Discord pings.",
" 1d. Do not complain about the pings if they're being used correctly. Remove the role, or you will be punished by moderators.",
"",
"2. Only server staff can use @ everyone & @ here.",
"3. If you are a Youtube Sponsor or Twitch Subscriber, you can get the role if you sync your Twitch/Youtube account with your Discord account by going into User Settings > Connections > Twitch/Youtube.",
" 3a. This might not work on mobile.",
" 3b. We cannot assign SponSub roles manually.",
"",
"4. Mankalor will ping @ notificationsquad for new videos and streams in #new-videos-streams. If you want these pings, type `m!role Notification Squad` in #self-assign-roles",
"",
"5. Server link in case you want to invite someone. This link is in the description of my videos, too: https://discord.gg/DQkWVbz",
"",
"Not following these rules will result in a warning, mute, or ban, depending on the severity and number of offenses.",
"",
"If you notice anything wrong, notify the *Server Staff*!",
"",
"Once you've sent the code, go say hi in *#general-off-topic*!",
"",
"**Update 01 Oct 2021:** Added `11.` and `11a.` to rules"
]
}
]

43
data/rules/rules.txt Normal file
View file

@ -0,0 +1,43 @@
> #https://i.imgur.com/bjH1gza.png
> Vylpes' Den
Welcome to Vylpes' Den! Make sure to say hi!
Invite link: https://discord.gg/UyAhAVp
> Discord TOS
All servers are required to follow the Discord Terms of Service. This includes minimum age requirements (13+). If the moderation team discover a breach of TOS we are required by discord to ban. Make sure you follow them! - https://discord.com/terms
> Rules
- **English Only**
In order for everyone to understand each other we would like to ask everyone to speak in English only.
- **No NSFW or Obscene Content**
This includes text, images, or links featuring nudity, sex, hard violence, or other graphically disturbing content.
- **Treat Everyone with Respect**
Absolutely no harassment, witch hunting, sexism, racism, or hate speech will be tolerated.
- **No spam or self promotion**
Outside of #self-promo. This includes DMing fellow members.
- **Keep Politics to #general**
And make sure it doesn't become too heated. Debate don't argue.
- **Drama From Other Servers**
Please don't bring up drama from other servers, keep that to DMs
- **Bot Abuse**
Don't abuse the bots or you will be blocked from using them
> Moderators Discretion
Don't argue with a mod's decision. A moderator's choice is final. If you have an issue with a member of the mod team DM me (Vylpes#0001).
> Supporters
If you are a Twitch Subscriber or a Patreon Member and have linked your profiles to your discord account you will get exclusive access to the Vylpes Plus channels, including early access to videos!
> Self-Assignable Roles
If you want to assign yourself roles, go to #bot-stuff and type v!role <role>. The current roles you can get are:
Notify: Get pinged when a new stream or video releases.
> Links
YouTube: https://www.youtube.com/channel/UCwPlzKwCmP5Q9bCX3fHk2BA
Patreon: https://www.patreon.com/vylpes
Twitch: https://www.twitch.tv/vylpes_
Twitter: https://twitter.com/vylpes
Reddit: https://reddit.com/r/vylpes
Ko-fi: https://ko-fi.com/vylpes

View file

@ -1,36 +0,0 @@
USAGE: <key> <set|reset> [value]
===[ KEYS ]===
bot.prefix: The bot prefix for the server (Default: "v!")
commands.disabled: Disabled commands, separated by commas (Default: "")
role.moderator: The moderator role name (Default: "Moderator")
role.administrator: The administrator role name (Default: "Administrator")
role.muted: The muted role name (Default: "Muted")
rules.file: The location of the rules file (Default: "data/rules/rules")
channels.logs.message: The channel message events will be logged to (Default: "message-logs")
channels.logs.member: The channel member events will be logged to (Default: "member-logs")
channels.logs.mod: The channel mod events will be logged to (Default: "mod-logs")
verification.enabled: Enables/Disables the verification feature (Default: "false")
verification.channel: The channel to listen to for entry codes (Default: "entry")
verification.role: The server access role (Default: "Entry")
verification.code: The entry code for the channel (Default: "")
event.message.delete.enabled: Enables/Disables the message delete log event (Default: "false")
event.message.delete.channel: Sets the channel the bot will log message delete events to (Default: "message-logs")
event.message.update.enabled: Enables/Disables the message delete log event (Default: "false")
event.message.update.channel: Sets the channel the bot will log message delete events to (Default: "message-logs")
event.member.add.enabled: Enables/Disables the member join log event (Default: "false")
event.member.add.channel: Sets the channel the bot will log member join events to (Default: "member-logs")
event.member.remove.enabled: Enables/Disables the member leave log event (Default: "false")
event.member.remove.channel: Sets the channel the bot will log member leave events to (Default: "member-logs")
event.member.update.enabled: Enables/Disables the member update log event (Default: "false")
event.member.update.channel: Sets the channel the bot will log member update events to (Default: "member-logs")

View file

@ -1,8 +0,0 @@
USAGE: config <add|remove> <Channel ID> <Role ID> [cooldown] [Game Name]
===[ EXAMPLE ]===
To add a channel:
- config add 000000000000000000 000000000000000000 30 Game Name
To remove a channel:
- config remove 000000000000000000

View file

@ -1,8 +0,0 @@
USAGE: config <add|remove> <Role ID>
===[ EXAMPLE ]===
To add a role:
- config add 000000000000000000
To remove a role:
- config remove 000000000000000000

View file

@ -1,11 +0,0 @@
CREATE TABLE `audit` (
`Id` varchar(255) NOT NULL,
`WhenCreated` datetime NOT NULL,
`WhenUpdated` datetime NOT NULL,
`AuditId` varchar(255) NOT NULL,
`UserId` varchar(255) NOT NULL,
`AuditType` int NOT NULL,
`Reason` varchar(255) NOT NULL,
`ModeratorId` varchar(255) NOT NULL,
`ServerId` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

View file

@ -1,5 +0,0 @@
CREATE TABLE `ignored_channel` (
`Id` varchar(255) NOT NULL,
`WhenCreated` datetime NOT NULL,
`WhenUpdated` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

View file

@ -1,10 +0,0 @@
CREATE TABLE `lobby` (
`Id` varchar(255) NOT NULL,
`WhenCreated` datetime NOT NULL,
`WhenUpdated` datetime NOT NULL,
`ChannelId` varchar(255) NOT NULL,
`RoleId` varchar(255) NOT NULL,
`Cooldown` int NOT NULL,
`LastUsed` datetime NOT NULL,
`Name` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

View file

@ -1,7 +0,0 @@
CREATE TABLE `role` (
`Id` varchar(255) NOT NULL,
`WhenCreated` datetime NOT NULL,
`WhenUpdated` datetime NOT NULL,
`RoleId` varchar(255) NOT NULL,
`serverId` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

View file

@ -1,5 +0,0 @@
CREATE TABLE `server` (
`Id` varchar(255) NOT NULL,
`WhenCreated` datetime NOT NULL,
`WhenUpdated` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

View file

@ -1,8 +0,0 @@
CREATE TABLE `setting` (
`Id` varchar(255) NOT NULL,
`WhenCreated` datetime NOT NULL,
`WhenUpdated` datetime NOT NULL,
`Key` varchar(255) NOT NULL,
`Value` varchar(255) NOT NULL,
`serverId` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

View file

@ -1,2 +0,0 @@
ALTER TABLE `audit`
ADD PRIMARY KEY (`Id`);

View file

@ -1,2 +0,0 @@
ALTER TABLE `ignored_channel`
ADD PRIMARY KEY (`Id`);

View file

@ -1,2 +0,0 @@
ALTER TABLE `lobby`
ADD PRIMARY KEY (`Id`);

View file

@ -1,3 +0,0 @@
ALTER TABLE `role`
ADD PRIMARY KEY (`Id`),
ADD KEY `FK_d9e438d88cfb64f7f8e1ae593c3` (`serverId`);

View file

@ -1,2 +0,0 @@
ALTER TABLE `server`
ADD PRIMARY KEY (`Id`);

View file

@ -1,3 +0,0 @@
ALTER TABLE `setting`
ADD PRIMARY KEY (`Id`),
ADD KEY `FK_a3623ec541bdb12fa0f58bdfde7` (`serverId`);

View file

@ -1,2 +0,0 @@
ALTER TABLE `role`
ADD CONSTRAINT `FK_d9e438d88cfb64f7f8e1ae593c3` FOREIGN KEY (`serverId`) REFERENCES `server` (`Id`);

View file

@ -1,2 +0,0 @@
ALTER TABLE `setting`
ADD CONSTRAINT `FK_a3623ec541bdb12fa0f58bdfde7` FOREIGN KEY (`serverId`) REFERENCES `server` (`Id`);

View file

@ -1,2 +0,0 @@
ALTER TABLE server
ADD LastCached datetime NOT NULL DEFAULT '2024-03-01 18:10:04';

View file

@ -1,17 +0,0 @@
version: "3.9"
services:
database:
image: mysql/mysql-server
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
- MYSQL_DATABASE=$DB_NAME
- MYSQL_USER=$DB_AUTH_USER
- MYSQL_PASSWORD=$DB_AUTH_PASS
- MYSQL_ROOT_PASSWORD=$DB_AUTH_PASS
- MYSQL_ROOT_HOST=$DB_ROOT_HOST
ports:
- "$DB_PORT:3306"
volumes:
- $DB_DATA_LOCATION:/var/lib/mysql

View file

@ -1,31 +0,0 @@
# Registry
The registry file is what is used to register the bot's commands and events. This is a script which is ran at startup and adds all the commands and events to the bot.
Although you can register these outside of the registry file, this script makes it a centralised place for it to be done at.
## Adding Commands
Commands are added in the `RegisterCommands` function.
The basic syntax is as follows:
```ts
client.RegisterCommand("Name", new Command(), "ServerId");
```
- `"Name"`: The name of the command, will be used by the user to call the command
- `new Command()`: The command class to be executed, must inherit the Command class
- `"ServerId"` (Optional): If given, will only be usable in that specific server
## Adding Events
Events are added in the `RegisterEvents` function.
The basic syntax is as follows:
```ts
client.RegisterEvent(new Events());
```
- `new Events()`: The event class to be executed

32
events/guildMemberAdd.js Normal file
View file

@ -0,0 +1,32 @@
// Required components
const { event } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
// Event variables
const embedColor = "0x3050ba";
const logchannel = "member-logs";
// Event class
class guildmemberadd extends event {
constructor() {
// Set the event's run method
super("guildmemberadd");
}
// Run method
guildmemberadd(member) {
// Create an embed with the user who joined's information
const embed = new MessageEmbed()
.setTitle("Member Joined")
.setColor(embedColor)
.addField("User", `${member} \`${member.user.tag}\``)
.addField("Created", `${member.user.createdAt}`)
.setFooter(`User ID: ${member.user.id}`)
.setThumbnail(member.user.displayAvatarURL({ type: 'png', dynamic: true }));
// Send the embed in the mod's log channel
member.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
}
}
module.exports = guildmemberadd;

View file

@ -0,0 +1,32 @@
// Required components
const { event } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
// Event variables
const embedColor = "0x3050ba";
const logchannel = "member-logs";
// Event class
class guildmemberremove extends event {
constructor() {
// Set the event's run method
super("guildmemberremove");
}
// Run method
guildmemberremove(member) {
// Create an embed with the user's information
const embed = new MessageEmbed()
.setTitle("Member Left")
.setColor(embedColor)
.addField("User", `${member} \`${member.user.tag}\``)
.addField("Joined", `${member.joinedAt}`)
.setFooter(`User ID: ${member.user.id}`)
.setThumbnail(member.user.displayAvatarURL({ type: 'png', dynamic: true }));
// Send the embed in the log channel
member.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
}
}
module.exports = guildmemberremove;

View file

@ -0,0 +1,41 @@
// Required components
const { event } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
// Event variables
const embedColor = "0x3050ba";
const logchannel = "member-logs";
// Event class
class guildmemberupdate extends event {
constructor() {
// Set the event's run method
super("guildmemberupdate");
}
// Run method
guildmemberupdate(oldMember, newMember) {
// If the user's nickname was changed
if (oldMember.nickname != newMember.nickname) {
// Get the user's name with tag, their old nickname and their new nickname
// If they didn't have a nickname or they removed it, set it to "none" in italics
const oldNickname = oldMember.nickname || "*none*";
const newNickname = newMember.nickname || "*none*";
// Create the embed with the user's information
const embed = new MessageEmbed()
.setTitle("Nickname Changed")
.setColor(embedColor)
.addField("User", `${newMember} \`${newMember.user.tag}\``)
.addField("Before", oldNickname, true)
.addField("After", newNickname, true)
.setFooter(`User ID: ${newMember.user.id}`)
.setThumbnail(newMember.user.displayAvatarURL({ type: 'png', dynamic: true }));
// Send the embed in the log channel
newMember.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
}
}
}
module.exports = guildmemberupdate;

32
events/messageDelete.js Normal file
View file

@ -0,0 +1,32 @@
// Required components
const { event } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
// Event variables
const embedColor = "0x3050ba";
const logchannel = "message-logs";
// Event class
class messagedelete extends event {
constructor() {
// The event's run method
super("messagedelete");
}
// Run method
messagedelete(message) {
// Create an embed with the message's information
const embed = new MessageEmbed()
.setTitle("Message Deleted")
.setColor(embedColor)
.addField("User", `${message.author} \`${message.author.tag}\``)
.addField("Channel", message.channel)
.addField("Content", `\`\`\`${message.content || "*none*"}\`\`\``)
.setThumbnail(message.author.displayAvatarURL({ type: 'png', dynamic: true }));
// Send the embed in the logging channel
message.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
}
}
module.exports = messagedelete;

37
events/messageUpdate.js Normal file
View file

@ -0,0 +1,37 @@
// Required components
const { event } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
// Event variables
const embedColor = "0x3050ba";
const logchannel = "message-logs";
// Event class
class messageupdate extends event {
constructor() {
// Set the event's run method
super("messageupdate");
}
// Run method
messageupdate(oldMessage, newMessage) {
// If the user is a bot or the content didn't change, return
if (newMessage.author.bot) return;
if (oldMessage.content == newMessage.content) return;
// Create an embed with the message's information
const embed = new MessageEmbed()
.setTitle("Message Edited")
.setColor(embedColor)
.addField("User", `${newMessage.author} \`${newMessage.author.tag}\``)
.addField("Channel", newMessage.channel)
.addField("Before", `\`\`\`${oldMessage.content || "*none*"}\`\`\``)
.addField("After", `\`\`\`${newMessage.content || "*none*"}\`\`\``)
.setThumbnail(newMessage.author.displayAvatarURL({ type: 'png', dynamic: true }));
// Send the embed into the log channel
newMessage.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
}
}
module.exports = messageupdate;

View file

@ -1,5 +0,0 @@
{
"preset": "ts-jest",
"testEnvironment": "node",
"setupFiles": ["./jest.setup.js"]
}

View file

@ -1,3 +0,0 @@
jest.setTimeout(1 * 1000); // 1 second
jest.resetModules();
jest.resetAllMocks();

9856
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,53 +1,29 @@
{ {
"name": "vylbot-app", "name": "vylbot-app",
"version": "3.2.2", "version": "2.1.1",
"description": "A discord bot made for Vylpes' Den", "description": "",
"main": "./dist/vylbot", "main": "vylbot.js",
"typings": "./dist",
"scripts": { "scripts": {
"clean": "rm -rf node_modules/ dist/", "start": "node vylbot.js",
"build": "tsc", "lint": "eslint .",
"start": "node ./dist/vylbot", "lint:fix": "eslint . --fix"
"test": "echo true",
"db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js",
"db:down": "typeorm migration:revert -d dist/database/dataSources/appDataSource.js",
"db:create": "typeorm migration:create ./src/database/migrations",
"release": "np --no-publish"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/Vylpes/vylbot-app" "url": "git+https://github.com/Vylpes/vylbot-app.git"
}, },
"author": "Vylpes", "author": "Vylpes",
"license": "MIT", "license": "ISC",
"bugs": { "bugs": {
"url": "https://github.com/Vylpes/vylbot-app/issues", "url": "https://github.com/Vylpes/vylbot-app/issues"
"email": "helpdesk@vylpes.com"
}, },
"homepage": "https://github.com/Vylpes/vylbot-app", "homepage": "https://github.com/Vylpes/vylbot-app#readme",
"funding": "https://ko-fi.com/vylpes",
"dependencies": { "dependencies": {
"@discordjs/rest": "^2.0.0", "emoji-regex": "^9.2.0",
"@types/jest": "^29.0.0", "random-bunny": "^1.0.0",
"@types/uuid": "^9.0.0", "vylbot-core": "^1.0.4"
"discord.js": "^14.3.0",
"dotenv": "^16.0.0",
"emoji-regex": "^10.0.0",
"jest": "^29.0.0",
"jest-mock-extended": "^3.0.0",
"minimatch": "9.0.3",
"mysql": "^2.18.1",
"random-bunny": "^2.1.6",
"ts-jest": "^29.0.0",
"typeorm": "0.3.20"
},
"resolutions": {
"**/semver": "^7.5.2",
"**/undici": "^6.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^20.0.0", "eslint": "^7.17.0"
"np": "^10.0.0",
"typescript": "^5.0.0"
} }
} }

View file

@ -1,4 +0,0 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"baseBranches": ["develop"]
}

View file

@ -1,23 +0,0 @@
#! /bin/bash
export PATH="$HOME/.yarn/bin:$PATH"
export PATH="$HOME/.nodeuse/bin:$PATH"
export BOT_TOKEN=$(cat $HOME/scripts/vylbot/prod_key.txt)
cd ~/apps/vylbot/vylbot_prod \
&& git checkout main \
&& git fetch \
&& git pull \
&& docker compose --file docker-compose.prod.yml down \
&& (pm2 stop vylbot_prod || true) \
&& (pm2 delete vylbot_prod || true) \
&& cp .prod.env .env \
&& yarn clean \
&& yarn install --frozen-lockfile \
&& yarn build \
&& docker compose --file docker-compose.prod.yml up -d \
&& echo "Sleeping for 10 seconds to let database load..." \
&& sleep 10 \
&& yarn run db:up \
&& NODE_ENV=production pm2 start --name vylbot_prod dist/vylbot.js

View file

@ -1,23 +0,0 @@
#! /bin/bash
export PATH="$HOME/.yarn/bin:$PATH"
export PATH="$HOME/.nodeuse/bin:$PATH"
export BOT_TOKEN=$(cat $HOME/scripts/vylbot/stage_key.txt)
cd ~/apps/vylbot/vylbot_stage \
&& git checkout develop \
&& git fetch \
&& git pull \
&& docker compose --file docker-compose.stage.yml down \
&& (pm2 stop vylbot_stage || true) \
&& (pm2 delete vylbot_stage || true) \
&& cp .stage.env .env \
&& yarn clean \
&& yarn install --frozen-lockfile \
&& yarn build \
&& docker compose --file docker-compose.stage.yml up -d \
&& echo "Sleeping for 10 seconds to let database load..." \
&& sleep 10 \
&& yarn run db:up \
&& NODE_ENV=production pm2 start --name vylbot_stage dist/vylbot.js

View file

@ -1,42 +0,0 @@
import { ButtonInteraction, CacheType } from "discord.js";
import { ButtonEvent } from "../type/buttonEvent";
import SettingsHelper from "../helpers/SettingsHelper";
export default class Verify extends ButtonEvent {
public override async execute(interaction: ButtonInteraction<CacheType>) {
if (!interaction.guildId || !interaction.guild) return;
const roleName = await SettingsHelper.GetSetting("verification.role", interaction.guildId);
if (!roleName) return;
const role = interaction.guild.roles.cache.find(x => x.name == roleName);
if (!role) {
await interaction.reply({
content: `Unable to find the role, ${roleName}`,
ephemeral: true,
});
return;
}
const member = interaction.guild.members.cache.find(x => x.id == interaction.user.id);
if (!member || !member.manageable) {
await interaction.reply({
content: "Unable to give role to user",
ephemeral: true,
});
return;
}
await member.roles.add(role);
await interaction.reply({
content: "Given role",
ephemeral: true,
});
}
}

View file

@ -1,98 +0,0 @@
import { Client, Partials } from "discord.js";
import * as dotenv from "dotenv";
import { createConnection } from "typeorm";
import { EventType } from "../constants/EventType";
import ICommandItem from "../contracts/ICommandItem";
import IEventItem from "../contracts/IEventItem";
import { Command } from "../type/command";
import { Events } from "./events";
import { Util } from "./util";
import AppDataSource from "../database/dataSources/appDataSource";
import ButtonEventItem from "../contracts/ButtonEventItem";
import { ButtonEvent } from "../type/buttonEvent";
import CacheHelper from "../helpers/CacheHelper";
export class CoreClient extends Client {
private static _commandItems: ICommandItem[];
private static _eventItems: IEventItem[];
private static _buttonEvents: ButtonEventItem[];
private _events: Events;
private _util: Util;
public static get commandItems(): ICommandItem[] {
return this._commandItems;
}
public static get eventItems(): IEventItem[] {
return this._eventItems;
}
public static get buttonEvents(): ButtonEventItem[] {
return this._buttonEvents;
}
constructor(intents: number[], partials: Partials[]) {
super({ intents: intents, partials: partials });
dotenv.config();
CoreClient._commandItems = [];
CoreClient._eventItems = [];
CoreClient._buttonEvents = [];
this._events = new Events();
this._util = new Util();
}
public async start() {
if (!process.env.BOT_TOKEN) {
console.error("BOT_TOKEN is not defined in .env");
return;
}
await AppDataSource.initialize()
.then(() => console.log("Data Source Initialized"))
.catch((err) => console.error("Error Initialising Data Source", err));
super.on("interactionCreate", this._events.onInteractionCreate);
super.on("ready", this._events.onReady);
await super.login(process.env.BOT_TOKEN);
this.guilds.cache.forEach(async (guild) => {
await CacheHelper.UpdateServerCache(guild);
});
this._util.loadEvents(this, CoreClient._eventItems);
this._util.loadSlashCommands(this);
}
public static RegisterCommand(name: string, command: Command, serverId?: string) {
const item: ICommandItem = {
Name: name,
Command: command,
ServerId: serverId,
};
CoreClient._commandItems.push(item);
}
public static RegisterEvent(eventType: EventType, func: Function) {
const item: IEventItem = {
EventType: eventType,
ExecutionFunction: func,
};
CoreClient._eventItems.push(item);
}
public static RegisterButtonEvent(buttonId: string, event: ButtonEvent) {
const item: ButtonEventItem = {
ButtonId: buttonId,
Event: event,
};
CoreClient._buttonEvents.push(item);
}
}

View file

@ -1,22 +0,0 @@
import { Interaction } from "discord.js";
import ChatInputCommand from "./interactionCreate/chatInputCommand";
import Button from "./interactionCreate/button";
export class Events {
public async onInteractionCreate(interaction: Interaction) {
if (!interaction.guildId) return;
if (interaction.isChatInputCommand()) {
ChatInputCommand.onChatInput(interaction);
}
if (interaction.isButton()) {
Button.onButtonClicked(interaction);
}
}
// Emit when bot is logged in and ready to use
public onReady() {
console.log("Ready");
}
}

View file

@ -1,17 +0,0 @@
import { ButtonInteraction } from "discord.js";
import { CoreClient } from "../client";
export default class Button {
public static async onButtonClicked(interaction: ButtonInteraction) {
if (!interaction.isButton) return;
const item = CoreClient.buttonEvents.find(x => x.ButtonId == interaction.customId.split(" ")[0]);
if (!item) {
await interaction.reply("Event not found.");
return;
}
item.Event.execute(interaction);
}
}

View file

@ -1,27 +0,0 @@
import { Interaction } from "discord.js";
import { CoreClient } from "../client";
import ICommandItem from "../../contracts/ICommandItem";
export default class ChatInputCommand {
public static async onChatInput(interaction: Interaction) {
if (!interaction.isChatInputCommand()) return;
const item = CoreClient.commandItems.find(x => x.Name == interaction.commandName && !x.ServerId);
const itemForServer = CoreClient.commandItems.find(x => x.Name == interaction.commandName && x.ServerId == interaction.guildId);
let itemToUse: ICommandItem;
if (!itemForServer) {
if (!item) {
await interaction.reply("Command not found.");
return;
}
itemToUse = item;
} else {
itemToUse = itemForServer;
}
itemToUse.Command.execute(interaction);
}
}

View file

@ -1,95 +0,0 @@
import { Client, REST, Routes, SlashCommandBuilder } from "discord.js";
import { EventType } from "../constants/EventType";
import IEventItem from "../contracts/IEventItem";
import { CoreClient } from "./client";
export class Util {
public loadSlashCommands(client: Client) {
const registeredCommands = CoreClient.commandItems;
const globalCommands = registeredCommands.filter(x => !x.ServerId);
const guildCommands = registeredCommands.filter(x => x.ServerId);
const globalCommandData: SlashCommandBuilder[] = globalCommands
.filter(x => x.Command.CommandBuilder)
.flatMap(x => x.Command.CommandBuilder);
const guildIds: string[] = [];
for (let command of guildCommands) {
if (!guildIds.find(x => x == command.ServerId)) {
guildIds.push(command.ServerId!);
}
}
const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN!);
rest.put(
Routes.applicationCommands(process.env.BOT_CLIENTID!),
{
body: globalCommandData
}
);
for (let guild of guildIds) {
const guildCommandData = guildCommands.filter(x => x.ServerId == guild)
.filter(x => x.Command.CommandBuilder)
.flatMap(x => x.Command.CommandBuilder);
if (!client.guilds.cache.has(guild)) continue;
rest.put(
Routes.applicationGuildCommands(process.env.BOT_CLIENTID!, guild),
{
body: guildCommandData
}
)
}
}
// Load the events
loadEvents(client: Client, events: IEventItem[]) {
events.forEach((e) => {
switch(e.EventType) {
case EventType.ChannelCreate:
client.on('channelCreate', (channel) => e.ExecutionFunction(channel));
break;
case EventType.ChannelDelete:
client.on('channelDelete', (channel) => e.ExecutionFunction(channel));
break;
case EventType.ChannelUpdate:
client.on('channelUpdate', (channel) => e.ExecutionFunction(channel));
break;
case EventType.GuildBanAdd:
client.on('guildBanAdd', (ban) => e.ExecutionFunction(ban));
break;
case EventType.GuildBanRemove:
client.on('guildBanRemove', (ban) => e.ExecutionFunction(ban));
break;
case EventType.GuildCreate:
client.on('guildCreate', (guild) => e.ExecutionFunction(guild));
break;
case EventType.GuildMemberAdd:
client.on('guildMemberAdd', (member) => e.ExecutionFunction(member));
break;
case EventType.GuildMemberRemove:
client.on('guildMemberRemove', (member) => e.ExecutionFunction(member));
break;
case EventType.GuildMemberUpdate:
client.on('guildMemberUpdate', (oldMember, newMember) => e.ExecutionFunction(oldMember, newMember));
break;
case EventType.MessageCreate:
client.on('messageCreate', (message) => e.ExecutionFunction(message));
break;
case EventType.MessageDelete:
client.on('messageDelete', (message) => e.ExecutionFunction(message));
break;
case EventType.MessageUpdate:
client.on('messageUpdate', (oldMessage, newMessage) => e.ExecutionFunction(oldMessage, newMessage));
break;
default:
console.error('Event not implemented.');
}
});
}
}

View file

@ -1,58 +0,0 @@
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { Command } from "../../../type/command";
import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby";
export default class AddRole extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('addlobby')
.setDescription('Add lobby channel')
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
.addChannelOption(option =>
option
.setName('channel')
.setDescription('The channel')
.setRequired(true))
.addRoleOption(option =>
option
.setName('role')
.setDescription('The role to ping on request')
.setRequired(true))
.addNumberOption(option =>
option
.setName('cooldown')
.setDescription('The cooldown in minutes')
.setRequired(true))
.addStringOption(option =>
option
.setName('name')
.setDescription('The game name')
.setRequired(true));
}
public override async execute(interaction: CommandInteraction) {
const channel = interaction.options.get('channel');
const role = interaction.options.get('role');
const cooldown = interaction.options.get('cooldown');
const gameName = interaction.options.get('name');
if (!channel || !channel.channel || !role || !role.role || !cooldown || !cooldown.value || !gameName || !gameName.value) {
await interaction.reply('Fields are required.');
return;
}
const lobby = await eLobby.FetchOneByChannelId(channel.channel.id);
if (lobby) {
await interaction.reply('This channel has already been setup.');
return;
}
const entity = new eLobby(channel.channel.id, role.role.id, cooldown.value as number, gameName.value as string);
await entity.Save(eLobby, entity);
await interaction.reply(`Added \`${channel.name}\` as a new lobby channel with a cooldown of \`${cooldown.value} minutes \` and will ping \`${role.name}\` on use`);
}
}

View file

@ -1,48 +0,0 @@
import { CacheType, CommandInteraction, EmbedBuilder, GuildBasedChannel, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { Command } from "../../../type/command";
import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby";
import EmbedColours from "../../../constants/EmbedColours";
export default class ListLobby extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('listlobby')
.setDescription('Lists all channels set up as lobbies')
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers);
}
public override async execute(interaction: CommandInteraction<CacheType>) {
if (!interaction.guild) {
await interaction.reply('Guild not found.');
return;
}
const channels: eLobby[] = [];
for (let channel of interaction.guild.channels.cache.map(x => x)) {
const lobby = await eLobby.FetchOneByChannelId(channel.id);
if (lobby) {
channels.push(lobby);
}
}
const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Lobbies")
.setDescription(`Channels: ${channels.length}`);
for (let lobby of channels) {
embed.addFields([
{
name: `# ${lobby.Name}`,
value: `Last Used: ${lobby.LastUsed}`
}
]);
}
await interaction.reply({ embeds: [ embed ]});
}
}

View file

@ -1,41 +0,0 @@
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
import { Command } from "../../../type/command";
import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby";
export default class Lobby extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('lobby')
.setDescription('Attempt to organise a lobby');
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.channelId) return;
const lobby = await eLobby.FetchOneByChannelId(interaction.channelId);
if (!lobby) {
await interaction.reply('This channel is disabled from using the lobby command.');
return;
}
const timeNow = Date.now();
const timeLength = lobby.Cooldown * 60 * 1000; // x minutes in ms
const timeAgo = timeNow - timeLength;
// If it was less than x minutes ago
if (lobby.LastUsed.getTime() > timeAgo) {
const timeLeft = Math.ceil((timeLength - (timeNow - lobby.LastUsed.getTime())) / 1000 / 60);
await interaction.reply(`Requesting a lobby for this game is on cooldown! Please try again in **${timeLeft} minutes**.`);
return;
}
lobby.MarkAsUsed();
await lobby.Save(eLobby, lobby);
await interaction.reply(`${interaction.user} would like to organise a lobby of **${lobby.Name}**! <@&${lobby.RoleId}>`);
}
}

View file

@ -1,40 +0,0 @@
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { Command } from "../../../type/command";
import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby";
import BaseEntity from "../../../contracts/BaseEntity";
export default class RemoveLobby extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('removelobby')
.setDescription('Remove a lobby channel')
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
.addChannelOption(option =>
option
.setName('channel')
.setDescription('The channel')
.setRequired(true));
}
public override async execute(interaction: CommandInteraction) {
const channel = interaction.options.get('channel');
if (!channel || !channel.channel) {
await interaction.reply('Channel is required.');
return;
}
const entity = await eLobby.FetchOneByChannelId(channel.channel.id);
if (!entity) {
await interaction.reply('Channel not found.');
return;
}
await BaseEntity.Remove<eLobby>(eLobby, entity);
await interaction.reply(`Removed <#${channel.channel.id}> from the list of lobby channels`);
}
}

View file

@ -1,29 +0,0 @@
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import EmbedColours from "../../constants/EmbedColours";
import SettingsHelper from "../../helpers/SettingsHelper";
import { Command } from "../../type/command";
export default class Entry extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('entry')
.setDescription('Sends the entry embed')
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers);
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.guildId) return;
if (!interaction.channel) return;
const rulesChannelId = await SettingsHelper.GetSetting("channels.rules", interaction.guildId) || "rules";
const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Welcome")
.setDescription(`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.`);
await interaction.channel.send({ embeds: [ embed ]});
}
}

View file

@ -1,54 +0,0 @@
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { Command } from "../../type/command";
import { default as eRole } from "../../database/entities/Role";
import Server from "../../database/entities/Server";
export default class ConfigRole extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('configrole')
.setDescription('Toggle your roles')
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles)
.addRoleOption(option =>
option
.setName('role')
.setDescription('The role name')
.setRequired(true));
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.guildId || !interaction.guild) return;
if (!interaction.member) return;
const role = interaction.options.get('role');
if (!role || !role.role) {
await interaction.reply('Fields are required.');
return;
}
const existingRole = await eRole.FetchOneByRoleId(role.role.id);
if (existingRole) {
await eRole.Remove(eRole, existingRole);
await interaction.reply('Removed role from configuration.');
} else {
const server = await Server.FetchOneById(Server, interaction.guildId);
if (!server) {
await interaction.reply('This server has not been setup.');
return;
}
const newRole = new eRole(role.role.id);
newRole.SetServer(server);
await newRole.Save(eRole, newRole);
await interaction.reply('Added role to configuration.');
}
}
}

View file

@ -1,109 +0,0 @@
import { CommandInteraction, EmbedBuilder, GuildMemberRoleManager, SlashCommandBuilder } from "discord.js";
import { Command } from "../../type/command";
import { default as eRole } from "../../database/entities/Role";
import EmbedColours from "../../constants/EmbedColours";
export default class Role extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('role')
.setDescription('Toggle your roles')
.addSubcommand(subcommand =>
subcommand
.setName('toggle')
.setDescription('Toggle your role')
.addRoleOption(option =>
option
.setName('role')
.setDescription('The role name')
.setRequired(true)))
.addSubcommand(subcommand =>
subcommand
.setName('list')
.setDescription('List togglable roles'));
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.isChatInputCommand()) return;
switch (interaction.options.getSubcommand()) {
case 'toggle':
await this.ToggleRole(interaction);
break;
case 'list':
await this.SendRolesList(interaction);
break;
default:
await interaction.reply('Subcommand not found.');
}
}
private async SendRolesList(interaction: CommandInteraction) {
const roles = await this.GetRolesList(interaction);
const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Roles")
.setDescription(`Roles: ${roles.length}\n\n${roles.join("\n")}`);
await interaction.reply({ embeds: [ embed ]});
}
private async ToggleRole(interaction: CommandInteraction) {
if (!interaction.guild) return;
if (!interaction.member) return;
const roles = await this.GetRolesList(interaction);
const requestedRole = interaction.options.get('role');
if (!requestedRole || !requestedRole.role) {
await interaction.reply('Fields are required.');
return;
}
if (!roles.includes(requestedRole.role.name)) {
await interaction.reply('This role isn\'t marked as assignable.');
return;
}
const roleManager = interaction.member.roles as GuildMemberRoleManager;
const userRole = roleManager.cache.find(x => x.name == requestedRole.role!.name);
const assignRole = interaction.guild.roles.cache.find(x => x.id == requestedRole.role!.id);
if (!assignRole) return;
if (!assignRole.editable) {
await interaction.reply('Insufficient permissions. Please contact a moderator.');
return;
}
if (!userRole) {
await roleManager.add(assignRole);
await interaction.reply(`Gave role: \`${assignRole.name}\``);
} else {
await roleManager.remove(assignRole);
await interaction.reply(`Removed role: \`${assignRole.name}\``);
}
}
private async GetRolesList(interaction: CommandInteraction): Promise<string[]> {
if (!interaction.guildId || !interaction.guild) return [];
const rolesArray = await eRole.FetchAllByServerId(interaction.guildId);
const roles: string[] = [];
for (let i = 0; i < rolesArray.length; i++) {
const serverRole = interaction.guild.roles.cache.find(x => x.id == rolesArray[i].RoleId);
if (serverRole) {
roles.push(serverRole.name);
}
}
return roles;
}
}

View file

@ -1,56 +0,0 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
import EmbedColours from "../constants/EmbedColours";
import { Command } from "../type/command";
export default class About extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('about')
.setDescription('About VylBot');
}
public override async execute(interaction: CommandInteraction) {
const fundingLink = process.env.ABOUT_FUNDING;
const repoLink = process.env.ABOUT_REPO;
const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("About")
.setDescription("Discord Bot made by Vylpes");
embed.addFields([
{
name: "Version",
value: process.env.BOT_VER!,
inline: true,
},
{
name: "Author",
value: process.env.BOT_AUTHOR!,
inline: true,
},
]);
const row = new ActionRowBuilder<ButtonBuilder>();
if (repoLink) {
row.addComponents(
new ButtonBuilder()
.setURL(repoLink)
.setLabel("Repo")
.setStyle(ButtonStyle.Link));
}
if (fundingLink) {
row.addComponents(
new ButtonBuilder()
.setURL(fundingLink)
.setLabel("Funding")
.setStyle(ButtonStyle.Link));
}
await interaction.reply({ embeds: [ embed ], components: row.components.length > 0 ? [ row ] : [] });
}
}

View file

@ -1,212 +0,0 @@
import Audit from "../database/entities/Audit";
import AuditTools from "../helpers/AuditTools";
import { Command } from "../type/command";
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { AuditType } from "../constants/AuditType";
import EmbedColours from "../constants/EmbedColours";
export default class Audits extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName("audits")
.setDescription("View audits of a particular user in the server")
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
.addSubcommand(subcommand =>
subcommand
.setName('user')
.setDescription('View all audits done against a user')
.addUserOption(option =>
option
.setName('target')
.setDescription('The user')
.setRequired(true)))
.addSubcommand(subcommand =>
subcommand
.setName('view')
.setDescription('View a particular audit')
.addStringOption(option =>
option
.setName('auditid')
.setDescription('The audit id in caps')
.setRequired(true)))
.addSubcommand(subcommand =>
subcommand
.setName('clear')
.setDescription('Clears an audit from a user')
.addStringOption(option =>
option
.setName('auditid')
.setDescription('The audit id in caps')
.setRequired(true)))
.addSubcommand(subcommand =>
subcommand
.setName('add')
.setDescription('Manually add an audit')
.addUserOption(option =>
option
.setName('target')
.setDescription('The user')
.setRequired(true))
.addStringOption(option =>
option
.setName('type')
.setDescription('The type of audit')
.setRequired(true)
.addChoices(
{ name: 'General', value: AuditType.General.toString() },
{ name: 'Warn', value: AuditType.Warn.toString() },
{ name: 'Mute', value: AuditType.Mute.toString() },
{ name: 'Kick', value: AuditType.Kick.toString() },
{ name: 'Ban', value: AuditType.Ban.toString() },
)
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason')));
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.isChatInputCommand()) return;
switch (interaction.options.getSubcommand()) {
case "user":
await this.SendAuditForUser(interaction);
break;
case "view":
await this.SendAudit(interaction);
break;
case "clear":
await this.ClearAudit(interaction);
break;
case "add":
await this.AddAudit(interaction);
break;
default:
await interaction.reply("Subcommand doesn't exist.");
}
}
private async SendAuditForUser(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const user = interaction.options.getUser('target');
if (!user) {
await interaction.reply("User not found.");
return;
}
const audits = await Audit.FetchAuditsByUserId(user.id, interaction.guildId);
if (!audits || audits.length == 0) {
await interaction.reply("There are no audits for this user.");
return;
}
const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Audits")
.setDescription(`Audits: ${audits.length}`);
for (let audit of audits) {
embed.addFields([
{
name: `${audit.AuditId} // ${AuditTools.TypeToFriendlyText(audit.AuditType)}`,
value: audit.WhenCreated.toString(),
}
]);
}
await interaction.reply({ embeds: [ embed ]});
}
private async SendAudit(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const auditId = interaction.options.get('auditid');
if (!auditId || !auditId.value) {
await interaction.reply("AuditId not found.");
return;
}
const audit = await Audit.FetchAuditByAuditId(auditId.value.toString().toUpperCase(), interaction.guildId);
if (!audit) {
await interaction.reply("Audit not found.");
return;
}
const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Audit")
.setDescription(audit.AuditId.toUpperCase())
.addFields([
{
name: "Reason",
value: audit.Reason || "*none*",
inline: true,
},
{
name: "Type",
value: AuditTools.TypeToFriendlyText(audit.AuditType),
inline: true,
},
{
name: "Moderator",
value: `<@${audit.ModeratorId}>`,
inline: true,
},
]);
await interaction.reply({ embeds: [ embed ]});
}
private async ClearAudit(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const auditId = interaction.options.get('auditid');
if (!auditId || !auditId.value) {
await interaction.reply("AuditId not found.");
return;
}
const audit = await Audit.FetchAuditByAuditId(auditId.value.toString().toUpperCase(), interaction.guildId);
if (!audit) {
await interaction.reply("Audit not found.");
return;
}
await Audit.Remove(Audit, audit);
await interaction.reply("Audit cleared.");
}
private async AddAudit(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const user = interaction.options.getUser('target');
const auditType = interaction.options.get('type');
const reasonInput = interaction.options.get('reason');
if (!user || !auditType || !auditType.value) {
await interaction.reply("Invalid input.");
return;
}
const type = auditType.value as AuditType;
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "";
const audit = new Audit(user.id, type, reason, interaction.user.id, interaction.guildId);
await audit.Save(Audit, audit);
await interaction.reply(`Created new audit with ID \`${audit.AuditId}\``);
}
}

View file

@ -1,80 +0,0 @@
import { Command } from "../type/command";
import Audit from "../database/entities/Audit";
import { AuditType } from "../constants/AuditType";
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
import EmbedColours from "../constants/EmbedColours";
import SettingsHelper from "../helpers/SettingsHelper";
export default class Ban extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName("ban")
.setDescription("Ban a member from the server with an optional reason")
.setDefaultMemberPermissions(PermissionsBitField.Flags.BanMembers)
.addUserOption(option =>
option
.setName('target')
.setDescription('The user')
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason'));
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.isChatInputCommand()) return;
if (!interaction.guildId) return;
if (!interaction.guild) return;
const targetUser = interaction.options.get('target');
const reasonInput = interaction.options.get('reason');
if (!targetUser || !targetUser.user || !targetUser.member) {
await interaction.reply("User not found.");
return;
}
const member = targetUser.member as GuildMember;
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
const logEmbed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Member Banned")
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
.setThumbnail(targetUser.user.avatarURL())
.addFields([
{
name: "Moderator",
value: `<@${interaction.user.id}>`,
},
{
name: "Reason",
value: reason,
},
]);
if (!member.bannable) {
await interaction.reply('Insufficient permissions. Please contact a moderator.');
return;
}
await member.ban();
await interaction.reply(`\`${targetUser.user.tag}\` has been banned.`);
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
if (!channelName) return;
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
if (channel) {
await channel.send({ embeds: [ logEmbed ]});
}
const audit = new Audit(targetUser.user.id, AuditType.Ban, reason, interaction.user.id, interaction.guildId);
await audit.Save(Audit, audit);
}
}

View file

@ -1,47 +0,0 @@
import { Command } from "../type/command";
import randomBunny from "random-bunny";
import { CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
import EmbedColours from "../constants/EmbedColours";
export default class Bunny extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName("bunny")
.setDescription("Get a random picture of a rabbit.");
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.isChatInputCommand()) return;
await interaction.deferReply();
const subreddits = [
'rabbits',
'bunnieswithhats',
'buncomfortable',
'bunnytongues',
'dutchbunnymafia',
];
const random = Math.floor(Math.random() * subreddits.length);
const selectedSubreddit = subreddits[random];
const result = await randomBunny(selectedSubreddit, 'hot');
if (result.IsSuccess) {
const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle(result.Result!.Title)
.setDescription(result.Result!.Permalink)
.setImage(result.Result!.Url)
.setURL(`https://reddit.com${result.Result!.Permalink}`)
.setFooter({ text: `r/${selectedSubreddit} · ${result.Result!.Ups} upvotes`});
await interaction.editReply({ embeds: [ embed ]});
} else {
await interaction.editReply("There was an error running this command.");
}
}
}

View file

@ -1,43 +0,0 @@
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
import { Command } from "../type/command";
export default class Clear extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName("clear")
.setDescription("Clears the channel of messages")
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages)
.addNumberOption(option =>
option
.setName('count')
.setDescription('The amount to delete')
.setRequired(true)
.setMinValue(1)
.setMaxValue(100));
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.isChatInputCommand()) return;
if (!interaction.channel) return;
const totalToClear = interaction.options.getNumber('count');
if (!totalToClear || totalToClear <= 0 || totalToClear > 100) {
await interaction.reply('Please specify an amount between 1 and 100.');
return;
}
const channel = interaction.channel as TextChannel;
if (!channel.manageable) {
await interaction.reply('Insufficient permissions. Please contact a moderator.');
return;
}
await channel.bulkDelete(totalToClear);
await interaction.reply(`${totalToClear} message(s) were removed.`);
}
}

View file

@ -1,64 +0,0 @@
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import SettingsHelper from "../helpers/SettingsHelper";
import StringTools from "../helpers/StringTools";
import { Command } from "../type/command";
export default class Code extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('code')
.setDescription('Manage the verification code of the server')
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
.addSubcommand(subcommand =>
subcommand
.setName('randomise')
.setDescription('Regenerates the verification code for this server'))
.addSubcommand(subcommand =>
subcommand
.setName('embed')
.setDescription('Sends the embed with the current code to the current channel'));
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.isChatInputCommand()) return;
switch (interaction.options.getSubcommand()) {
case "randomise":
await this.Randomise(interaction);
break;
case "embed":
await this.SendEmbed(interaction);
break;
}
}
private async Randomise(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const randomCode = StringTools.RandomString(5);
await SettingsHelper.SetSetting("verification.code", interaction.guildId, randomCode);
await interaction.reply(`Entry code has been set to \`${randomCode}\``);
}
private async SendEmbed(interaction: CommandInteraction) {
if (!interaction.guildId) return;
if (!interaction.channel) return;
const code = await SettingsHelper.GetSetting("verification.code", interaction.guildId);
if (!code || code == "") {
await interaction.reply("There is no code for this server setup.");
return;
}
const embed = new EmbedBuilder()
.setTitle("Entry Code")
.setDescription(code);
await interaction.channel.send({ embeds: [ embed ]});
}
}

View file

@ -1,200 +0,0 @@
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { readFileSync } from "fs";
import DefaultValues from "../constants/DefaultValues";
import EmbedColours from "../constants/EmbedColours";
import Server from "../database/entities/Server";
import Setting from "../database/entities/Setting";
import { Command } from "../type/command";
export default class Config extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('config')
.setDescription('Configure the current server')
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
.addSubcommand(subcommand =>
subcommand
.setName('reset')
.setDescription('Reset a setting to the default')
.addStringOption(option =>
option
.setName('key')
.setDescription('The key')
.setRequired(true)))
.addSubcommand(subcommand =>
subcommand
.setName('get')
.setDescription('Gets a setting for the server')
.addStringOption(option =>
option
.setName('key')
.setDescription('The key')
.setRequired(true)))
.addSubcommand(subcommand =>
subcommand
.setName('set')
.setDescription('Sets a setting to a specified value')
.addStringOption(option =>
option
.setName('key')
.setDescription('The key')
.setRequired(true))
.addStringOption(option =>
option
.setName('value')
.setDescription('The value')
.setRequired(true)))
.addSubcommand(subcommand =>
subcommand
.setName('list')
.setDescription('Lists all settings'))
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.isChatInputCommand()) return;
if (!interaction.guildId) return;
const server = await Server.FetchOneById<Server>(Server, interaction.guildId, [
"Settings",
]);
if (!server) {
await interaction.reply('Server not setup. Please use the setup command,');
return;
}
switch (interaction.options.getSubcommand()) {
case 'list':
await this.SendHelpText(interaction);
break;
case 'reset':
await this.ResetValue(interaction);
break;
case 'get':
await this.GetValue(interaction);
break;
case 'set':
await this.SetValue(interaction);
break;
default:
await interaction.reply('Subcommand not found.');
}
}
private async SendHelpText(interaction: CommandInteraction) {
const description = readFileSync(`${process.cwd()}/data/usage/config.txt`).toString();
const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Config")
.setDescription(description);
await interaction.reply({ embeds: [ embed ]});
}
private async GetValue(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const key = interaction.options.get('key');
if (!key || !key.value) {
await interaction.reply('Fields are required.');
return;
}
const server = await Server.FetchOneById<Server>(Server, interaction.guildId, [
"Settings",
]);
if (!server) {
await interaction.reply('Server not found.');
return;
}
const setting = server.Settings.filter(x => x.Key == key.value)[0];
if (setting) {
await interaction.reply(`\`${key.value}\`: \`${setting.Value}\``);
} else {
var defaultValue = DefaultValues.GetValue(key.value.toString());
if (defaultValue) {
await interaction.reply(`\`${key.value}\`: \`${defaultValue}\` <DEFAULT>`);
} else {
await interaction.reply(`\`${key.value}\`: <NONE>`);
}
}
}
private async ResetValue(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const key = interaction.options.get('key');
if (!key || !key.value) {
await interaction.reply('Fields are required.');
return;
}
const server = await Server.FetchOneById<Server>(Server, interaction.guildId, [
"Settings",
]);
if (!server) {
await interaction.reply('Server not found.');
return;
}
const setting = server.Settings.filter(x => x.Key == key.value)[0];
if (!setting) {
await interaction.reply('Setting not found.');
return;
}
await Setting.Remove(Setting, setting);
await interaction.reply('The setting has been reset to the default.');
}
private async SetValue(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const key = interaction.options.get('key');
const value = interaction.options.get('value');
if (!key || !key.value || !value || !value.value) {
await interaction.reply('Fields are required.');
return;
}
const server = await Server.FetchOneById<Server>(Server, interaction.guildId, [
"Settings",
]);
if (!server) {
await interaction.reply('Server not found.');
return;
}
const setting = server.Settings.filter(x => x.Key == key.value)[0];
if (setting) {
setting.UpdateBasicDetails(key.value.toString(), value.value.toString());
await setting.Save(Setting, setting);
} else {
const newSetting = new Setting(key.value.toString(), value.value.toString());
await newSetting.Save(Setting, newSetting);
server.AddSettingToServer(newSetting);
await server.Save(Server, server);
}
await interaction.reply('Setting has been set.');
}
}

View file

@ -1,91 +0,0 @@
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import SettingsHelper from "../helpers/SettingsHelper";
import { Command } from "../type/command";
export default class Disable extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('disable')
.setDescription('Disables a command')
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
.addSubcommand(subcommand =>
subcommand
.setName('add')
.setDescription('Disables a command for the server')
.addStringOption(option =>
option
.setName('name')
.setDescription('The name of the command')
.setRequired(true)))
.addSubcommand(subcommand =>
subcommand
.setName('remove')
.setDescription('Enables a command for the server')
.addStringOption(option =>
option
.setName('name')
.setDescription('The name of the command')
.setRequired(true)));
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.isChatInputCommand()) return;
switch (interaction.options.getSubcommand()) {
case "add":
await this.Add(interaction);
break;
case "remove":
await this.Remove(interaction);
break;
default:
await interaction.reply('Subcommand not found.');
}
}
private async Add(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const commandName = interaction.options.get('name');
if (!commandName || !commandName.value) {
await interaction.reply('Fields are required.');
return;
}
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", interaction.guildId);
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
disabledCommands?.push(commandName.value.toString());
await SettingsHelper.SetSetting("commands.disabled", interaction.guildId, disabledCommands!.join(","));
await interaction.reply(`Disabled command ${commandName.value}`);
}
private async Remove(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const commandName = interaction.options.get('name');
if (!commandName || !commandName.value) {
await interaction.reply('Fields are required.');
return;
}
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", interaction.guildId);
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
const disabledCommandsInstance = disabledCommands?.findIndex(x => x == commandName.value!.toString());
if (disabledCommandsInstance! > -1) {
disabledCommands?.splice(disabledCommandsInstance!, 1);
}
await SettingsHelper.SetSetting("commands.disabled", interaction.guildId, disabledCommands!.join(","));
await interaction.reply(`Enabled command ${commandName.value}`);
}
}

View file

@ -1,39 +0,0 @@
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import IgnoredChannel from "../database/entities/IgnoredChannel";
import { Command } from "../type/command";
export default class Ignore extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('ignore')
.setDescription('Ignore events in this channel')
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const isChannelIgnored = await IgnoredChannel.IsChannelIgnored(interaction.guildId);
if (isChannelIgnored) {
const entity = await IgnoredChannel.FetchOneById(IgnoredChannel, interaction.guildId);
if (!entity) {
await interaction.reply('Unable to find channel.');
return;
}
await IgnoredChannel.Remove(IgnoredChannel, entity);
await interaction.reply('This channel will start being logged again.');
} else {
const entity = new IgnoredChannel(interaction.guildId);
await entity.Save(IgnoredChannel, entity);
await interaction.reply('This channel will now be ignored from logging.');
}
}
}

View file

@ -1,80 +0,0 @@
import { Command } from "../type/command";
import Audit from "../database/entities/Audit";
import { AuditType } from "../constants/AuditType";
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
import EmbedColours from "../constants/EmbedColours";
import SettingsHelper from "../helpers/SettingsHelper";
export default class Kick extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName("kick")
.setDescription("Kick a member from the server with an optional reason")
.setDefaultMemberPermissions(PermissionsBitField.Flags.KickMembers)
.addUserOption(option =>
option
.setName('target')
.setDescription('The user')
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason'));
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.isChatInputCommand()) return;
if (!interaction.guildId) return;
if (!interaction.guild) return;
const targetUser = interaction.options.get('target');
const reasonInput = interaction.options.get('reason');
if (!targetUser || !targetUser.user || !targetUser.member) {
await interaction.reply("User not found.");
return;
}
const member = targetUser.member as GuildMember;
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
const logEmbed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Member Kicked")
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
.setThumbnail(targetUser.user.avatarURL())
.addFields([
{
name: "Moderator",
value: `<@${interaction.user.id}>`,
},
{
name: "Reason",
value: reason,
},
]);
if (!member.kickable) {
await interaction.reply('Insufficient permissions. Please contact a moderator.');
return;
}
await member.kick();
await interaction.reply(`\`${targetUser.user.tag}\` has been kicked.`);
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
if (!channelName) return;
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
if (channel) {
await channel.send({ embeds: [ logEmbed ]});
}
const audit = new Audit(targetUser.user.id, AuditType.Kick, reason, interaction.user.id, interaction.guildId);
await audit.Save(Audit, audit);
}
}

View file

@ -1,93 +0,0 @@
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
import { AuditType } from "../constants/AuditType";
import EmbedColours from "../constants/EmbedColours";
import Audit from "../database/entities/Audit";
import SettingsHelper from "../helpers/SettingsHelper";
import { Command } from "../type/command";
export default class Mute extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName("mute")
.setDescription("(DEPRECATED) Mute a member in the server with an optional reason")
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
.addUserOption(option =>
option
.setName('target')
.setDescription('The user')
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason'));
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.guild || !interaction.guildId) return;
const targetUser = interaction.options.get('target');
const reasonInput = interaction.options.get('reason');
if (!targetUser || !targetUser.user || !targetUser.member) {
await interaction.reply('Fields are required.');
return;
}
const targetMember = targetUser.member as GuildMember;
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
const logEmbed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Member Muted")
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
.setThumbnail(targetUser.user.avatarURL())
.addFields([
{
name: "Moderator",
value: `<@${interaction.user.id}>`,
},
{
name: "Reason",
value: reason,
},
]);
const mutedRoleName = await SettingsHelper.GetSetting('role.muted', interaction.guildId);
if (!mutedRoleName) {
await interaction.reply('Unable to find configuration. Please contact the bot author.');
return;
}
const mutedRole = interaction.guild.roles.cache.find(role => role.name == mutedRoleName);
if (!mutedRole) {
await interaction.reply('Muted role not found.');
return;
}
if (!targetMember.manageable) {
await interaction.reply('Insufficient permissions. Please contact a moderator.');
return;
}
await targetMember.roles.add(mutedRole);
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
if (!channelName) return;
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
if (channel) {
await channel.send({ embeds: [ logEmbed ]});
}
const audit = new Audit(targetUser.user.id, AuditType.Mute, reason, interaction.user.id, interaction.guildId);
await audit.Save(Audit, audit);
await interaction.reply("Please note the mute and unmute commands have been deprecated and will be removed in a future update. Please use timeout instead");
}
}

View file

@ -1,91 +0,0 @@
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
import { Command } from "../type/command";
import { EmbedBuilder } from "@discordjs/builders";
import EmbedColours from "../constants/EmbedColours";
export default class Poll extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('poll')
.setDescription('Run a poll, automatically adding reaction emojis as options')
.addStringOption(option =>
option
.setName('title')
.setDescription('Title of the poll')
.setRequired(true))
.addStringOption(option =>
option
.setName('option1')
.setDescription('Option 1')
.setRequired(true))
.addStringOption(option =>
option
.setName('option2')
.setDescription('Option 2')
.setRequired(true))
.addStringOption(option =>
option
.setName('option3')
.setDescription('Option 3'))
.addStringOption(option =>
option
.setName('option4')
.setDescription('Option 4'))
.addStringOption(option =>
option
.setName('option5')
.setDescription('Option 5'));
}
public override async execute(interaction: CommandInteraction) {
const title = interaction.options.get('title');
const option1 = interaction.options.get('option1');
const option2 = interaction.options.get('option2');
const option3 = interaction.options.get('option3');
const option4 = interaction.options.get('option4');
const option5 = interaction.options.get('option5');
if (!title || !option1 || !option2) return;
const description = [
option1.value as string,
option2.value as string,
option3?.value as string,
option4?.value as string,
option5?.value as string
]
.filter(x => x != null);
const arrayOfNumbers = [
':one:',
':two:',
':three:',
':four:',
':five:',
];
const reactionEmojis = ["1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣"];
description.forEach((value, index) => {
description[index] = `${reactionEmojis[index]} ${description[index]}`;
});
const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle(title.value as string)
.setDescription(description.join('\n'))
.setFooter({
text: `Poll by ${interaction.user.username}`,
iconURL: interaction.user.avatarURL()!,
});
const message = await interaction.reply({ embeds: [ embed ]});
description.forEach(async (value, index) => {
await (await message.fetch()).react(reactionEmojis[index]);
});
}
}

View file

@ -1,121 +0,0 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { existsSync, readFileSync } from "fs";
import EmbedColours from "../constants/EmbedColours";
import { Command } from "../type/command";
import SettingsHelper from "../helpers/SettingsHelper";
interface IRules {
title?: string;
description?: string[];
image?: string;
footer?: string;
}
export default class Rules extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('rules')
.setDescription("Rules-related commands")
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
.addSubcommand(x =>
x
.setName('embeds')
.setDescription('Send the rules embeds for this server'))
.addSubcommand(x =>
x
.setName('access')
.setDescription('Send the server verification embed button'));
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.isChatInputCommand()) return;
switch (interaction.options.getSubcommand()) {
case "embeds":
await this.SendEmbeds(interaction);
break;
case "access":
await this.SendAccessButton(interaction);
break;
default:
await interaction.reply("Subcommand doesn't exist.");
}
}
private async SendEmbeds(interaction: CommandInteraction) {
if (!interaction.guildId) return;
if (!existsSync(`${process.cwd()}/data/rules/${interaction.guildId}.json`)) {
await interaction.reply('Rules file doesn\'t exist.');
return;
}
const rulesFile = readFileSync(`${process.cwd()}/data/rules/${interaction.guildId}.json`).toString();
const rules = JSON.parse(rulesFile) as IRules[];
const embeds: EmbedBuilder[] = [];
if (rules.length == 0) {
await interaction.reply({ content: "No rules have been supplied within code base for this server.", ephemeral: true });
return;
}
rules.forEach(rule => {
const embed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle(rule.title || "Rules")
.setDescription(rule.description ? rule.description.join("\n") : "*none*");
if (rule.image) {
embed.setImage(rule.image);
}
if (rule.footer) {
embed.setFooter({ text: rule.footer });
}
embeds.push(embed);
});
const channel = interaction.channel;
if (!channel) {
await interaction.reply({ content: "Channel not found.", ephemeral: true });
return;
}
await channel.send({ embeds: embeds });
const successEmbed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Success")
.setDescription("The rules have sent to this channel successfully");
await interaction.reply({ embeds: [ successEmbed ], ephemeral: true });
}
private async SendAccessButton(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const buttonLabel = await SettingsHelper.GetSetting("rules.access.label", interaction.guildId);
const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents([
new ButtonBuilder()
.setCustomId('verify')
.setStyle(ButtonStyle.Primary)
.setLabel(buttonLabel || "Verify")
]);
await interaction.channel?.send({
components: [ row ]
});
await interaction.reply({
content: "Success",
ephemeral: true,
});
}
}

View file

@ -1,31 +0,0 @@
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import Server from "../database/entities/Server";
import { Command } from "../type/command";
export default class Setup extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName('setup')
.setDescription('Makes the server ready to be configured')
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const server = await Server.FetchOneById(Server, interaction.guildId);
if (server) {
await interaction.reply('This server has already been setup, please configure using the config command.');
return;
}
const newServer = new Server(interaction.guildId);
await newServer.Save(Server, newServer);
await interaction.reply('Success, please configure using the configure command.');
}
}

View file

@ -1,157 +0,0 @@
import { CacheType, CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
import { AuditType } from "../constants/AuditType";
import EmbedColours from "../constants/EmbedColours";
import Audit from "../database/entities/Audit";
import SettingsHelper from "../helpers/SettingsHelper";
import TimeLengthInput from "../helpers/TimeLengthInput";
import { Command } from "../type/command";
export default class Timeout extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName("timeout")
.setDescription("Timeouts a user out, sending them a DM with the reason if possible")
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
.addUserOption(option =>
option
.setName('target')
.setDescription('The user')
.setRequired(true))
.addStringOption(option =>
option
.setName("length")
.setDescription("How long to timeout for? (Example: 24h, 60m)")
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason'));
}
public override async execute(interaction: CommandInteraction<CacheType>) {
if (!interaction.guild || !interaction.guildId) return;
// Interaction Inputs
const targetUser = interaction.options.get('target');
const lengthInput = interaction.options.get('length');
const reasonInput = interaction.options.get('reason');
// Validation
if (!targetUser || !targetUser.user || !targetUser.member) {
await interaction.reply('Fields are required.');
return;
}
if (!lengthInput || !lengthInput.value) {
await interaction.reply('Fields are required.');
return;
}
if (targetUser.user.bot) {
await interaction.reply('Cannot timeout bots.');
return;
}
// General Variables
const targetMember = targetUser.member as GuildMember;
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : null;
const timeLength = new TimeLengthInput(lengthInput.value.toString());
const logEmbed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Member Timed Out")
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
.setThumbnail(targetUser.user.avatarURL())
.addFields([
{
name: "Moderator",
value: `<@${interaction.user.id}>`,
},
{
name: "Reason",
value: reason || "*none*",
},
{
name: "Length",
value: timeLength.GetLengthShort(),
},
{
name: "Until",
value: timeLength.GetDateFromNow().toString(),
},
]);
// Bot Permissions Check
if (!targetMember.manageable) {
await interaction.reply('Insufficient bot permissions. Please contact a moderator.');
return;
}
// Execute Timeout
await targetMember.timeout(timeLength.GetMilliseconds(), reason || "");
// Log Embed To Channel
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
if (!channelName) return;
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
if (channel) {
await channel.send({ embeds: [ logEmbed ]});
}
// Create Audit
const audit = new Audit(targetUser.user.id, AuditType.Timeout, reason || "*none*", interaction.user.id, interaction.guildId);
await audit.Save(Audit, audit);
// DM User, if possible
const resultEmbed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setDescription(`<@${targetUser.user.id}> has been timed out`);
const dmEmbed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setDescription(`You have been timed out in ${interaction.guild.name}`)
.addFields([
{
name: "Reason",
value: reason || "*none*"
},
{
name: "Length",
value: timeLength.GetLengthShort(),
},
{
name: "Until",
value: timeLength.GetDateFromNow().toString(),
},
]);
try {
const dmChannel = await targetUser.user.createDM();
await dmChannel.send({ embeds: [ dmEmbed ]});
resultEmbed.addFields([
{
name: "DM Sent",
value: "true",
},
]);
} catch {
resultEmbed.addFields([
{
name: "DM Sent",
value: "false",
},
]);
}
// Success Reply
await interaction.reply({ embeds: [ resultEmbed ]});
}
}

View file

@ -1,88 +0,0 @@
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
import EmbedColours from "../constants/EmbedColours";
import SettingsHelper from "../helpers/SettingsHelper";
import { Command } from "../type/command";
export default class Unmute extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName("unmute")
.setDescription("(DEPRECATED) Unmute a member in the server with an optional reason")
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
.addUserOption(option =>
option
.setName('target')
.setDescription('The user')
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason'));
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.guild || !interaction.guildId) return;
const targetUser = interaction.options.get('target');
const reasonInput = interaction.options.get('reason');
if (!targetUser || !targetUser.user || !targetUser.member) {
await interaction.reply('Fields are required.');
return;
}
const targetMember = targetUser.member as GuildMember;
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
const logEmbed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Member Unmuted")
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
.setThumbnail(targetUser.user.avatarURL())
.addFields([
{
name: "Moderator",
value: `<@${interaction.user.id}>`,
},
{
name: "Reason",
value: reason,
},
]);
const mutedRoleName = await SettingsHelper.GetSetting('role.muted', interaction.guildId);
if (!mutedRoleName) {
await interaction.reply('Unable to find configuration. Please contact the bot author.');
return;
}
const mutedRole = interaction.guild.roles.cache.find(role => role.name == mutedRoleName);
if (!mutedRole) {
await interaction.reply('Muted role not found.');
return;
}
if (!targetMember.manageable) {
await interaction.reply('Insufficient permissions. Please contact a moderator.');
return;
}
await targetMember.roles.remove(mutedRole);
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
if (!channelName) return;
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
if (channel) {
await channel.send({ embeds: [ logEmbed ]});
}
await interaction.reply("Please note the mute and unmute commands have been deprecated and will be removed in a future update. Please use timeout instead");
}
}

View file

@ -1,71 +0,0 @@
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
import { AuditType } from "../constants/AuditType";
import EmbedColours from "../constants/EmbedColours";
import Audit from "../database/entities/Audit";
import SettingsHelper from "../helpers/SettingsHelper";
import { Command } from "../type/command";
export default class Warn extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName("warn")
.setDescription("Warns a member in the server with an optional reason")
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
.addUserOption(option =>
option
.setName('target')
.setDescription('The user')
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason'));
}
public override async execute(interaction: CommandInteraction) {
if (!interaction.guild || !interaction.guildId) return;
const targetUser = interaction.options.get('target');
const reasonInput = interaction.options.get('reason');
if (!targetUser || !targetUser.user || !targetUser.member) {
await interaction.reply('Fields are required.');
return;
}
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
const logEmbed = new EmbedBuilder()
.setColor(EmbedColours.Ok)
.setTitle("Member Warned")
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
.setThumbnail(targetUser.user.avatarURL())
.addFields([
{
name: "Moderator",
value: `<@${interaction.user.id}>`,
},
{
name: "Reason",
value: reason,
},
]);
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
if (!channelName) return;
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
if (channel) {
await channel.send({ embeds: [ logEmbed ]});
}
const audit = new Audit(targetUser.user.id, AuditType.Warn, reason, interaction.user.id, interaction.guildId);
await audit.Save(Audit, audit);
await interaction.reply('Successfully warned user.');
}
}

View file

@ -1,8 +0,0 @@
export enum AuditType {
General,
Warn,
Mute,
Kick,
Ban,
Timeout,
}

View file

@ -1,70 +0,0 @@
export default class DefaultValues {
public static values: ISettingValue[] = [];
public static useDevPrefix: boolean = false;
public static GetValue(key: string): string | undefined {
this.SetValues();
const res = this.values.find(x => x.Key == key);
if (!res) {
return undefined;
}
return res.Value;
}
private static SetValues() {
if (this.values.length == 0) {
// Bot
this.values.push({ Key: "bot.prefix", Value: process.env.BOT_PREFIX || "v!" })
// Commands
this.values.push({ Key: "commands.disabled", Value: "" });
this.values.push({ Key: "commands.disabled.message", Value: "This command is disabled." });
// Role (Command)
this.values.push({ Key: "role.assignable", Value: "" });
this.values.push({ Key: "role.moderator", Value: "Moderator" });
this.values.push({ Key: "role.administrator", Value: "Administrator"});
this.values.push({ Key: "role.muted", Value: "Muted" });
// Rules (Command)
this.values.push({ Key: "rules.file", Value: "data/rules/rules" });
this.values.push({ Key: "rules.access.label", Value: "Verify" });
// Channels
this.values.push({ Key: "channels.logs.message", Value: "message-logs" });
this.values.push({ Key: "channels.logs.member", Value: "member-logs" });
this.values.push({ Key: "channels.logs.mod", Value: "mod-logs" });
// Verification
this.values.push({ Key: "verification.enabled", Value: "false" });
this.values.push({ Key: "verification.channel", Value: "entry" });
this.values.push({ Key: "verification.role", Value: "Entry" });
this.values.push({ Key: "verification.code", Value: "" });
// Event
this.values.push({ Key: "event.message.delete.enabled", Value: "false" });
this.values.push({ Key: "event.message.delete.channel", Value: "message-logs" });
this.values.push({ Key: "event.message.update.enabled", Value: "false" });
this.values.push({ Key: "event.message.update.channel", Value: "message-logs" });
this.values.push({ Key: "event.member.add.enabled", Value: "false" });
this.values.push({ Key: "event.member.add.channel", Value: "member-logs" });
this.values.push({ Key: "event.member.remove.enabled", Value: "false" });
this.values.push({ Key: "event.member.remove.channel", Value: "member-logs" });
this.values.push({ Key: "event.member.update.enabled", Value: "false" });
this.values.push({ Key: "event.member.update.channel", Value: "member-logs" });
}
}
}
export interface ISettingValue {
Key: string,
Value: string,
};

View file

@ -1,3 +0,0 @@
export default class EmbedColours {
public static readonly Ok = 0x3050ba;
}

View file

@ -1,15 +0,0 @@
export enum EventType {
ChannelCreate,
ChannelDelete,
ChannelUpdate,
GuildBanAdd,
GuildBanRemove,
GuildCreate,
GuildMemberAdd,
GuildMemberRemove,
GuildMemberUpdate,
MessageCreate,
MessageDelete,
MessageUpdate,
Ready,
}

Some files were not shown because too many files have changed in this diff Show more