Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Merge pull request #74 from RightCapitalHQ/feature/migrate-to-eslint-v9
Browse files Browse the repository at this point in the history
chore: bump ESLint to v9
  • Loading branch information
rainx authored Nov 1, 2024
2 parents 151daf7 + e06e450 commit f09747f
Show file tree
Hide file tree
Showing 9 changed files with 1,353 additions and 308 deletions.
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.9.0
20.18.0
11 changes: 11 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import rcPreset from '@rightcapital/eslint-config';

const { config } = rcPreset.utils;

export default config(...rcPreset.configs.recommended, {
files: ['**/*.{ts,cts,mts}'],
rules: {
// false positives
'import-x/no-named-as-default': 'off',
},
});
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"@commitlint/cli": "18.4.3",
"@commitlint/config-conventional": "18.4.3",
"@commitlint/cz-commitlint": "18.4.3",
"@rightcapital/eslint-config-javascript": "16.0.1",
"@rightcapital/eslint-config-typescript": "16.0.1",
"@rightcapital/eslint-config": "38.0.0",
"@rightcapital/prettier-config": "6.0.8",
"@tsconfig/node18": "18.2.2",
"@types/async-retry": "1.4.8",
Expand All @@ -39,7 +38,7 @@
"babel-jest": "29.7.0",
"beachball": "2.39.0",
"commitizen": "4.3.0",
"eslint": "8.56.0",
"eslint": "9.13.0",
"husky": "8.0.3",
"inquirer": "9.2.12",
"jest": "29.7.0",
Expand All @@ -66,8 +65,8 @@
"check": "beachball check",
"preinstall": "npx only-allow pnpm",
"prepare": "husky install",
"eslint": "eslint --report-unused-disable-directives 'src/**/*.ts*'",
"eslint:fix": "eslint --report-unused-disable-directives --fix 'src/**/*.ts*'",
"eslint": "eslint --report-unused-disable-directives .",
"eslint:fix": "eslint --report-unused-disable-directives --fix .",
"test": "jest",
"bolt:start": "nodemon ./dist/app.js",
"start": "pnpm run \"/(build:watch|bolt:start)/\""
Expand Down
1,610 changes: 1,319 additions & 291 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { App } from '@slack/bolt';
import {
ChatPostMessageResponse,
WebClient,
WebAPIPlatformError,
type ChatPostMessageResponse,
ErrorCode,
type WebAPIPlatformError,
type WebClient,
} from '@slack/web-api';

import { PromptParserHelpers } from './helpers/prompt-parser.helpers';
import { SlackHelpers } from './helpers/slack.helpers';
import { OpenAIService } from './service/openai.service';
Expand Down Expand Up @@ -98,14 +99,15 @@ async function generateReplyMessageByPrompt(
const generatedImageUrls =
await OpenAIService.instance.createNewImageByPrompt(parsedPromptParts);
for await (const generatedImageUrl of generatedImageUrls) {
if (generatedImageUrl)
if (generatedImageUrl) {
await SlackHelpers.uploadImageToSlackFileServer(
client,
channelId,
threadTs,
generatedImageUrl,
prompt,
);
}
}

if (message.channel && message.ts) {
Expand Down
7 changes: 4 additions & 3 deletions src/helpers/image-source-url.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { File } from 'buffer';
import { BinaryLike } from 'node:crypto';
import { File } from 'node:buffer';
import type { BinaryLike } from 'node:crypto';

import { InvalidArgumentException } from '@rightcapital/exceptions';

export class ImageSourceUrlHelpers {
Expand All @@ -8,7 +9,7 @@ export class ImageSourceUrlHelpers {

try {
url = new URL(possibleUrl);
} catch (_) {
} catch {
return false;
}
return url.hostname === 'pasteboard.co';
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/prompt-parser.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { cloneDeep } from 'lodash';

import { ImageSourceUrlHelpers } from './image-source-url.helpers';

export interface IParsedPromptParts {
Expand Down Expand Up @@ -127,7 +128,7 @@ export class PromptParserHelpers {

try {
url = new URL(possibleUrl);
} catch (_) {
} catch {
return false;
}

Expand Down
6 changes: 4 additions & 2 deletions src/helpers/slack.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import https from 'https';
import { FilesUploadResponse, WebClient } from '@slack/web-api';
import https from 'node:https';

import type { FilesUploadResponse, WebClient } from '@slack/web-api';
import type { Message as ReplyMessage } from '@slack/web-api/dist/response/ConversationsRepliesResponse';
import { snakeCase } from 'lodash';

Expand Down Expand Up @@ -41,6 +42,7 @@ export class SlackHelpers {
resolve(result);
});
} catch (exception) {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
reject(exception);
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/service/openai.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { UnexpectedValueException } from '@rightcapital/exceptions';
import retry from 'async-retry';
import OpenAI from 'openai';

import { ImageSourceUrlHelpers } from '../helpers/image-source-url.helpers';
import { IParsedPromptParts } from '../helpers/prompt-parser.helpers';
import type { IParsedPromptParts } from '../helpers/prompt-parser.helpers';
import type { Message } from '../helpers/slack.helpers';

const OPENAI_CHAT_MODEL = process.env.OPENAI_CHAT_MODEL || 'gpt-3.5-turbo';
Expand Down

0 comments on commit f09747f

Please sign in to comment.