mirror of
https://github.com/DarthKilroy/Spot.git
synced 2025-12-19 18:26:48 +00:00
Re-add jira logic
This commit is contained in:
parent
0ee296033c
commit
6c8cf194a7
3 changed files with 81 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -5,3 +5,4 @@ deploy.sh
|
||||||
config.*json*
|
config.*json*
|
||||||
!config.json.sample
|
!config.json.sample
|
||||||
.env
|
.env
|
||||||
|
/tmp
|
||||||
73
bot.ts
73
bot.ts
|
|
@ -1,12 +1,22 @@
|
||||||
import { Client, GatewayIntentBits, GuildMember, Channel, TextBasedChannel, Events, Message, SlashCommandBuilder, Collection } from 'discord.js';
|
import { Client, GatewayIntentBits, GuildMember, Channel, TextBasedChannel, Events, Message, SlashCommandBuilder, Collection } from 'discord.js';
|
||||||
import * as dotenv from 'dotenv';
|
import * as dotenv from 'dotenv';
|
||||||
|
import path from 'node:path';
|
||||||
|
import fs from 'node:fs'
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
|
declare module "discord.js" {
|
||||||
|
export interface Client {
|
||||||
|
commands: Collection<any, any>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
import config from "./config";
|
import config from "./config";
|
||||||
|
|
||||||
export const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
|
export const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
|
||||||
|
|
||||||
import handleMessage from './messageHandler';
|
import handleMessage from './messageHandler';
|
||||||
|
import search from './model/jira';
|
||||||
|
|
||||||
client.on("ready", () => {
|
client.on("ready", () => {
|
||||||
console.log("successfully logged in");
|
console.log("successfully logged in");
|
||||||
|
|
@ -23,7 +33,70 @@ client.on("guildMemberAdd", async (member: GuildMember) => {
|
||||||
|
|
||||||
|
|
||||||
client.on(Events.MessageCreate, async (msg: Message) => {
|
client.on(Events.MessageCreate, 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);
|
await handleMessage(msg).catch(console.error);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.login(process.env.token);
|
client.login(process.env.token);
|
||||||
|
|
|
||||||
|
|
@ -13,18 +13,19 @@ export default async function search(version?: string): Promise<any[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const issues: any[] = [];
|
const issues: any[] = [];
|
||||||
let response: any | null = null;
|
let jsonResponse: any | null = null;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const httpParams = Object.keys(params).map(key => `${key}=${params[key]}`).join('&');
|
const httpParams = Object.keys(params).map(key => `${key}=${params[key]}`).join('&');
|
||||||
const url = `${config.jira.baseUrl}/search?${httpParams}`;
|
const url = `${config.jira.baseUrl}/search?${httpParams}`;
|
||||||
// what even is this
|
|
||||||
response = JSON.parse((await new axios.Axios({}).get(url)).data);
|
|
||||||
|
|
||||||
issues.push(...response!.issues);
|
const serverResponse = await new axios.Axios({}).get(url);
|
||||||
|
jsonResponse = JSON.parse(serverResponse.data);
|
||||||
|
|
||||||
|
issues.push(...jsonResponse!.issues);
|
||||||
params.startAt += 100;
|
params.startAt += 100;
|
||||||
} while (response!.issues.length > 99 && response!.total > 100);
|
} while (jsonResponse!.issues.length > 99 && jsonResponse!.total > 100);
|
||||||
|
|
||||||
return issues;
|
return issues;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue