DisKan/working

193 lines
6.7 KiB
Plaintext
Raw Normal View History

2022-02-20 21:28:37 -05:00
// For HTTP Requests
var http = require('unirest');
const jsonfile = require('jsonfile')
const { MessageActionRow, MessageSelectMenu } = require('discord.js');
require("dotenv").config();
exports.run = async (client, interaction) => {
let boardList = []
let embed = []
let pages = []
let projectID
let title
let userID
// eslint-disable-line no-unused-vars
//await interaction.deferReply();
const jsonfile = require('jsonfile')
const usercache = 'cache/' + interaction.user.id + '.user'
jsonfile.readFile(usercache)
.then(obj => {
userID = obj.userid
// 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 });
// 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) {
// console.log(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({ label: board.name, description: board.name, value: board.id });
data.forEach(pusherFunc);
console.log(boardList)
const row = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('select')
.setPlaceholder('Select a Project')
.addOptions(boardList),
);
(async function () {
await interaction.editReply({ content: 'Use the menu below to choose a Project', components: [row] });
})()
// await interaction.reply({ content: 'Pong!', components: [row] });
client.on('interactionCreate', interaction => {
if (!interaction.isSelectMenu()) return;
console.log(interaction)
if (interaction.customId === 'select') {
console.log(interaction.values[0]);
projectID = interaction.values[0]
const discordModals = require('discord-modals') // Define the discord-modals package!
const { Modal, TextInputComponent, showModal } = require('discord-modals') // Now we extract the showModal method
discordModals(client); // Provide the client to the discord-modals package
let titleCompontent = new TextInputComponent() // We create an Text Input Component
.setCustomId('title') // We set the customId to title
.setLabel('Title Name Here')
.setStyle('SHORT') //IMPORTANT: Text Input Component Style can be 'SHORT' or 'LONG'
.setMinLength(4)
.setMaxLength(15)
.setPlaceholder('Write a text here')
.setRequired(true) // If it's required or not
.setValue('value')
let descCompontent = new TextInputComponent() // We create an Text Input Component
.setCustomId('desc') // We set the customId to title
.setLabel('Description')
.setStyle('LONG') //IMPORTANT: Text Input Component Style can be 'SHORT' or 'LONG'
.setMinLength(4)
.setMaxLength(250)
.setPlaceholder('Write a text here')
.setRequired(true) // If it's required or not
.setValue('value')
let components = [titleCompontent, descCompontent]
console.log(components)
const modal = new Modal() // We create a Modal
.setCustomId('title')
.setTitle('Task Information')
.addComponents(components);
showModal(modal, {
client: client, // The showModal() method needs the client to send the modal through the API.
interaction: interaction // The showModal() method needs the interaction to send the modal with the Interaction ID & Token.
})
client.on('modalSubmit', (modal) => {
if (modal.customId === 'title') {
(async () => {
title = modal.getTextInputValue('title')
desc = modal.getTextInputValue('desc')
var Request = http.post('https://' + process.env.ROOT_DOMAIN + '/jsonrpc.php').headers({ Accept: 'application/json', 'Content-Type': 'application/json' }).send({
"jsonrpc": "2.0",
"method": "createTask",
"id": 1176509098,
"params": {
"owner_id": userID,
"creator_id": userID,
"date_due": "",
"description": desc,
"category_id": 0,
"score": 0,
"title": title,
"project_id": projectID,
"color_id": "yellow",
"column_id": 0,
"recurrence_status": 0,
"recurrence_trigger": 0,
"recurrence_factor": 0,
"recurrence_timeframe": 0,
"recurrence_basedate": 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) {
console.log(response.body)
})
await modal.reply({ content: 'Task Created!', components: [] });
// boardList = []
// embed = []
// pages = []
projectID = null
userID = null
title = null
desc = null
titleCompontent = null
descCompontent = null
components = null
interaction = null
modal = null
})()
}
})
}
})
})
})
};
exports.commandData = {
name: "createtask",
description: "generate a task",
// options: [{ "name": "name", "description": "The name of your new task", "type": 3, "name": "projectname", "description": "The name of the project to create in", "type": 3 }],
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
};