2022-01-24 17:09:22 -05:00
|
|
|
|
// Import our needed HTTP Lib
|
|
|
|
|
var http = require('unirest');
|
|
|
|
|
const { MessageActionRow, MessageSelectMenu } = require('discord.js');
|
|
|
|
|
|
|
|
|
|
// Our main list array - STORAGE
|
2022-01-24 17:16:19 -05:00
|
|
|
|
let boardList = []
|
2022-01-24 17:09:22 -05:00
|
|
|
|
let data
|
|
|
|
|
let desc
|
|
|
|
|
let columns = [];
|
2022-01-24 18:41:22 -05:00
|
|
|
|
let tasksInfo = []
|
|
|
|
|
let projectName
|
2022-01-24 17:09:22 -05:00
|
|
|
|
//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) => {
|
2022-01-24 17:16:19 -05:00
|
|
|
|
|
2022-01-24 17:09:22 -05:00
|
|
|
|
// eslint-disable-line no-unused-vars
|
|
|
|
|
// Defer to aloow for embed building
|
|
|
|
|
await interaction.deferReply();
|
2022-01-24 17:16:19 -05:00
|
|
|
|
|
2022-01-24 17:09:22 -05:00
|
|
|
|
// Setting up our Request, using getAllProjects method
|
|
|
|
|
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 17:16:19 -05:00
|
|
|
|
// Begin the request and send authenication using the jsonrpc2.0 protocol.
|
2022-01-24 17:09:22 -05:00
|
|
|
|
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
|
2022-01-24 17:16:19 -05:00
|
|
|
|
const pusherFunc = board => boardList.push({ label: board.name, description: board.name, value: board.id });
|
2022-01-24 17:09:22 -05:00
|
|
|
|
data.forEach(pusherFunc);
|
2022-01-24 17:16:19 -05:00
|
|
|
|
|
2022-01-24 17:09:22 -05:00
|
|
|
|
console.log(boardList)
|
|
|
|
|
const row = new MessageActionRow()
|
2022-01-24 17:16:19 -05:00
|
|
|
|
.addComponents(
|
|
|
|
|
new MessageSelectMenu()
|
|
|
|
|
.setCustomId('select')
|
|
|
|
|
.setPlaceholder('Select a Project')
|
|
|
|
|
.addOptions(boardList),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
(async function () {
|
2022-01-24 17:09:22 -05:00
|
|
|
|
await interaction.editReply({ content: 'Use the menu below to choose a Project', components: [row] });
|
2022-01-24 17:16:19 -05:00
|
|
|
|
})()
|
2022-01-24 17:09:22 -05:00
|
|
|
|
|
|
|
|
|
// await interaction.reply({ content: 'Pong!', components: [row] });
|
|
|
|
|
client.on('interactionCreate', interaction => {
|
|
|
|
|
if (!interaction.isSelectMenu()) return;
|
|
|
|
|
|
|
|
|
|
if (interaction.customId === 'select') {
|
|
|
|
|
(async () => {
|
2022-01-24 18:41:22 -05:00
|
|
|
|
await interaction.update({ content: '', components: [] });
|
2022-01-24 17:09:22 -05:00
|
|
|
|
console.log(interaction.values[0]);
|
|
|
|
|
|
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": "getBoard", "id": 0, "params": [interaction.values[0]] });
|
2022-01-24 17:09:22 -05:00
|
|
|
|
|
2022-01-24 17:16:19 -05:00
|
|
|
|
// 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) {
|
|
|
|
|
data = response.body.result[0]
|
|
|
|
|
console.log(data)
|
|
|
|
|
|
|
|
|
|
const date = require('date-and-time');
|
|
|
|
|
const now = new Date();
|
|
|
|
|
|
|
|
|
|
if (data.description == '') {
|
|
|
|
|
desc = "N/A"
|
|
|
|
|
} else {
|
|
|
|
|
desc = data.description
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 18:41:22 -05:00
|
|
|
|
const pusherFunc = column => columns.push(column.title + " " + column.nb_tasks + " tasks.\n");
|
2022-01-24 17:16:19 -05:00
|
|
|
|
data.columns.forEach(pusherFunc);
|
|
|
|
|
|
2022-01-24 18:41:22 -05:00
|
|
|
|
let dataTasks = response.body.result[0].columns
|
|
|
|
|
dataTasks.forEach(function(column) {
|
|
|
|
|
if (column.tasks != []){
|
|
|
|
|
column.tasks.forEach(function(task) {
|
|
|
|
|
// console.log(task)
|
|
|
|
|
//console.log (task.title + " in " + task.column_name + " for " + task.project_name)
|
|
|
|
|
if (task.is_active == 0) return
|
|
|
|
|
tasksInfo.push(task.title + " in " + task.column_name + "\n")
|
|
|
|
|
|
|
|
|
|
})}
|
|
|
|
|
});
|
|
|
|
|
console.log(tasksInfo)
|
|
|
|
|
|
2022-01-24 17:16:19 -05:00
|
|
|
|
const mainEmbed = new MessageEmbed()
|
|
|
|
|
.setColor('#0099ff')
|
|
|
|
|
.addFields(
|
|
|
|
|
{ name: 'Project ID', value: data.project_id, inline: true },
|
2022-01-24 18:41:22 -05:00
|
|
|
|
{ name: 'Swimlane Description', value: desc },
|
2022-01-24 17:16:19 -05:00
|
|
|
|
{ name: 'Task Info', value: columns.join(" "), inline: true },
|
2022-01-24 18:41:22 -05:00
|
|
|
|
{ name: 'Open Task Breakdown', value: tasksInfo.join(" "), inline: false },
|
2022-01-24 17:16:19 -05:00
|
|
|
|
{ name: 'link', value: "https://" + process.env.ROOT_DOMAIN + "/board/" + data.project_id, inline: true })
|
|
|
|
|
.setTitle('Requested Details')
|
2022-01-24 18:41:22 -05:00
|
|
|
|
.setDescription("Swimlane: " + data.name)
|
2022-01-24 17:16:19 -05:00
|
|
|
|
.setFooter(date.format(now, 'MM/DD/YYYY hh:mm:ss'));
|
|
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
|
await interaction.editReply({ embeds: [mainEmbed] });
|
|
|
|
|
// Clear the list
|
|
|
|
|
boardList = [];
|
|
|
|
|
columns = [];
|
|
|
|
|
desc = "";
|
2022-01-24 18:41:22 -05:00
|
|
|
|
tasksInfo = [];
|
2022-01-24 17:16:19 -05:00
|
|
|
|
})();
|
|
|
|
|
})
|
2022-01-24 17:09:22 -05:00
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
2022-01-24 17:16:19 -05:00
|
|
|
|
})
|
2022-01-24 17:09:22 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.commandData = {
|
|
|
|
|
name: "projectdetails",
|
|
|
|
|
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: true
|
|
|
|
|
};
|