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

Discord-side moderation of matrix users #210

Merged
merged 16 commits into from Sep 23, 2018

Conversation

Projects
None yet
2 participants
@Sorunome
Copy link
Collaborator

commented Jul 29, 2018

This PR allows admins of a discord guild to kick, ban and unban members on the matrix side.

!matrix help output:

Available Messages:
 - kick <name>: Kicks a user on the matrix side
 - ban <name>: Bans a user on the matrix side
 - unban <name>: Unbans a user on the matrix side

The name must be the display name or the mxid of the user to perform the action on.

Sorunome added some commits Jul 29, 2018

@Sorunome Sorunome added the feature label Jul 29, 2018

Sorunome added some commits Jul 29, 2018

@Sorunome

This comment has been minimized.

Copy link
Collaborator Author

commented Jul 29, 2018

tslint is at it again, saying that Bluebird.all() wouldn't be a promise function so we can't await it......any suggestions, @Half-Shot ?

@Half-Shot

This comment has been minimized.

Copy link
Owner

commented Jul 29, 2018

I just stick an ignore on it. Though Promise.all is a thing it will accept.

Sorunome added some commits Jul 30, 2018

@@ -386,6 +386,139 @@ export class MatrixRoomHandler {
return Promise.reject({err: "Unsupported", code: HTTP_UNSUPPORTED});
}

public async HandleDiscordCommand(msg: Discord.Message) {
if (!msg.member.hasPermission("ADMINISTRATOR")) {

This comment has been minimized.

Copy link
@Half-Shot

Half-Shot Jul 30, 2018

Owner

This requirement seems a bit extreme, I'd check permissions per command since we might have commands that regulars might want.

}
}

let replyMessage = "Error, unkown command. Try `!matrix help` to see all commands";

This comment has been minimized.

Copy link
@Half-Shot
let replyMessage = "Error, unkown command. Try `!matrix help` to see all commands";

const intent = this.bridge.getIntent();
const doAction = async (funcKey, action) => {

This comment has been minimized.

Copy link
@Half-Shot

Half-Shot Jul 30, 2018

Owner

I wonder if this would be better as a private function rather than embedded in a function, would make for prettier typescript

This comment has been minimized.

Copy link
@Sorunome

Sorunome Jul 30, 2018

Author Collaborator

I don't think it'd be too good to make that a private, as it is pretty specifically tailored.While it takes use of intent and replyMessage could be a return value, i have the feeling that for it being a private it should have some more abstract output maybe, not something such specific....i'm not sure

@Half-Shot
Copy link
Owner

left a comment

Good stuff, but a few things that need addressing

const matrixUsers = {};
let matches = 0;
/* tslint:disable:await-promise */
await Bluebird.all(channels.map((c) => {

This comment has been minimized.

Copy link
@Half-Shot

Half-Shot Jul 30, 2018

Owner

You can just use Promise.all here?

msg.channel.send(replyMessage);
}

private async GetMxidFromName(name: string, channels: string[]) {

This comment has been minimized.

Copy link
@Half-Shot

Half-Shot Jul 30, 2018

Owner

This definitely feels like it belongs in Util

msg.channel.send(replyMessage);
}

private async GetMxidFromName(name: string, channels: string[]) {

This comment has been minimized.

Copy link
@Half-Shot

Half-Shot Jul 30, 2018

Owner

Is this a list of discord channels or roomids, the variable name isn't helpful.

const matrixUsers = {};
let matches = 0;
/* tslint:disable:await-promise */
await Bluebird.all(channels.map((c) => {

This comment has been minimized.

Copy link
@Half-Shot

Half-Shot Jul 30, 2018

Owner

I have a passionate hate for variables that don't describe what they are. c should be at least chan or channel. I suspect it's a roomId though.

// but we also want to be able to search through banned members
// so we gotta roll our own thing
return client._http.authedRequestWithPrefix(
undefined, "GET", "/rooms/" + encodeURIComponent(c) + "/members",

This comment has been minimized.

Copy link
@Half-Shot

Half-Shot Jul 30, 2018

Owner

All these undefined's make me sad, but I don't know what we can do about it :/

We should at least have each of these on a newline though

undefined, "GET", "/rooms/" + encodeURIComponent(c) + "/members",
undefined, undefined, "/_matrix/client/r0",
).then((res) => {
res.chunk.forEach((member) => {

This comment has been minimized.

Copy link
@Half-Shot

Half-Shot Jul 30, 2018

Owner

What happens if this is chunked and the user is not found in the first chunk?

This comment has been minimized.

Copy link
@Sorunome

Sorunome Jul 30, 2018

Author Collaborator

What do you mean? There can be multiple chunks / we need multiple /members calls under some circumstances?

return this.discord.GetRoomIdsFromChannel(c).then((chans) => {
allChannels = allChannels.concat(chans);
}).catch((e) => {
// pass, non-text-channel

This comment has been minimized.

Copy link
@Half-Shot

Half-Shot Jul 30, 2018

Owner

Do we want to at least log this?

try {
const userMxid = await this.GetMxidFromName(name, channels);
let allChannels = [];
/* tslint:disable:await-promise */

This comment has been minimized.

Sorunome added some commits Jul 30, 2018

@Half-Shot

This comment has been minimized.

Copy link
Owner

commented Jul 30, 2018

Wow this is looking much slicker

Sorunome added some commits Jul 30, 2018

@Half-Shot

This comment has been minimized.

Copy link
Owner

commented Jul 31, 2018

Just need tests for bans and unbans?

],
};
const intent = CreateMockIntent(mockRooms);
expect(Util.GetMxidFromName(intent, "badboy", ["abc"])).to.eventually.be.rejected;

This comment has been minimized.

Copy link
@Half-Shot

Half-Shot Sep 10, 2018

Owner

I think .eventually. calls need to return

This comment has been minimized.

Copy link
@Half-Shot

Half-Shot Sep 14, 2018

Owner

Actually, I suspect I'm wrong Nope, this needs doing and then you are free to go :)

// we would use this.bridge.getBot().getJoinedMembers()
// but we also want to be able to search through banned members
// so we gotta roll our own thing
return client._http.authedRequestWithPrefix(

This comment has been minimized.

Copy link
@Half-Shot

Half-Shot Sep 10, 2018

Owner

Eek, this looks expensive :(

This comment has been minimized.

Copy link
@Sorunome

Sorunome Sep 14, 2018

Author Collaborator

It doesn't get called frequently, so i thought it wasn't too big a concern? Any suggestion ideas, though? (we did discuss exactly this in the matrix room once o.o)

@Half-Shot

This comment has been minimized.

Copy link
Owner

commented Sep 14, 2018

I might have said "sod it, let's see how it goes" with TravisR weeping in the corner.

@Sorunome

This comment has been minimized.

Copy link
Collaborator Author

commented Sep 21, 2018

I might have said "sod it, let's see how it goes" with TravisR weeping in the corner.

Yep, iirc it was that way

@Half-Shot Half-Shot merged commit 68d095e into develop Sep 23, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@Sorunome Sorunome deleted the soru/moderating branch Nov 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.