Skip to content

Commit

Permalink
Merge branch 'develop' into j94/matrixroomhandler-types
Browse files Browse the repository at this point in the history
  • Loading branch information
jaller94 authored Jan 24, 2024
2 parents 823f78d + 8ae61dd commit 5cfc8e2
Show file tree
Hide file tree
Showing 47 changed files with 1,029 additions and 766 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/sign-off.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ on:

jobs:
signoff:
uses: matrix-org/backend-meta/.github/workflows/[email protected]

uses: matrix-org/backend-meta/.github/workflows/sign-off.yml@v2
8 changes: 2 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 16
# Workaround for https://github.com/matrix-org/matrix-appservice-discord/issues/803
- run: git config --global url.https://github.com/.insteadOf git://github.com/
node-version: 18
- run: yarn
- run: yarn lint
test:
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [16, 18]
node_version: [18, 20]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}
# Workaround for https://github.com/matrix-org/matrix-appservice-discord/issues/803
- run: git config --global url.https://github.com/.insteadOf git://github.com/
- run: yarn
- run: yarn test
77 changes: 77 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
4.0.0 (2023-09-15)
==================

Bugfixes
--------

- Prefer server-level display names when available. ([\#888](https://github.com/matrix-org/matrix-appservice-discord/issues/888))
- Update matrix-appservice-bridge to use a non-deprecated method of authenticating to a homeserver. Fixes #896. ([\#897](https://github.com/matrix-org/matrix-appservice-discord/issues/897))
- Let file logs correctly ignore modules matching `"logging.files[*].disabled"` in the configuration file. ([\#902](https://github.com/matrix-org/matrix-appservice-discord/issues/902))


Deprecations and Removals
-------------------------

- Node.JS 16 is now unsupported, please upgrade to Node.JS 18 or later. Node.JS 18 is now used for Docker. ([\#897](https://github.com/matrix-org/matrix-appservice-discord/issues/897))


Internal Changes
----------------

- Update the package registry for better-discord.js, and use its latest release. ([\#898](https://github.com/matrix-org/matrix-appservice-discord/issues/898))
- Modify the "start" and "debug" package scripts to not trigger a TypeScript build, and to accept a user-supplied command line option for the path to the bridge configuration file. ([\#900](https://github.com/matrix-org/matrix-appservice-discord/issues/900))
- Update the GitHub action used for checking pull requests for sign-off status. ([\#901](https://github.com/matrix-org/matrix-appservice-discord/issues/901))


3.1.1 (2022-11-10)
==================

Bugfixes
--------

- Fix a crash caused by processing metrics for Matrix events. ([\#869](https://github.com/matrix-org/matrix-appservice-discord/issues/869))


3.1.0 (2022-11-03)
==================

Features
--------

- Adds a config value, in order to disable forwarding room topic changes from Matrix to Discord (`disableRoomTopicNotifications`, false by default). ([\#836](https://github.com/matrix-org/matrix-appservice-discord/issues/836))


Bugfixes
--------

- Include the domain name in the regular expression. ([\#834](https://github.com/matrix-org/matrix-appservice-discord/issues/834))
- Remove usage of unreliable field `age` on events, allowing the bridge to work with non-Synapse homeserver implementations. ([\#842](https://github.com/matrix-org/matrix-appservice-discord/issues/842))
- Prevent crashes when handling messages sent to voice channels. ([\#858](https://github.com/matrix-org/matrix-appservice-discord/issues/858))


3.0.0 (2022-08-12)
==================

Bugfixes
--------

- Make sure we don't lose errors thrown when checking usage limits. ([\#823](https://github.com/matrix-org/matrix-appservice-discord/issues/823))
- Fix Docker instances not starting due to being unable to load a dynamic library in the latest unstable image. ([\#828](https://github.com/matrix-org/matrix-appservice-discord/issues/828))
- Remove matrix.to hyperlinks when relaying non-Discord user mentions to Discord.
Fix mentioning Matrix users in Discord. ([\#829](https://github.com/matrix-org/matrix-appservice-discord/issues/829))


Deprecations and Removals
-------------------------

- Minimum required Node.js version is now 16. ([\#825](https://github.com/matrix-org/matrix-appservice-discord/issues/825))


Internal Changes
----------------

- Remove unused variables. ([\#657](https://github.com/matrix-org/matrix-appservice-discord/issues/657))
- Add workflow for building docker images, and push new docker images to ghcr.io. ([\#826](https://github.com/matrix-org/matrix-appservice-discord/issues/826))
- Remove `git config` workaround to pull a dependency from github.com. ([\#830](https://github.com/matrix-org/matrix-appservice-discord/issues/830))


2.0.0 (2022-08-05)
==================

Expand Down
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
FROM node:16-slim AS BUILD
FROM node:18-slim AS BUILD
COPY . /tmp/src
# install some dependencies needed for the build process
RUN apt update && apt install -y build-essential make gcc g++ python3 ca-certificates libc-dev wget git

# Workaround for https://github.com/matrix-org/matrix-appservice-discord/issues/803
RUN git config --global url.https://github.com/.insteadOf git://github.com/

RUN cd /tmp/src \
&& yarn

FROM node:16-slim
FROM node:18-slim
ENV NODE_ENV=production
COPY --from=BUILD /tmp/src/build /build
COPY --from=BUILD /tmp/src/config /config
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Please also be aware that this is an unoffical project worked on in our spare ti
The bridge has been tested against the [Synapse](https://github.com/matrix-org/synapse) homeserver, although any homeserver
that implements the [AS API](https://matrix.org/docs/spec/application_service/r0.1.0.html) should work with this bridge.

The bridge supports any version of Node.js between v14.X - v18.X. View the [releases](https://nodejs.org/en/about/releases/) for more details.
The bridge supports any version of Node.js between v18.X - v20.X. View the [releases](https://nodejs.org/en/about/releases/) for more details.

The bridge uses Yarn for dependency management and package scripts.
For the time being, **only Yarn Classic / v1 is supported.** To install it, follow [these instructions](https://classic.yarnpkg.com/en/docs/install).
Expand All @@ -49,7 +49,7 @@ by running ``yarn set version classic`` in the directory where you cloned this r
homeserverUrl: "https://example.com"
```
* Run ``node build/src/discordas.js -r -u "http://localhost:9005" -c config.yaml``
* Run ``yarn start -r -u "http://localhost:9005"``
* Modify your HSs appservices config so that it includes the generated file.
* e.g. On synapse, adding to ``app_service_config_files`` array in ``homeserver.yaml``
Expand Down
1 change: 0 additions & 1 deletion changelog.d/823.bugfix

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/825.removal

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/826.misc

This file was deleted.

1 change: 0 additions & 1 deletion changelog.d/828.bugfix

This file was deleted.

2 changes: 0 additions & 2 deletions changelog.d/829.bugfix

This file was deleted.

6 changes: 4 additions & 2 deletions config/config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ bridge:
disableJoinLeaveNotifications: false
# Disable Invite echos from matrix
disableInviteNotifications: false
# Disable Room Topic echos from matrix
disableRoomTopicNotifications: false
# Auto-determine the language of code blocks (this can be CPU-intensive)
determineCodeLanguage: false
# MXID of an admin user that will be PMd if the bridge experiences problems. Optional
Expand All @@ -56,13 +58,13 @@ logging:
lineDateFormat: "MMM-D HH:mm:ss.SSS" # This is in moment.js format
files:
- file: "debug.log"
disable:
disabled:
- "PresenceHandler" # Will not capture presence logging
- file: "warn.log" # Will capture warnings
level: "warn"
- file: "botlogs.log" # Will capture logs from DiscordBot
level: "info"
enable:
enabled:
- "DiscordBot"
database:
# You may either use SQLite or Postgresql for the bridge database, which contains
Expand Down
2 changes: 2 additions & 0 deletions config/config.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ properties:
type: "boolean"
disableInviteNotifications:
type: "boolean"
disableRoomTopicNotifications:
type: "boolean"
userActivity:
type: "object"
required: ["minUserActiveDays", "inactiveAfterDays"]
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "matrix-appservice-discord",
"version": "2.0.0",
"version": "4.0.0",
"description": "A bridge between Matrix and Discord",
"main": "discordas.js",
"engines": {
"npm": "please-use-yarn",
"node": ">=16 <=18"
"node": ">=18 <=20"
},
"scripts": {
"test": "mocha -r ts-node/register test/config.ts test/test_*.ts test/**/test_*.ts",
"lint": "eslint -c .eslintrc --max-warnings 200 src/**/*.ts test/**/*.ts",
"coverage": "tsc && nyc mocha build/test/config.js build/test",
"build": "tsc",
"postinstall": "yarn build",
"start": "yarn build && node ./build/src/discordas.js -c config.yaml",
"debug": "yarn build && node --inspect ./build/src/discordas.js -c config.yaml",
"start": "node ./build/src/discordas.js",
"debug": "node --inspect ./build/src/discordas.js",
"addbot": "node ./build/tools/addbot.js",
"adminme": "node ./build/tools/adminme.js",
"usertool": "node ./build/tools/userClientTools.js",
Expand All @@ -40,18 +40,17 @@
},
"homepage": "https://github.com/Half-Shot/matrix-appservice-discord#readme",
"dependencies": {
"@mx-puppet/matrix-discord-parser": "0.1.10",
"better-discord.js": "git+https://github.com/Sorunome/better-discord.js.git#b5a28499899fe2d9e6aa1aa3b3c5d693ae672117",
"better-sqlite3": "^7.1.0",
"@mx-puppet/better-discord.js": "^12.5.1",
"@mx-puppet/matrix-discord-parser": "^0.1.10",
"better-sqlite3": "^8.6.0",
"command-line-args": "^5.1.1",
"command-line-usage": "^6.1.0",
"escape-html": "^1.0.3",
"escape-string-regexp": "^4.0.0",
"js-yaml": "^3.14.0",
"marked": "^1.2.2",
"matrix-appservice-bridge": "^5.0.0",
"matrix-appservice-bridge": "^9.0.1",
"mime": "^2.4.6",
"node-html-parser": "^1.2.19",
"p-queue": "^6.4.0",
"pg-promise": "^10.5.6",
"prom-client": "^12.0.0",
Expand Down
18 changes: 10 additions & 8 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import * as Discord from "@mx-puppet/better-discord.js";
import { IDiscordMessageParserResult } from "@mx-puppet/matrix-discord-parser";
import { DiscordBridgeConfig } from "./config";
import { DiscordClientFactory } from "./clientfactory";
import { DiscordStore } from "./store";
import { DbEmoji } from "./db/dbdataemoji";
import { DbEvent } from "./db/dbdataevent";
import { DiscordMessageProcessor } from "./discordmessageprocessor";
import { IDiscordMessageParserResult } from "@mx-puppet/matrix-discord-parser";
import { MatrixEventProcessor, MatrixEventProcessorOpts, IMatrixEventProcessorResult } from "./matrixeventprocessor";
import { PresenceHandler } from "./presencehandler";
import { Provisioner } from "./provisioner";
import { UserSyncroniser } from "./usersyncroniser";
import { ChannelSyncroniser } from "./channelsyncroniser";
import { MatrixRoomHandler } from "./matrixroomhandler";
import { Log } from "./log";
import * as Discord from "better-discord.js";
import * as mime from "mime";
import { IMatrixEvent, IMatrixMediaInfo, IMatrixMessage } from "./matrixtypes";
import { Appservice, Intent, MatrixClient } from "matrix-bot-sdk";
Expand Down Expand Up @@ -94,7 +94,6 @@ class DiscordBridgeBlocker extends BridgeBlocker {
export class DiscordBot {
private clientFactory: DiscordClientFactory;
private _bot: Discord.Client|undefined;
private presenceInterval: number;
private sentMessages: string[];
private lastEventIds: { [channelId: string]: string };
private discordMsgProcessor: DiscordMessageProcessor;
Expand Down Expand Up @@ -344,7 +343,7 @@ export class DiscordBot {
client.on("userUpdate", async (_, user) => {
try {
if (!(user instanceof Discord.User)) {
log.warn(`Ignoring update for ${user.username}. User was partial.`);
log.warn(`Ignoring update for ${(<any>user).username}. User was partial.`);
return;
}
await this.userSync.OnUpdateUser(user);
Expand All @@ -353,7 +352,7 @@ export class DiscordBot {
client.on("guildMemberAdd", async (member) => {
try {
if (!(member instanceof Discord.GuildMember)) {
log.warn(`Ignoring update for ${member.guild.id} ${member.id}. User was partial.`);
log.warn(`Ignoring update for ${(<any>member).guild?.id} ${(<any>member).id}. User was partial.`);
return;
}
await this.userSync.OnAddGuildMember(member);
Expand All @@ -371,7 +370,7 @@ export class DiscordBot {
client.on("guildMemberUpdate", async (_, member) => {
try {
if (!(member instanceof Discord.GuildMember)) {
log.warn(`Ignoring update for ${member.guild.id} ${member.id}. User was partial.`);
log.warn(`Ignoring update for ${(<any>member).guild.id} ${(<any>member).id}. User was partial.`);
return;
}
await this.userSync.OnUpdateGuildMember(member);
Expand Down Expand Up @@ -1028,7 +1027,7 @@ export class DiscordBot {
}

// Update presence because sometimes discord misses people.
await this.userSync.OnUpdateUser(msg.author, Boolean(msg.webhookID));
await this.userSync.OnUpdateUser(msg.author, Boolean(msg.webhookID), msg);
let rooms: string[];
try {
rooms = await this.channelSync.GetRoomIdsFromChannel(msg.channel);
Expand Down Expand Up @@ -1234,7 +1233,10 @@ export class DiscordBot {

private async onUserActivityChanged(state: UserActivityState) {
for (const userId of state.changed) {
await this.store.storeUserActivity(userId, state.dataSet.users[userId]);
const activity = state.dataSet.get(userId);
if (activity) {
await this.store.storeUserActivity(userId, activity);
}
}
log.verbose(`Checking bridge limits (${state.activeUsers} active users)`);
this.bridgeBlocker?.checkLimits(state.activeUsers).catch(err => {
Expand Down
2 changes: 1 addition & 1 deletion src/channelsyncroniser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import * as Discord from "better-discord.js";
import * as Discord from "@mx-puppet/better-discord.js";
import { DiscordBot } from "./bot";
import { Util } from "./util";
import { DiscordBridgeConfig, DiscordBridgeConfigChannelDeleteOptions } from "./config";
Expand Down
2 changes: 1 addition & 1 deletion src/clientfactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { Client as DiscordClient, Intents, TextChannel } from "@mx-puppet/better-discord.js";
import { DiscordBridgeConfigAuth } from "./config";
import { DiscordStore } from "./store";
import { Client as DiscordClient, Intents, TextChannel } from "better-discord.js";
import { Log } from "./log";
import { MetricPeg } from "./metrics";

Expand Down
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class DiscordBridgeConfig {
}
}

class DiscordBridgeConfigBridge {
export class DiscordBridgeConfigBridge {
public domain: string;
public homeserverUrl: string;
public port: number;
Expand All @@ -97,6 +97,7 @@ class DiscordBridgeConfigBridge {
public disableHereMention: boolean = false;
public disableJoinLeaveNotifications: boolean = false;
public disableInviteNotifications: boolean = false;
public disableRoomTopicNotifications: boolean = false;
public determineCodeLanguage: boolean = false;
public activityTracker: UserActivityTrackerConfig = UserActivityTrackerConfig.DEFAULT;
public userLimit: number|null = null;
Expand Down
4 changes: 1 addition & 3 deletions src/db/roomstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const log = new Log("DbRoomStore");

/**
* A RoomStore compatible with
* https://github.com/matrix-org/matrix-appservice-bridge/blob/master/lib/components/room-bridge-store.js
* https://github.com/matrix-org/matrix-appservice-bridge/blob/master/src/components/room-bridge-store.ts
* that accesses the database instead.
*/

Expand Down Expand Up @@ -122,8 +122,6 @@ export class DbRoomStore {
}

public async upsertEntry(entry: IRoomStoreEntry) {
const promises: Promise<void>[] = [];

const row = (await this.db.Get("SELECT * FROM room_entries WHERE id = $id", {id: entry.id})) || {};

if (!row.id) {
Expand Down
1 change: 0 additions & 1 deletion src/db/schema/v8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.

import {IDbSchema} from "./dbschema";
import {DiscordStore} from "../../store";
import { Log } from "../../log";

export class Schema implements IDbSchema {
public description = "create room store tables";
Expand Down
Loading

0 comments on commit 5cfc8e2

Please sign in to comment.