initial commit

This commit is contained in:
Aiden
2022-10-07 14:31:30 +02:00
parent b8b1aee4e6
commit f06f277329
18 changed files with 2606 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
// require("../../requires")
const { PartialGroupDMChannel } = require("discord.js");
// Here you can add functions that will be run at each startup of the bot
module.exports = {
name:"Startup_function",
async function(msg, args){
setTimeout(async () => {
console.log("-------------------------------- Startup Function ------------------------------");
// await commands.get("registerCommands").function(false)
// plogger.info("Startup done")
// commands.get("garbage_collector").function()
console.log("--------------------------------------------------------------------------------");
}, 500);
}
}
+40
View File
@@ -0,0 +1,40 @@
module.exports = {
name: "profile_handler",
async function(interactionObject) {
return new Promise(async resolve => {
var user = interactionObject.user
var guild = interactionObject.guild
// Check if profiles object exists, and create it if not
if(!sharedVars.profiles){
sharedVars.profiles = {}
}
// Check if user exists in profiles object, if not, create
if(!sharedVars.profiles[user.id]){
sharedVars.profiles[user.id] = {}
var userdata = await commands.get("queryCommand").function(`SELECT * FROM tbl_users WHERE dtDiscordID = ?`,[user.id])
if(userdata.length == 0){
resolve(false)
return
}
sharedVars.profiles[user.id].key = userdata[0].dtKey
sharedVars.profiles[user.id].userid = userdata[0].idUser
sharedVars.profiles[user.id].credits = userdata[0].dtCredits
}
sharedVars.profiles[user.id].lastEdit = new Date().getTime()
resolve(true)
})
},
getKey : async function(interactionObject){
return new Promise(async resolve => {
var userid = interactionObject.user.id
if(!sharedVars.profiles){ resolve(false);return}
if(!sharedVars.profiles[userid]){ resolve(false);return}
if(!sharedVars.profiles[userid].key){ resolve(false);return}
resolve(sharedVars.profiles[userid].key)
})
}
}
+47
View File
@@ -0,0 +1,47 @@
// const included = require("../../requires")
var pool = mysql.createPool({
connectionLimit : 10,
host: config.database.host,
port: config.database.port,
user: config.database.username,
password: config.database.password,
database: config.database.dbname,
charset : 'utf8mb4'
});
module.exports = {
name: "queryCommand",
async function(msg, query, values){
if(values == undefined){
values = query
query = msg
}
return new Promise(resolve => {
// connection.query(query, values, function (error, results, fields) {
// if (error) throw error;
// resolve(results)
// });
pool.getConnection(function(err, connection) {
if (err) throw err; // not connected!
// Use the connection
connection.query(query, values, function (error, results, fields) {
// When done with the connection, release it.
connection.release();
// Handle error after the release.
if (error){
// console.log(error) //-------------------------------------------------------------------------- DEBUGGING
resolve(false)
}
resolve(results)
// Don't use the connection here, it has been returned to the pool.
});
});
})
}
}
+67
View File
@@ -0,0 +1,67 @@
// require("../../requires")
module.exports = {
name: "registerCommands",
async function(global, guild){
return new Promise(resolve => {
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v10');
const token = config.token
const commandsList = []
var commandstopush = "| "
commands.forEach(element => {
if(element.slashcommand != undefined){
if(global){
if(element.slashcommandGlobal){
commandstopush += `${element.name} | `
commandsList.push(element.slashcommand)
}
}else{
commandstopush += `${element.name} | `
commandsList.push(element.slashcommand)
}
// commandsList.push(element.slashcommand)
}
});
console.log(commandstopush);
const rest = new REST({ version: '10' }).setToken(token);
const clientId = client.user.id;
const guildId = '976160478432735272';
(async () => {
try {
if(!global){
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commandsList },
);
}else{
if(guild == undefined){
await rest.put(
Routes.applicationCommands(clientId),
{ body: commandsList },
);
}else{
await rest.put(
Routes.applicationGuildCommands(clientId, guild.id),
{ body: commandsList },
);
}
}
console.log('Successfully registered application commands.');
resolve()
} catch (error) {
console.error(error);
resolve()
}
})();
})
}
}
+28
View File
@@ -0,0 +1,28 @@
const included = require("../../requires")
// Here you can add functions that will be run at each startup of the bot
module.exports = {
name:"reloadCommands",
async function(msg, args){
commands.clear()
var path = `${__dirname}/../../functions`
var folders = fs.readdirSync(path).filter(function (file) {
return fs.statSync(path+'/'+file).isDirectory();
});
folders.forEach(element => {
var commandFiles = fs.readdirSync(`${path}/${element}`).filter(file => file.endsWith('.js') && !file.startsWith("index"));
for (const file of commandFiles) {
delete require.cache[require.resolve(`${path}/${element}/${file}`)];
try {
const command = require(`${path}/${element}/${file}`);
commands.set(command.name, command);
} catch (error) {
console.log(error);
}
}
});
console.log(`Reloading ${commands.size} modules done`)
}
}