code cleanup and comments added
This commit is contained in:
parent
6d200b53cb
commit
06241fb389
@ -1,34 +1,42 @@
|
||||
const { version } = require("discord.js");
|
||||
const { codeBlock } = require("@discordjs/builders");
|
||||
const { DurationFormatter } = require("@sapphire/time-utilities");
|
||||
const durationFormatter = new DurationFormatter();
|
||||
// Needed for FS operations
|
||||
const fs = require("fs");
|
||||
|
||||
// Init our global config
|
||||
require("dotenv").config();
|
||||
|
||||
// Import our needed HTTP Lib
|
||||
var http = require('unirest');
|
||||
|
||||
// Grab RUN - get Client, Message, Command arguemtns and permission level from the bot
|
||||
exports.run = (client, message, args, level) => { // eslint-disable-line no-unused-vars
|
||||
|
||||
// Setting the username from args
|
||||
let username = args
|
||||
|
||||
// Our File Cache for the user - DISCORDID
|
||||
const path = 'cache/' + message.author.id + ".user"
|
||||
|
||||
|
||||
|
||||
console.log(username[0])
|
||||
// Setting up our Request, using getUserByName method
|
||||
var Request = http.get('https://board.grwh.work/jsonrpc.php').headers({ Accept: 'application/json', 'Content-Type': 'application/json' }).send({ "jsonrpc": "2.0", "method": "getUserByName", "id": 0, "params": { "username": username[0] } });
|
||||
|
||||
// Begin the request and send authenication using the jsonrpc2.0 protocol.
|
||||
Request.auth({
|
||||
user: 'jsonrpc',
|
||||
pass: process.env.KANBOARD_API_KEY,
|
||||
sendImmediately: false
|
||||
}).then(function (response) {
|
||||
|
||||
// We have a response, lets set it as a var
|
||||
let data = response.body.result
|
||||
|
||||
// using fs to check for the cache, if it exists, lets tell the user
|
||||
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 {
|
||||
console.log("No Channel PWD Found! Generating!")
|
||||
// Ok, there is no file, lets make one!
|
||||
fs.writeFile('./cache/' + message.author.id + ".user", "{\"userid\":\"" + data.id + "\"}", function (err) {
|
||||
message.channel.send("You have registered your DiscordID successfully!")
|
||||
})
|
||||
|
@ -1,15 +1,20 @@
|
||||
// For HTTP Requests
|
||||
// Import our needed HTTP Lib
|
||||
var http = require('unirest');
|
||||
|
||||
// Our main list array - STORAGE
|
||||
let boardList=[]
|
||||
let embed = []
|
||||
let pages =[]
|
||||
|
||||
//Requiring our discord components and paginator
|
||||
const { MessageEmbed, MessageButton } = require("discord.js");
|
||||
const { Pagination } = require("pagination.djs");
|
||||
|
||||
// Setting up our Global Config
|
||||
require("dotenv").config();
|
||||
|
||||
// Grab RUN - get Client, interaction from the bot
|
||||
exports.run = async (client, interaction) => {
|
||||
|
||||
// Init our paginator, lets set up custom emojis, then add our limit from the global config - // These are NOT required
|
||||
const pagination = new Pagination(interaction, {
|
||||
firstEmoji: "⏮", // First button emoji
|
||||
prevEmoji: "◀️", // Previous button emoji
|
||||
@ -25,31 +30,41 @@ exports.run = async (client, interaction) => {
|
||||
});
|
||||
|
||||
// eslint-disable-line no-unused-vars
|
||||
// Defer to aloow for embed building
|
||||
await interaction.deferReply();
|
||||
// const reply = await interaction.editReply("Ping?");
|
||||
// await interaction.editReply(`Pong! Latency is ${reply.createdTimestamp - interaction.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms.`);
|
||||
|
||||
// Setting up our Request, using getAllProjects method
|
||||
var Request = http.get('https://board.grwh.work/jsonrpc.php').headers({ Accept: 'application/json', 'Content-Type': 'application/json' }).send({ "jsonrpc": "2.0", "method": "getAllProjects", "id": 0 });
|
||||
|
||||
// Begin the request and send authenication using the jsonrpc2.0 protocol.
|
||||
Request.auth({
|
||||
user: 'jsonrpc',
|
||||
pass: process.env.KANBOARD_API_KEY,
|
||||
sendImmediately: false
|
||||
}).then(function (response) {
|
||||
|
||||
// We have a response, lets set up a var
|
||||
let data = response.body.result
|
||||
|
||||
// Setting up the correct formatting for our paginator
|
||||
const pusherFunc = board=>boardList.push({name:"Project Name", value:board.name + "\nID: " + board.id + "\n" + "https://" + process.env.ROOT_DOMAIN + "/board/" + board.id});
|
||||
data.forEach(pusherFunc);
|
||||
|
||||
console.log(boardList)
|
||||
// Getting the last of the embed set up
|
||||
pagination.setTitle("Project List");
|
||||
pagination.setDescription("This is a list of all currently active projects.");
|
||||
|
||||
pagination.setColor("#00ff00");
|
||||
pagination.setFooter("Boards:");
|
||||
pagination.setFooter("Projects:");
|
||||
pagination.setTimestamp();
|
||||
|
||||
pagination.addFields(boardList);
|
||||
pagination.paginateFields(true);
|
||||
|
||||
// RENDER
|
||||
pagination.render();
|
||||
|
||||
// Clear the list
|
||||
boardList = [];
|
||||
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user