{"action":"created","comment":{"url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls/comments/237720664","pull_request_review_id":180090447,"id":237720664,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNzcyMDY2NA==","diff_hunk":"@@ -0,0 +1,281 @@\n+import * as Discord from \"discord.js\";\n+import { IMatrixMessage, IMatrixEvent } from \"./matrixtypes\";\n+import * as Parser from \"node-html-parser\";\n+import { Util } from \"./util\";\n+import { DiscordBot } from \"./bot\";\n+\n+const MIN_NAME_LENGTH = 2;\n+const MAX_NAME_LENGTH = 32;\n+const MATRIX_TO_LINK = \"https://matrix.to/#/\";\n+\n+export class MatrixMessageProcessorOpts {\n+    constructor(readonly disableEveryone: boolean = true, readonly disableHere: boolean = true) { }\n+}\n+\n+export class MatrixMessageProcessor {\n+    private guild: Discord.Guild;\n+    private listDepth: number = 0;\n+    private listBulletPoints: string[] = [\"●\", \"○\", \"■\", \"‣\"];\n+    constructor(public bot: DiscordBot, public opts: MatrixMessageProcessorOpts) { }\n+    public async FormatMessage(\n+        msg: IMatrixMessage,\n+        guild: Discord.Guild,\n+        profile?: IMatrixEvent | null,\n+    ): Promise<string> {\n+        this.guild = guild;\n+        this.listDepth = 0;\n+        let reply = \"\";\n+        if (msg.formatted_body) {\n+            // parser needs everything wrapped in html elements\n+            // so we wrap everything in <div> just to be sure stuff is wrapped\n+            // as <div> will be un-touched anyways\n+            const parsed = Parser.parse(`<div>${msg.formatted_body}</div>`, {\n+                lowerCaseTagName: true,\n+                pre: true,\n+            // tslint:disable-next-line no-any\n+            } as any);\n+            reply = await this.walkNode(parsed);\n+            reply = reply.replace(/\\s*$/, \"\"); // trim off whitespace at end\n+        } else {\n+            reply = this.escapeDiscord(msg.body);\n+        }\n+\n+        if (msg.msgtype === \"m.emote\") {\n+            if (profile &&\n+                profile.displayname &&\n+                profile.displayname.length >= MIN_NAME_LENGTH &&\n+                profile.displayname.length <= MAX_NAME_LENGTH) {\n+                reply = `_${profile.displayname} ${reply}_`;\n+            } else {\n+                reply = `_${reply}_`;\n+            }\n+        }\n+        return reply;\n+    }\n+\n+    private escapeDiscord(msg: string): string {\n+        if (this.opts.disableEveryone) {\n+            msg = msg.replace(/@everyone/g, \"@ everyone\");\n+        }\n+        if (this.opts.disableHere) {\n+            msg = msg.replace(/@here/g, \"@ here\");\n+        }\n+        msg = msg.replace(/@room/g, \"@here\");","path":"src/matrixmessageprocessor.ts","position":63,"original_position":63,"commit_id":"8a0d3515a8e791a9aa356bcdae9809728c9c8256","original_commit_id":"8a0d3515a8e791a9aa356bcdae9809728c9c8256","user":{"login":"Half-Shot","id":2072976,"node_id":"MDQ6VXNlcjIwNzI5NzY=","avatar_url":"https://avatars1.githubusercontent.com/u/2072976?v=4","gravatar_id":"","url":"https://api.github.com/users/Half-Shot","html_url":"https://github.com/Half-Shot","followers_url":"https://api.github.com/users/Half-Shot/followers","following_url":"https://api.github.com/users/Half-Shot/following{/other_user}","gists_url":"https://api.github.com/users/Half-Shot/gists{/gist_id}","starred_url":"https://api.github.com/users/Half-Shot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Half-Shot/subscriptions","organizations_url":"https://api.github.com/users/Half-Shot/orgs","repos_url":"https://api.github.com/users/Half-Shot/repos","events_url":"https://api.github.com/users/Half-Shot/events{/privacy}","received_events_url":"https://api.github.com/users/Half-Shot/received_events","type":"User","site_admin":false},"body":"Question: This still potentially allows anyone to spam here on the discord side?","created_at":"2018-11-30T01:35:15Z","updated_at":"2018-11-30T01:39:31Z","html_url":"https://github.com/Half-Shot/matrix-appservice-discord/pull/316#discussion_r237720664","pull_request_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls/316","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls/comments/237720664"},"html":{"href":"https://github.com/Half-Shot/matrix-appservice-discord/pull/316#discussion_r237720664"},"pull_request":{"href":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls/316"}}},"pull_request":{"url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls/316","id":231793487,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMxNzkzNDg3","html_url":"https://github.com/Half-Shot/matrix-appservice-discord/pull/316","diff_url":"https://github.com/Half-Shot/matrix-appservice-discord/pull/316.diff","patch_url":"https://github.com/Half-Shot/matrix-appservice-discord/pull/316.patch","issue_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/issues/316","number":316,"state":"open","locked":false,"title":"HTML to markdown parsing for M->D","user":{"login":"Sorunome","id":2433620,"node_id":"MDQ6VXNlcjI0MzM2MjA=","avatar_url":"https://avatars3.githubusercontent.com/u/2433620?v=4","gravatar_id":"","url":"https://api.github.com/users/Sorunome","html_url":"https://github.com/Sorunome","followers_url":"https://api.github.com/users/Sorunome/followers","following_url":"https://api.github.com/users/Sorunome/following{/other_user}","gists_url":"https://api.github.com/users/Sorunome/gists{/gist_id}","starred_url":"https://api.github.com/users/Sorunome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sorunome/subscriptions","organizations_url":"https://api.github.com/users/Sorunome/orgs","repos_url":"https://api.github.com/users/Sorunome/repos","events_url":"https://api.github.com/users/Sorunome/events{/privacy}","received_events_url":"https://api.github.com/users/Sorunome/received_events","type":"User","site_admin":false},"body":"this introduces an HTML to markdown parser for sending messages M->D\r\n\r\nin the background it uses `node-html-parser` ( https://www.npmjs.com/package/node-html-parser )\r\n\r\nThis tackles #301, #201, #163 and #82, and should maintenance and bugfixes in the future easier.","created_at":"2018-11-18T15:01:54Z","updated_at":"2018-11-30T01:39:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"64c5dd9cc840097b7be6d66a07286b3fc37fc631","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls/316/commits","review_comments_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls/316/comments","review_comment_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/issues/316/comments","statuses_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/statuses/8a0d3515a8e791a9aa356bcdae9809728c9c8256","head":{"label":"Half-Shot:soru/html-to-markdown","ref":"soru/html-to-markdown","sha":"8a0d3515a8e791a9aa356bcdae9809728c9c8256","user":{"login":"Half-Shot","id":2072976,"node_id":"MDQ6VXNlcjIwNzI5NzY=","avatar_url":"https://avatars1.githubusercontent.com/u/2072976?v=4","gravatar_id":"","url":"https://api.github.com/users/Half-Shot","html_url":"https://github.com/Half-Shot","followers_url":"https://api.github.com/users/Half-Shot/followers","following_url":"https://api.github.com/users/Half-Shot/following{/other_user}","gists_url":"https://api.github.com/users/Half-Shot/gists{/gist_id}","starred_url":"https://api.github.com/users/Half-Shot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Half-Shot/subscriptions","organizations_url":"https://api.github.com/users/Half-Shot/orgs","repos_url":"https://api.github.com/users/Half-Shot/repos","events_url":"https://api.github.com/users/Half-Shot/events{/privacy}","received_events_url":"https://api.github.com/users/Half-Shot/received_events","type":"User","site_admin":false},"repo":{"id":61456075,"node_id":"MDEwOlJlcG9zaXRvcnk2MTQ1NjA3NQ==","name":"matrix-appservice-discord","full_name":"Half-Shot/matrix-appservice-discord","private":false,"owner":{"login":"Half-Shot","id":2072976,"node_id":"MDQ6VXNlcjIwNzI5NzY=","avatar_url":"https://avatars1.githubusercontent.com/u/2072976?v=4","gravatar_id":"","url":"https://api.github.com/users/Half-Shot","html_url":"https://github.com/Half-Shot","followers_url":"https://api.github.com/users/Half-Shot/followers","following_url":"https://api.github.com/users/Half-Shot/following{/other_user}","gists_url":"https://api.github.com/users/Half-Shot/gists{/gist_id}","starred_url":"https://api.github.com/users/Half-Shot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Half-Shot/subscriptions","organizations_url":"https://api.github.com/users/Half-Shot/orgs","repos_url":"https://api.github.com/users/Half-Shot/repos","events_url":"https://api.github.com/users/Half-Shot/events{/privacy}","received_events_url":"https://api.github.com/users/Half-Shot/received_events","type":"User","site_admin":false},"html_url":"https://github.com/Half-Shot/matrix-appservice-discord","description":"A bridge between Matrix and Discord.","fork":false,"url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord","forks_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/forks","keys_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/teams","hooks_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/hooks","issue_events_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/issues/events{/number}","events_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/events","assignees_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/assignees{/user}","branches_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/branches{/branch}","tags_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/tags","blobs_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/git/refs{/sha}","trees_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/statuses/{sha}","languages_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/languages","stargazers_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/stargazers","contributors_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/contributors","subscribers_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/subscribers","subscription_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/subscription","commits_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/commits{/sha}","git_commits_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/git/commits{/sha}","comments_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/comments{/number}","issue_comment_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/issues/comments{/number}","contents_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/contents/{+path}","compare_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/merges","archive_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/downloads","issues_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/issues{/number}","pulls_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls{/number}","milestones_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/milestones{/number}","notifications_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/labels{/name}","releases_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/releases{/id}","deployments_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/deployments","created_at":"2016-06-18T23:09:33Z","updated_at":"2018-11-22T01:41:02Z","pushed_at":"2018-11-28T19:23:35Z","git_url":"git://github.com/Half-Shot/matrix-appservice-discord.git","ssh_url":"git@github.com:Half-Shot/matrix-appservice-discord.git","clone_url":"https://github.com/Half-Shot/matrix-appservice-discord.git","svn_url":"https://github.com/Half-Shot/matrix-appservice-discord","homepage":"","size":3392,"stargazers_count":123,"watchers_count":123,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":27,"mirror_url":null,"archived":false,"open_issues_count":77,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":27,"open_issues":77,"watchers":123,"default_branch":"master"}},"base":{"label":"Half-Shot:develop","ref":"develop","sha":"fa7c1c85e3c62bdb3079e0261c7df8f173b83016","user":{"login":"Half-Shot","id":2072976,"node_id":"MDQ6VXNlcjIwNzI5NzY=","avatar_url":"https://avatars1.githubusercontent.com/u/2072976?v=4","gravatar_id":"","url":"https://api.github.com/users/Half-Shot","html_url":"https://github.com/Half-Shot","followers_url":"https://api.github.com/users/Half-Shot/followers","following_url":"https://api.github.com/users/Half-Shot/following{/other_user}","gists_url":"https://api.github.com/users/Half-Shot/gists{/gist_id}","starred_url":"https://api.github.com/users/Half-Shot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Half-Shot/subscriptions","organizations_url":"https://api.github.com/users/Half-Shot/orgs","repos_url":"https://api.github.com/users/Half-Shot/repos","events_url":"https://api.github.com/users/Half-Shot/events{/privacy}","received_events_url":"https://api.github.com/users/Half-Shot/received_events","type":"User","site_admin":false},"repo":{"id":61456075,"node_id":"MDEwOlJlcG9zaXRvcnk2MTQ1NjA3NQ==","name":"matrix-appservice-discord","full_name":"Half-Shot/matrix-appservice-discord","private":false,"owner":{"login":"Half-Shot","id":2072976,"node_id":"MDQ6VXNlcjIwNzI5NzY=","avatar_url":"https://avatars1.githubusercontent.com/u/2072976?v=4","gravatar_id":"","url":"https://api.github.com/users/Half-Shot","html_url":"https://github.com/Half-Shot","followers_url":"https://api.github.com/users/Half-Shot/followers","following_url":"https://api.github.com/users/Half-Shot/following{/other_user}","gists_url":"https://api.github.com/users/Half-Shot/gists{/gist_id}","starred_url":"https://api.github.com/users/Half-Shot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Half-Shot/subscriptions","organizations_url":"https://api.github.com/users/Half-Shot/orgs","repos_url":"https://api.github.com/users/Half-Shot/repos","events_url":"https://api.github.com/users/Half-Shot/events{/privacy}","received_events_url":"https://api.github.com/users/Half-Shot/received_events","type":"User","site_admin":false},"html_url":"https://github.com/Half-Shot/matrix-appservice-discord","description":"A bridge between Matrix and Discord.","fork":false,"url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord","forks_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/forks","keys_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/teams","hooks_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/hooks","issue_events_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/issues/events{/number}","events_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/events","assignees_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/assignees{/user}","branches_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/branches{/branch}","tags_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/tags","blobs_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/git/refs{/sha}","trees_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/statuses/{sha}","languages_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/languages","stargazers_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/stargazers","contributors_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/contributors","subscribers_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/subscribers","subscription_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/subscription","commits_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/commits{/sha}","git_commits_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/git/commits{/sha}","comments_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/comments{/number}","issue_comment_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/issues/comments{/number}","contents_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/contents/{+path}","compare_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/merges","archive_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/downloads","issues_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/issues{/number}","pulls_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls{/number}","milestones_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/milestones{/number}","notifications_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/labels{/name}","releases_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/releases{/id}","deployments_url":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/deployments","created_at":"2016-06-18T23:09:33Z","updated_at":"2018-11-22T01:41:02Z","pushed_at":"2018-11-28T19:23:35Z","git_url":"git://github.com/Half-Shot/matrix-appservice-discord.git","ssh_url":"git@github.com:Half-Shot/matrix-appservice-discord.git","clone_url":"https://github.com/Half-Shot/matrix-appservice-discord.git","svn_url":"https://github.com/Half-Shot/matrix-appservice-discord","homepage":"","size":3392,"stargazers_count":123,"watchers_count":123,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":27,"mirror_url":null,"archived":false,"open_issues_count":77,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":27,"open_issues":77,"watchers":123,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls/316"},"html":{"href":"https://github.com/Half-Shot/matrix-appservice-discord/pull/316"},"issue":{"href":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/issues/316"},"comments":{"href":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/issues/316/comments"},"review_comments":{"href":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls/316/comments"},"review_comment":{"href":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/pulls/316/commits"},"statuses":{"href":"https://api.github.com/repos/Half-Shot/matrix-appservice-discord/statuses/8a0d3515a8e791a9aa356bcdae9809728c9c8256"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"Half-Shot"}}