Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Sep 20, 2021
2 parents eb6d837 + f8f5dbb commit cd0796a
Show file tree
Hide file tree
Showing 14 changed files with 344 additions and 33 deletions.
42 changes: 41 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
0.30.0 (2021-08-18)
0.31.0 (2021-09-20)
========================

Bugfixes
--------

- Fixed an issue where bridges using the NEdB datastore would still erroneously require IRC usernames to be unique. ([\#1471](https://github.com/matrix-org/matrix-appservice-irc/issues/1471))
- Fixed a bug where `!help` in an admin room would not show admin commands. ([\#1478](https://github.com/matrix-org/matrix-appservice-irc/issues/1478))
- Fix an edgecase where an nickname was not always set right for matrix users in PMs ([\#1479](https://github.com/matrix-org/matrix-appservice-irc/issues/1479))


0.31.0-rc1 (2021-08-23)
========================

Features
--------

- Render Matrix message edits as sed-like diff statements, falling back to asterisk formatted messages ([\#1465](https://github.com/matrix-org/matrix-appservice-irc/issues/1465))


Bugfixes
--------

- Make sure we don't exceed the line limit when trimming long messages ([\#1459](https://github.com/matrix-org/matrix-appservice-irc/issues/1459))
- Make sure Matrix notice messages are also pastebinned when they exceed the line limit for IRC. ([\#1461](https://github.com/matrix-org/matrix-appservice-irc/issues/1461))
- Fallback to sending an invite as a bot if the regular invite fails ([\#1467](https://github.com/matrix-org/matrix-appservice-irc/issues/1467))


Improved Documentation
----------------------

- Replace HOWTO.md with a link to our hosted documentation, and generally improve documentation wording. ([\#1458](https://github.com/matrix-org/matrix-appservice-irc/issues/1458))


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

- Remove extra `encodingFallback` from sample config. ([\#1468](https://github.com/matrix-org/matrix-appservice-irc/issues/1468))


0.30.0 (2021-08-18)
====================

No significant changes.
Expand Down
1 change: 0 additions & 1 deletion changelog.d/1458.doc

This file was deleted.

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

This file was deleted.

2 changes: 1 addition & 1 deletion config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ ircService:
# Encoding fallback - which text encoding to try if text is not UTF-8. Default: not set.
# List of supported encodings: https://www.npmjs.com/package/iconv#supported-encodings
# encodingFallback: "ISO-8859-15"
encodingFallback: "ISO-8859-15"

# Configuration for logging. Optional. Default: console debug level logging
# only.
# This key CANNOT be hot-reloaded
Expand Down
31 changes: 29 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matrix-appservice-irc",
"version": "0.30.0",
"version": "0.31.0",
"description": "An IRC Bridge for Matrix",
"main": "app.js",
"bin": "./bin/matrix-appservice-irc",
Expand Down Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"@sentry/node": "^5.27.1",
"bluebird": "^3.7.2",
"diff": "^5.0.0",
"escape-string-regexp": "^4.0.0",
"extend": "^3.0.2",
"he": "^1.2.0",
Expand All @@ -50,6 +51,7 @@
},
"devDependencies": {
"@types/bluebird": "^3.5.32",
"@types/diff": "^5.0.1",
"@types/express": "^4.17.7",
"@types/extend": "^3.0.1",
"@types/he": "^1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion spec/integ/matrix-to-irc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ describe("Matrix-to-IRC message bridging", function() {
expect(client.nick).toEqual(testUser.nick);
expect(client.addr).toEqual(roomMapping.server);
expect(channel).toEqual(roomMapping.channel);
expect(text).toEqual(`<${repliesUser.nick}> "This" <- Reply Text`);
expect(text).toEqual(`<${repliesUser.nick}> "This..." <- Reply Text`);
}
);
const formatted_body = constructHTMLReply(
Expand Down
56 changes: 56 additions & 0 deletions spec/unit/MessageDiff.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"use strict";
const { messageDiff } = require("../../lib/util/MessageDiff.js");

describe('messageDiff', function() {
[
[
'should not generate a diff if the message is short enough',
'hello everyone', 'hello world',
undefined,
],
[
'should generate a diff for short, multiline messages',
'one\nfoo\nthree', 'one\ntwo\nthree',
's/foo/two/',
],
[
'should generate sed-like substitution when a short part of the message changes',
"Sounds good – I'll be there before 9", "Sounds good – I'll be there after 9",
's/before/after/'
],
[
'should only show changes from the line that has changed in multiline messages',
'in a marmalade forest\nbetween the make-believe trees\nI forgot the third verse, sorry',
'in a marmalade forest\nbetween the make-believe trees\nin a cottage-cheese cottage...',
's/I forgot the third verse, sorry/in a cottage-cheese cottage.../',
],
[
'should not use diffs with newlines in them',
'a\nb\nc', 'bla\nbleh\nc',
's/a/bla/, s/b/bleh/',
],
[
'should only show small portion of the message when a new word is added',
'this is a message where i a word', 'this is a message where i missed a word',
'* where i missed a word',
],
[
'should only show small portion of the message when a new word is added at the beginning',
'get lunch now, be back a bit later', 'gonna get lunch now, be back a bit later',
'* gonna get lunch',
],
[
'should only show small portion of the message when a new word is added at the beginning',
"I'm gonna get lunch now", "I'm gonna get lunch now, bbl",
'* lunch now, bbl',
],
[
'should show word removals as s/foo//',
'I gotta go clean up my filthy room', 'I gotta go clean up my room',
's/filthy//'
],
].forEach(c => it(c[0], () => {
const result = messageDiff(c[1], c[2]);
expect(result).toBe(c[3]);
}));
});
33 changes: 23 additions & 10 deletions src/bridge/AdminRoomHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ import { IdentGenerator } from "../irc/IdentGenerator";

const log = logging("AdminRoomHandler");

enum CommandPermission {
User,
Admin,
}

// This is just a length to avoid silly long usernames
const SANE_USERNAME_LENGTH = 64;

interface Command {
example: string;
summary: string;
requiresPermission?: string;
requiresPermission?: CommandPermission;
}

interface Heading {
Expand Down Expand Up @@ -104,7 +109,7 @@ const COMMANDS: {[command: string]: Command|Heading} = {
'!plumb': {
example: `!plumb !room:example.com irc.example.net #foobar`,
summary: "Plumb an IRC channel into a Matrix room.",
requiresPermission: 'admin'
requiresPermission: CommandPermission.Admin,
},
'!unlink': {
example: "!unlink !room:example.com irc.example.net #foobar",
Expand Down Expand Up @@ -151,6 +156,11 @@ export class AdminRoomHandler {
}

private async handleCommand(cmd: string, args: string[], req: BridgeRequest, event: MatrixSimpleMessage) {
const userPermission = this.getUserPermission(event.sender);
const requiredPermission = (COMMANDS[cmd] as Command|undefined)?.requiresPermission;
if (requiredPermission && requiredPermission > userPermission) {
return new MatrixAction("notice", "You do not have permission to use this command");
}
switch (cmd) {
case "!join":
return await this.handleJoin(req, args, event.sender);
Expand Down Expand Up @@ -191,10 +201,6 @@ export class AdminRoomHandler {
}

private async handlePlumb(args: string[], sender: string) {
const userPermission = this.getUserPermission(sender);
if (userPermission !== 'admin') {
return new MatrixAction("notice", "You must be an admin to use this command");
}
const [matrixRoomId, serverDomain, ircChannel] = args;
const server = serverDomain && this.ircBridge.getServer(serverDomain);
if (!server) {
Expand Down Expand Up @@ -249,7 +255,7 @@ export class AdminRoomHandler {
user_id: sender,
},
),
userPermission === "admin"
userPermission === CommandPermission.Admin
);
}
catch (ex) {
Expand Down Expand Up @@ -714,7 +720,8 @@ export class AdminRoomHandler {
return new MatrixAction("notice", `BridgeVersion: ${getBridgeVersion()}`);
}

private showHelp(userPermission: string|undefined): MatrixAction {
private showHelp(sender: string): MatrixAction {
const userPermission = this.getUserPermission(sender);
let body = "This is an IRC admin room for controlling your IRC connection and sending " +
"commands directly to IRC.<br/>" +
"See the <a href=\"https://matrix-org.github.io/matrix-appservice-irc/latest/usage.html\">" +
Expand Down Expand Up @@ -753,12 +760,18 @@ export class AdminRoomHandler {
return this.ircBridge.getBridgedClientsForUserId(userId);
}

private getUserPermission(userId: string): string|undefined {
private getUserPermission(userId: string): CommandPermission {
const userDomain = userId.split(':')[1];

return this.ircBridge.config.ircService.permissions &&
const permissionString = this.ircBridge.config.ircService.permissions &&
(this.ircBridge.config.ircService.permissions[userId] || // This takes priority
this.ircBridge.config.ircService.permissions[userDomain] || // Then the domain
this.ircBridge.config.ircService.permissions['*']); // Finally wildcard.
switch (permissionString) {
case "admin":
return CommandPermission.Admin;
default:
return CommandPermission.User;
}
}
}
13 changes: 12 additions & 1 deletion src/bridge/IrcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,18 @@ export class IrcHandler {
virtualMatrixUser.getId()
).invite(
room.getId(), invitee
);
).catch(err => {
req.log.warn(
`Failed to invite ${invitee} as the inviter user (reason: ${err}),
inviting as a bot as fallback`
);
return this.ircBridge.getAppServiceBridge().getIntent().sendStateEvent(
room.getId(), "m.room.member", invitee, {
membership: "invite",
reason: `Invited by ${virtualMatrixUser.getDisplayName()} (${virtualMatrixUser.getId()})`,
}
);
});
});
await Promise.all(invitePromises);
return undefined;
Expand Down
Loading

0 comments on commit cd0796a

Please sign in to comment.