Skip to content

Commit

Permalink
Merge branch 'develop' into update-readme-badges
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFerr authored Sep 15, 2023
2 parents 15a6648 + a546c1b commit 4e93322
Show file tree
Hide file tree
Showing 37 changed files with 847 additions and 688 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
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 16
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 }}
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +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

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 @@ -26,7 +26,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 @@ -48,7 +48,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: 1 addition & 0 deletions changelog.d/888.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prefer server-level display names when available.
1 change: 1 addition & 0 deletions changelog.d/897.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update matrix-appservice-bridge to use a non-deprecated method of authenticating to a homeserver. Fixes #896.
1 change: 1 addition & 0 deletions changelog.d/897.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Node.JS 16 is now unsupported, please upgrade to Node.JS 18 or later. Node.JS 18 is now used for Docker.
1 change: 1 addition & 0 deletions changelog.d/898.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update the package registry for better-discord.js, and use its latest release.
1 change: 1 addition & 0 deletions changelog.d/900.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
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.
1 change: 1 addition & 0 deletions changelog.d/901.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update the GitHub action used for checking pull requests for sign-off status.
1 change: 1 addition & 0 deletions changelog.d/902.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Let file logs correctly ignore modules matching "logging.files[*].disabled" in the configuration file.
4 changes: 2 additions & 2 deletions config/config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,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
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"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,16 +40,16 @@
},
"homepage": "https://github.com/Half-Shot/matrix-appservice-discord#readme",
"dependencies": {
"@mx-puppet/matrix-discord-parser": "0.1.10",
"better-discord.js": "github:matrix-org/better-discord.js#5024781db755259e88abe915630b7d5b3ba5f48f",
"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",
"p-queue": "^6.4.0",
"pg-promise": "^10.5.6",
Expand Down
11 changes: 7 additions & 4 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 @@ -1027,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 @@ -1233,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
2 changes: 1 addition & 1 deletion src/discordcommandhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import * as Discord from "@mx-puppet/better-discord.js";
import { DiscordBot } from "./bot";
import * as Discord from "better-discord.js";
import { Util, ICommandActions, ICommandParameters, CommandPermissonCheck } from "./util";
import { Log } from "./log";
import { Appservice } from "matrix-bot-sdk";
Expand Down
2 changes: 1 addition & 1 deletion src/discordmessageprocessor.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 { Log } from "./log";
import {
Expand Down
2 changes: 1 addition & 1 deletion src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class Log {
private static setupFileTransport(config: LoggingFile): transports.FileTransportInstance {
config = Object.assign(new LoggingFile(), config);
const filterOutMods = format((info, _) => {
if (config.disabled.includes(info.module) &&
if (config.disabled.includes(info.module) ||
config.enabled.length > 0 &&
!config.enabled.includes(info.module)
) {
Expand Down
2 changes: 1 addition & 1 deletion src/matrixcommandhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import * as Discord from "@mx-puppet/better-discord.js";
import { DiscordBot } from "./bot";
import { Log } from "./log";
import { DiscordBridgeConfig } from "./config";
import { IMatrixEvent } from "./matrixtypes";
import { Provisioner } from "./provisioner";
import { Util, ICommandActions, ICommandParameters, CommandPermissonCheck } from "./util";
import * as Discord from "better-discord.js";
import { Appservice } from "matrix-bot-sdk";
import { IRoomStoreEntry } from "./db/roomstore";
import * as markdown from "marked";
Expand Down
2 changes: 1 addition & 1 deletion src/matrixeventprocessor.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 { DiscordBridgeConfig } from "./config";
import { Util, wrapError } from "./util";
Expand Down
2 changes: 1 addition & 1 deletion src/matrixmessageprocessor.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 { IMatrixMessage } from "./matrixtypes";
import { Util } from "./util";
import { DiscordBot } from "./bot";
Expand Down
2 changes: 1 addition & 1 deletion src/matrixroomhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
import { DiscordBot, IThirdPartyLookup } from "./bot";
import { DiscordBridgeConfig } from "./config";

import * as Discord from "better-discord.js";
import * as Discord from "@mx-puppet/better-discord.js";
import { Util } from "./util";
import { Log } from "./log";
const log = new Log("MatrixRoomHandler");
Expand Down
2 changes: 1 addition & 1 deletion src/presencehandler.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 { User, Presence } from "better-discord.js";
import { User, Presence } from "@mx-puppet/better-discord.js";
import { DiscordBot } from "./bot";
import { Log } from "./log";
import { MetricPeg } from "./metrics";
Expand Down
2 changes: 1 addition & 1 deletion src/provisioner.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 { DbRoomStore, RemoteStoreRoom, MatrixStoreRoom } from "./db/roomstore";
import { ChannelSyncroniser } from "./channelsyncroniser";
import { Log } from "./log";
Expand Down
4 changes: 2 additions & 2 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,15 @@ export class DiscordStore implements IAppserviceStorageProvider {

public async getUserActivity(): Promise<UserActivitySet> {
const rows = await this.db.All('SELECT * FROM user_activity');
const users: {[mxid: string]: any} = {};
const users = new Map<string, UserActivity>();
for (const row of rows) {
let data = row.data as any;
if (typeof data === 'string') { // sqlite has no first-class JSON
data = JSON.parse(data);
}
users[row.user_id as string] = data;
}
return { users };
return users;
}

public async storeUserActivity(userId: string, activity: UserActivity): Promise<void> {
Expand Down
10 changes: 5 additions & 5 deletions src/usersyncroniser.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 { User, GuildMember } from "better-discord.js";
import { User, GuildMember, Message } from "@mx-puppet/better-discord.js";
import { DiscordBot } from "./bot";
import { Util } from "./util";
import { DiscordBridgeConfig } from "./config";
Expand Down Expand Up @@ -96,8 +96,8 @@ export class UserSyncroniser {
* @returns {Promise<void>}
* @constructor
*/
public async OnUpdateUser(discordUser: User, isWebhook: boolean = false) {
const userState = await this.GetUserUpdateState(discordUser, isWebhook);
public async OnUpdateUser(discordUser: User, isWebhook: boolean = false, msg?: Message) {
const userState = await this.GetUserUpdateState(discordUser, isWebhook, msg);
try {
await this.ApplyStateToProfile(userState);
} catch (e) {
Expand Down Expand Up @@ -230,7 +230,7 @@ export class UserSyncroniser {
}
}

public async GetUserUpdateState(discordUser: User, isWebhook: boolean = false): Promise<IUserState> {
public async GetUserUpdateState(discordUser: User, isWebhook: boolean = false, msg?: Message): Promise<IUserState> {
log.verbose(`State update requested for ${discordUser.id}`);
let mxidExtra = "";
if (isWebhook) {
Expand All @@ -244,7 +244,7 @@ export class UserSyncroniser {
id: discordUser.id + mxidExtra,
mxUserId: `@_discord_${discordUser.id}${mxidExtra}:${this.config.bridge.domain}`,
});
const displayName = Util.ApplyPatternString(this.config.ghosts.usernamePattern, {
const displayName = msg?.member?.nickname || Util.ApplyPatternString(this.config.ghosts.usernamePattern, {
id: discordUser.id,
tag: discordUser.discriminator,
username: discordUser.username,
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { Permissions } from "@mx-puppet/better-discord.js";
import * as http from "http";
import * as https from "https";
import { Buffer } from "buffer";
import { Permissions } from "better-discord.js";
import { DiscordBridgeConfig } from "./config";
import { IMatrixEvent } from "./matrixtypes";

Expand Down
2 changes: 1 addition & 1 deletion test/mocks/channel.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 {Permissions, PermissionResolvable, TextChannel} from "@mx-puppet/better-discord.js";
import {MockMember} from "./member";
import {MockCollection} from "./collection";
import {Permissions, PermissionResolvable, TextChannel} from "better-discord.js";
import { MockGuild } from "./guild";

// we are a test file and thus need those
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/collection.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 { Collection } from "better-discord.js";
import { Collection } from "@mx-puppet/better-discord.js";

export class MockCollection<T1, T2> extends Collection<T1, T2> {
public array(): T2[] {
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import {Channel} from "@mx-puppet/better-discord.js";
import {MockCollectionManager} from "./collection";
import {MockMember} from "./member";
import {MockEmoji} from "./emoji";
import {Channel} from "better-discord.js";
import {MockRole} from "./role";

// we are a test file and thus need those
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import * as Discord from "@mx-puppet/better-discord.js";
import {MockCollectionManager} from "./collection";
import {MockUser} from "./user";
import {MockRole} from "./role";
import * as Discord from "better-discord.js";

// we are a test file and thus need those
/* tslint:disable:no-unused-expression max-file-line-count no-any */
Expand Down
Loading

0 comments on commit 4e93322

Please sign in to comment.