From 7a91cd2d888140af350e78792f8bc45b4f9a6a25 Mon Sep 17 00:00:00 2001 From: Markus-Rost Date: Thu, 29 Oct 2020 23:35:07 +0100 Subject: [PATCH 1/3] Set embed colors close #31 --- settings.json.example | 184 ++++++++++++++++++++++++++---------------- 1 file changed, 116 insertions(+), 68 deletions(-) diff --git a/settings.json.example b/settings.json.example index 78be31d..2070561 100644 --- a/settings.json.example +++ b/settings.json.example @@ -23,17 +23,17 @@ "level": 15 }, "file": { - "formatter": "standard", - "class": "logging.handlers.TimedRotatingFileHandler", - "filename": "logs/error.log", + "formatter": "standard", + "class": "logging.handlers.TimedRotatingFileHandler", + "filename": "logs/error.log", "interval": 7, "when": "D", "level": 25 }, "debug": { - "formatter": "standard", - "class": "logging.handlers.TimedRotatingFileHandler", - "filename": "debug.log", + "formatter": "standard", + "class": "logging.handlers.TimedRotatingFileHandler", + "filename": "logs/debug.log", "interval": 7, "when": "D", "level": 0 @@ -53,16 +53,12 @@ "rcgcdb.wiki": {} } }, - "appearance": { + "appearance": { "mode": "embed", "embed": { "show_footer": true, "show_edit_changes": true, "embed_images": true, - "daily_overview": { - "color": 16312092, - "icon": "" - }, "new": { "icon": "https://i.imgur.com/6HIbEq8.png", "color": "THIS COLOR DEPENDS ON EDIT SIZE, PLEASE DON'T CHANGE" @@ -77,11 +73,11 @@ }, "upload/upload": { "icon": "https://i.imgur.com/egJpa81.png", - "color": null + "color": 12390624 }, "upload/revert": { "icon": "https://i.imgur.com/egJpa81.png", - "color": null + "color": 12390624 }, "delete/delete": { "icon": "https://i.imgur.com/BU77GD3.png", @@ -93,27 +89,27 @@ }, "delete/restore": { "icon": "https://i.imgur.com/9MnROIU.png", - "color": null + "color": 1 }, "delete/revision": { "icon": "https://i.imgur.com/1gps6EZ.png", - "color": null + "color": 1 }, "delete/event": { "icon": "https://i.imgur.com/1gps6EZ.png", - "color": null + "color": 1 }, "merge/merge": { "icon": "https://i.imgur.com/uQMK9XK.png", - "color": null + "color": 25600 }, "move/move": { "icon": "https://i.imgur.com/eXz9dog.png", - "color": null + "color": 25600 }, "move/move_redir": { "icon": "https://i.imgur.com/UtC3YX2.png", - "color": null + "color": 25600 }, "block/block": { "icon": "https://i.imgur.com/g7KgZHf.png", @@ -129,167 +125,219 @@ }, "protect/protect": { "icon": "https://i.imgur.com/bzPt89Z.png", - "color": null + "color": 16312092 }, "protect/modify": { "icon": "https://i.imgur.com/bzPt89Z.png", - "color": null + "color": 16312092 }, "protect/move_prot": { "icon": "https://i.imgur.com/bzPt89Z.png", - "color": null + "color": 16312092 }, "protect/unprotect": { "icon": "https://i.imgur.com/2wN3Qcq.png", - "color": null + "color": 16312092 }, "import/upload": { "icon": "", - "color": null + "color": 65280 }, "import/interwiki": { "icon": "https://i.imgur.com/sFkhghb.png", - "color": null + "color": 65280 }, "rights/rights": { "icon": "", - "color": null + "color": 16711680 }, "abusefilter/abusefilter": { "icon": "https://i.imgur.com/Sn2NzRJ.png", - "color": null + "color": 16711680 }, "abusefilter/modify": { "icon": "https://i.imgur.com/Sn2NzRJ.png", - "color": null + "color": 16711680 }, "abusefilter/create": { "icon": "https://i.imgur.com/Sn2NzRJ.png", - "color": null + "color": 16711680 }, "interwiki/iw_add": { "icon": "https://i.imgur.com/sFkhghb.png", - "color": null + "color": 16711680 }, "interwiki/iw_edit": { "icon": "https://i.imgur.com/sFkhghb.png", - "color": null + "color": 16711680 }, "interwiki/iw_delete": { "icon": "https://i.imgur.com/sFkhghb.png", - "color": null + "color": 16711680 }, "curseprofile/comment-created": { "icon": "https://i.imgur.com/Lvy5E32.png", - "color": null + "color": 16089376 }, "curseprofile/comment-edited": { "icon": "https://i.imgur.com/Lvy5E32.png", - "color": null + "color": 16089376 }, "curseprofile/comment-deleted": { "icon": "", - "color": null + "color": 16089376 }, "curseprofile/comment-purged":{ "icon":"", - "color":null + "color":16089376 }, "curseprofile/comment-replied": { "icon": "https://i.imgur.com/hkyYsI1.png", - "color": null + "color": 16089376 }, "curseprofile/profile-edited": { "icon": "", - "color": null + "color": 16089376 }, "contentmodel/change": { "icon": "", - "color": null + "color": 25600 }, "cargo/deletetable": { "icon": "", - "color": null - }, - "cargo/createtable": { + "color": 16776960 + }, + "cargo/createtable": { "icon": "", - "color": null - }, - "cargo/replacetable": { + "color": 16776960 + }, + "cargo/replacetable": { "icon": "", - "color": null - }, - "cargo/recreatetable": { + "color": 16776960 + }, + "cargo/recreatetable": { "icon": "", - "color": null - }, + "color": 16776960 + }, "sprite/sprite": { "icon": "", - "color": null + "color": 16776960 }, "sprite/sheet": { "icon": "", - "color": null + "color": 16776960 }, "sprite/slice": { "icon": "", - "color": null + "color": 16776960 }, "managetags/create": { "icon": "", - "color": null + "color": 16776960 }, "managetags/delete": { "icon": "", - "color": null + "color": 16776960 }, "managetags/activate": { "icon": "", - "color": null + "color": 16776960 }, "managetags/deactivate": { "icon": "", - "color": null + "color": 16776960 }, "tag/update": { "icon": "", - "color": null + "color": 16776960 + }, + "newusers/autocreate": { + "icon": "", + "color": 65280 + }, + "newusers/byemail": { + "icon": "", + "color": 65280 + }, + "newusers/create": { + "icon": "", + "color": 65280 + }, + "newusers/create2": { + "icon": "", + "color": 65280 + }, + "newusers/newusers": { + "icon": "", + "color": 65280 + }, + "managewiki/delete": { + "icon": "", + "color": 8421504 + }, + "managewiki/lock": { + "icon": "", + "color": 8421504 + }, + "managewiki/namespaces": { + "icon": "", + "color": 8421504 + }, + "managewiki/namespaces-delete": { + "icon": "", + "color": 8421504 + }, + "managewiki/rights": { + "icon": "", + "color": 8421504 + }, + "managewiki/settings": { + "icon": "", + "color": 8421504 + }, + "managewiki/undelete": { + "icon": "", + "color": 8421504 + }, + "managewiki/unlock": { + "icon": "", + "color": 8421504 }, "suppressed": { "icon": "https://i.imgur.com/1gps6EZ.png", - "color": 8092539 + "color": 1 }, "discussion/forum/post": { "icon": "", - "color":null + "color": 54998 }, "discussion/forum/reply": { "icon": "", - "color":null - }, + "color": 54998 + }, "discussion/forum/poll": { "icon": "", - "color":null + "color": 54998 }, "discussion/forum/quiz": { "icon": "", - "color":null + "color": 54998 }, "discussion/wall/post": { "icon": "", - "color":null + "color": 3752525 }, "discussion/wall/reply": { "icon": "", - "color":null + "color": 3752525 }, "discussion/comment/post": { "icon": "", - "color":null + "color": 10802 }, "discussion/comment/reply": { "icon": "", - "color":null + "color": 10802 } } } From 203ed8984789d1268a0f906a9e155910345be8d8 Mon Sep 17 00:00:00 2001 From: Markus-Rost Date: Thu, 5 Nov 2020 22:46:04 +0100 Subject: [PATCH 2/3] fix compact protect message --- src/formatters/rc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/formatters/rc.py b/src/formatters/rc.py index 81b6176..60eafd2 100644 --- a/src/formatters/rc.py +++ b/src/formatters/rc.py @@ -214,7 +214,7 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH)) content = "🔒 "+_("[{author}]({author_url}) protected [{article}]({article_url}) with the following settings: {settings}{comment}").format(author=author, author_url=author_url, article=change["title"], article_url=link, - settings=change["logparams"]["description"]+_(" [cascading]") if "cascade" in change["logparams"] else "", + settings=change["logparams"]["description"]+(_(" [cascading]") if "cascade" in change["logparams"] else ""), comment=parsed_comment) elif action == "protect/modify": link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH)) @@ -222,7 +222,7 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c "[{author}]({author_url}) modified protection settings of [{article}]({article_url}) to: {settings}{comment}").format( author=author, author_url=author_url, article=change["title"], article_url=link, - settings=change["logparams"]["description"] + _(" [cascading]") if "cascade" in change["logparams"] else "", + settings=change["logparams"]["description"] + (_(" [cascading]") if "cascade" in change["logparams"] else ""), comment=parsed_comment) elif action == "protect/unprotect": link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH)) From 1ad94b2e3edf036d2d196320e965f5ae82cf03be Mon Sep 17 00:00:00 2001 From: Markus-Rost Date: Mon, 9 Nov 2020 18:05:02 +0100 Subject: [PATCH 3/3] Update diff parser Based on Wiki-Bot diff parser --- src/misc.py | 83 +++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/src/misc.py b/src/misc.py index eea1814..15f7861 100644 --- a/src/misc.py +++ b/src/misc.py @@ -112,9 +112,11 @@ def profile_field_name(name, embed, lang): class ContentParser(HTMLParser): current_tag = "" + last_ins = None + last_del = None + empty = False small_prev_ins = "" small_prev_del = "" - added = False def __init__(self, lang): super().__init__() @@ -125,58 +127,57 @@ class ContentParser(HTMLParser): def handle_starttag(self, tagname, attribs): if tagname == "ins" or tagname == "del": self.current_tag = tagname - if tagname == "td" and 'diff-addedline' in attribs[0]: - self.current_tag = tagname + "a" - if tagname == "td" and 'diff-deletedline' in attribs[0]: - self.current_tag = tagname + "d" - if tagname == "td" and 'diff-marker' in attribs[0]: - self.added = True + if tagname == "td" and "diff-addedline" in attribs[0] and self.ins_length <= 1000: + self.current_tag = "tda" + self.last_ins = "" + if tagname == "td" and "diff-deletedline" in attribs[0] and self.del_length <= 1000: + self.current_tag = "tdd" + self.last_del = "" + if tagname == "td" and "diff-empty" in attribs[0]: + self.empty = True def handle_data(self, data): data = escape_formatting(data) if self.current_tag == "ins" and self.ins_length <= 1000: - self.ins_length += len("**" + data + '**') + self.ins_length += len("**" + data + "**") if self.ins_length <= 1000: - self.small_prev_ins = self.small_prev_ins + "**" + data + '**' - else: - self.small_prev_ins = self.small_prev_ins + self.more + self.last_ins = self.last_ins + "**" + data + "**" if self.current_tag == "del" and self.del_length <= 1000: - self.del_length += len("~~" + data + '~~') + self.del_length += len("~~" + data + "~~") if self.del_length <= 1000: - self.small_prev_del = self.small_prev_del + "~~" + data + '~~' - else: - self.small_prev_del = self.small_prev_del + self.more - if (self.current_tag == "afterins" or self.current_tag == "tda") and self.ins_length <= 1000: + self.last_del = self.last_del + "~~" + data + "~~" + if self.current_tag == "tda" and self.ins_length <= 1000: self.ins_length += len(data) if self.ins_length <= 1000: - self.small_prev_ins = self.small_prev_ins + data - else: - self.small_prev_ins = self.small_prev_ins + self.more - if (self.current_tag == "afterdel" or self.current_tag == "tdd") and self.del_length <= 1000: + self.last_ins = self.last_ins + data + if self.current_tag == "tdd" and self.del_length <= 1000: self.del_length += len(data) if self.del_length <= 1000: - self.small_prev_del = self.small_prev_del + data - else: - self.small_prev_del = self.small_prev_del + self.more - if self.added: - if data == '+' and self.ins_length <= 1000: - self.ins_length += 1 - if self.ins_length <= 1000: - self.small_prev_ins = self.small_prev_ins + '\n' - else: - self.small_prev_ins = self.small_prev_ins + self.more - if data == '−' and self.del_length <= 1000: - self.del_length += 1 - if self.del_length <= 1000: - self.small_prev_del = self.small_prev_del + '\n' - else: - self.small_prev_del = self.small_prev_del + self.more - self.added = False + self.last_del = self.last_del + data def handle_endtag(self, tagname): + self.current_tag = "" if tagname == "ins": - self.current_tag = "afterins" + self.current_tag = "tda" elif tagname == "del": - self.current_tag = "afterdel" - else: - self.current_tag = "" + self.current_tag = "tdd" + elif tagname == "tr": + if self.last_ins is not None: + self.ins_length += 1 + if self.empty and not self.last_ins.isspace() and "**" not in self.last_ins: + self.ins_length += 4 + self.last_ins = "**" + self.last_ins + "**" + self.small_prev_ins = self.small_prev_ins + "\n" + self.last_ins + if self.ins_length > 1000: + self.small_prev_ins = self.small_prev_ins + self.more + self.last_ins = None + if self.last_del is not None: + self.del_length += 1 + if self.empty and not self.last_del.isspace() and "~~" not in self.last_del: + self.del_length += 4 + self.last_del = "~~" + self.last_del + "~~" + self.small_prev_del = self.small_prev_del + "\n" + self.last_del + if self.del_length > 1000: + self.small_prev_del = self.small_prev_del + self.more + self.last_del = None + self.empty = False