mirror of
https://github.com/xHyroM/bun-discord-bot.git
synced 2024-11-22 14:41:05 +01:00
chore: updates
feat(commands): version command fix(githubUtils): freeze unused variables fix(index): fix native errors
This commit is contained in:
parent
ca35010cef
commit
f5c821344c
7 changed files with 35 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
||||||
# Created by https://www.toptal.com/developers/gitignore/api/node
|
# Created by https://www.toptal.com/developers/gitignore/api/node
|
||||||
# Edit at https://www.toptal.com/developers/gitignore?templates=node
|
# Edit at https://www.toptal.com/developers/gitignore?templates=node
|
||||||
|
|
||||||
|
files/database.sqlite
|
||||||
files/config.toml
|
files/config.toml
|
||||||
requests.rest
|
requests.rest
|
||||||
|
|
||||||
|
|
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
Binary file not shown.
|
@ -10,6 +10,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/collection": "^0.7.0",
|
"@discordjs/collection": "^0.7.0",
|
||||||
|
"bun-utilities": "^0.1.2",
|
||||||
"create-hmac": "^1.1.7",
|
"create-hmac": "^1.1.7",
|
||||||
"discord-api-types": "^0.36.1",
|
"discord-api-types": "^0.36.1",
|
||||||
"hono": "^1.6.4",
|
"hono": "^1.6.4",
|
||||||
|
|
22
src/commands/version.ts
Normal file
22
src/commands/version.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import { InteractionResponseType, MessageFlags } from 'discord-api-types/v10';
|
||||||
|
import { Command } from '../structures/Command';
|
||||||
|
import { exec } from 'bun-utilities';
|
||||||
|
|
||||||
|
const commitHash = (await exec(['git', 'log', '--pretty=format:\'%h\'', '-n', '1'])).stdout.replaceAll('\'', '');
|
||||||
|
|
||||||
|
new Command({
|
||||||
|
name: 'version',
|
||||||
|
description: 'Check bot and bun version',
|
||||||
|
run: (ctx) => {
|
||||||
|
return ctx.respond({
|
||||||
|
type: InteractionResponseType.ChannelMessageWithSource,
|
||||||
|
data: {
|
||||||
|
content: [
|
||||||
|
`Bot version: [git-bun-discord-bot-"${commitHash}"](<https://github.com/xHyroM/bun-discord-bot/commit/${commitHash})>`,
|
||||||
|
`Bun version: [${process.version}](<https://github.com/oven-sh/bun/releases/tag/bun-${process.version}>)`,
|
||||||
|
].join('\n'),
|
||||||
|
flags: MessageFlags.Ephemeral,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
10
src/index.ts
10
src/index.ts
|
@ -85,7 +85,7 @@ app.post('/interaction', bodyParse(), async(c) => {
|
||||||
app.post('/github_webhook', bodyParse(), (c) => {
|
app.post('/github_webhook', bodyParse(), (c) => {
|
||||||
if (
|
if (
|
||||||
!c.req.headers.get('User-Agent').startsWith('GitHub-Hookshot/') ||
|
!c.req.headers.get('User-Agent').startsWith('GitHub-Hookshot/') ||
|
||||||
typeof c.req.parsedBody !== 'object'
|
typeof c.req?.parsedBody !== 'object'
|
||||||
) return c.redirect('https://www.youtube.com/watch?v=FMhScnY0dME'); // fireship :D
|
) return c.redirect('https://www.youtube.com/watch?v=FMhScnY0dME'); // fireship :D
|
||||||
|
|
||||||
const githubWebhooksSecret = new TextEncoder().encode(config.api.github_webhooks_secret);
|
const githubWebhooksSecret = new TextEncoder().encode(config.api.github_webhooks_secret);
|
||||||
|
@ -94,7 +94,7 @@ app.post('/github_webhook', bodyParse(), (c) => {
|
||||||
|
|
||||||
const issueOrPr = c.req.parsedBody;
|
const issueOrPr = c.req.parsedBody;
|
||||||
if (issueOrPr.action !== 'deleted') {
|
if (issueOrPr.action !== 'deleted') {
|
||||||
if (issueOrPr.issue) {
|
if ('issue' in issueOrPr) {
|
||||||
setIssue({
|
setIssue({
|
||||||
id: issueOrPr.issue.number,
|
id: issueOrPr.issue.number,
|
||||||
repository: issueOrPr.issue.repository_url.replace('https://api.github.com/repos/', ''),
|
repository: issueOrPr.issue.repository_url.replace('https://api.github.com/repos/', ''),
|
||||||
|
@ -109,7 +109,7 @@ app.post('/github_webhook', bodyParse(), (c) => {
|
||||||
type: '(IS)',
|
type: '(IS)',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else if('pull_request' in issueOrPr) {
|
||||||
setPullRequest({
|
setPullRequest({
|
||||||
id: issueOrPr.pull_request.number,
|
id: issueOrPr.pull_request.number,
|
||||||
repository: issueOrPr.pull_request.html_url.replace('https://github.com/', '').replace(`/pull/${issueOrPr.pull_request.number}`, ''),
|
repository: issueOrPr.pull_request.html_url.replace('https://github.com/', '').replace(`/pull/${issueOrPr.pull_request.number}`, ''),
|
||||||
|
@ -126,10 +126,10 @@ app.post('/github_webhook', bodyParse(), (c) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (issueOrPr.issue) deleteIssueOrPR(
|
if ('issue' in issueOrPr) deleteIssueOrPR(
|
||||||
issueOrPr.issue.number, issueOrPr.issue.repository_url.replace('https://api.github.com/repos/', '')
|
issueOrPr.issue.number, issueOrPr.issue.repository_url.replace('https://api.github.com/repos/', '')
|
||||||
);
|
);
|
||||||
else deleteIssueOrPR(
|
else if('pull_request' in issueOrPr) deleteIssueOrPR(
|
||||||
issueOrPr.pull_request.number,
|
issueOrPr.pull_request.number,
|
||||||
issueOrPr.pull_request.html_url
|
issueOrPr.pull_request.html_url
|
||||||
.replace('https://github.com/', '')
|
.replace('https://github.com/', '')
|
||||||
|
|
|
@ -78,9 +78,10 @@ export const fetchIssues = async() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.success(`Issues have been fetched for ${repository} - ${issues}`);
|
Logger.success(`Issues have been fetched for ${repository} - ${issues}`);
|
||||||
|
}
|
||||||
|
|
||||||
issues = null;
|
issues = null;
|
||||||
Object.freeze(issues);
|
Object.freeze(issues);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchPullRequests = async() => {
|
export const fetchPullRequests = async() => {
|
||||||
|
@ -123,9 +124,10 @@ export const fetchPullRequests = async() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.success(`Pull requests have been fetched for ${repository} - ${pulls}`);
|
Logger.success(`Pull requests have been fetched for ${repository} - ${pulls}`);
|
||||||
|
}
|
||||||
|
|
||||||
pulls = null;
|
pulls = null;
|
||||||
Object.freeze(pulls);
|
Object.freeze(pulls);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setIssue = async(issue: Issue) => {
|
export const setIssue = async(issue: Issue) => {
|
||||||
|
|
Loading…
Reference in a new issue