Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple discobot from commonwealth #6203

Merged
merged 9 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/discord-bot/Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
listener: node --max_old_space_size=$(./scripts/get-max-old-space-size.sh) packages/discord-bot/build/discord-bot/discord-listener/discordListener.js
consumer: node --max_old_space_size=$(./scripts/get-max-old-space-size.sh) packages/discord-bot/build/discord-bot/discord-consumer/discordConsumer.js
listener: node --max_old_space_size=$(./scripts/get-max-old-space-size.sh) packages/discord-bot/build/packages/discord-bot/src/discord-listener/discordListener.js
consumer: node --max_old_space_size=$(./scripts/get-max-old-space-size.sh) packages/discord-bot/build/packages/discord-bot/src/discord-consumer/discordConsumer.js
4 changes: 3 additions & 1 deletion packages/discord-bot/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
For documentation, see the [Discobot knowledge base entry](../../knowledge_base/Discobot.md).
# Discord-Bot

For documentation, see the [Discobot knowledge base entry](../../knowledge_base/Discobot.md).
8 changes: 4 additions & 4 deletions packages/discord-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "",
"scripts": {
"build": "tsc --project tsconfig.json && tsc-alias",
"start": "ts-node discord-listener/discordListener.ts",
"start-consumer": "ts-node discord-consumer/discordConsumer.ts",
"start": "ts-node src/discord-listener/discordListener.ts",
"start-consumer": "ts-node src/discord-consumer/discordConsumer.ts",
"check-types": "tsc --noEmit",
"start-prod-consumer": "node build/discord-bot/discord-consumer/discordConsumer.js",
"start-prod-listener": "node build/discord-bot/discord-listener/discordListener.js",
"start-prod-consumer": "node build/packages/discord-bot/src/discord-consumer/discordConsumer.js",
"start-prod-listener": "node build/packages/discord-bot/src/discord-listener/discordListener.js",
"switch-staging-app": "chmod u+x scripts/switch-discobot-staging-env.sh && ./scripts/switch-discobot-staging-env.sh"
},
"keywords": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import {
startHealthCheckLoop,
} from 'common-common/src/scripts/startHealthCheckLoop';
import { StatsDController } from 'common-common/src/statsd';
import v8 from 'v8';
import {
handleCommentMessages,
handleThreadMessages,
} from 'discord-bot/discord-consumer/handlers';
import { rollbar } from 'discord-bot/utils/rollbar';
import { getForumLinkedTopic } from 'discord-bot/utils/util';
import v8 from 'v8';
} from '../discord-consumer/handlers';
import { CW_BOT_KEY, DISCOBOT_ADDRESS, RABBITMQ_URI } from '../utils/config';
import { rollbar } from '../utils/rollbar';
import { getForumLinkedTopic } from '../utils/util';

let isServiceHealthy = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import {
ThreadDiscordActions,
} from '@hicommonwealth/core';
import axios from 'axios';
import { TopicAttributes } from 'commonwealth/server/models/topic';
import { SERVER_URL } from 'discord-bot/utils/config';
import { sequelize } from 'discord-bot/utils/database';
import { SERVER_URL } from '../utils/config';
import { sequelize } from '../utils/database';

export async function handleThreadMessages(
action: ThreadDiscordActions,
message: IDiscordMessage,
topic: TopicAttributes,
topic: { id: string; name: string },
sharedReqData: Record<string, any>,
): Promise<void> {
switch (action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import {
ServiceKey,
startHealthCheckLoop,
} from 'common-common/src/scripts/startHealthCheckLoop';
import {
handleMessage,
handleThreadChannel,
} from 'discord-bot/discord-listener/handlers';
import { rollbar } from 'discord-bot/utils/rollbar';
import {
Client,
IntentsBitField,
Expand All @@ -21,7 +16,12 @@ import {
ThreadChannel,
} from 'discord.js';
import v8 from 'v8';
import {
handleMessage,
handleThreadChannel,
} from '../discord-listener/handlers';
import { DISCORD_TOKEN, RABBITMQ_URI } from '../utils/config';
import { rollbar } from '../utils/rollbar';

const log = factory.getLogger(formatFilename(__filename));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { DiscordAction, IDiscordMessage } from '@hicommonwealth/core';
import { factory, formatFilename } from 'common-common/src/logging';
import { RabbitMQController } from 'common-common/src/rabbitmq';
import { RascalPublications } from 'common-common/src/rabbitmq/types';
import { getImageUrls } from 'discord-bot/discord-listener/util';
import { Client, Message, ThreadChannel } from 'discord.js';
import { getImageUrls } from '../discord-listener/util';
import { rollbar } from '../utils/rollbar';
import { getForumLinkedTopic } from '../utils/util';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { TopicAttributes } from 'commonwealth/server/models/topic';
import { QueryTypes } from 'sequelize';
import { sequelize } from './database';

/**
* Searches the Commonwealth database Topics table for any topics that are linked to the given Discord Forum
*/
export async function getForumLinkedTopic(
forumId: string,
): Promise<TopicAttributes> {
const result: TopicAttributes[] = await sequelize.query(
export async function getForumLinkedTopic(forumId: string): Promise<any> {
const result = await sequelize.query(
`
SELECT * FROM "Topics" WHERE channel_id = :forumId AND deleted_at IS NULL LIMIT 1;
`,
Expand Down
14 changes: 3 additions & 11 deletions packages/discord-bot/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@
"lib": ["es2020"],
"typeRoots": ["./node_modules/@types"],
"skipLibCheck": true,
"outDir": "./build",
"baseUrl": "."
// TODO: "rootDir": "src",
"outDir": "build"
},
"paths": {
"@hicommonwealth/*": ["../../libs/*/src"],
"common-common": ["../../packages/common-common"],
"common-common/*": ["../../packages/common-common/*"],
"commonwealth": ["../../packages/commonwealth"],
"commonwealth/*": ["../../packages/commonwealth/*"]
},
"include": ["discord-consumer", "discord-listener", "utils"],
"exclude": ["./node_modules", "node_modules", "build"]
"include": ["src"]
}
11 changes: 5 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
"esModuleInterop": true,
"downlevelIteration": true,
"traceResolution": false,
"baseUrl": ".",
"paths": {
"@hicommonwealth/*": ["libs/*/src"],
"common-common": ["./packages/common-common"],
"common-common/*": ["./packages/common-common/*"],
"common-common": ["packages/common-common"],
"common-common/*": ["packages/common-common/*"],
"chain-testing/*": [
"./packages/commonwealth/test/util/evm-chain-testing/*"
"packages/commonwealth/test/util/evm-chain-testing/*"
],
"token-balance-cache": ["./packages/token-balance-cache"],
"token-balance-cache/*": ["./packages/token-balance-cache/*"],
"discord-bot": ["./packages/discord-bot"],
"discord-bot/*": ["./packages/discord-bot/*"]
"token-balance-cache/*": ["./packages/token-balance-cache/*"]
}
},
"ts-node": {
Expand Down
Loading