mirror of
https://github.com/DarthKilroy/Spot.git
synced 2026-02-12 21:50:08 +00:00
Add create jira bug
This commit is contained in:
parent
6c8cf194a7
commit
1a7822ea69
13 changed files with 418 additions and 97 deletions
70
events/message-create.ts
Normal file
70
events/message-create.ts
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import { Message } from "discord.js";
|
||||
import handleMessage from "../messageHandler";
|
||||
import search from "../model/jira";
|
||||
|
||||
export const onMessageCreate = async (msg: Message) => {
|
||||
|
||||
if (msg.content.startsWith(".cl ")) {
|
||||
const version = msg.content.substring(4)
|
||||
try {
|
||||
// Test if a number
|
||||
const versionNumber = Number(version)
|
||||
const issues = await search(version);
|
||||
|
||||
const issueDataList: { title: string, key: string }[] = []
|
||||
|
||||
issues.forEach((issue) => {
|
||||
issueDataList.push({ title: issue.fields.summary, key: issue.key })
|
||||
})
|
||||
|
||||
const issueTextList: string[] = []
|
||||
|
||||
issueDataList.forEach((issue) => {
|
||||
issueTextList.push(`[${issue.key}] ${issue.title}`)
|
||||
})
|
||||
|
||||
let issueIndex = 0
|
||||
|
||||
let messagesToSend: string[] = []
|
||||
|
||||
let parsedAll = false
|
||||
while (!parsedAll) {
|
||||
let formattedMsg = ""
|
||||
|
||||
let foundLength = 6
|
||||
for (let i = issueIndex; i < issueTextList.length + 1; ++i) {
|
||||
if (i == issueTextList.length) {
|
||||
parsedAll = true;
|
||||
break;
|
||||
}
|
||||
|
||||
const line = `${issueTextList[i]}\n`
|
||||
if (foundLength + line.length > 1999) {
|
||||
break;
|
||||
}
|
||||
|
||||
formattedMsg += line
|
||||
foundLength += line.length
|
||||
issueIndex = i;
|
||||
}
|
||||
|
||||
messagesToSend.push(`\`\`\`${formattedMsg}\`\`\``)
|
||||
}
|
||||
|
||||
let index = 0
|
||||
messagesToSend.forEach((messageToSend) => {
|
||||
let waitMultiplier = index + 1
|
||||
let waitTime = 1000 * waitMultiplier
|
||||
setTimeout(() => {
|
||||
msg.channel.send(messageToSend)
|
||||
}, waitTime);
|
||||
index++;
|
||||
})
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
await handleMessage(msg).catch(console.error);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue