DisKan/slash/list_projects.js

85 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-01-24 15:25:25 -05:00
// Import our needed HTTP Lib
2022-01-24 14:05:30 -05:00
var http = require('unirest');
2022-01-24 15:25:25 -05:00
// Our main list array - STORAGE
2022-01-24 14:05:30 -05:00
let boardList=[]
2022-01-24 15:25:25 -05:00
//Requiring our discord components and paginator
2022-01-24 14:05:30 -05:00
const { MessageEmbed, MessageButton } = require("discord.js");
const { Pagination } = require("pagination.djs");
2022-01-24 15:25:25 -05:00
// Setting up our Global Config
2022-01-24 14:05:30 -05:00
require("dotenv").config();
2022-01-24 15:25:25 -05:00
// Grab RUN - get Client, interaction from the bot
2022-01-24 14:05:30 -05:00
exports.run = async (client, interaction) => {
2022-01-24 15:25:25 -05:00
// Init our paginator, lets set up custom emojis, then add our limit from the global config - // These are NOT required
2022-01-24 14:05:30 -05:00
const pagination = new Pagination(interaction, {
firstEmoji: "⏮", // First button emoji
prevEmoji: "◀️", // Previous button emoji
nextEmoji: "▶️", // Next button emoji
lastEmoji: "⏭", // Last button emoji
2022-01-24 14:21:34 -05:00
limit: process.env.PER_PAGE, // number of entries per page
2022-01-24 14:05:30 -05:00
idle: 30000, // idle time in ms before the pagination closes
ephemeral: false, // ephemeral reply
prevDescription: "",
postDescription: "",
buttonStyle: "SECONDARY",
loop: false, // loop through the pages
});
// eslint-disable-line no-unused-vars
2022-01-24 15:25:25 -05:00
// Defer to aloow for embed building
2022-01-24 14:05:30 -05:00
await interaction.deferReply();
2022-01-24 15:25:25 -05:00
// Setting up our Request, using getAllProjects 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": "getAllProjects", "id": 0 });
2022-01-24 14:05:30 -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:05:30 -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 up a var
2022-01-24 14:05:30 -05:00
let data = response.body.result
2022-01-24 15:25:25 -05:00
// Setting up the correct formatting for our paginator
2022-01-24 14:21:34 -05:00
const pusherFunc = board=>boardList.push({name:"Project Name", value:board.name + "\nID: " + board.id + "\n" + "https://" + process.env.ROOT_DOMAIN + "/board/" + board.id});
2022-01-24 14:05:30 -05:00
data.forEach(pusherFunc);
2022-01-24 15:25:25 -05:00
// Getting the last of the embed set up
2022-01-24 14:05:30 -05:00
pagination.setTitle("Project List");
pagination.setDescription("This is a list of all currently active projects.");
pagination.setColor("#00ff00");
2022-01-24 15:25:25 -05:00
pagination.setFooter("Projects:");
2022-01-24 14:05:30 -05:00
pagination.setTimestamp();
pagination.addFields(boardList);
pagination.paginateFields(true);
2022-01-24 15:25:25 -05:00
// RENDER
2022-01-24 14:05:30 -05:00
pagination.render();
2022-01-24 15:25:25 -05:00
// Clear the list
boardList = [];
2022-01-24 14:05:30 -05:00
})
};
exports.commandData = {
name: "list",
description: "Lists all of the current projects",
options: [],
defaultPermission: true,
};
// Set guildOnly to true if you want it to be available on guilds only.
// Otherwise false is global.
exports.conf = {
permLevel: "User",
guildOnly: false
};