Merge pull request #180 from ryanccn/support-improvements

This commit is contained in:
Sefa Eyeoglu 2023-06-10 13:04:46 +02:00 committed by GitHub
commit 3d89c95848
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 1750 additions and 1681 deletions

View file

@ -1,2 +1,6 @@
node_modules/ node_modules/
.git .git/
.env
.env.*
!.env.example

View file

@ -1,4 +1,2 @@
DISCORD_TOKEN= DISCORD_TOKEN=
DISCORD_APP=
SAY_LOGS_CHANNEL= SAY_LOGS_CHANNEL=

View file

@ -1,11 +1,23 @@
name: Lint name: Lint
on: [push] on:
push:
pull_request:
jobs: jobs:
lint: lint:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - name: Checkout repository
- run: yarn install --frozen-lockfile uses: actions/checkout@v3
- run: yarn lint - name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 20
- name: Install pnpm
uses: pnpm/action-setup@v2
- name: Install dependencies
run: pnpm install
- name: Lint
run: pnpm run lint

9
.gitignore vendored
View file

@ -1,11 +1,10 @@
node_modules/ node_modules/
/index.js
dist
.env .env
.env.local .env.*
.direnv !.env.example
.direnv/
.pre-commit-config.yaml .pre-commit-config.yaml
eslint_report.json eslint_report.json

View file

@ -1,6 +1,11 @@
FROM docker.io/library/node:19-alpine FROM docker.io/library/node:20-alpine
RUN corepack enable
RUN corepack prepare pnpm@latest --activate
WORKDIR /app WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile COPY package.json pnpm-lock.yaml .
RUN pnpm install
COPY . . COPY . .
CMD [ "yarn", "start" ] CMD [ "pnpm", "run", "start" ]

26
flake.lock generated
View file

@ -21,11 +21,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1681202837, "lastModified": 1685518550,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401", "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -57,11 +57,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1683968890, "lastModified": 1686368671,
"narHash": "sha256-FuNtjMvT07cJydY5NRyRhIni/dEwkSkijmFEdsmqdkA=", "narHash": "sha256-/I1IsENqXtqCzmpcd+poC0vu6JZRlzjHMdi3FXYr5qI=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "ea11a3977f4cba013d8680667616be827c967ac0", "rev": "8f21f3a0a3b65567f21697597d7b061a4731345a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -73,16 +73,16 @@
}, },
"nixpkgs-stable": { "nixpkgs-stable": {
"locked": { "locked": {
"lastModified": 1678872516, "lastModified": 1685801374,
"narHash": "sha256-/E1YwtMtFAu2KUQKV/1+KFuReYPANM2Rzehk84VxVoc=", "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "9b8e5abb18324c7fe9f07cb100c3cd4a29cda8b8", "rev": "c37ca420157f4abc31e26f436c1145f8951ff373",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "nixos-22.11", "ref": "nixos-23.05",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
@ -100,11 +100,11 @@
"nixpkgs-stable": "nixpkgs-stable" "nixpkgs-stable": "nixpkgs-stable"
}, },
"locked": { "locked": {
"lastModified": 1682596858, "lastModified": 1686213770,
"narHash": "sha256-Hf9XVpqaGqe/4oDGr30W8HlsWvJXtMsEPHDqHZA6dDg=", "narHash": "sha256-Re6xXLEqQ/HRnThryumyGzEf3Uv0Pl4cuG50MrDofP8=",
"owner": "cachix", "owner": "cachix",
"repo": "pre-commit-hooks.nix", "repo": "pre-commit-hooks.nix",
"rev": "fb58866e20af98779017134319b5663b8215d912", "rev": "182af51202998af5b64ddecaa7ff9be06425399b",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -32,7 +32,7 @@
}; };
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook; inherit (self.checks.${system}.pre-commit-check) shellHook;
packages = with pkgs; [yarn]; packages = with pkgs; [nodePackages.pnpm];
}; };
}); });
} }

View file

@ -19,14 +19,15 @@
"url-regex": "5.0.0" "url-regex": "5.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "18.16.16", "@types/node": "20.2.5",
"@typescript-eslint/eslint-plugin": "5.59.8", "@typescript-eslint/eslint-plugin": "5.59.8",
"@typescript-eslint/parser": "5.59.8", "@typescript-eslint/parser": "5.59.8",
"dotenv": "16.1.1", "dotenv": "16.1.4",
"esbuild": "0.17.19", "esbuild": "0.17.19",
"eslint": "8.42.0", "eslint": "8.42.0",
"gray-matter": "4.0.3", "gray-matter": "4.0.3",
"prettier": "2.8.8", "prettier": "2.8.8",
"typescript": "5.1.3" "typescript": "5.1.3"
} },
"packageManager": "pnpm@8.6.0"
} }

1641
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,9 @@
import { SlashCommandBuilder, Routes, PermissionFlagsBits } from 'discord.js'; import {
SlashCommandBuilder,
Routes,
PermissionFlagsBits,
type RESTGetAPIOAuth2CurrentApplicationResult,
} from 'discord.js';
import { REST } from '@discordjs/rest'; import { REST } from '@discordjs/rest';
import { getTags } from './tags'; import { getTags } from './tags';
@ -62,7 +67,11 @@ export const reuploadCommands = async () => {
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN!); const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN!);
await rest.put(Routes.applicationCommands(process.env.DISCORD_APP!), { const { id: appId } = (await rest.get(
Routes.oauth2CurrentApplication()
)) as RESTGetAPIOAuth2CurrentApplicationResult;
await rest.put(Routes.applicationCommands(appId), {
body: commands, body: commands,
}); });

View file

@ -5,6 +5,8 @@ import {
OAuth2Scopes, OAuth2Scopes,
InteractionType, InteractionType,
PermissionFlagsBits, PermissionFlagsBits,
ChannelType,
Events,
} from 'discord.js'; } from 'discord.js';
import { reuploadCommands } from './_reupload'; import { reuploadCommands } from './_reupload';
@ -76,7 +78,7 @@ client.once('ready', async () => {
status: 'online', status: 'online',
}); });
client.on('messageCreate', async (e) => { client.on(Events.MessageCreate, async (e) => {
try { try {
if (e.channel.partial) await e.channel.fetch(); if (e.channel.partial) await e.channel.fetch();
if (e.author.partial) await e.author.fetch(); if (e.author.partial) await e.author.fetch();
@ -98,12 +100,12 @@ client.once('ready', async () => {
} }
await expandDiscordLink(e); await expandDiscordLink(e);
} catch (error) { } catch (error) {
console.error('Unhandled exception on messageCreate', error); console.error('Unhandled exception on MessageCreate', error);
} }
}); });
}); });
client.on('interactionCreate', async (interaction) => { client.on(Events.InteractionCreate, async (interaction) => {
try { try {
if (!interaction.isChatInputCommand()) return; if (!interaction.isChatInputCommand()) return;
@ -130,16 +132,16 @@ client.on('interactionCreate', async (interaction) => {
await roryCommand(interaction); await roryCommand(interaction);
} }
} catch (error) { } catch (error) {
console.error('Unhandled exception on interactionCreate', error); console.error('Unhandled exception on InteractionCreate', error);
} }
}); });
client.on('messageReactionAdd', async (reaction, user) => { client.on(Events.MessageReactionAdd, async (reaction, user) => {
try { try {
if (reaction.partial) { if (reaction.partial) {
try { try {
await reaction.fetch(); await reaction.fetch();
} catch (error) { } catch (error) {
console.error('Something went wrong when fetching the message:', error); console.error('Something went wrong when fetching the message:', error);
return; return;
} }
@ -147,14 +149,45 @@ client.on('messageReactionAdd', async (reaction, user) => {
if ( if (
reaction.message.interaction && reaction.message.interaction &&
reaction.message.interaction?.type === InteractionType.ApplicationCommand && reaction.message.interaction?.type ===
InteractionType.ApplicationCommand &&
reaction.message.interaction?.user === user && reaction.message.interaction?.user === user &&
reaction.emoji.name === '❌' reaction.emoji.name === '❌'
) { ) {
await reaction.message.delete(); await reaction.message.delete();
} }
} catch (error) { } catch (error) {
console.error('Unhandled exception on messageReactionAdd', error); console.error('Unhandled exception on MessageReactionAdd', error);
}
});
client.on(Events.ThreadCreate, async (channel) => {
try {
if (
channel.type === ChannelType.PublicThread &&
channel.parent &&
channel.parent.name === 'support' &&
channel.guild
) {
const pingRole = channel.guild.roles.cache.find(
(r) => r.name === 'Moderators'
);
if (!pingRole) return;
await channel.send({
content: `
<@${channel.ownerId}> We've received your support ticket! Please upload your logs and post the link here if possible. Also, remember not to ping ${pingRole} for support, as they are not support staff!
`.trim(),
allowedMentions: {
repliedUser: true,
roles: [],
users: channel.ownerId ? [channel.ownerId] : [],
},
});
}
} catch (error) {
console.error('Error handling ThreadCreate', error);
} }
}); });

View file

@ -79,6 +79,7 @@ export async function expandDiscordLink(message: Message): Promise<void> {
resultEmbeds.push(embed); resultEmbeds.push(embed);
} catch (ignored) { } catch (ignored) {
/* */
} }
} }

View file

@ -1,13 +1,13 @@
{ {
"compilerOptions": { "compilerOptions": {
"strict": true, "strict": true,
"esModuleInterop": true,
"downlevelIteration": true, "downlevelIteration": true,
"module": "esnext", "module": "esnext",
"target": "ES2018", "target": "esnext",
"moduleResolution": "node", "moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"rootDir": "src", "skipLibCheck": true,
"outDir": "dist" "noEmit": true
} }
} }

1634
yarn.lock

File diff suppressed because it is too large Load diff