Merge pull request #180 from ryanccn/support-improvements
This commit is contained in:
commit
3d89c95848
14 changed files with 1750 additions and 1681 deletions
|
@ -1,2 +1,6 @@
|
|||
node_modules/
|
||||
.git
|
||||
.git/
|
||||
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
|
|
@ -1,4 +1,2 @@
|
|||
DISCORD_TOKEN=
|
||||
DISCORD_APP=
|
||||
|
||||
SAY_LOGS_CHANNEL=
|
||||
|
|
20
.github/workflows/lint.yml
vendored
20
.github/workflows/lint.yml
vendored
|
@ -1,11 +1,23 @@
|
|||
name: Lint
|
||||
|
||||
on: [push]
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: yarn install --frozen-lockfile
|
||||
- run: yarn lint
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- 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
9
.gitignore
vendored
|
@ -1,11 +1,10 @@
|
|||
node_modules/
|
||||
/index.js
|
||||
|
||||
dist
|
||||
|
||||
.env
|
||||
.env.local
|
||||
.direnv
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
.direnv/
|
||||
.pre-commit-config.yaml
|
||||
|
||||
eslint_report.json
|
||||
|
|
13
Dockerfile
13
Dockerfile
|
@ -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
|
||||
COPY package.json yarn.lock ./
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
COPY package.json pnpm-lock.yaml .
|
||||
RUN pnpm install
|
||||
|
||||
COPY . .
|
||||
CMD [ "yarn", "start" ]
|
||||
CMD [ "pnpm", "run", "start" ]
|
||||
|
|
26
flake.lock
generated
26
flake.lock
generated
|
@ -21,11 +21,11 @@
|
|||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1681202837,
|
||||
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
|
||||
"lastModified": 1685518550,
|
||||
"narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
|
||||
"rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -57,11 +57,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1683968890,
|
||||
"narHash": "sha256-FuNtjMvT07cJydY5NRyRhIni/dEwkSkijmFEdsmqdkA=",
|
||||
"lastModified": 1686368671,
|
||||
"narHash": "sha256-/I1IsENqXtqCzmpcd+poC0vu6JZRlzjHMdi3FXYr5qI=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "ea11a3977f4cba013d8680667616be827c967ac0",
|
||||
"rev": "8f21f3a0a3b65567f21697597d7b061a4731345a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -73,16 +73,16 @@
|
|||
},
|
||||
"nixpkgs-stable": {
|
||||
"locked": {
|
||||
"lastModified": 1678872516,
|
||||
"narHash": "sha256-/E1YwtMtFAu2KUQKV/1+KFuReYPANM2Rzehk84VxVoc=",
|
||||
"lastModified": 1685801374,
|
||||
"narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "9b8e5abb18324c7fe9f07cb100c3cd4a29cda8b8",
|
||||
"rev": "c37ca420157f4abc31e26f436c1145f8951ff373",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-22.11",
|
||||
"ref": "nixos-23.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
|
@ -100,11 +100,11 @@
|
|||
"nixpkgs-stable": "nixpkgs-stable"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1682596858,
|
||||
"narHash": "sha256-Hf9XVpqaGqe/4oDGr30W8HlsWvJXtMsEPHDqHZA6dDg=",
|
||||
"lastModified": 1686213770,
|
||||
"narHash": "sha256-Re6xXLEqQ/HRnThryumyGzEf3Uv0Pl4cuG50MrDofP8=",
|
||||
"owner": "cachix",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"rev": "fb58866e20af98779017134319b5663b8215d912",
|
||||
"rev": "182af51202998af5b64ddecaa7ff9be06425399b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
};
|
||||
devShells.default = pkgs.mkShell {
|
||||
inherit (self.checks.${system}.pre-commit-check) shellHook;
|
||||
packages = with pkgs; [yarn];
|
||||
packages = with pkgs; [nodePackages.pnpm];
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
@ -19,14 +19,15 @@
|
|||
"url-regex": "5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "18.16.16",
|
||||
"@types/node": "20.2.5",
|
||||
"@typescript-eslint/eslint-plugin": "5.59.8",
|
||||
"@typescript-eslint/parser": "5.59.8",
|
||||
"dotenv": "16.1.1",
|
||||
"dotenv": "16.1.4",
|
||||
"esbuild": "0.17.19",
|
||||
"eslint": "8.42.0",
|
||||
"gray-matter": "4.0.3",
|
||||
"prettier": "2.8.8",
|
||||
"typescript": "5.1.3"
|
||||
}
|
||||
},
|
||||
"packageManager": "pnpm@8.6.0"
|
||||
}
|
||||
|
|
1641
pnpm-lock.yaml
generated
Normal file
1641
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -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 { getTags } from './tags';
|
||||
|
||||
|
@ -62,7 +67,11 @@ export const reuploadCommands = async () => {
|
|||
|
||||
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,
|
||||
});
|
||||
|
||||
|
|
47
src/index.ts
47
src/index.ts
|
@ -5,6 +5,8 @@ import {
|
|||
OAuth2Scopes,
|
||||
InteractionType,
|
||||
PermissionFlagsBits,
|
||||
ChannelType,
|
||||
Events,
|
||||
} from 'discord.js';
|
||||
import { reuploadCommands } from './_reupload';
|
||||
|
||||
|
@ -76,7 +78,7 @@ client.once('ready', async () => {
|
|||
status: 'online',
|
||||
});
|
||||
|
||||
client.on('messageCreate', async (e) => {
|
||||
client.on(Events.MessageCreate, async (e) => {
|
||||
try {
|
||||
if (e.channel.partial) await e.channel.fetch();
|
||||
if (e.author.partial) await e.author.fetch();
|
||||
|
@ -98,12 +100,12 @@ client.once('ready', async () => {
|
|||
}
|
||||
await expandDiscordLink(e);
|
||||
} 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 {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
|
@ -130,11 +132,11 @@ client.on('interactionCreate', async (interaction) => {
|
|||
await roryCommand(interaction);
|
||||
}
|
||||
} 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 {
|
||||
if (reaction.partial) {
|
||||
try {
|
||||
|
@ -147,14 +149,45 @@ client.on('messageReactionAdd', async (reaction, user) => {
|
|||
|
||||
if (
|
||||
reaction.message.interaction &&
|
||||
reaction.message.interaction?.type === InteractionType.ApplicationCommand &&
|
||||
reaction.message.interaction?.type ===
|
||||
InteractionType.ApplicationCommand &&
|
||||
reaction.message.interaction?.user === user &&
|
||||
reaction.emoji.name === '❌'
|
||||
) {
|
||||
await reaction.message.delete();
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ export async function expandDiscordLink(message: Message): Promise<void> {
|
|||
|
||||
resultEmbeds.push(embed);
|
||||
} catch (ignored) {
|
||||
/* */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"downlevelIteration": true,
|
||||
"module": "esnext",
|
||||
"target": "ES2018",
|
||||
"target": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
"skipLibCheck": true,
|
||||
"noEmit": true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue