chore: updates

feat(commands): version command

fix(githubUtils): freeze unused variables

fix(index): fix native errors
This commit is contained in:
xHyroM 2022-07-13 22:18:14 +02:00
parent ca35010cef
commit f5c821344c
7 changed files with 35 additions and 9 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node
files/database.sqlite
files/config.toml
requests.rest

BIN
bun.lockb

Binary file not shown.

Binary file not shown.

View file

@ -10,6 +10,7 @@
},
"dependencies": {
"@discordjs/collection": "^0.7.0",
"bun-utilities": "^0.1.2",
"create-hmac": "^1.1.7",
"discord-api-types": "^0.36.1",
"hono": "^1.6.4",

22
src/commands/version.ts Normal file
View 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,
}
})
}
})

View file

@ -85,7 +85,7 @@ app.post('/interaction', bodyParse(), async(c) => {
app.post('/github_webhook', bodyParse(), (c) => {
if (
!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
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;
if (issueOrPr.action !== 'deleted') {
if (issueOrPr.issue) {
if ('issue' in issueOrPr) {
setIssue({
id: issueOrPr.issue.number,
repository: issueOrPr.issue.repository_url.replace('https://api.github.com/repos/', ''),
@ -109,7 +109,7 @@ app.post('/github_webhook', bodyParse(), (c) => {
type: '(IS)',
})
}
else {
else if('pull_request' in issueOrPr) {
setPullRequest({
id: 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 {
if (issueOrPr.issue) deleteIssueOrPR(
if ('issue' in issueOrPr) deleteIssueOrPR(
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.html_url
.replace('https://github.com/', '')

View file

@ -78,9 +78,10 @@ export const fetchIssues = async() => {
}
Logger.success(`Issues have been fetched for ${repository} - ${issues}`);
issues = null;
Object.freeze(issues);
}
issues = null;
Object.freeze(issues);
}
export const fetchPullRequests = async() => {
@ -123,9 +124,10 @@ export const fetchPullRequests = async() => {
}
Logger.success(`Pull requests have been fetched for ${repository} - ${pulls}`);
pulls = null;
Object.freeze(pulls);
}
pulls = null;
Object.freeze(pulls);
}
export const setIssue = async(issue: Issue) => {