Skip to content

Commit e88f41f

Browse files
authored
Issue 191: Fix Issue with Pun Command and Add Version Hyperlink (#192)
* Update pun.ts * fixed a bug in pun command and added version hyperlink to help card * remove unnecessary file and fix makefile * run docker container build test in parallel * fix linter bugs and docker build test workflow bug
1 parent 9b5efd1 commit e88f41f

File tree

12 files changed

+52
-30
lines changed

12 files changed

+52
-30
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ jobs:
3939
- uses: CultureHQ/actions-yarn@master
4040
with:
4141
args: --cwd services/bot lint
42+
build-test:
43+
needs: setup
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@master
47+
- name: Test Docker Container Builds
48+
run: docker build -t testing:latest services/bot
4249
test:
4350
needs: setup
4451
runs-on: ubuntu-latest

Makefile

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,23 @@
22
build:
33
docker compose -f docker-compose.yml -f docker-compose.dev.yml build
44

5-
.PHONY: build-prod
6-
build-prod:
7-
docker compose build
8-
95
.PHONY: up
106
up:
117
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build -d
128
yarn --cwd services/bot start:dev-bot
13-
9+
10+
.PHONY: deploy $(VERSION)
11+
deploy:
12+
${MAKE} build
13+
./bin/deploy $(VERSION)
14+
1415
.PHONY: logs
1516
logs:
16-
docker-compose logs -f bot
17-
18-
.PHONY: up-prod
19-
up-prod:
20-
docker-compose up -d
17+
docker compose logs -f bot
2118

2219
.PHONY: down
2320
down:
24-
docker compose -f docker-compose.yml -f docker-compose.dev.yml down
21+
docker compose down
2522

2623
.PHONY: test
2724
test:

docker-compose.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3.3'
1+
version: '3.9'
22
services:
33
bot:
44
build:

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3.3'
1+
version: '3.9'
22
services:
33
bot:
44
image: ${QUTEX_IMAGE:-qutex_bot:latest}

services/bot/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:16.9.0-alpine3.13
1+
FROM node:16.10.0-alpine3.13
22

33
# Set the working directory
44
WORKDIR /app

services/bot/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@types/jest": "^26.0.22",
5050
"@types/mock-fs": "^4.13.0",
5151
"@types/mongoose": "^5.11.97",
52-
"@types/node": "^16.9.1",
52+
"@types/node": "^15.14.9",
5353
"@types/uuid": "^8.3.0",
5454
"@typescript-eslint/eslint-plugin": "^4.31.2",
5555
"@typescript-eslint/parser": "^4.29.0",
@@ -60,17 +60,17 @@
6060
"mock-fs": "^5.1.1",
6161
"mockdate": "^3.0.5",
6262
"mrm-task-npm-docker": "^1.3.0",
63-
"ngrok": "^4.1.0",
63+
"ngrok": "^4.2.2",
6464
"nodemon": "^2.0.7",
6565
"rimraf": "^3.0.2",
6666
"ts-jest": "^26.5.5",
6767
"ts-node": "^10.2.1",
68-
"typescript": "^4.3.4"
68+
"typescript": "^4.4.3"
6969
},
7070
"dependencies": {
7171
"axios": "^0.21.2",
7272
"chartjs-to-image": "^1.0.4",
73-
"express": "^4.16.4",
73+
"express": "^4.17.1",
7474
"migrate-mongo": "^8.2.2",
7575
"moment": "^2.29.1",
7676
"mongoose": "^5.13.0",

services/bot/src/commands/eggs/pun.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ export class Pun extends CommandBase implements ICommand {
2626
*/
2727
public async relax (initiative: IInitiative): Promise<string> {
2828
LOGGER.verbose(`Getting pun for user: ${initiative.user.id}`);
29-
// Only return a list of projects that the user is an admin for.
30-
const response = await axios({ url: 'https://icanhazdadjoke.com/', headers: { 'Accept': 'text/plain' } });
29+
// There's an issue perhaps with the website or the axios library that basically doesn't work properly
30+
// when the axios is used as the User-Agent. Thus, pretend that we are a curl request.
31+
const response = await axios({
32+
url: 'https://icanhazdadjoke.com/',
33+
headers: { 'Accept': 'text/plain', 'User-Agent': 'curl/7.64.1' }
34+
});
3135
LOGGER.info(`Pun: ${JSON.stringify(response.data, null, 2)}`);
3236
return response.data;
3337
}
34-
}
38+
}

services/bot/src/commands/help/card.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class Card extends CommandBase implements ICommand {
3838
card.attachments[0].content.body[2].actions[2].card.body = superAdminCommands;
3939

4040
// Set "about" information
41-
card.attachments[0].content.body[1].columns[1].items[0].text = process.env.VERSION;
41+
card.attachments[0].content.body[1].columns[1].items[0].text = `[${process.env.VERSION}](https://github.com/amthorn/qutex/releases/tag/${process.env.VERSION})`;
4242
card.attachments[0].content.body[1].columns[1].items[1].text = process.env.RELEASE_DATE;
4343
card.attachments[0].content.body[1].columns[1].items[2].text = `${process.env.AUTHOR_NAME} (${process.env.AUTHOR_EMAIL})`;
4444

services/bot/src/handler.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,31 @@ export class Handler {
7272
const now = new Date();
7373
LOGGER.error(`TRACE ID: ${traceId}`);
7474
LOGGER.error(`OCCURRED AT: ${now}`);
75-
LOGGER.error(e.stack);
75+
// Typescript has a quirk where it doesn't know the type of the error object
76+
// leading to: Object is of type 'unknown'
77+
let errorMessage = 'An unknown error has occurred in Qutex';
78+
let errorStack: string | undefined = 'Stack Trace not found.';
79+
if (e instanceof Error) {
80+
errorMessage = e.message;
81+
errorStack = e.stack;
82+
}
83+
LOGGER.error(errorMessage);
7684
try {
7785
await BOT.messages.create({
78-
markdown: `An unexpected error occurred. Please open an issue by using the "help" command:\n${e}`,
86+
markdown: `An unexpected error occurred. Please open an issue by using the "help" command:\nError: ${errorMessage}`,
7987
roomId: request.body.data.roomId
8088
});
8189

8290
await BOT.messages.create({
83-
markdown: `An unexpected error occurred at ${now}.\n\`\`\`\nTRACE ID: ${traceId}\n${e.stack}\n\`\`\``,
91+
markdown: `An unexpected error occurred at ${now}.\n\`\`\`\nTRACE ID: ${traceId}\n${errorStack}\n\`\`\``,
8492
toPersonEmail: process.env.DEBUG_EMAIL
8593
});
8694
} catch (exc) {
87-
LOGGER.error(exc);
95+
let innerError = 'A very unknown error has occurred in Qutex!!';
96+
if (exc instanceof Error) {
97+
innerError = exc.message;
98+
}
99+
LOGGER.error(innerError);
88100
}
89101
}
90102
}

services/bot/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
/// <reference path="../types/index.d.ts" />
77

8-
import express from 'express';
8+
import express, { RequestHandler } from 'express';
99
import { Handler } from './handler';
1010
import mongoose from 'mongoose';
1111
import { GET } from './secrets';
@@ -19,7 +19,9 @@ mongoUri += '?authSource=admin';
1919
mongoose.connect(mongoUri, { useCreateIndex: true, useNewUrlParser: true, useUnifiedTopology: true });
2020

2121
const APP = express();
22-
APP.use(express.json());
22+
// without the "as" expression here, there's a bug which yields the error: error TS2769: No overload matches this call
23+
// https://letscodepare.com/blog/argument-of-type-nexthandlefunction-is-not-assignable-nodejs
24+
APP.use(express.json() as RequestHandler);
2325

2426
const HOST = '0.0.0.0';
2527
const PORT = 3000;

0 commit comments

Comments
 (0)