mirror of
https://github.com/DarthKilroy/Spot.git
synced 2026-02-04 02:26:48 +00:00
Add create jira bug
This commit is contained in:
parent
6c8cf194a7
commit
1a7822ea69
13 changed files with 418 additions and 97 deletions
12
events/guild-member-add.ts
Normal file
12
events/guild-member-add.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { GuildMember, TextBasedChannel } from "discord.js";
|
||||
import { client } from "../bot";
|
||||
import config from "../config";
|
||||
|
||||
export const onGuildMemberAdd = async (member: GuildMember) => {
|
||||
const msg = `Welcome, <@${member.id}>! If you joined for any specific support questions `
|
||||
+ `please check out <#863171642905591830> first to see if your issue is known, `
|
||||
+ `and make sure that your app is up-to-date before posting.`;
|
||||
|
||||
const channel: TextBasedChannel | null = await client.channels.fetch(config.channels.joins) as TextBasedChannel;
|
||||
channel?.send(msg);
|
||||
}
|
||||
32
events/interaction-create.ts
Normal file
32
events/interaction-create.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
import axios from "axios";
|
||||
import { CacheType, ChatInputCommandInteraction, Interaction, MessageContextMenuCommandInteraction, ModalSubmitInteraction, UserContextMenuCommandInteraction } from "discord.js";
|
||||
import { client } from "../bot";
|
||||
import config from "../config";
|
||||
import { frequencies, getJiraToken, severites } from "../utils/jira";
|
||||
|
||||
export const onInteractionCreate = async (interaction: Interaction) => {
|
||||
if (interaction.isChatInputCommand() || interaction.isContextMenuCommand()) {
|
||||
onCommand(interaction);
|
||||
}
|
||||
}
|
||||
|
||||
const onCommand = async (interaction: ChatInputCommandInteraction<CacheType> | MessageContextMenuCommandInteraction<CacheType> | UserContextMenuCommandInteraction) => {
|
||||
const command = client.commands.get(interaction.commandName);
|
||||
|
||||
if (!command) {
|
||||
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||
} else {
|
||||
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
3
events/ready.ts
Normal file
3
events/ready.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export const onReady = () => {
|
||||
console.log("Bot ready!")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue