Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit 930c28f

Browse files
committed
new code
1 parent 65acc9b commit 930c28f

26 files changed

+1224
-432
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
node_modules/
2-
dist/
2+
build/

.eslintrc

Lines changed: 0 additions & 6 deletions
This file was deleted.

.eslintrc.cjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* eslint-env node */
2+
3+
module.exports = {
4+
root: true,
5+
parser: '@typescript-eslint/parser',
6+
plugins: ['@typescript-eslint'],
7+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
8+
rules: {
9+
'@typescript-eslint/no-non-null-assertion': 0,
10+
},
11+
};

.github/workflows/docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
uses: docker/build-push-action@v4
2020
with:
2121
push: true
22-
tags: ghcr.io/prismlauncher/linkedroles:latest
22+
tags: ghcr.io/prismlauncher/linkedroles:latest

Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
FROM node:19 AS builder
1+
FROM node:20 AS builder
22
WORKDIR /app
33
COPY package*.json ./
4-
RUN npm ci
54
COPY . .
6-
RUN npm run build
5+
RUN yarn run build
76

8-
FROM node:19
7+
FROM node:20
98
WORKDIR /app
109
COPY package* ./
11-
RUN npm ci --production
1210
COPY --from=builder ./app/build/src ./build/src
1311
EXPOSE 8080
1412
CMD ["yarn", "start"]

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# LinkedRoles
2-
Linked Roles for the Prism Discord
2+
Linked Roles for the Prism Discord
3+
4+
uses https://github.com/JustinBeckwith/fitbit-discord-bot as a template

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@
2020
"cookie-parser": "1.4.6",
2121
"discord-interactions": "3.3.0",
2222
"express": "4.18.2",
23-
"node-fetch": "3.3.1",
23+
"gaxios": "^5.1.0",
2424
"nconf": "0.12.0",
2525
"redis": "4.6.5"
2626
},
2727
"devDependencies": {
2828
"@types/express": "4.17.17",
29-
"@types/node": "18.15.4",
30-
"@typescript-eslint/eslint-plugin": "5.56.0",
31-
"@typescript-eslint/parser": "5.56.0",
29+
"@types/node": "18.16.1",
30+
"@typescript-eslint/eslint-plugin": "5.59.1",
31+
"@typescript-eslint/parser": "5.59.1",
3232
"dotenv": "16.0.3",
33-
"gray-matter": "4.0.3",
34-
"prettier": "2.8.5",
35-
"eslint": "8.36.0",
33+
"eslint": "8.39.0",
3634
"eslint-config-prettier": "8.8.0",
3735
"eslint-plugin-prettier": "4.2.1",
38-
"nodemon": "2.0.21",
39-
"typescript": "5.0.2"
36+
"gray-matter": "4.0.3",
37+
"nodemon": "2.0.22",
38+
"prettier": "2.8.8",
39+
"typescript": "5.0.4"
4040
},
4141
"keywords": [],
4242
"author": "IThundxr <[email protected]>"

src/commands.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Share command metadata from a common spot to be used for both runtime
3+
* and registration.
4+
*/
5+
6+
export const DISCONNECT = {
7+
name: 'disconnect',
8+
description: 'Clear all associated Github data and disconnect your account.',
9+
};
10+
11+
export const GET_PROFILE = {
12+
name: 'get-profile',
13+
description: 'Fetch the linked Github account profile information.',
14+
};

src/common.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as storage from './storage.js';
2+
import * as github from './github.js';
3+
import * as discord from './discord.js';
4+
5+
/**
6+
* Shared utility function. For a given Github UserId, fetch profile metadata,
7+
* transform it, and push it to the Discord metadata endpoint.
8+
*/
9+
export async function updateMetadata(userId: string) {
10+
const githubTokens = await storage.getGithubTokens(userId);
11+
const discordTokens = await storage.getDiscordTokens(
12+
githubTokens.discord_user_id
13+
);
14+
15+
// Fetch the user profile data from Github
16+
let metadata: Record<string, string>;
17+
try {
18+
const profile = await github.getProfile(userId, githubTokens);
19+
// Transform the data from the profile, and grab only the bits of data used by Discord.
20+
metadata = {
21+
iscoder: profile.user.iscoder,
22+
isdocumentation: profile.user.iscoder,
23+
};
24+
} catch (e) {
25+
e.message = `Error fetching Github profile data: ${e.message}`;
26+
console.error(e);
27+
// If fetching the profile data for the Github user fails for any reason,
28+
// ensure metadata on the Discord side is nulled out. This prevents cases
29+
// where the user revokes the Github app permissions, and is left with
30+
// stale verified role data.
31+
metadata = {
32+
iscoder: undefined,
33+
isdocumentation: undefined,
34+
};
35+
}
36+
37+
// Push the data to Discord.
38+
await discord.pushMetadata(userId, discordTokens, metadata);
39+
}

src/discord.js

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)