Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
0c45055e0f |
|||
|
345a03a3b0 |
|||
|
7702f10587 |
|||
|
eae1e9130e |
|||
|
570a8e49b7 |
|||
|
904fa25a6d |
|||
|
f28055e024 |
|||
|
5a4cfd0a5f |
|||
|
4b53d875e4 |
|||
|
aaa10cb57a |
|||
|
b89b926f9a |
|||
|
34c5f08806 |
|||
|
a3e9e1f90c |
|||
|
bab508e4b9 |
|||
|
85821f5fa3 |
28 changed files with 1483 additions and 189 deletions
22
.github/workflows/lint.yml
vendored
Normal file
22
.github/workflows/lint.yml
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
name: Lint Codebase
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
eslint:
|
||||||
|
runs-on: node
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 'latest'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm install
|
||||||
|
|
||||||
|
- name: Run ESLint
|
||||||
|
run: npm run lint
|
||||||
42
.github/workflows/njsscan.yml
vendored
42
.github/workflows/njsscan.yml
vendored
|
|
@ -1,42 +0,0 @@
|
||||||
# This workflow uses actions that are not certified by GitHub.
|
|
||||||
# They are provided by a third-party and are governed by
|
|
||||||
# separate terms of service, privacy policy, and support
|
|
||||||
# documentation.
|
|
||||||
|
|
||||||
# This workflow integrates njsscan with GitHub's Code Scanning feature
|
|
||||||
# nodejsscan is a static security code scanner that finds insecure code patterns in your Node.js applications
|
|
||||||
|
|
||||||
name: njsscan sarif
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "master", "devbot" ]
|
|
||||||
pull_request:
|
|
||||||
# The branches below must be a subset of the branches above
|
|
||||||
branches: [ "master", "devbot" ]
|
|
||||||
schedule:
|
|
||||||
- cron: '43 12 * * 6'
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
njsscan:
|
|
||||||
permissions:
|
|
||||||
contents: read # for actions/checkout to fetch code
|
|
||||||
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
|
|
||||||
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: njsscan code scanning
|
|
||||||
steps:
|
|
||||||
- name: Checkout the code
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: nodejsscan scan
|
|
||||||
id: njsscan
|
|
||||||
uses: ajinabraham/njsscan-action@v7
|
|
||||||
with:
|
|
||||||
args: '. --sarif --output results.sarif || true'
|
|
||||||
- name: Upload njsscan report
|
|
||||||
uses: github/codeql-action/upload-sarif@v3
|
|
||||||
with:
|
|
||||||
sarif_file: results.sarif
|
|
||||||
|
|
@ -27,7 +27,7 @@ You can also change the global prefix.
|
||||||
You should enter you discord user id, so you can use the admin commands.
|
You should enter you discord user id, so you can use the admin commands.
|
||||||
Every time you want to change something in this file, you have to restart the bot.
|
Every time you want to change something in this file, you have to restart the bot.
|
||||||
|
|
||||||
If the config is ever changed, you need to either delete it and repeat the steps above or take a look at the util/createInitialConfig.js file.
|
If the config is ever changed, you need to either delete it and repeat the steps above or take a look at the [util/createInitialConfig.js](./util/createInitialConfig.js) file.
|
||||||
|
|
||||||
|
|
||||||
## Known issues
|
## Known issues
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
const fs = require('fs');
|
|
||||||
const {EmbedBuilder} = require('discord.js');
|
const {EmbedBuilder} = require('discord.js');
|
||||||
const getSubdirFiles = require('../../util/getSubdirFiles');
|
const getSubdirFiles = require('../../util/getSubdirFiles');
|
||||||
|
|
||||||
|
|
@ -17,7 +16,6 @@ module.exports = {
|
||||||
let fieldName = `Page [[page]]/${Math.round(client.commands.size / 10)}`;
|
let fieldName = `Page [[page]]/${Math.round(client.commands.size / 10)}`;
|
||||||
let iteration = 0;
|
let iteration = 0;
|
||||||
let num_in_args = false;
|
let num_in_args = false;
|
||||||
let added_commands = 0;
|
|
||||||
let page = -1;
|
let page = -1;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -53,7 +51,6 @@ module.exports = {
|
||||||
if (!command.admin){
|
if (!command.admin){
|
||||||
if(start < iteration){
|
if(start < iteration){
|
||||||
}else{
|
}else{
|
||||||
added_commands++
|
|
||||||
commands = commands + `${prefix}${command.name} | ${command.description}\n`;
|
commands = commands + `${prefix}${command.name} | ${command.description}\n`;
|
||||||
iteration++
|
iteration++
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,10 @@ module.exports = {
|
||||||
"<prefix>custom remove - Delete your custom commands.",
|
"<prefix>custom remove - Delete your custom commands.",
|
||||||
"<prefix>custom owner - check owner of custom command",
|
"<prefix>custom owner - check owner of custom command",
|
||||||
"<prefix>custom list - list all custom commands",
|
"<prefix>custom list - list all custom commands",
|
||||||
"<prefix>custom variables - list all variables you can use"
|
"<prefix>custom variables - list all variables you can use",
|
||||||
|
"<prefix>custom count - display the amount of custom commands"
|
||||||
],
|
],
|
||||||
execute({message, args, client, prefix, owners}) {
|
async execute({message, args, client, prefix, owners}) {
|
||||||
const customPath = 'data/customCommands.json';
|
|
||||||
if(!fs.existsSync(customPath)){
|
|
||||||
fs.writeFileSync(customPath,"[]")
|
|
||||||
}
|
|
||||||
let sendText;
|
let sendText;
|
||||||
let isEmbed = false;
|
let isEmbed = false;
|
||||||
if (args){
|
if (args){
|
||||||
|
|
@ -31,19 +28,21 @@ module.exports = {
|
||||||
let customMessage = args.slice(2, args.length).join(" ");
|
let customMessage = args.slice(2, args.length).join(" ");
|
||||||
|
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "add":
|
case "add":{
|
||||||
if(!customMessage) {
|
if(!customMessage) {
|
||||||
message.channel.send("Message can't be empty");
|
message.channel.send("Message can't be empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendText = addCustomCommand(customName, customMessage, message.author.id);
|
sendText = await addCustomCommand(client, customName, customMessage, message.author.id);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "remove":
|
case "remove":
|
||||||
case "delete":
|
case "delete":{
|
||||||
sendText = deleteCustomCommand(customName, message.author.id, owners);
|
sendText = deleteCustomCommand(customName, message.author.id, owners);
|
||||||
break;
|
break;
|
||||||
case "owner":
|
}
|
||||||
let author = getOwnerOfCustomCommand(customName);
|
case "owner":{
|
||||||
|
let author = await getOwnerOfCustomCommand(customName);
|
||||||
let user;
|
let user;
|
||||||
if(!author)
|
if(!author)
|
||||||
sendText = `${customName} does not exist`
|
sendText = `${customName} does not exist`
|
||||||
|
|
@ -55,10 +54,11 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "list":
|
}
|
||||||
|
case "list": {
|
||||||
const embed = new EmbedBuilder();
|
const embed = new EmbedBuilder();
|
||||||
sendText = getAllCustomCommands();
|
sendText = getAllCustomCommands(client);
|
||||||
if(sendText != ""){
|
if(sendText !== ""){
|
||||||
embed.setColor(15780145)
|
embed.setColor(15780145)
|
||||||
embed.addFields(
|
embed.addFields(
|
||||||
{ name: "Custom commands", value: sendText },
|
{ name: "Custom commands", value: sendText },
|
||||||
|
|
@ -67,13 +67,16 @@ module.exports = {
|
||||||
isEmbed = true;
|
isEmbed = true;
|
||||||
}else sendText = "NO CUSTOM COMMANDS"
|
}else sendText = "NO CUSTOM COMMANDS"
|
||||||
break;
|
break;
|
||||||
case "variables":
|
}
|
||||||
|
case "variables": {
|
||||||
sendText = "The variables you can use are:\n<prefix>\n<globalPrefix>\n<username>\n<nickname>\n<user_id>\n<guild_name>\n<guild_id>"
|
sendText = "The variables you can use are:\n<prefix>\n<globalPrefix>\n<username>\n<nickname>\n<user_id>\n<guild_name>\n<guild_id>"
|
||||||
break;
|
break;
|
||||||
case "edit":
|
}
|
||||||
|
case "edit": {
|
||||||
sendText = editCustomCommand(customName, message.author.id, customMessage)
|
sendText = editCustomCommand(customName, message.author.id, customMessage)
|
||||||
break;
|
break;
|
||||||
case "show":
|
}
|
||||||
|
case "show": {
|
||||||
let json = fs.readFileSync(customPath, 'utf8');
|
let json = fs.readFileSync(customPath, 'utf8');
|
||||||
let customCommands = JSON.parse(json)
|
let customCommands = JSON.parse(json)
|
||||||
sendText = "Command not found."
|
sendText = "Command not found."
|
||||||
|
|
@ -83,12 +86,22 @@ module.exports = {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "rename":
|
}
|
||||||
|
case "rename": {
|
||||||
sendText = renameCustomCommand(customName, args[2], message.author.id);
|
sendText = renameCustomCommand(customName, args[2], message.author.id);
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
case "count": {
|
||||||
|
const customPath = './data/customCommands.json';
|
||||||
|
let json = fs.readFileSync(customPath, 'utf8');
|
||||||
|
let customCommands = JSON.parse(json)
|
||||||
|
sendText = `There are ${customCommands.length} custom commands in total`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
sendText = `Argument not recognized.\n"${prefix}help custom" to see all arguments you can use.`
|
sendText = `Argument not recognized.\n"${prefix}help custom" to see all arguments you can use.`
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isEmbed) message.channel.send({embeds :[sendText]})
|
if(isEmbed) message.channel.send({embeds :[sendText]})
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@ module.exports = {
|
||||||
try {
|
try {
|
||||||
num = num.slice(0, -1);
|
num = num.slice(0, -1);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.channel.send("There was an error.");
|
console.error(e)
|
||||||
|
message.channel.send("There was an error. Check the logs");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
message.channel.send("https://cdn.discordapp.com/emojis/" + num + extension);
|
message.channel.send("https://cdn.discordapp.com/emojis/" + num + extension);
|
||||||
|
|
|
||||||
|
|
@ -17,21 +17,25 @@ module.exports = {
|
||||||
let sendText = "This should never happen.";
|
let sendText = "This should never happen.";
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "add":
|
case "add":
|
||||||
case "create":
|
case "create": {
|
||||||
sendText = await createTimer(message, args, false);
|
sendText = await createTimer(message, args, false);
|
||||||
break;
|
break;
|
||||||
case "edit":
|
}
|
||||||
|
case "edit": {
|
||||||
sendText = "not implemented yet"
|
sendText = "not implemented yet"
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "delete":
|
case "delete":
|
||||||
case "remove":
|
case "remove": {
|
||||||
let timerID = args[1];
|
let timerID = args[1];
|
||||||
sendText = await deleteTimer(message.author.id, timerID);
|
sendText = await deleteTimer(message.author.id, timerID);
|
||||||
break;
|
break;
|
||||||
case "show":
|
}
|
||||||
|
case "show": {
|
||||||
sendText = await showTimer(message.author.id, args[1]);
|
sendText = await showTimer(message.author.id, args[1]);
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
default: {
|
||||||
sendText = "not sure what you mean";
|
sendText = "not sure what you mean";
|
||||||
if(args.length < 2){
|
if(args.length < 2){
|
||||||
sendText = "Please specify a time, and a message to send after the timer has finished";
|
sendText = "Please specify a time, and a message to send after the timer has finished";
|
||||||
|
|
@ -40,6 +44,7 @@ module.exports = {
|
||||||
if(!isNaN(parseTime(args[0], Math.floor(new Date() / 1000))))
|
if(!isNaN(parseTime(args[0], Math.floor(new Date() / 1000))))
|
||||||
sendText = await createTimer(message, args, true);
|
sendText = await createTimer(message, args, true);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
message.channel.send(sendText);
|
message.channel.send(sendText);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
eslint.config.mjs
Normal file
32
eslint.config.mjs
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
import jest from "eslint-plugin-jest";
|
||||||
|
import globals from "globals";
|
||||||
|
export default [{
|
||||||
|
plugins: {
|
||||||
|
jest,
|
||||||
|
},
|
||||||
|
|
||||||
|
languageOptions: {
|
||||||
|
globals: {
|
||||||
|
...globals.jest,
|
||||||
|
...jest.environments.globals.globals,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
rules: {
|
||||||
|
"no-fallthrough": "error",
|
||||||
|
"no-case-declarations": "error",
|
||||||
|
"no-unused-vars": "warn"
|
||||||
|
},
|
||||||
|
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// /** @type {import('eslint').Linter.Config[]} */
|
||||||
|
// export default [
|
||||||
|
// {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}},
|
||||||
|
// {languageOptions: { globals: globals.node }},
|
||||||
|
// pluginJs.configs.recommended,
|
||||||
|
// ];
|
||||||
1135
package-lock.json
generated
1135
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -11,7 +11,8 @@
|
||||||
"sqlite3": "^5.1.6"
|
"sqlite3": "^5.1.6"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest"
|
"test": "jest",
|
||||||
|
"lint": "npx eslint ."
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
@ -20,7 +21,11 @@
|
||||||
"author": "SileNce5k",
|
"author": "SileNce5k",
|
||||||
"license": "UNLICENSE",
|
"license": "UNLICENSE",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^9.14.0",
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^29.5.14",
|
||||||
|
"eslint": "^9.14.0",
|
||||||
|
"eslint-plugin-jest": "^28.8.3",
|
||||||
|
"globals": "^15.12.0",
|
||||||
"jest": "^29.7.0"
|
"jest": "^29.7.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
169
server.js
169
server.js
|
|
@ -1,72 +1,139 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const createInitialConfig = require("./util/createInitialConfig")
|
const createInitialConfig = require("./util/createInitialConfig")
|
||||||
const convertJSONToSQL = require('./util/timer/convertJSONToSQL');
|
const convertTimerJSONToSQL = require('./util/timer/convertTimerJSONToSQL.js');
|
||||||
|
const createTimersTable = require('./server/createDatabaseTables/createTimersTable');
|
||||||
|
const createCustomCommandsTable = require('./server/createDatabaseTables/createCustomCommandsTable.js');
|
||||||
|
const convertCustomCommandsJSONToSQL = require('./server/convertCustomCommandsJSONToSQL.js');
|
||||||
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
if(!fs.existsSync("./data/config.json")) {
|
if(!fs.existsSync("./data/config.json")) {
|
||||||
createInitialConfig();
|
createInitialConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const { Collection, Client, GatewayIntentBits, Partials } = require('discord.js');
|
||||||
|
const client = new Client({ intents: [GatewayIntentBits.Guilds,
|
||||||
|
GatewayIntentBits.GuildMessages,
|
||||||
|
GatewayIntentBits.MessageContent,
|
||||||
|
GatewayIntentBits.GuildMembers,
|
||||||
|
GatewayIntentBits.GuildPresences
|
||||||
|
], partials: [Partials.Channel] });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function checkAndConvertJSONToSQL(){
|
async function checkAndConvertJSONToSQL(){
|
||||||
process.stdout.write("Checking if timers.json exists... ")
|
process.stdout.write("Checking if timers.json exists... ")
|
||||||
if(fs.existsSync("./data/timers.json")){
|
if(fs.existsSync("./data/timers.json")){
|
||||||
process.stdout.write(true + "\n")
|
process.stdout.write(true + "\n")
|
||||||
await createDatabaseTables();
|
await convertTimerJSONToSQL();
|
||||||
await convertJSONToSQL();
|
|
||||||
fs.renameSync('data/timers.json', 'data/timers.json.old');
|
fs.renameSync('data/timers.json', 'data/timers.json.old');
|
||||||
console.log("Renamed timers.json to timers.json.old");
|
console.log("Renamed timers.json to timers.json.old");
|
||||||
}else{
|
}else{
|
||||||
process.stdout.write(false + "\n")
|
process.stdout.write(false + "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process.stdout.write("Checking if customCommands.json exists... ")
|
||||||
|
if(fs.existsSync('./data/customCommands.json')){
|
||||||
|
process.stdout.write(true + "\n")
|
||||||
|
await convertCustomCommandsJSONToSQL();
|
||||||
|
|
||||||
|
fs.renameSync('data/customCommands.json', 'data/customCommands.json.old');
|
||||||
|
}else{
|
||||||
|
process.stdout.write(false + "\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const createDatabaseTables = require('./server/createDatabaseTables');
|
|
||||||
const createLastfmTable = require('./server/createLastfmTable');
|
|
||||||
createLastfmTable();
|
|
||||||
checkAndConvertJSONToSQL();
|
|
||||||
const { Collection, Client, GatewayIntentBits, Partials } = require('discord.js');
|
|
||||||
const client = new Client({ intents: [GatewayIntentBits.Guilds,
|
|
||||||
GatewayIntentBits.GuildMessages,
|
|
||||||
GatewayIntentBits.MessageContent,
|
|
||||||
GatewayIntentBits.GuildMembers,
|
|
||||||
GatewayIntentBits.GuildPresences
|
|
||||||
], partials: [Partials.Channel] });
|
|
||||||
const {
|
|
||||||
globalPrefix,
|
|
||||||
token,
|
|
||||||
loginMessage,
|
|
||||||
loginChannel,
|
|
||||||
enableLoginMessage,
|
|
||||||
owners,
|
|
||||||
presenceType,
|
|
||||||
presenceText
|
|
||||||
} = require('./data/config.json');
|
|
||||||
|
|
||||||
client.settings = new Collection();
|
async function loadcustomCommands() {
|
||||||
client.commands = new Collection();
|
const db = new sqlite3.Database('data/database.db');
|
||||||
client.serverPrefixes = new Collection();
|
client.customCommands = new Collection();
|
||||||
|
db.all("SELECT * FROM customCommands", (error, commands) => {
|
||||||
|
if(error){
|
||||||
|
console.error("Error while loading custom commands:\n",error.message)
|
||||||
|
}else {
|
||||||
|
commands.forEach(command => {
|
||||||
|
client.customCommands.set(command.customName, command.customMessage);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
client.settings.set("presenceType", presenceType);
|
function startBot(){
|
||||||
client.settings.set("presenceText", presenceText);
|
const {
|
||||||
|
globalPrefix,
|
||||||
|
token,
|
||||||
|
loginMessage,
|
||||||
|
loginChannel,
|
||||||
|
enableLoginMessage,
|
||||||
|
owners,
|
||||||
|
presenceType,
|
||||||
|
presenceText
|
||||||
|
} = require('./data/config.json');
|
||||||
|
|
||||||
const reloadCommands = require("./util/reloadCommands.js");
|
client.settings = new Collection();
|
||||||
const onMessage = require('./server/message');
|
client.commands = new Collection();
|
||||||
const onReady = require('./server/ready');
|
client.serverPrefixes = new Collection();
|
||||||
|
|
||||||
reloadCommands(client)
|
|
||||||
|
|
||||||
client.once('ready', () => {
|
|
||||||
onReady(client, enableLoginMessage, loginChannel, loginMessage)
|
|
||||||
});
|
|
||||||
|
|
||||||
client.once('reconnecting', () => {
|
|
||||||
console.log('Reconnecting!');
|
|
||||||
});
|
|
||||||
|
|
||||||
client.once('disconnect', () => {
|
|
||||||
console.log('Disconnect!');
|
|
||||||
});
|
|
||||||
|
|
||||||
client.on('messageCreate', async message => {
|
|
||||||
onMessage(client, owners, message, globalPrefix);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
client.login(token);
|
client.settings.set("presenceType", presenceType);
|
||||||
|
client.settings.set("presenceText", presenceText);
|
||||||
|
|
||||||
|
const reloadCommands = require("./util/reloadCommands.js");
|
||||||
|
const onMessage = require('./server/message');
|
||||||
|
const onReady = require('./server/ready');
|
||||||
|
|
||||||
|
reloadCommands(client)
|
||||||
|
|
||||||
|
client.once('ready', () => {
|
||||||
|
onReady(client, enableLoginMessage, loginChannel, loginMessage)
|
||||||
|
});
|
||||||
|
|
||||||
|
client.once('reconnecting', () => {
|
||||||
|
console.log('Reconnecting!');
|
||||||
|
});
|
||||||
|
|
||||||
|
client.once('disconnect', () => {
|
||||||
|
console.log('Disconnect!');
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('messageCreate', async message => {
|
||||||
|
onMessage(client, owners, message, globalPrefix);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
client.login(token);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async function prepareBot(){
|
||||||
|
const createLastfmTable = require('./server/createDatabaseTables/createLastfmTable');
|
||||||
|
|
||||||
|
|
||||||
|
const taskGroups = [
|
||||||
|
[
|
||||||
|
createTimersTable,
|
||||||
|
createLastfmTable,
|
||||||
|
createCustomCommandsTable
|
||||||
|
],
|
||||||
|
[
|
||||||
|
checkAndConvertJSONToSQL
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
for (const taskGroup of taskGroups) {
|
||||||
|
await Promise.all(taskGroup.map(task => task()));
|
||||||
|
}
|
||||||
|
loadcustomCommands()
|
||||||
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareBot().then( () => {
|
||||||
|
startBot();
|
||||||
|
}).catch(error => {
|
||||||
|
console.error("Error preparing the bot:\n", error)
|
||||||
|
})
|
||||||
|
|
|
||||||
28
server/convertCustomCommandsJSONToSQL.js
Normal file
28
server/convertCustomCommandsJSONToSQL.js
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
|
module.exports = async function () {
|
||||||
|
const customCommands = require('../data/customCommands.json')
|
||||||
|
const db = new sqlite3.Database('data/database.db');
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
customCommands.forEach(command => {
|
||||||
|
const isDeleted = false;
|
||||||
|
|
||||||
|
db.run(`INSERT INTO customCommands (
|
||||||
|
customName,
|
||||||
|
customMessage,
|
||||||
|
author,
|
||||||
|
isDeleted
|
||||||
|
) VALUES (?, ?, ?, ?)`, [command.customName, command.customMessage, command.author, isDeleted], function (error) {
|
||||||
|
if (error) {
|
||||||
|
console.error(`Error while converting customCommands.json to SQL: ${error}`)
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
db.close();
|
||||||
|
console.log("Converted customCommands.json to SQL successfully.");
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
}
|
||||||
24
server/createDatabaseTables/createCustomCommandsTable.js
Normal file
24
server/createDatabaseTables/createCustomCommandsTable.js
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
|
|
||||||
|
module.exports = async function () {
|
||||||
|
const db = new sqlite3.Database('data/database.db');
|
||||||
|
return new Promise ((resolve, reject)=>{
|
||||||
|
db.run(
|
||||||
|
`CREATE TABLE IF NOT EXISTS customCommands (
|
||||||
|
customName TEXT PRIMARY KEY,
|
||||||
|
customMessage TEXT,
|
||||||
|
author TEXT,
|
||||||
|
isDeleted INTEGER)`,
|
||||||
|
(err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(`Error while creating table 'customCommands': ${err}`);
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
console.log("Table 'customCommands' created successfully.");
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -23,16 +23,10 @@ module.exports = function(client, owners, message, globalPrefix){
|
||||||
const commandName = args.shift().toLowerCase();
|
const commandName = args.shift().toLowerCase();
|
||||||
const command = client.commands.get(commandName);
|
const command = client.commands.get(commandName);
|
||||||
if (!command){
|
if (!command){
|
||||||
const customPath = './data/customCommands.json';
|
const command = client.customCommands.get(commandName);
|
||||||
if(fs.existsSync(customPath)){
|
if(command){
|
||||||
let json = fs.readFileSync(customPath, 'utf8');
|
let customMessage = customReplaceWithVariables(command, message, prefix, globalPrefix);
|
||||||
let customCommands = JSON.parse(json)
|
message.channel.send(customMessage);
|
||||||
customCommands.forEach(function (customCommand) {
|
|
||||||
if (customCommand.customName === commandName) {
|
|
||||||
let customMessage = customReplaceWithVariables(customCommand.customMessage, message, prefix, globalPrefix)
|
|
||||||
message.channel.send(customMessage)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@ module.exports = function(client, enableLoginMessage, loginChannel, loginMessage
|
||||||
try{
|
try{
|
||||||
client.channels.cache.get(loginChannel).send(loginMessage)
|
client.channels.cache.get(loginChannel).send(loginMessage)
|
||||||
}catch(err){
|
}catch(err){
|
||||||
console.log("Failed trying to send a message on login.\n")
|
console.error("Failed trying to send a message on login.\n")
|
||||||
|
console.error(err)
|
||||||
}
|
}
|
||||||
loadServerPrefixes(client)
|
loadServerPrefixes(client)
|
||||||
checkTimer(client);
|
checkTimer(client);
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,33 @@
|
||||||
const fs = require('fs');
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
module.exports = function(customName, customMessage, author){
|
module.exports = async function(client, customName, customMessage, author){
|
||||||
let sendText;
|
|
||||||
const customPath = './data/customCommands.json';
|
let sendText = "";
|
||||||
|
let isExists = client.customCommands.get(customName);
|
||||||
let json = fs.readFileSync(customPath, 'utf8');
|
|
||||||
let customCommands = JSON.parse(json)
|
|
||||||
|
|
||||||
let isExists = false;
|
|
||||||
customCommands.forEach(function (customCommand) {
|
|
||||||
if (customCommand.customName === customName) {
|
|
||||||
sendText = "This custom command already exists";
|
|
||||||
isExists = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!isExists) {
|
if (!isExists) {
|
||||||
let newCustomCommand = {
|
const db = new sqlite3.Database("data/database.db");
|
||||||
"customName": customName, "customMessage": customMessage, "author": author
|
sendText = await new Promise((resolve, reject)=>{
|
||||||
}
|
|
||||||
customCommands.push(newCustomCommand)
|
db.run(`INSERT INTO customCommands (
|
||||||
sendText = `New custom command with the name "${customName}" added`
|
customName,
|
||||||
|
customMessage,
|
||||||
|
author,
|
||||||
|
isDeleted
|
||||||
|
) VALUES (?, ?, ?, ?)`, [customName, customMessage, author, false],
|
||||||
|
|
||||||
|
function(error){
|
||||||
|
if(error){
|
||||||
|
console.error(error)
|
||||||
|
let sendText = "Error while inserting new custom command.";
|
||||||
|
reject(sendText);
|
||||||
|
}else{
|
||||||
|
client.customCommands.set(customName, customMessage)
|
||||||
|
let sendText = `New custom command with the name "${customName}" added`
|
||||||
|
resolve(sendText)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
db.close();
|
||||||
}
|
}
|
||||||
fs.writeFileSync(customPath, JSON.stringify(customCommands, null, 4))
|
|
||||||
return sendText;
|
return sendText;
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +1,7 @@
|
||||||
const fs = require('fs');
|
|
||||||
module.exports = function(){
|
|
||||||
const customPath = './data/customCommands.json';
|
module.exports = function(client){
|
||||||
let list = "";
|
let list = "";
|
||||||
|
client.customCommands.keys().forEach(commandName => list += `${commandName}\n`)
|
||||||
let json = fs.readFileSync(customPath, 'utf8');
|
|
||||||
let customCommands = JSON.parse(json)
|
|
||||||
customCommands.forEach(function (customCommand) {
|
|
||||||
list = list + customCommand.customName+"\n";
|
|
||||||
});
|
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,24 @@
|
||||||
const fs = require('fs');
|
|
||||||
module.exports = function(customName){
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
const customPath = './data/customCommands.json';
|
module.exports = async function(customName){
|
||||||
let json = fs.readFileSync(customPath, 'utf8');
|
const db = new sqlite3.Database("data/database.db");
|
||||||
let customCommands = JSON.parse(json)
|
|
||||||
let author = customCommands.filter(customCommands => customCommands.customName === customName);
|
let author = await new Promise((resolve, reject)=>{
|
||||||
if(author.length === 0) return false;
|
db.get("SELECT * FROM customCommands WHERE customName = ? AND isDeleted = 0", [customName],
|
||||||
return author[0].author;
|
function(error, command){
|
||||||
|
if(error){
|
||||||
|
console.error(error)
|
||||||
|
let author = "Error when getting the owner of this custom command. Check console.";
|
||||||
|
reject(author)
|
||||||
|
}else {
|
||||||
|
let author;
|
||||||
|
if(command){
|
||||||
|
author = command.author;
|
||||||
|
}
|
||||||
|
resolve(author)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return author;
|
||||||
}
|
}
|
||||||
|
|
@ -25,6 +25,7 @@ module.exports = async function(userID, guild) {
|
||||||
try {
|
try {
|
||||||
track = data.recenttracks.track[0];
|
track = data.recenttracks.track[0];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
scrobble.error = true;
|
scrobble.error = true;
|
||||||
switch(data.error){
|
switch(data.error){
|
||||||
case 6:
|
case 6:
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ module.exports = async function (userID, guild) {
|
||||||
}
|
}
|
||||||
resolve(tracks);
|
resolve(tracks);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
let scrobble = {};
|
let scrobble = {};
|
||||||
scrobble.error = true;
|
scrobble.error = true;
|
||||||
if (data.error === 6) {
|
if (data.error === 6) {
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,40 @@
|
||||||
module.exports = function (user) {
|
module.exports = function (user) {
|
||||||
let details;
|
let details;
|
||||||
switch (user.presence.activities[0].name) {
|
switch (user.presence.activities[0].name) {
|
||||||
case "foobar2000":
|
case "foobar2000": {
|
||||||
let artist = user.presence.activities[0].state.split(":")[0];
|
let artist = user.presence.activities[0].state.split(":")[0];
|
||||||
let album = user.presence.activities[0].state.split(":")[1].slice(1);
|
let album = user.presence.activities[0].state.split(":")[1].slice(1);
|
||||||
|
|
||||||
details = `Artist: ${artist}\nAlbum: ${album}\nSong: ${user.presence.activities[0].details}\n`
|
details = `Artist: ${artist}\nAlbum: ${album}\nSong: ${user.presence.activities[0].details}\n`
|
||||||
break;
|
break;
|
||||||
case "Apple Music":
|
}
|
||||||
|
case "Apple Music": {
|
||||||
details = `Artist/Song: ${user.presence.activities[0].details} \nAlbum: ${user.presence.activities[0].state}\n`
|
details = `Artist/Song: ${user.presence.activities[0].details} \nAlbum: ${user.presence.activities[0].state}\n`
|
||||||
break;
|
break;
|
||||||
case "Spotify":
|
}
|
||||||
|
case "Spotify": {
|
||||||
details = `Artist: ${user.presence.activities[0].state}\nAlbum: ${user.presence.activities[0].details}\nSong: ${user.presence.activities[0].assets.largeText}\n`
|
details = `Artist: ${user.presence.activities[0].state}\nAlbum: ${user.presence.activities[0].details}\nSong: ${user.presence.activities[0].assets.largeText}\n`
|
||||||
break;
|
break;
|
||||||
case "Custom Status":
|
}
|
||||||
|
case "Custom Status": {
|
||||||
if(user.presence.activities[0].state !== null)
|
if(user.presence.activities[0].state !== null)
|
||||||
details = `"${user.presence.activities[0].state}"\n`
|
details = `"${user.presence.activities[0].state}"\n`
|
||||||
else
|
else
|
||||||
details = "";
|
details = "";
|
||||||
break;
|
break;
|
||||||
case "Code":
|
}
|
||||||
|
case "Code": {
|
||||||
if(user.presence.activities[0].details != null)
|
if(user.presence.activities[0].details != null)
|
||||||
if(user.presence.activities[0].details.slice(0, 7) === "Editing")
|
if(user.presence.activities[0].details.slice(0, 7) === "Editing")
|
||||||
details = `Workspace: ${user.presence.activities[0].state}\nEditing: ${user.presence.activities[0].details.slice(8)}\n`
|
details = `Workspace: ${user.presence.activities[0].state}\nEditing: ${user.presence.activities[0].details.slice(8)}\n`
|
||||||
else
|
else
|
||||||
details = `Workspace: ${user.presence.activities[0].state}\n${user.presence.activities[0].details}\n`
|
details = `Workspace: ${user.presence.activities[0].state}\n${user.presence.activities[0].details}\n`
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
default: {
|
||||||
details = 0;
|
details = 0;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return details
|
return details
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
const fs = require('fs');
|
|
||||||
const getSubdirFiles = require('./getSubdirFiles');
|
const getSubdirFiles = require('./getSubdirFiles');
|
||||||
const commandPath = 'commands/'
|
const commandPath = 'commands/'
|
||||||
const utilPath = 'util/'
|
const utilPath = 'util/'
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
const sendTimerReminder = require('./sendTimerReminder')
|
const sendTimerReminder = require('./sendTimerReminder')
|
||||||
const fs = require('fs')
|
|
||||||
const sqlite3 = require('sqlite3').verbose();
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
module.exports = async function (client) {
|
module.exports = async function (client) {
|
||||||
const checkTimer = require('./checkTimer')
|
const checkTimer = require('./checkTimer')
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
const fs = require('fs');
|
|
||||||
const sqlite3 = require('sqlite3').verbose();
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
module.exports = async function () {
|
module.exports = async function () {
|
||||||
const timers = require('../../data/timers.json')
|
const timers = require('../../data/timers.json')
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
const fs = require('fs');
|
|
||||||
const parseTime = require('./parseTime');
|
const parseTime = require('./parseTime');
|
||||||
const sqlite3 = require('sqlite3').verbose();
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
module.exports = async function (message, args, compatibility) {
|
module.exports = async function (message, args, compatibility) {
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ module.exports = function(time, currentUnixTime){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function getTime(time, currentUnixTime) {
|
// function getTime(time, currentUnixTime) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return timeInSeconds;
|
// return timeInSeconds;
|
||||||
}
|
// }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue