initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// const { Chart } = require("chart.js");
|
||||
const wait = require('util').promisify(setTimeout);
|
||||
|
||||
module.exports = {
|
||||
name: "dbg",
|
||||
slashcommand:
|
||||
new SlashCommandBuilder()
|
||||
.setName("dbg")
|
||||
.setDescription("This command is for debugging purposes only, only the dev can issue the command"),
|
||||
slashcommandGlobal:false,
|
||||
async function(interactionObject) {
|
||||
// interactionObject.deferReply()
|
||||
var modal = new Modal()
|
||||
.setCustomId("testModal")
|
||||
.setTitle("Fill me uwu")
|
||||
|
||||
var testInput1 = new TextInputComponent()
|
||||
.setCustomId("testInput")
|
||||
.setLabel("Input some data into me uwu")
|
||||
.setStyle("SHORT")
|
||||
|
||||
const firstActionRow = new MessageActionRow().addComponents(testInput1)
|
||||
const secondActionRow = new MessageActionRow().addComponents(textMenu)
|
||||
modal.addComponents(firstActionRow, secondActionRow)
|
||||
|
||||
await interactionObject.showModal(modal).then(res => {
|
||||
console.log(res);
|
||||
})
|
||||
|
||||
// Collect a modal submit interaction
|
||||
const filter = (b) => b.customId === 'testModal' && b.user.id == interactionObject.user.id && b.channelid == interactionObject.channelid;
|
||||
interactionObject.awaitModalSubmit({ filter, time: 30000 })
|
||||
.then(i => {
|
||||
// console.log(interactionObject.id)
|
||||
// console.log(i.id);
|
||||
i.reply(`${i.fields.getTextInputValue('testInput')}`)
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// const included = require(`../../requires`)
|
||||
|
||||
/*
|
||||
|
||||
DO NOT FORGET TO ADD EVERY SINGLE EVENT ADDED HERE TO THE REMOVELISTENER ARRAY
|
||||
|
||||
*/
|
||||
|
||||
client.removeAllListeners("interactionCreate")
|
||||
|
||||
client.on("interactionCreate", async (interaction) => {
|
||||
if(interaction.isCommand()){
|
||||
commands.get("onSlashCommand").function(interaction)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,12 @@
|
||||
const included = require("../../requires")
|
||||
|
||||
|
||||
module.exports = {
|
||||
name:"buttonClick",
|
||||
event:true,
|
||||
async function(button){
|
||||
|
||||
|
||||
// button.reply.defer()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
const included = require("../../requires")
|
||||
|
||||
|
||||
module.exports = {
|
||||
name:"onSlashCommand",
|
||||
event:true,
|
||||
async function(interaction){
|
||||
// console.log(interaction)
|
||||
if(commands.get(interaction.commandName)){
|
||||
// interaction.reply("a", {ephermal:true})
|
||||
commands.get(interaction.commandName).function(interaction)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// require("../../requires")
|
||||
// const Canvas = require("canvas");
|
||||
|
||||
|
||||
// const { Chart } = require("chart.js");
|
||||
const wait = require('util').promisify(setTimeout);
|
||||
|
||||
module.exports = {
|
||||
name: "command",
|
||||
slashcommand:
|
||||
new SlashCommandBuilder()
|
||||
.setName("command")
|
||||
.setDescription("Send command to the server console")
|
||||
.addStringOption(option => option
|
||||
.setName("command")
|
||||
.setDescription("The action to perform on a user")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption(option => option
|
||||
.setRequired(true)
|
||||
.setName("server_identifier")
|
||||
.setDescription("The server to perform the action on")
|
||||
)
|
||||
.addStringOption(option => option
|
||||
.setName("visibility")
|
||||
.setDescription("Show the result only to yourself, or everyone in chat")
|
||||
.addChoices(
|
||||
{ name: 'public', value: '0' },
|
||||
{ name: 'private', value: '1' }
|
||||
)
|
||||
)
|
||||
|
||||
,
|
||||
slashcommandGlobal:false,
|
||||
async function(interactionObject) {
|
||||
let ephemeral = interactionObject.options.getString("visibility")
|
||||
let serverid = interactionObject.options.getString("server_identifier")
|
||||
let command = interactionObject.options.getString("command")
|
||||
if(ephemeral == undefined){
|
||||
ephemeral = true
|
||||
}else{
|
||||
if(ephemeral == "1"){
|
||||
ephemeral = true
|
||||
}else{
|
||||
ephemeral = false
|
||||
}
|
||||
}
|
||||
await interactionObject.deferReply({ephemeral:ephemeral})
|
||||
|
||||
|
||||
if(!await commands.get("profile_handler").function(interactionObject)){
|
||||
interactionObject.editReply("You need to have an account in order to use this command, please register first")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
fetch(`${config.panel.url}/api/client/servers/${serverid}/command`,{
|
||||
"method": "POST",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${await commands.get("profile_handler").getKey(interactionObject)}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
},
|
||||
"body": JSON.stringify({
|
||||
"command": `${command}`
|
||||
})
|
||||
})
|
||||
.then(async response => {
|
||||
// console.log(response);
|
||||
var message = {
|
||||
embeds:[{
|
||||
color: `#F7A8B8`,
|
||||
description: `Server has received the command \`${command}\``
|
||||
}]
|
||||
}
|
||||
switch(response.status){
|
||||
case 204:
|
||||
// change nothing
|
||||
break;
|
||||
case 404:
|
||||
message.embeds[0].description = `You do not seem to have permissions to perform this action on the specified server`
|
||||
break
|
||||
case 502:
|
||||
message.embeds[0].description = `The server must be running in order for the command to be passed to it`
|
||||
break
|
||||
default:
|
||||
message.embeds[0].description = `Unknown error, please try again\nIf the issue persists, contact your server administrator\nResponse Code : ${response.status}`
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
interactionObject.editReply(message)
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
// require("../../requires")
|
||||
// const Canvas = require("canvas");
|
||||
|
||||
|
||||
// const { Chart } = require("chart.js");
|
||||
const wait = require('util').promisify(setTimeout);
|
||||
|
||||
module.exports = {
|
||||
name: "power",
|
||||
slashcommand:
|
||||
new SlashCommandBuilder()
|
||||
.setName("power")
|
||||
.setDescription("Send power options to the server")
|
||||
.addStringOption(option => option
|
||||
.setName("action")
|
||||
.setDescription("The action to perform on the server")
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: 'start', value: 'start' },
|
||||
{ name: 'restart', value: 'restart'},
|
||||
{ name: 'stop', value: 'stop' },
|
||||
{ name: 'kill', value: 'kill' }
|
||||
)
|
||||
)
|
||||
.addStringOption(option => option
|
||||
.setRequired(true)
|
||||
.setName("server_identifier")
|
||||
.setDescription("The server to perform the action on")
|
||||
)
|
||||
.addStringOption(option => option
|
||||
.setName("visibility")
|
||||
.setDescription("Show the result only to yourself, or everyone in chat")
|
||||
.addChoices(
|
||||
{ name: 'public', value: '0' },
|
||||
{ name: 'private', value: '1' }
|
||||
)
|
||||
)
|
||||
|
||||
,
|
||||
slashcommandGlobal:false,
|
||||
async function(interactionObject) {
|
||||
let ephemeral = interactionObject.options.getString("visibility")
|
||||
let action = interactionObject.options.getString("action")
|
||||
let serverid = interactionObject.options.getString("server_identifier")
|
||||
if(ephemeral == undefined){
|
||||
ephemeral = true
|
||||
}else{
|
||||
if(ephemeral == "1"){
|
||||
ephemeral = true
|
||||
}else{
|
||||
ephemeral = false
|
||||
}
|
||||
}
|
||||
await interactionObject.deferReply({ephemeral:ephemeral})
|
||||
|
||||
|
||||
|
||||
if(!await commands.get("profile_handler").function(interactionObject)){
|
||||
interactionObject.editReply("You need to have an account in order to use this command, please register first")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
switch(action){
|
||||
case "start":
|
||||
case "restart":
|
||||
case "stop":
|
||||
case "kill":
|
||||
break;
|
||||
|
||||
default:
|
||||
interactionObject.editReply("You somehow managed to supply an invalid power option, please dont try to break this system, thanks")
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`${config.panel.url}/api/client/servers/${serverid}/power`,{
|
||||
"method": "POST",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${await commands.get("profile_handler").getKey(interactionObject)}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
},
|
||||
"body": JSON.stringify({
|
||||
"signal": `${action}`
|
||||
})
|
||||
})
|
||||
.then(async response => {
|
||||
// console.log(response);
|
||||
var message = {
|
||||
embeds:[{
|
||||
color: `#F7A8B8`,
|
||||
description: `Server has received \`${action}\` power option`
|
||||
}]
|
||||
}
|
||||
switch(response.status){
|
||||
case 204:
|
||||
// message.embeds[0].title
|
||||
break;
|
||||
case 404:
|
||||
message.embeds[0].description = `You do not seem to have permissions to perform this action on the specified server`
|
||||
break
|
||||
default:
|
||||
message.embeds[0].description = `Unknown error, please try again\nIf the issue persists, contact your server administrator\nResponse Code : ${response.status}`
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
interactionObject.editReply(message)
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
const { config } = require('process');
|
||||
|
||||
const wait = require('util').promisify(setTimeout);
|
||||
|
||||
module.exports = {
|
||||
name: "register",
|
||||
slashcommand:
|
||||
new SlashCommandBuilder()
|
||||
.setName("register")
|
||||
.setDescription("Register an account on the local pterodactyl web panel")
|
||||
.addStringOption(option => option
|
||||
.setName("username")
|
||||
.setDescription("The username for your account (needed if no client key is supplied)")
|
||||
)
|
||||
.addStringOption(option => option
|
||||
.setName("client_key")
|
||||
.setDescription("If you already have an account, create a client key, and add that one here to link your account")
|
||||
),
|
||||
slashcommandGlobal:false,
|
||||
async function(interactionObject) {
|
||||
|
||||
var username = interactionObject.options.getString("username")
|
||||
var client_key = interactionObject.options.getString("client_key")
|
||||
var firstname = interactionObject.options.getString("firstname")
|
||||
var lastname = interactionObject.options.getString("lastname")
|
||||
|
||||
var password = hashids.encode(Math.floor(Math.random() * 1000000))
|
||||
|
||||
var ephemeral = true
|
||||
if(client_key != null){
|
||||
ephemeral = true
|
||||
}
|
||||
await interactionObject.deferReply({ephemeral:ephemeral})
|
||||
|
||||
|
||||
|
||||
if(!config.panel.allowRegistration){
|
||||
return;
|
||||
}
|
||||
|
||||
// This part triggers only when the client key is present, and is the only part that will trigger in that case
|
||||
// It will request the user's data based on the presented key, and then append that data to the account in the database or create one if none should be found
|
||||
if(client_key != null){
|
||||
if(client_key.length != 48){
|
||||
interactionObject.editReply("Incorrect Client Key size")
|
||||
return
|
||||
}
|
||||
fetch(`${config.panel.url}/api/client/account`,{
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${client_key}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
}
|
||||
})
|
||||
.then(async response => {
|
||||
response = await response.json()
|
||||
if(response.errors){
|
||||
switch(response.errors[0].status){
|
||||
case "500":
|
||||
interactionObject.editReply("Server Error")
|
||||
break;
|
||||
}
|
||||
return
|
||||
}
|
||||
commands.get("queryCommand").function("INSERT INTO tbl_users (idUser,dtDiscordID,dtKey) VALUES (?,?,?) ON DUPLICATE KEY UPDATE dtKey = ?",[response.attributes.id,interactionObject.user.id,client_key,client_key]).then(result => {
|
||||
if(!result){
|
||||
interactionObject.editReply(`There was an error trying to write the user to the database \nMake sure that the bot was set up correctly`)
|
||||
return
|
||||
}
|
||||
interactionObject.editReply(`User ${response.attributes.username} linked`)
|
||||
})
|
||||
console.log(response);
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
|
||||
if(client_key != null)
|
||||
return
|
||||
|
||||
if(username == null){
|
||||
interactionObject.editReply("You need to supply a valid username or a client key if you already have an account")
|
||||
return}
|
||||
|
||||
if(!config.panel.allowRegistration){
|
||||
interactionObject.editReply("Registering new account has been disabled by the administrator")
|
||||
return
|
||||
}
|
||||
|
||||
fetch(`${config.panel.url}/api/application/users`,{
|
||||
"method": "POST",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${config.panel.applicationKey}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
},
|
||||
"body":JSON.stringify({
|
||||
"email": `${interactionObject.user.id}@goodanimemes.com`,
|
||||
"username": `${username}`,
|
||||
"first_name": `${firstname}`,
|
||||
"last_name": `${lastname}`,
|
||||
"password": `${password}`
|
||||
})
|
||||
})
|
||||
.then(async response => {
|
||||
response = await response.json()
|
||||
console.log(response);
|
||||
if(response.errors){
|
||||
switch(response.errors[0].status){
|
||||
case "500":
|
||||
interactionObject.editReply("Server Error")
|
||||
break;
|
||||
case "422":
|
||||
interactionObject.editReply(response.errors[0].detail)
|
||||
break;
|
||||
}
|
||||
return
|
||||
}
|
||||
commands.get("queryCommand").function("INSERT INTO tbl_users (idUser,dtDiscordID) VALUES (?,?)",[response.attributes.id,interactionObject.user.id]).then(result => {
|
||||
if(!result){
|
||||
interactionObject.editReply(`There was an error trying to write the user to the database \nMake sure that the bot was set up correctly`)
|
||||
return
|
||||
}
|
||||
interactionObject.editReply(`User ${response.attributes.username} created`)
|
||||
|
||||
|
||||
|
||||
|
||||
interactionObject.user.send(
|
||||
`${config.panel.url}\n
|
||||
The password for your account __${username}__ is __${password}__\n\n
|
||||
Now you can log into your account and go to your profile settings\n
|
||||
Go to \`API Credentials\` and create a new key\n
|
||||
Then go back to the server and use the register command again, this time using the \`client_key\` parameter with the key you just created
|
||||
This message will get deleted in 2 minutes`
|
||||
).then(dm => {
|
||||
setTimeout(() => {
|
||||
dm.delete()
|
||||
}, 120000);
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
// require("../../requires")
|
||||
// const Canvas = require("canvas");
|
||||
|
||||
|
||||
// const { Chart } = require("chart.js");
|
||||
const wait = require('util').promisify(setTimeout);
|
||||
|
||||
module.exports = {
|
||||
name: "list_servers",
|
||||
slashcommand:
|
||||
new SlashCommandBuilder()
|
||||
.setName("list_servers")
|
||||
.setDescription("List my servers")
|
||||
.addStringOption(option => option
|
||||
.setName("server_identifier")
|
||||
.setDescription("To get details on a server, you need to supply the server's identifier (ex : )")
|
||||
)
|
||||
.addStringOption(option => option
|
||||
.setName("visibility")
|
||||
.setDescription("Show the result only to yourself, or everyone in chat")
|
||||
.addChoices(
|
||||
{ name: 'public', value: '0' },
|
||||
{ name: 'private', value: '1' }
|
||||
)
|
||||
)
|
||||
|
||||
,
|
||||
slashcommandGlobal:false,
|
||||
async function(interactionObject) {
|
||||
let ephemeral = interactionObject.options.getString("visibility")
|
||||
let serverid = interactionObject.options.getString("server_identifier")
|
||||
if(ephemeral == undefined){
|
||||
ephemeral = true
|
||||
}else{
|
||||
if(ephemeral == "1"){
|
||||
ephemeral = true
|
||||
}else{
|
||||
ephemeral = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await interactionObject.deferReply({ephemeral:ephemeral})
|
||||
if(!await commands.get("profile_handler").function(interactionObject)){
|
||||
interactionObject.editReply("You need to have an account in order to use this command, please register first")
|
||||
return
|
||||
}
|
||||
|
||||
if(serverid != undefined){
|
||||
if(serverid.length != 8){
|
||||
interactionObject.editReply("The server id you supplied is incorrect")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
fetch(`${config.panel.url}/api/client/servers/${serverid}`,{
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${await commands.get("profile_handler").getKey(interactionObject)}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
}
|
||||
})
|
||||
.then(async response => {
|
||||
response = await response.json()
|
||||
|
||||
var response2 = await fetch(`${config.panel.url}/api/client/servers/${serverid}/resources`,{
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${await commands.get("profile_handler").getKey(interactionObject)}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
}
|
||||
})
|
||||
|
||||
var response2 = await response2.json()
|
||||
var resources = response2.attributes.resources
|
||||
|
||||
var serverStatus
|
||||
switch(response2.attributes.current_state){
|
||||
case "running": serverStatus = "Running 🟢"; break;
|
||||
case "starting": serverStatus = "Starting 🟡"; break;
|
||||
case "offline": serverStatus = "Offline 🔴"; break;
|
||||
default: serverStatus = "Unknown ⚫"; break;
|
||||
}
|
||||
|
||||
var attributes = response.attributes
|
||||
var limits = response.attributes.limits
|
||||
var fields = [
|
||||
{
|
||||
"name": `Attributes`,
|
||||
"value": `\`Status : ${serverStatus}\`\n\`Node : ${attributes.node}\`\n\`Is Owner : ${attributes.server_owner}\`\n\`Suspended : ${attributes.is_suspended}\`\n`,
|
||||
},
|
||||
{
|
||||
"name": `Limits`,
|
||||
"value": `\`CPU : ${Math.round(resources.cpu_absolute * 10) / 10}/${limits.cpu}%\`\n\`RAM : ${Math.round(resources.memory_bytes / 100000) / 10}/${limits.memory}MB\`\n\`DISK : ${Math.round(resources.disk_bytes / 100000) / 10}/${limits.disk}MB\`\n`,
|
||||
},
|
||||
]
|
||||
var message = {
|
||||
embeds:[{
|
||||
color: `#F7A8B8`,
|
||||
title: `${response.attributes.name}`,
|
||||
fields:fields
|
||||
}]
|
||||
}
|
||||
interactionObject.editReply(message)
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
if(serverid != undefined)
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
||||
fetch(`${config.panel.url}/api/client`,{
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${await commands.get("profile_handler").getKey(interactionObject)}`,
|
||||
'User-Agent': `${config.panel.useragent}`,
|
||||
}
|
||||
})
|
||||
.then(async response => {
|
||||
response = await response.json()
|
||||
// console.log(response);
|
||||
// console.log(response.data[0].attributes);
|
||||
|
||||
|
||||
var message = ""
|
||||
if(response.data.length == 0){
|
||||
interactionObject.editReply(`You currently dont have any servers connected to your account`)
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < response.data.length; i++) {
|
||||
// if(response.data[i].attributes.user == 9)
|
||||
// console.log(response.data[i].attributes.name);
|
||||
message += `\`${response.data[i].attributes.identifier}\` : ${response.data[i].attributes.name}\n`
|
||||
}
|
||||
if(message.length <= 4000){
|
||||
interactionObject.editReply(message)
|
||||
}else{
|
||||
interactionObject.editReply(message.slice(0,3999))
|
||||
}
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
})();
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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`)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user