Initial Commit
This commit is contained in:
commit
3dfe642e90
5
.dockerignore
Normal file
5
.dockerignore
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
env.dev
|
||||||
|
env.prod
|
||||||
|
.env
|
49
.eslintrc.json
Normal file
49
.eslintrc.json
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"extends": "eslint:recommended",
|
||||||
|
"env": {
|
||||||
|
"node": true,
|
||||||
|
"es6": true
|
||||||
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2021
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"arrow-spacing": ["warn", { "before": true, "after": true }],
|
||||||
|
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
|
||||||
|
"comma-dangle": ["error", "always-multiline"],
|
||||||
|
"comma-spacing": "error",
|
||||||
|
"comma-style": "error",
|
||||||
|
"curly": ["error", "multi-line", "consistent"],
|
||||||
|
"dot-location": ["error", "property"],
|
||||||
|
"handle-callback-err": "off",
|
||||||
|
"indent": ["error", "tab"],
|
||||||
|
"keyword-spacing": "error",
|
||||||
|
"max-nested-callbacks": ["error", { "max": 4 }],
|
||||||
|
"max-statements-per-line": ["error", { "max": 2 }],
|
||||||
|
"no-console": "off",
|
||||||
|
"no-empty-function": "error",
|
||||||
|
"no-floating-decimal": "error",
|
||||||
|
"no-inline-comments": "error",
|
||||||
|
"no-lonely-if": "error",
|
||||||
|
"no-multi-spaces": "error",
|
||||||
|
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
|
||||||
|
"no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }],
|
||||||
|
"no-trailing-spaces": ["error"],
|
||||||
|
"no-var": "error",
|
||||||
|
"object-curly-spacing": ["error", "always"],
|
||||||
|
"prefer-const": "error",
|
||||||
|
"quotes": ["error", "single"],
|
||||||
|
"semi": ["error", "always"],
|
||||||
|
"space-before-blocks": "error",
|
||||||
|
"space-before-function-paren": ["error", {
|
||||||
|
"anonymous": "never",
|
||||||
|
"named": "never",
|
||||||
|
"asyncArrow": "always"
|
||||||
|
}],
|
||||||
|
"space-in-parens": "error",
|
||||||
|
"space-infix-ops": "error",
|
||||||
|
"space-unary-ops": "error",
|
||||||
|
"spaced-comment": "error",
|
||||||
|
"yoda": "error"
|
||||||
|
}
|
||||||
|
}
|
26
.github/workflows/docker-image.yml
vendored
Normal file
26
.github/workflows/docker-image.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
name: Docker Image CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "main" ]
|
||||||
|
|
||||||
|
env:
|
||||||
|
DHUB_UNAME: ${{ secrets.DHUB_UNAME }}
|
||||||
|
DHUB_PWORD: ${{ secrets.DHUB_PWORD }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Build the Docker image
|
||||||
|
run: docker build . --file Dockerfile --tag v0idf1sh/nodbot
|
||||||
|
- name: Log into Docker Hub
|
||||||
|
run: docker login -u $DHUB_UNAME -p $DHUB_PWORD
|
||||||
|
- name: Push image to Docker Hub
|
||||||
|
run: docker push v0idf1sh/nodbot
|
117
.gitignore
vendored
Normal file
117
.gitignore
vendored
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
# IDE Config Files
|
||||||
|
.vscode
|
||||||
|
package-lock.json
|
||||||
|
.VSCodeCounter/
|
||||||
|
env.dev
|
||||||
|
env.prod
|
||||||
|
|
||||||
|
# Custom folders
|
||||||
|
# gifs/*
|
||||||
|
# pastas/*
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
.env.test
|
||||||
|
.env.dev
|
||||||
|
.env.prod
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
.next
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
.cache/
|
||||||
|
# Comment in the public line in if your project uses Gatsby and *not* Next.js
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
.tern-port
|
12
CHANGELOG.md
Normal file
12
CHANGELOG.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
## Changes
|
||||||
|
|
||||||
|
v3.0.1 - Migrate TenorJS API Endpoint
|
||||||
|
v3.0.2 - Add medical advice commands
|
||||||
|
v3.0.3 - Fix broken `/requests` command
|
||||||
|
v3.0.4 - Add ability to use multiple aliases
|
||||||
|
v3.0.5 - Add ability to save strains
|
||||||
|
v3.0.6 - Move `.strain` to `/strain` and add Autocomplete
|
||||||
|
v3.0.7 - Add `.spongebob` replies
|
||||||
|
v3.0.8 - Add ability to open requests by pages
|
||||||
|
|
||||||
|
v3.1.0 - Migrate to Discord.js Version 14
|
8
Dockerfile
Normal file
8
Dockerfile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
FROM node:16
|
||||||
|
RUN mkdir -p /usr/src/app
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
COPY package.json ./
|
||||||
|
RUN npm install
|
||||||
|
COPY . .
|
||||||
|
CMD [ "node", "main.js" ]
|
100
README.md
Normal file
100
README.md
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
# About Nodbot
|
||||||
|
Nodbot is a content saving and serving Discord bot. Nodbot is able to search Tenor for GIFs, save custom copypastas, and look up marijuana strain information. Nodbot is in semi-active development by voidf1sh. It's buggy as hell and very shoddily built. Don't use it.
|
||||||
|
|
||||||
|
# Nodbot Help
|
||||||
|
|
||||||
|
Use the `/help` command to see the bot's help message.
|
||||||
|
|
||||||
|
## Create Docker Image
|
||||||
|
`docker build --tag=name/nodbot .`
|
||||||
|
|
||||||
|
## Push Docker Image
|
||||||
|
`docker push name/nodbot`
|
||||||
|
|
||||||
|
# Immediate To-Do
|
||||||
|
|
||||||
|
1. ~~Sanitize inputs for SQL queries.~~ Done.
|
||||||
|
2. ~~Move environment variables so they don't get included in the image.~~
|
||||||
|
3. Implement error handling on all actions.
|
||||||
|
4. Ephemeral responses to some/most slash commands.
|
||||||
|
5. Comment the code! Document!
|
||||||
|
6. Check for and create database tables if necessary. Handle errors.
|
||||||
|
|
||||||
|
# Deploy NodBot Yourself
|
||||||
|
|
||||||
|
1. Create an application at the [Discord Developer Portal](https://discord.com/developers/applications)
|
||||||
|
2. Convert the application into a Bot
|
||||||
|
3. Note down the token provided and keep this safe. You cannot view this token again, only regenerate a new one.
|
||||||
|
4. Create a Tenor account and obtain an API key.
|
||||||
|
5. Install and configure MySQL or MariaDB with a user for the bot and a datbase
|
||||||
|
* Create the table structure as outlined below (* Nodbot will soon create its own table structure)
|
||||||
|
6. Configure your environment variables as outlined below.
|
||||||
|
7. Fire it up with `node main.js`
|
||||||
|
|
||||||
|
## Table Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
Table: gifs
|
||||||
|
+-----------+---------------+------+-----+---------+----------------+
|
||||||
|
| Field | Type | Null | Key | Default | Extra |
|
||||||
|
+-----------+---------------+------+-----+---------+----------------+
|
||||||
|
| id | int(11) | NO | MUL | NULL | auto_increment |
|
||||||
|
| name | varchar(100) | NO | | NULL | |
|
||||||
|
| embed_url | varchar(1000) | NO | | NULL | |
|
||||||
|
+-----------+---------------+------+-----+---------+----------------+
|
||||||
|
|
||||||
|
Table: joints
|
||||||
|
+---------+---------------+------+-----+---------+----------------+
|
||||||
|
| Field | Type | Null | Key | Default | Extra |
|
||||||
|
+---------+---------------+------+-----+---------+----------------+
|
||||||
|
| id | int(11) | NO | MUL | NULL | auto_increment |
|
||||||
|
| content | varchar(1000) | NO | | NULL | |
|
||||||
|
+---------+---------------+------+-----+---------+----------------+
|
||||||
|
|
||||||
|
Table: pastas
|
||||||
|
+---------+---------------+------+-----+---------+----------------+
|
||||||
|
| Field | Type | Null | Key | Default | Extra |
|
||||||
|
+---------+---------------+------+-----+---------+----------------+
|
||||||
|
| id | int(11) | NO | MUL | NULL | auto_increment |
|
||||||
|
| name | varchar(100) | NO | | NULL | |
|
||||||
|
| content | varchar(1900) | NO | | NULL | |
|
||||||
|
| iconurl | varchar(200) | NO | | (url) | |
|
||||||
|
+---------+---------------+------+-----+---------+----------------+
|
||||||
|
|
||||||
|
Table: requests
|
||||||
|
+---------+---------------+------+-----+---------+----------------+
|
||||||
|
| Field | Type | Null | Key | Default | Extra |
|
||||||
|
+---------+---------------+------+-----+---------+----------------+
|
||||||
|
| id | int(11) | NO | MUL | NULL | auto_increment |
|
||||||
|
| author | varchar(100) | NO | | NULL | |
|
||||||
|
| request | varchar(1000) | NO | | NULL | |
|
||||||
|
| status | varchar(10) | YES | | Active | |
|
||||||
|
+---------+---------------+------+-----+---------+----------------+
|
||||||
|
|
||||||
|
Table: strains
|
||||||
|
+---------+-------------+------+-----+---------+-------+
|
||||||
|
| Field | Type | Null | Key | Default | Extra |
|
||||||
|
+---------+-------------+------+-----+---------+-------+
|
||||||
|
| id | smallint(6) | NO | | NULL | |
|
||||||
|
| name | varchar(60) | YES | | NULL | |
|
||||||
|
| type | varchar(10) | YES | | NULL | |
|
||||||
|
| effects | varchar(80) | YES | | NULL | |
|
||||||
|
| ailment | varchar(70) | YES | | NULL | |
|
||||||
|
| flavor | varchar(30) | YES | | NULL | |
|
||||||
|
+---------+-------------+------+-----+---------+-------+
|
||||||
|
```
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
```
|
||||||
|
TOKEN=<your bot's token from step 3>
|
||||||
|
isDev=<true/false>
|
||||||
|
dbHost=<mySQL host>
|
||||||
|
dbPort=<mySQL port (3306)>
|
||||||
|
dbUser=<mySQL username>
|
||||||
|
dbPass=<mySQL user password>
|
||||||
|
dbName=<mySQL table name>
|
||||||
|
tenorAPIKey=<Tenor API Key>
|
||||||
|
ownerId=<your Discord user ID>
|
||||||
|
statusChannelId=<Discord channel ID of channel used for status messages>
|
||||||
|
clientId=<Discord user ID of your bot>
|
||||||
|
```
|
14
Roadmap.md
Normal file
14
Roadmap.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# v3.1.0
|
||||||
|
|
||||||
|
* Name checking for saving content
|
||||||
|
* .jpg, .wav
|
||||||
|
* Audio/Video attachments for saved content.
|
||||||
|
* Pass The Joint
|
||||||
|
* Voting system for Super Adventure Club
|
||||||
|
|
||||||
|
# v4.0.0
|
||||||
|
* Scalability: modify the code to allow the bot to be used in multiple servers
|
||||||
|
* including saved content, saved commands, preferences, etc.
|
||||||
|
|
||||||
|
# v3.?.?
|
||||||
|
= Joke generator for Hallihan
|
27
_clear-commands.js
Normal file
27
_clear-commands.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// dotenv for handling environment variables
|
||||||
|
const dotenv = require('dotenv');
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const { REST } = require('@discordjs/rest');
|
||||||
|
const { Routes } = require('discord-api-types/v9');
|
||||||
|
const clientId = process.env.clientId;
|
||||||
|
const { guildId } = require('../config.json');
|
||||||
|
const token = process.env.TOKEN;
|
||||||
|
|
||||||
|
const rest = new REST({ version: '9' }).setToken(token);
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
console.log('Started refreshing application (/) commands.');
|
||||||
|
|
||||||
|
await rest.put(
|
||||||
|
Routes.applicationGuildCommands(clientId, guildId),
|
||||||
|
{ body: '' },
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('Successfully reloaded application (/) commands.');
|
||||||
|
process.exit();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
})();
|
40
_deploy-commands.js
Normal file
40
_deploy-commands.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// dotenv for handling environment variables
|
||||||
|
const dotenv = require('dotenv');
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const { REST } = require('@discordjs/rest');
|
||||||
|
const { Routes } = require('discord-api-types/v9');
|
||||||
|
const { guildId } = require('./config.json');
|
||||||
|
const clientId = process.env.clientId;
|
||||||
|
const token = process.env.TOKEN;
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const commands = [];
|
||||||
|
const commandFiles = fs.readdirSync('./slash-commands').filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const command = require(`./slash-commands/${file}`);
|
||||||
|
if (command.data != undefined) {
|
||||||
|
commands.push(command.data.toJSON());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(commands);
|
||||||
|
|
||||||
|
const rest = new REST({ version: '9' }).setToken(token);
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
console.log('Started refreshing application (/) commands.');
|
||||||
|
|
||||||
|
await rest.put(
|
||||||
|
Routes.applicationGuildCommands(clientId, guildId),
|
||||||
|
{ body: commands },
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('Successfully reloaded application (/) commands.');
|
||||||
|
process.exit();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
})();
|
39
_deploy-global.js
Normal file
39
_deploy-global.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// dotenv for handling environment variables
|
||||||
|
const dotenv = require('dotenv');
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const { REST } = require('@discordjs/rest');
|
||||||
|
const { Routes } = require('discord-api-types/v9');
|
||||||
|
const clientId = process.env.clientId;
|
||||||
|
const token = process.env.TOKEN;
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const commands = [];
|
||||||
|
const commandFiles = fs.readdirSync('./slash-commands').filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const command = require(`./slash-commands/${file}`);
|
||||||
|
if (command.data != undefined) {
|
||||||
|
commands.push(command.data.toJSON());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(commands);
|
||||||
|
|
||||||
|
const rest = new REST({ version: '9' }).setToken(token);
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
console.log('Started refreshing application (/) commands.');
|
||||||
|
|
||||||
|
await rest.put(
|
||||||
|
Routes.applicationCommands(clientId),
|
||||||
|
{ body: commands },
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('Successfully reloaded application (/) commands.');
|
||||||
|
process.exit();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
})();
|
4
config.json
Normal file
4
config.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"guildId": "868542949737246730",
|
||||||
|
"validCommands": []
|
||||||
|
}
|
BIN
dot-commands/.DS_Store
vendored
Normal file
BIN
dot-commands/.DS_Store
vendored
Normal file
Binary file not shown.
30
dot-commands/spongebob.js
Normal file
30
dot-commands/spongebob.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
const fn = require('../functions.js');
|
||||||
|
const config = require('../config.json');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'spongebob',
|
||||||
|
alias: 'sb',
|
||||||
|
description: 'SpOnGeBoB-iFy AnYtHiNg AuToMaTiCaLly',
|
||||||
|
usage: '<text to convert>.spongebob',
|
||||||
|
execute(message, commandData) {
|
||||||
|
// message.reply(fn.spongebob(commandData)).then(() => {
|
||||||
|
// message.delete();
|
||||||
|
// });
|
||||||
|
if (message.reference != undefined) {
|
||||||
|
const repliedMessageId = message.reference.messageId;
|
||||||
|
message.channel.messages.fetch(repliedMessageId)
|
||||||
|
.then(repliedMessage => {
|
||||||
|
repliedMessage.reply(fn.spongebob({ args: repliedMessage.content })).then(() => {
|
||||||
|
message.delete();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
message.channel.send(fn.spongebob(commandData)).then(() => {
|
||||||
|
message.delete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
576
functions.js
Normal file
576
functions.js
Normal file
@ -0,0 +1,576 @@
|
|||||||
|
/* eslint-disable comma-dangle */
|
||||||
|
// dotenv for handling environment variables
|
||||||
|
const dotenv = require('dotenv');
|
||||||
|
dotenv.config();
|
||||||
|
// Assignment of environment variables for database access
|
||||||
|
const dbHost = process.env.dbHost;
|
||||||
|
const dbUser = process.env.dbUser;
|
||||||
|
const dbName = process.env.dbName;
|
||||||
|
const dbPass = process.env.dbPass;
|
||||||
|
const dbPort = process.env.dbPort;
|
||||||
|
const isDev = process.env.isDev;
|
||||||
|
|
||||||
|
const ownerId = process.env.ownerId;
|
||||||
|
|
||||||
|
// filesystem
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
// Discord.js
|
||||||
|
const Discord = require('discord.js');
|
||||||
|
|
||||||
|
// Fuzzy text matching for db lookups
|
||||||
|
const FuzzySearch = require('fuzzy-search');
|
||||||
|
|
||||||
|
// Various imports from other files
|
||||||
|
const config = require('./config.json');
|
||||||
|
const strings = require('./strings.json');
|
||||||
|
const slashCommandFiles = fs.readdirSync('./slash-commands/').filter(file => file.endsWith('.js'));
|
||||||
|
const dotCommandFiles = fs.readdirSync('./dot-commands/').filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
|
// MySQL database connection
|
||||||
|
const mysql = require('mysql');
|
||||||
|
const db = new mysql.createPool({
|
||||||
|
connectionLimit: 10,
|
||||||
|
host: dbHost,
|
||||||
|
user: dbUser,
|
||||||
|
password: dbPass,
|
||||||
|
database: dbName,
|
||||||
|
port: dbPort,
|
||||||
|
});
|
||||||
|
|
||||||
|
const functions = {
|
||||||
|
// Functions for managing and creating Collections
|
||||||
|
collections: {
|
||||||
|
// Create the collection of slash commands
|
||||||
|
slashCommands(client) {
|
||||||
|
if (!client.slashCommands) client.slashCommands = new Discord.Collection();
|
||||||
|
client.slashCommands.clear();
|
||||||
|
for (const file of slashCommandFiles) {
|
||||||
|
const slashCommand = require(`./slash-commands/${file}`);
|
||||||
|
if (slashCommand.data != undefined) {
|
||||||
|
client.slashCommands.set(slashCommand.data.name, slashCommand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isDev) console.log('Slash Commands Collection Built');
|
||||||
|
},
|
||||||
|
setvalidCommands(client) {
|
||||||
|
for (const entry of client.dotCommands.map(command => command)) {
|
||||||
|
config.validCommands.push(entry.name);
|
||||||
|
if (Array.isArray(entry.alias)) {
|
||||||
|
entry.alias.forEach(element => {
|
||||||
|
config.validCommands.push(element);
|
||||||
|
});
|
||||||
|
} else if (entry.alias != undefined) {
|
||||||
|
config.validCommands.push(entry.alias);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isDev) console.log(`Valid Commands Added to Config\n${config.validCommands}`);
|
||||||
|
},
|
||||||
|
dotCommands(client) {
|
||||||
|
if (!client.dotCommands) client.dotCommands = new Discord.Collection();
|
||||||
|
client.dotCommands.clear();
|
||||||
|
for (const file of dotCommandFiles) {
|
||||||
|
const dotCommand = require(`./dot-commands/${file}`);
|
||||||
|
client.dotCommands.set(dotCommand.name, dotCommand);
|
||||||
|
if (Array.isArray(dotCommand.alias)) {
|
||||||
|
dotCommand.alias.forEach(element => {
|
||||||
|
client.dotCommands.set(element, dotCommand);
|
||||||
|
});
|
||||||
|
} else if (dotCommand.alias != undefined) {
|
||||||
|
client.dotCommands.set(dotCommand.alias, dotCommand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isDev) console.log('Dot Commands Collection Built');
|
||||||
|
},
|
||||||
|
gifs(rows, client) {
|
||||||
|
if (!client.gifs) client.gifs = new Discord.Collection();
|
||||||
|
client.gifs.clear();
|
||||||
|
for (const row of rows) {
|
||||||
|
const gif = {
|
||||||
|
id: row.id,
|
||||||
|
name: row.name,
|
||||||
|
embed_url: row.embed_url
|
||||||
|
};
|
||||||
|
client.gifs.set(gif.name, gif);
|
||||||
|
}
|
||||||
|
if (isDev) console.log('GIFs Collection Built');
|
||||||
|
},
|
||||||
|
joints(rows, client) {
|
||||||
|
if (!client.joints) client.joints = new Discord.Collection();
|
||||||
|
client.joints.clear();
|
||||||
|
for (const row of rows) {
|
||||||
|
const joint = {
|
||||||
|
id: row.id,
|
||||||
|
content: row.content
|
||||||
|
};
|
||||||
|
client.joints.set(joint.id, joint);
|
||||||
|
}
|
||||||
|
if (isDev) console.log('Joints Collection Built');
|
||||||
|
},
|
||||||
|
pastas(rows, client) {
|
||||||
|
if (!client.pastas) client.pastas = new Discord.Collection();
|
||||||
|
client.pastas.clear();
|
||||||
|
for (const row of rows) {
|
||||||
|
const pasta = {
|
||||||
|
id: row.id,
|
||||||
|
name: row.name,
|
||||||
|
content: row.content,
|
||||||
|
iconUrl: row.iconurl,
|
||||||
|
};
|
||||||
|
client.pastas.set(pasta.name, pasta);
|
||||||
|
}
|
||||||
|
if (isDev) console.log('Pastas Collection Built');
|
||||||
|
},
|
||||||
|
requests(rows, client) {
|
||||||
|
if (!client.requests) client.requests = new Discord.Collection();
|
||||||
|
client.requests.clear();
|
||||||
|
for (const row of rows) {
|
||||||
|
const request = {
|
||||||
|
id: row.id,
|
||||||
|
author: row.author,
|
||||||
|
request: row.request,
|
||||||
|
};
|
||||||
|
client.requests.set(request.id, request);
|
||||||
|
}
|
||||||
|
if (isDev) console.log('Requests Collection Built');
|
||||||
|
},
|
||||||
|
strains(rows, client) {
|
||||||
|
if (!client.strains) client.strains = new Discord.Collection();
|
||||||
|
client.strains.clear();
|
||||||
|
for (const row of rows) {
|
||||||
|
const strain = {
|
||||||
|
id: row.id,
|
||||||
|
name: row.strain,
|
||||||
|
};
|
||||||
|
client.strains.set(strain.name, strain);
|
||||||
|
// if (isDev) console.log(strain)
|
||||||
|
}
|
||||||
|
if (isDev) console.log('Strains Collection Built');
|
||||||
|
},
|
||||||
|
medicalAdvice(rows, client) {
|
||||||
|
if (!client.medicalAdviceCol) client.medicalAdviceColl = new Discord.Collection();
|
||||||
|
client.medicalAdviceColl.clear();
|
||||||
|
for (const row of rows) {
|
||||||
|
const medicalAdvice = {
|
||||||
|
id: row.id,
|
||||||
|
content: row.content
|
||||||
|
};
|
||||||
|
client.medicalAdviceColl.set(medicalAdvice.id, medicalAdvice);
|
||||||
|
}
|
||||||
|
if (isDev) console.log('Medical Advice Collection Built');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dot: {
|
||||||
|
getCommandData(message) {
|
||||||
|
const commandData = {};
|
||||||
|
// Split the message content at the final instance of a period
|
||||||
|
const finalPeriod = message.content.lastIndexOf('.');
|
||||||
|
if(isDev) console.log(message.content);
|
||||||
|
// If the final period is the last character, or doesn't exist
|
||||||
|
if (finalPeriod < 0) {
|
||||||
|
if (isDev) console.log(finalPeriod);
|
||||||
|
commandData.isCommand = false;
|
||||||
|
return commandData;
|
||||||
|
}
|
||||||
|
commandData.isCommand = true;
|
||||||
|
// Get the first part of the message, everything leading up to the final period
|
||||||
|
commandData.args = message.content.slice(0,finalPeriod).toLowerCase();
|
||||||
|
// Get the last part of the message, everything after the final period
|
||||||
|
commandData.command = message.content.slice(finalPeriod).replace('.','').toLowerCase();
|
||||||
|
commandData.author = `${message.author.username}#${message.author.discriminator}`;
|
||||||
|
return this.checkCommand(commandData);
|
||||||
|
},
|
||||||
|
checkCommand(commandData) {
|
||||||
|
if (commandData.isCommand) {
|
||||||
|
const validCommands = require('./config.json').validCommands;
|
||||||
|
commandData.isValid = validCommands.includes(commandData.command);
|
||||||
|
// Add exceptions for messages that contain only a link
|
||||||
|
if (commandData.args.startsWith('http')) commandData.isValid = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
commandData.isValid = false;
|
||||||
|
console.error('Somehow a non-command made it to checkCommands()');
|
||||||
|
}
|
||||||
|
return commandData;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
embeds: {
|
||||||
|
help(interaction) {
|
||||||
|
// Construct the Help Embed
|
||||||
|
const helpEmbed = new Discord.MessageEmbed()
|
||||||
|
.setColor('BLUE')
|
||||||
|
.setAuthor('Help Page')
|
||||||
|
.setDescription(strings.help.description)
|
||||||
|
.setThumbnail(strings.urls.avatar);
|
||||||
|
|
||||||
|
// Construct the Slash Commands help
|
||||||
|
|
||||||
|
let slashCommandsFields = [];
|
||||||
|
|
||||||
|
const slashCommandsMap = interaction.client.slashCommands.map(e => {
|
||||||
|
return {
|
||||||
|
name: e.data.name,
|
||||||
|
description: e.data.description
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
for (const e of slashCommandsMap) {
|
||||||
|
slashCommandsFields.push({
|
||||||
|
name: `- /${e.name}`,
|
||||||
|
value: e.description,
|
||||||
|
inline: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct the Dot Commands Help
|
||||||
|
let dotCommandsFields = [];
|
||||||
|
|
||||||
|
const dotCommandsMap = interaction.client.dotCommands.map(e => {
|
||||||
|
return {
|
||||||
|
name: e.name,
|
||||||
|
description: e.description,
|
||||||
|
usage: e.usage
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const e of dotCommandsMap) {
|
||||||
|
dotCommandsFields.push({
|
||||||
|
name: `- .${e.name}`,
|
||||||
|
value: `${e.description}\nUsage: ${e.usage}`,
|
||||||
|
inline: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
helpEmbed.addField('Slash Commands', strings.help.slash);
|
||||||
|
helpEmbed.addFields(slashCommandsFields);
|
||||||
|
helpEmbed.addField('Dot Commands', strings.help.dot);
|
||||||
|
helpEmbed.addFields(dotCommandsFields);
|
||||||
|
|
||||||
|
return { embeds: [
|
||||||
|
helpEmbed
|
||||||
|
], ephemeral: true };
|
||||||
|
},
|
||||||
|
gif(commandData) {
|
||||||
|
return { embeds: [new Discord.MessageEmbed()
|
||||||
|
.setAuthor(`${commandData.args}.${commandData.command}`)
|
||||||
|
.setImage(commandData.embed_url)
|
||||||
|
.setTimestamp()
|
||||||
|
.setFooter(commandData.author)]};
|
||||||
|
},
|
||||||
|
pasta(commandData) {
|
||||||
|
return { embeds: [ new Discord.MessageEmbed()
|
||||||
|
.setAuthor(`${commandData.args}.${commandData.command}`)
|
||||||
|
.setDescription(commandData.content)
|
||||||
|
.setThumbnail(commandData.iconUrl)
|
||||||
|
.setTimestamp()
|
||||||
|
.setFooter(commandData.author)]};
|
||||||
|
},
|
||||||
|
pastas(commandData) {
|
||||||
|
const pastasArray = [];
|
||||||
|
const pastasEmbed = new Discord.MessageEmbed()
|
||||||
|
.setAuthor(commandData.command)
|
||||||
|
.setTimestamp()
|
||||||
|
.setFooter(commandData.author);
|
||||||
|
|
||||||
|
for (const row of commandData.pastas) {
|
||||||
|
pastasArray.push(`#${row.id} - ${row.name}.pasta`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const pastasString = pastasArray.join('\n');
|
||||||
|
pastasEmbed.setDescription(pastasString);
|
||||||
|
|
||||||
|
return { embeds: [pastasEmbed], ephemeral: true };
|
||||||
|
},
|
||||||
|
gifs(commandData) {
|
||||||
|
const gifsArray = [];
|
||||||
|
const gifsEmbed = new Discord.MessageEmbed()
|
||||||
|
.setAuthor(commandData.command)
|
||||||
|
.setTimestamp()
|
||||||
|
.setFooter(commandData.author);
|
||||||
|
|
||||||
|
for (const row of commandData.gifs) {
|
||||||
|
gifsArray.push(`#${row.id} - ${row.name}.gif`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const gifsString = gifsArray.join('\n');
|
||||||
|
gifsEmbed.setDescription(gifsString);
|
||||||
|
|
||||||
|
return { embeds: [gifsEmbed] };
|
||||||
|
},
|
||||||
|
text(commandData) {
|
||||||
|
return { embeds: [new Discord.MessageEmbed()
|
||||||
|
.setAuthor(commandData.command)
|
||||||
|
.setDescription(commandData.content)
|
||||||
|
.setTimestamp()
|
||||||
|
.setFooter(commandData.author)]};
|
||||||
|
},
|
||||||
|
requests(commandData) {
|
||||||
|
const requestsEmbed = new Discord.MessageEmbed()
|
||||||
|
.setAuthor(commandData.command)
|
||||||
|
.setTimestamp()
|
||||||
|
.setFooter(commandData.author);
|
||||||
|
|
||||||
|
const requestsArray = [];
|
||||||
|
|
||||||
|
for (const row of commandData.requests) {
|
||||||
|
requestsArray.push(
|
||||||
|
`**#${row.id} - ${row.author}**`,
|
||||||
|
`Request: ${row.request}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
requestsEmbed.setDescription(requestsArray.join('\n'));
|
||||||
|
|
||||||
|
return { embeds: [requestsEmbed], ephemeral: true };
|
||||||
|
},
|
||||||
|
strain(strainInfo, interaction) {
|
||||||
|
const strainEmbed = new Discord.MessageEmbed()
|
||||||
|
.setTimestamp();
|
||||||
|
strainEmbed.addFields([
|
||||||
|
{
|
||||||
|
name: 'Strain Name',
|
||||||
|
value: `${strainInfo.strain}`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Type',
|
||||||
|
value: `${strainInfo.type}`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Effects',
|
||||||
|
value: `${strainInfo.effects}`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Flavor',
|
||||||
|
value: `${strainInfo.flavor}`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Rating',
|
||||||
|
value: `⭐️${strainInfo.rating}`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Description',
|
||||||
|
value: `${strainInfo.description}`,
|
||||||
|
inline: false,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
interaction.reply({ embeds: [ strainEmbed ]});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
collect: {
|
||||||
|
gifName(interaction) {
|
||||||
|
const gifNameFilter = m => m.author.id == strings.temp.gifUserId;
|
||||||
|
return interaction.channel.createMessageCollector({ filter: gifNameFilter, time: 30000 });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
upload: {
|
||||||
|
request(commandData, client) {
|
||||||
|
const query = `INSERT INTO requests (author, request, status) VALUES (${db.escape(commandData.author)},${db.escape(commandData.args)},'Active')`;
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
functions.download.requests(client);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
pasta(pastaData, client) {
|
||||||
|
const query = `INSERT INTO pastas (name, content) VALUES (${db.escape(pastaData.name)},${db.escape(pastaData.content)})`;
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
functions.download.pastas(client);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
joint(content, client) {
|
||||||
|
const query = `INSERT INTO joints (content) VALUES (${db.escape(content)})`;
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
functions.download.joints(client);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
gif(gifData, client) {
|
||||||
|
const query = `INSERT INTO gifs (name, embed_url) VALUES (${db.escape(gifData.name)}, ${db.escape(gifData.embed_url)})`;
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
functions.download.gifs(client);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
setup(interaction) {
|
||||||
|
/* Tables:
|
||||||
|
* - gifs
|
||||||
|
* - joints
|
||||||
|
* - pastas
|
||||||
|
* - requests
|
||||||
|
* - strains */
|
||||||
|
const gifsQuery = "CREATE TABLE 'gifs' (id int(11), name varchar(100), embed_url varchar(1000), PRIMARY KEY(id))";
|
||||||
|
const jointsQuery = "CREATE TABLE 'joints' (id int(11), content varchar(1000), PRIMARY KEY(id))";
|
||||||
|
const pastasQuery = "CREATE TABLE 'pastas' (id int(11), name varchar(100), content varchar(1900), iconurl varchar(200) DEFAULT 'https://cdn.discordapp.com/avatars/513184762073055252/12227aa23a06d5178853e59b72c7487b.webp?size=128', PRIMARY KEY(id))";
|
||||||
|
const requestsQuery = "CREATE TABLE 'requests' (id int(11), author varchar(100), request varchar(1000), status varchar(10) DEFAULT 'Active', PRIMARY KEY(id))";
|
||||||
|
const strainsQuery = "CREATE TABLE 'strains' (id smallint(6), name varchar(60), type varchar(10), effects varchat(80), ailment varchar(70), flavor varchar(30), PRIMARY KEY(id))";
|
||||||
|
|
||||||
|
// Check for owner
|
||||||
|
if (interaction.user.id == ownerId) {
|
||||||
|
db.query(gifsQuery, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
|
db.query(jointsQuery, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
|
db.query(pastasQuery, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
|
db.query(requestsQuery, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
|
db.query(strainsQuery, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
|
return 'I\'ve created the required tables. Please check your database to validate this.';
|
||||||
|
} else {
|
||||||
|
return 'Sorry, you don\'t have permission to do that.';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
medicalAdvice(content, client) {
|
||||||
|
const query = `INSERT INTO medical_advice (content) VALUES (${db.escape(content)})`;
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
functions.download.medicalAdvice(client);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
strain(interaction) {
|
||||||
|
const strain = db.escape(interaction.options.getString('name'));
|
||||||
|
const type = db.escape(interaction.options.getString('type'));
|
||||||
|
const effects = db.escape(( interaction.options.getString('effects') || 'Unkown' ));
|
||||||
|
const description = db.escape(( interaction.options.getString('description') || 'Unknown' ));
|
||||||
|
const flavor = db.escape(( interaction.options.getString('flavor') || 'Unknown' ));
|
||||||
|
const rating = db.escape(( interaction.options.getString('rating') || '3' ));
|
||||||
|
const strainQuery = `INSERT INTO strains (strain, type, effects, description, flavor, rating) VALUES (${strain}, ${type}, ${effects}, ${description}, ${flavor}, ${rating})`;
|
||||||
|
console.log(strainQuery);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
db.query(strainQuery, (err, rows, fields) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
functions.download.strains(interaction.client);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
download: {
|
||||||
|
requests(client) {
|
||||||
|
const query = 'SELECT * FROM requests WHERE status = \'Active\' ORDER BY id DESC';
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
functions.collections.requests(rows, client);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
pastas(client) {
|
||||||
|
const query = 'SELECT * FROM pastas ORDER BY id ASC';
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
functions.collections.pastas(rows, client);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
gifs(client) {
|
||||||
|
const query = 'SELECT * FROM gifs ORDER BY id ASC';
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
functions.collections.gifs(rows, client);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
joints(client) {
|
||||||
|
const query = 'SELECT * FROM joints ORDER BY id ASC';
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
functions.collections.joints(rows, client);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
strain(strainName, interaction) {
|
||||||
|
const query = `SELECT id, strain, type, effects, description, flavor, rating FROM strains WHERE strain = ${db.escape(strainName)}`;
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (rows != undefined) {
|
||||||
|
const strainInfo = {
|
||||||
|
id: `${rows[0].id}`,
|
||||||
|
strain: `${rows[0].strain}`,
|
||||||
|
type: `${rows[0].type}`,
|
||||||
|
effects: `${rows[0].effects}`,
|
||||||
|
description: `${rows[0].description}`,
|
||||||
|
flavor: `${rows[0].flavor}`,
|
||||||
|
rating: `${rows[0].rating}`,
|
||||||
|
};
|
||||||
|
functions.embeds.strain(strainInfo, interaction);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
strains(client) {
|
||||||
|
const query = 'SELECT id, strain FROM strains';
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
functions.collections.strains(rows, client);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
medicalAdvice(client) {
|
||||||
|
const query = 'SELECT * FROM medical_advice ORDER BY id ASC';
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
functions.collections.medicalAdvice(rows, client);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
weed: {
|
||||||
|
strain: {
|
||||||
|
lookup(strainName, client) {
|
||||||
|
const strainSearcher = new FuzzySearch(client.strains.map(e => e.name));
|
||||||
|
return strainSearcher.search(strainName).slice(0,25);
|
||||||
|
},
|
||||||
|
submit(strainName) {
|
||||||
|
const query = ``
|
||||||
|
return strainName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Parent-Level functions (miscellaneuous)
|
||||||
|
closeRequest(requestId, interaction) {
|
||||||
|
if (interaction.user.id == ownerId) {
|
||||||
|
const { client } = interaction;
|
||||||
|
const query = `UPDATE requests SET status = 'Closed' WHERE id = ${db.escape(requestId)}`;
|
||||||
|
db.query(query, (err, rows, fields) => {
|
||||||
|
if (err) throw err;
|
||||||
|
functions.download.requests(client);
|
||||||
|
});
|
||||||
|
interaction.reply({ content: `Request #${requestId} has been closed.`, ephemeral: true });
|
||||||
|
} else {
|
||||||
|
interaction.reply({ content: 'You do not have permission to do that.', ephemeral: true });
|
||||||
|
}
|
||||||
|
if (isDev) {
|
||||||
|
console.log(requestId, interaction, ownerId);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
spongebob(commandData) {
|
||||||
|
let newText = '';
|
||||||
|
for (const letter of commandData.args) {
|
||||||
|
if (letter == ' ') {
|
||||||
|
newText += letter;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (letter == 'i' || letter == 'I') {
|
||||||
|
newText += 'i';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (letter == 'l' || letter == 'L') {
|
||||||
|
newText += 'L';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Math.random() > 0.5) {
|
||||||
|
newText += letter.toUpperCase();
|
||||||
|
} else {
|
||||||
|
newText += letter.toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newText + ' <:spongebob:1053398825965985822>';
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = functions;
|
217
main.js
Normal file
217
main.js
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
/* eslint-disable no-case-declarations */
|
||||||
|
/* eslint-disable indent */
|
||||||
|
// dotenv for handling environment variables
|
||||||
|
const dotenv = require('dotenv');
|
||||||
|
dotenv.config();
|
||||||
|
const token = process.env.TOKEN;
|
||||||
|
const statusChannelId = process.env.statusChannelId;
|
||||||
|
|
||||||
|
// Discord.JS
|
||||||
|
const { Client, GatewayIntentBits, Partials } = require('discord.js');
|
||||||
|
const client = new Client({
|
||||||
|
intents: [
|
||||||
|
GatewayIntentBits.Guilds,
|
||||||
|
GatewayIntentBits.GuildMessages,
|
||||||
|
GatewayIntentBits.GuildMessageReactions,
|
||||||
|
GatewayIntentBits.DirectMessages
|
||||||
|
],
|
||||||
|
partials: [
|
||||||
|
Partials.Channel,
|
||||||
|
Partials.Message,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const { MessageActionRow, MessageButton } = require('discord.js');
|
||||||
|
|
||||||
|
// Various imports
|
||||||
|
const fn = require('./functions.js');
|
||||||
|
const config = require('./config.json');
|
||||||
|
const strings = require('./strings.json');
|
||||||
|
const isDev = process.env.isDev;
|
||||||
|
|
||||||
|
client.once('ready', () => {
|
||||||
|
fn.collections.slashCommands(client);
|
||||||
|
fn.collections.dotCommands(client);
|
||||||
|
fn.collections.setvalidCommands(client);
|
||||||
|
fn.download.gifs(client);
|
||||||
|
fn.download.pastas(client);
|
||||||
|
fn.download.joints(client);
|
||||||
|
fn.download.requests(client);
|
||||||
|
fn.download.strains(client);
|
||||||
|
fn.download.medicalAdvice(client);
|
||||||
|
console.log('Ready!');
|
||||||
|
client.channels.fetch(statusChannelId).then(channel => {
|
||||||
|
channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// slash-commands
|
||||||
|
client.on('interactionCreate', async interaction => {
|
||||||
|
if (interaction.isCommand()) {
|
||||||
|
if (isDev) {
|
||||||
|
console.log(interaction);
|
||||||
|
}
|
||||||
|
const { commandName } = interaction;
|
||||||
|
|
||||||
|
if (client.slashCommands.has(commandName)) {
|
||||||
|
client.slashCommands.get(commandName).execute(interaction);
|
||||||
|
} else {
|
||||||
|
interaction.reply('Sorry, I don\'t have access to that command.');
|
||||||
|
console.error('Slash command attempted to run but not found: ' + commandName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interaction.isButton()) {
|
||||||
|
if (interaction.user.id != strings.temp.gifUserId) return;
|
||||||
|
// Get some meta info from strings
|
||||||
|
const index = strings.temp.gifIndex;
|
||||||
|
const limit = strings.temp.gifLimit;
|
||||||
|
let newIndex;
|
||||||
|
const buttonId = interaction.component.customId;
|
||||||
|
switch (buttonId) {
|
||||||
|
case 'prevGif':
|
||||||
|
newIndex = index - 1;
|
||||||
|
strings.temp.gifIndex = newIndex;
|
||||||
|
// If we're leaving the last GIF, enable the Next GIF button
|
||||||
|
if (index == limit) {
|
||||||
|
// Re-Send Previous GIF button
|
||||||
|
const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY');
|
||||||
|
// Re-Send Confirm GIF Button
|
||||||
|
const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY');
|
||||||
|
// Enable Next GIF Button
|
||||||
|
const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY');
|
||||||
|
// Re-Send Cancel Button
|
||||||
|
const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Cancel').setStyle('DANGER');
|
||||||
|
// Put all the above into an ActionRow to be sent as a component of the reply
|
||||||
|
const row = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton);
|
||||||
|
|
||||||
|
interaction.update({ content: strings.temp.gifs[newIndex].embed_url, components: [row] });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// If we're going into the first GIF, disable the Previous GIF button
|
||||||
|
if (newIndex == 0) {
|
||||||
|
// Disable Previous GIF button
|
||||||
|
const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY').setDisabled();
|
||||||
|
// Re-Send Confirm GIF Button
|
||||||
|
const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY');
|
||||||
|
// Re-Send Next GIF Button
|
||||||
|
const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY');
|
||||||
|
// Re-Send Cancel Button
|
||||||
|
const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Canceled').setStyle('DANGER');
|
||||||
|
// Put all the above into an ActionRow to be sent as a component of the reply
|
||||||
|
const row = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton);
|
||||||
|
|
||||||
|
interaction.update({ content: strings.temp.gifs[newIndex].embed_url, components: [row] });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
interaction.update(strings.temp.gifs[newIndex].embed_url);
|
||||||
|
break;
|
||||||
|
case 'confirmGif':
|
||||||
|
const gifData = {
|
||||||
|
name: strings.temp.gifName,
|
||||||
|
embed_url: strings.temp.gifs[strings.temp.gifIndex].embed_url,
|
||||||
|
};
|
||||||
|
fn.upload.gif(gifData, client);
|
||||||
|
interaction.update({ content: `I've saved the GIF as ${gifData.name}.gif`, components: [] });
|
||||||
|
fn.download.gifs(interaction.client);
|
||||||
|
break;
|
||||||
|
case 'nextGif':
|
||||||
|
newIndex = index + 1;
|
||||||
|
strings.temp.gifIndex = newIndex;
|
||||||
|
// If we're leaving the first GIF, enable the Previous GIF button
|
||||||
|
if (index == 0) {
|
||||||
|
// Enable Previous GIF button
|
||||||
|
const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY').setDisabled(false);
|
||||||
|
// Re-Send Confirm GIF Button
|
||||||
|
const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY');
|
||||||
|
// Re-Send Next GIF Button
|
||||||
|
const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY');
|
||||||
|
// Re-Send Cancel Button
|
||||||
|
const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Cancel').setStyle('DANGER');
|
||||||
|
// Put all the above into an ActionRow to be sent as a component of the reply
|
||||||
|
const row = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton);
|
||||||
|
|
||||||
|
interaction.update({ content: strings.temp.gifs[newIndex].embed_url, components: [row] });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// If we're going into the last GIF, disable the Next GIF button
|
||||||
|
if (newIndex == strings.temp.gifLimit) {
|
||||||
|
// Re-Send Previous GIF button
|
||||||
|
const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY');
|
||||||
|
// Re-Send Confirm GIF Button
|
||||||
|
const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY');
|
||||||
|
// Disable Next GIF Button
|
||||||
|
const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY').setDisabled();
|
||||||
|
// Re-Send Cancel Button
|
||||||
|
const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Canceled').setStyle('DANGER');
|
||||||
|
// Put all the above into an ActionRow to be sent as a component of the reply
|
||||||
|
const row = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton);
|
||||||
|
|
||||||
|
interaction.update({ content: strings.temp.gifs[newIndex].embed_url, components: [row] });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
interaction.update(strings.temp.gifs[newIndex].embed_url);
|
||||||
|
break;
|
||||||
|
case 'cancelGif':
|
||||||
|
// Previous GIF button
|
||||||
|
const prevButton = new MessageButton().setCustomId('prevGif').setLabel('Previous GIF').setStyle('SECONDARY').setDisabled();
|
||||||
|
// Confirm GIF Button
|
||||||
|
const confirmButton = new MessageButton().setCustomId('confirmGif').setLabel('Confirm').setStyle('PRIMARY').setDisabled();
|
||||||
|
// Next GIF Button
|
||||||
|
const nextButton = new MessageButton().setCustomId('nextGif').setLabel('Next GIF').setStyle('SECONDARY').setDisabled();
|
||||||
|
// Cancel Button
|
||||||
|
const cancelButton = new MessageButton().setCustomId('cancelGif').setLabel('Canceled').setStyle('DANGER');
|
||||||
|
// Put all the above into an ActionRow to be sent as a component of the reply
|
||||||
|
const row = new MessageActionRow().addComponents(prevButton, confirmButton, nextButton, cancelButton);
|
||||||
|
interaction.component.setDisabled(true);
|
||||||
|
|
||||||
|
interaction.update({ content: 'Canceled.', components: [row] });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle autocomplete requests
|
||||||
|
if (interaction.isAutocomplete()) {
|
||||||
|
if (interaction.commandName == 'strain') {
|
||||||
|
const searchString = interaction.options.getFocused();
|
||||||
|
const choices = fn.weed.strain.lookup(searchString, interaction.client);
|
||||||
|
await interaction.respond(
|
||||||
|
choices.map(choice => ({ name: choice, value: choice }))
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// dot-commands
|
||||||
|
client.on('messageCreate', message => {
|
||||||
|
// Some basic checking to prevent running unnecessary code
|
||||||
|
if (message.author.bot) return;
|
||||||
|
|
||||||
|
// Wildcard Responses, will respond if any message contains the trigger word(s), excluding self-messages
|
||||||
|
const lowerContent = message.content.toLowerCase();
|
||||||
|
if (lowerContent.includes('big') && lowerContent.includes('doinks')) message.reply('gang.');
|
||||||
|
if (lowerContent.includes('ligma')) message.reply('ligma balls, goteem');
|
||||||
|
if (lowerContent.includes('frfr') || lowerContent.includes('fr fr') || lowerContent.includes('bussin') || lowerContent.includes(' ong') || lowerContent.startsWith('ong')) message.reply('ongggg no :billed_cap: fr fr str8 bussin');
|
||||||
|
|
||||||
|
// Break the message down into its components and analyze it
|
||||||
|
const commandData = fn.dot.getCommandData(message);
|
||||||
|
console.log(commandData);
|
||||||
|
|
||||||
|
if (commandData.isValid && commandData.isCommand) {
|
||||||
|
try {
|
||||||
|
client.dotCommands.get(commandData.command).execute(message, commandData);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
message.reply('There was an error trying to execute that command.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
|
client.login(token);
|
33
package.json
Normal file
33
package.json
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "nodbot",
|
||||||
|
"version": "3.0.8",
|
||||||
|
"description": "Nods and Nod Accessories.",
|
||||||
|
"main": "main.js",
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^0.21.4",
|
||||||
|
"discord.js": "^14.7.1",
|
||||||
|
"dotenv": "^10.0.0",
|
||||||
|
"fuzzy-search": "^3.2.1",
|
||||||
|
"mysql": "^2.18.1",
|
||||||
|
"tenorjs": "^1.0.10"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "18.x"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"eslint": "^7.32.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/voidf1sh/nodbot.git"
|
||||||
|
},
|
||||||
|
"author": "voidf1sh#0420",
|
||||||
|
"license": "ISC",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/voidf1sh/nodbot/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/voidf1sh/nodbot#readme"
|
||||||
|
}
|
BIN
slash-commands/.DS_Store
vendored
Normal file
BIN
slash-commands/.DS_Store
vendored
Normal file
Binary file not shown.
11
slash-commands/template
Normal file
11
slash-commands/template
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
|
const fn = require('../functions.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('')
|
||||||
|
.setDescription(''),
|
||||||
|
async execute(interaction) {
|
||||||
|
await
|
||||||
|
},
|
||||||
|
};
|
18
strings.json
Normal file
18
strings.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"help": {
|
||||||
|
"description": "Hi there! Thanks for checking out NodBot. NodBot is used in two distinct ways: with 'Slash Commands' (/help), and with 'Dot Commands' (nod.gif). The two types will be outlined below, along with usage examples.",
|
||||||
|
"slash": "Slash Commands always begin with a / and a menu will pop up to help complete the commands.",
|
||||||
|
"dot": "Dot Commands have the command at the end of the message, for example to search for a gif of 'nod', type 'nod.gif'"
|
||||||
|
},
|
||||||
|
"emoji": {
|
||||||
|
"joint": "<:joint:862082955902976000>",
|
||||||
|
"next": "⏭️",
|
||||||
|
"previous": "⏮️",
|
||||||
|
"confirm": "☑️",
|
||||||
|
"cancel": "❌"
|
||||||
|
},
|
||||||
|
"urls": {
|
||||||
|
"avatar": "https://cdn.discordapp.com/avatars/513184762073055252/12227aa23a06d5178853e59b72c7487b.webp?size=128"
|
||||||
|
},
|
||||||
|
"temp": {}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user