Compare commits

...

2 Commits

Author SHA1 Message Date
Raven Scott
e721187aff Merge branch 'master' of git.codingvm.codes:snxraven/DisKan 2022-02-21 02:28:55 +00:00
Raven Scott
5227fce48d Restructure Modals to work 2022-02-21 02:28:37 +00:00
7 changed files with 521 additions and 56 deletions

60
c2.js Normal file
View File

@ -0,0 +1,60 @@
const { Permissions } = require("discord.js");
const discordModals = require('discord-modals') // Define the discord-modals package!
const { MessageActionRow, MessageSelectMenu } = require('discord.js');
var http = require('unirest');
var http = require('unirest');
exports.run = async (client, interaction) => { // eslint-disable-line no-unused-vars
discordModals(client); // discord-modals needs your client in order to interact with modals+
//await interaction.deferReply();
const { Modal, TextInputComponent, showModal } = require('discord-modals') // Now we extract the showModal method
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);
// Let's say that the interaction will be an Slash Command called 'ping'.
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.
})
};
exports.commandData = {
name: "createtask2",
description: "Test Command",
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
};

View File

@ -29,7 +29,9 @@
"axios": "^0.25.0",
"colorette": "^1.3.0",
"date-and-time": "^2.1.0",
"discord-modals": "^1.1.8",
"discord.js": "^13.0.1",
"discordjs-modal": "^1.0.0-beta.2",
"dotenv": "^10.0.0",
"enmap": "^5.8.5",
"jsonfile": "^6.1.0",

195
slash/createTask.js Normal file
View File

@ -0,0 +1,195 @@
// For HTTP Requests
var http = require('unirest');
let count = 0
const jsonfile = require('jsonfile')
const { MessageActionRow, MessageSelectMenu } = require('discord.js');
require("dotenv").config();
exports.run = async (client, interaction) => {
let interactionT = interaction;
let boardList = []
let embed = []
let pages = []
let projectID
let title
let userID
let inter = interaction
var rand = Math.floor(Math.random() * 999999999);
// eslint-disable-line no-unused-vars
await interaction.deferReply();
console.log("DeferReply called")
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)
})
client.on('modalSubmit', (modal) => {
if (interaction.customId === 'select') {
console.log(interaction.values[0]);
projectID = interaction.values[0]
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);
if (modal.customId === 'title') {
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.
})
}
}
(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: true
}).then(function (response) {
(async () => {
console.log(response.body)
await interaction.editReply({ content: 'Task Created!', components: [] });
})()
boardList = []
embed = []
pages = []
projectID = null
userID = null
title = null
desc = null
count = 0
titleCompontent = null
descCompontent = null
components = null
modal = null
rand = Math.floor(Math.random() * 999999999);
}
)
})()
})
})
})
}
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
};

View File

@ -1,41 +0,0 @@
// For HTTP Requests
var http = require('unirest');
let boardList=[]
let embed = []
let pages =[]
require("dotenv").config();
exports.run = async (client, interaction) => {
// eslint-disable-line no-unused-vars
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.`);
var Request = http.post('https://' + process.env.ROOT_DOMAIN + '/jsonrpc.php').headers({ Accept: 'application/json', 'Content-Type': 'application/json' }).send({ "jsonrpc": "2.0", "method": "getAllProjects", "id": 0 });
Request.auth({
user: 'jsonrpc',
pass: process.env.KANBOARD_API_KEY,
sendImmediately: false
}).then(function (response) {
let data = response.body.result
console.log(data)
})
};
exports.commandData = {
name: "test",
description: "create a task",
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
};

View File

@ -86,26 +86,28 @@ exports.run = async (client, interaction) => {
data.columns.forEach(pusherFunc);
let dataTasks = response.body.result[0].columns
dataTasks.forEach(function(column) {
if (column.tasks != []){
column.tasks.forEach(function(task) {
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)
const mainEmbed = new MessageEmbed()
// { name: 'link', value: "https://" + process.env.ROOT_DOMAIN + "/board/" + data.project_id, inline: true })
.setColor('#0099ff')
.addFields(
{ name: 'Project ID', value: data.project_id, inline: true },
{ name: 'Swimlane Description', value: desc },
{ name: 'Task Info', value: columns.join(" "), inline: true },
{ name: 'Open Task Breakdown', value: tasksInfo.join(" "), inline: false },
{ name: 'link', value: "https://" + process.env.ROOT_DOMAIN + "/board/" + data.project_id, inline: true })
{ name: 'Open Task Breakdown', value: tasksInfo.join(" "), inline: false })
.setTitle('Requested Details')
.setDescription("Swimlane: " + data.name)
.setFooter(date.format(now, 'MM/DD/YYYY hh:mm:ss'));
@ -123,6 +125,59 @@ exports.run = async (client, 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.
})
}
})
})

View File

@ -1,8 +1,9 @@
exports.run = async (client, interaction) => { // eslint-disable-line no-unused-vars
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.`);
};
// 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.`);
}
exports.commandData = {
name: "ping",

193
working Normal file
View File

@ -0,0 +1,193 @@
// 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
};