2022-01-24 15:25:25 -05:00
|
|
|
// Needed for FS operations
|
2022-01-24 14:59:38 -05:00
|
|
|
const fs = require("fs");
|
|
|
|
|
2022-01-24 15:25:25 -05:00
|
|
|
// Init our global config
|
2022-01-24 14:59:38 -05:00
|
|
|
require("dotenv").config();
|
2022-01-24 15:25:25 -05:00
|
|
|
|
|
|
|
// Import our needed HTTP Lib
|
2022-01-24 14:59:38 -05:00
|
|
|
var http = require('unirest');
|
|
|
|
|
2022-01-24 15:25:25 -05:00
|
|
|
// Grab RUN - get Client, Message, Command arguemtns and permission level from the bot
|
2022-01-24 14:59:38 -05:00
|
|
|
exports.run = (client, message, args, level) => { // eslint-disable-line no-unused-vars
|
2022-01-24 15:25:25 -05:00
|
|
|
|
|
|
|
// Setting the username from args
|
2022-01-24 14:59:38 -05:00
|
|
|
let username = args
|
|
|
|
|
2022-01-24 15:25:25 -05:00
|
|
|
// Our File Cache for the user - DISCORDID
|
|
|
|
const path = 'cache/' + message.author.id + ".user"
|
|
|
|
|
|
|
|
|
|
|
|
// Setting up our Request, using getUserByName method
|
2022-01-24 18:45:16 -05:00
|
|
|
var Request = http.get('https://' + process.env.ROOT_DOMAIN + '/jsonrpc.php').headers({ Accept: 'application/json', 'Content-Type': 'application/json' }).send({ "jsonrpc": "2.0", "method": "getUserByName", "id": 0, "params": { "username": username[0] } });
|
2022-01-24 14:59:38 -05:00
|
|
|
|
2022-01-24 15:25:25 -05:00
|
|
|
// Begin the request and send authenication using the jsonrpc2.0 protocol.
|
2022-01-24 14:59:38 -05:00
|
|
|
Request.auth({
|
|
|
|
user: 'jsonrpc',
|
|
|
|
pass: process.env.KANBOARD_API_KEY,
|
|
|
|
sendImmediately: false
|
|
|
|
}).then(function (response) {
|
2022-01-24 15:25:25 -05:00
|
|
|
|
|
|
|
// We have a response, lets set it as a var
|
2022-01-24 14:59:38 -05:00
|
|
|
let data = response.body.result
|
|
|
|
|
2022-01-24 15:25:25 -05:00
|
|
|
// using fs to check for the cache, if it exists, lets tell the user
|
2022-01-24 14:59:38 -05:00
|
|
|
if (fs.existsSync(path)) {
|
|
|
|
console.log("User already exists")
|
|
|
|
message.channel.send("That user is already in our system and cannot be registered again.")
|
|
|
|
}
|
|
|
|
else {
|
2022-01-24 15:25:25 -05:00
|
|
|
// Ok, there is no file, lets make one!
|
2022-01-24 14:59:38 -05:00
|
|
|
fs.writeFile('./cache/' + message.author.id + ".user", "{\"userid\":\"" + data.id + "\"}", function (err) {
|
|
|
|
message.channel.send("You have registered your DiscordID successfully!")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.conf = {
|
|
|
|
enabled: true,
|
|
|
|
guildOnly: false,
|
|
|
|
aliases: [],
|
|
|
|
permLevel: "User"
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.help = {
|
|
|
|
name: "register",
|
|
|
|
category: "Main",
|
|
|
|
description: "Bind your discordID to your board username.",
|
|
|
|
usage: "register $BOARDUSERNAME"
|
|
|
|
};
|