mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Added #147 with few exceptions, switched supported_logs variable to more performant set
This commit is contained in:
parent
0147e29817
commit
5129d9b04b
|
@ -134,9 +134,11 @@ class MessageQueue:
|
||||||
self.cut_messages(num)
|
self.cut_messages(num)
|
||||||
misc_logger.debug(self._queue)
|
misc_logger.debug(self._queue)
|
||||||
|
|
||||||
|
|
||||||
messagequeue = MessageQueue()
|
messagequeue = MessageQueue()
|
||||||
datafile = DataFile()
|
datafile = DataFile()
|
||||||
|
|
||||||
|
|
||||||
def weighted_average(value, weight, new_value):
|
def weighted_average(value, weight, new_value):
|
||||||
"""Calculates weighted average of value number with weight weight and new_value with weight 1"""
|
"""Calculates weighted average of value number with weight weight and new_value with weight 1"""
|
||||||
return round(((value * weight) + new_value) / (weight + 1), 2)
|
return round(((value * weight) + new_value) / (weight + 1), 2)
|
||||||
|
@ -146,10 +148,12 @@ def link_formatter(link):
|
||||||
"""Formats a link to not embed it"""
|
"""Formats a link to not embed it"""
|
||||||
return "<" + quote(link.replace(" ", "_"), "/:?") + ">"
|
return "<" + quote(link.replace(" ", "_"), "/:?") + ">"
|
||||||
|
|
||||||
|
|
||||||
def escape_formatting(data):
|
def escape_formatting(data):
|
||||||
"""Escape Discord formatting"""
|
"""Escape Discord formatting"""
|
||||||
return re.sub(r"([`_*~<>{}@/|\\])", "\\\\\\1", data, 0)
|
return re.sub(r"([`_*~<>{}@/|\\])", "\\\\\\1", data, 0)
|
||||||
|
|
||||||
|
|
||||||
class ContentParser(HTMLParser):
|
class ContentParser(HTMLParser):
|
||||||
more = _("\n__And more__")
|
more = _("\n__And more__")
|
||||||
current_tag = ""
|
current_tag = ""
|
||||||
|
|
15
src/rc.py
15
src/rc.py
|
@ -19,7 +19,20 @@ storage = datafile
|
||||||
|
|
||||||
logger = logging.getLogger("rcgcdw.rc")
|
logger = logging.getLogger("rcgcdw.rc")
|
||||||
|
|
||||||
supported_logs = ["protect/protect", "protect/modify", "protect/unprotect", "upload/overwrite", "upload/upload", "delete/delete", "delete/delete_redir", "delete/restore", "delete/revision", "delete/event", "import/upload", "import/interwiki", "merge/merge", "move/move", "move/move_redir", "protect/move_prot", "block/block", "block/unblock", "block/reblock", "rights/rights", "rights/autopromote", "abusefilter/modify", "abusefilter/create", "interwiki/iw_add", "interwiki/iw_edit", "interwiki/iw_delete", "curseprofile/comment-created", "curseprofile/comment-edited", "curseprofile/comment-deleted", "curseprofile/comment-purged", "curseprofile/profile-edited", "curseprofile/comment-replied", "contentmodel/change", "sprite/sprite", "sprite/sheet", "sprite/slice", "managetags/create", "managetags/delete", "managetags/activate", "managetags/deactivate", "tag/update", "cargo/createtable", "cargo/deletetable", "cargo/recreatetable", "cargo/replacetable", "upload/revert", "newusers/create", "newusers/autocreate", "newusers/create2", "newusers/byemail", "newusers/newusers", "managewiki/settings"]
|
supported_logs = {"protect/protect", "protect/modify", "protect/unprotect", "upload/overwrite", "upload/upload",
|
||||||
|
"delete/delete", "delete/delete_redir", "delete/restore", "delete/revision", "delete/event",
|
||||||
|
"import/upload", "import/interwiki", "merge/merge", "move/move", "move/move_redir",
|
||||||
|
"protect/move_prot", "block/block", "block/unblock", "block/reblock", "rights/rights",
|
||||||
|
"rights/autopromote", "abusefilter/modify", "abusefilter/create", "interwiki/iw_add",
|
||||||
|
"interwiki/iw_edit", "interwiki/iw_delete", "curseprofile/comment-created",
|
||||||
|
"curseprofile/comment-edited", "curseprofile/comment-deleted", "curseprofile/comment-purged",
|
||||||
|
"curseprofile/profile-edited", "curseprofile/comment-replied", "contentmodel/change", "sprite/sprite",
|
||||||
|
"sprite/sheet", "sprite/slice", "managetags/create", "managetags/delete", "managetags/activate",
|
||||||
|
"managetags/deactivate", "tag/update", "cargo/createtable", "cargo/deletetable",
|
||||||
|
"cargo/recreatetable", "cargo/replacetable", "upload/revert", "newusers/create",
|
||||||
|
"newusers/autocreate", "newusers/create2", "newusers/byemail", "newusers/newusers",
|
||||||
|
"managewiki/settings", "managewiki/delete", "managewiki/lock", "managewiki/unlock",
|
||||||
|
"managewiki/namespaces", "managewiki/namespaces-delete", "managewiki/rights", "managewiki/undelete"}
|
||||||
|
|
||||||
# Set the proper formatter
|
# Set the proper formatter
|
||||||
if settings["appearance"]["mode"] == "embed":
|
if settings["appearance"]["mode"] == "embed":
|
||||||
|
|
|
@ -364,6 +364,35 @@ def compact_formatter(action, change, parsed_comment, categories, recent_changes
|
||||||
content = "🏷️ "+_("[{author}]({author_url}) deactivated a [tag]({tag_url}) \"{tag}\"").format(author=author, author_url=author_url, tag=change["logparams"]["tag"], tag_url=link)
|
content = "🏷️ "+_("[{author}]({author_url}) deactivated a [tag]({tag_url}) \"{tag}\"").format(author=author, author_url=author_url, tag=change["logparams"]["tag"], tag_url=link)
|
||||||
elif action == "managewiki/settings": # Miraheze's ManageWiki extension https://github.com/miraheze/ManageWiki
|
elif action == "managewiki/settings": # Miraheze's ManageWiki extension https://github.com/miraheze/ManageWiki
|
||||||
content = "⚙️ "+_("[{author}]({author_url}) changed wiki settings ({reason})".format(author=author, author_url=author_url, reason=parsed_comment))
|
content = "⚙️ "+_("[{author}]({author_url}) changed wiki settings ({reason})".format(author=author, author_url=author_url, reason=parsed_comment))
|
||||||
|
elif action == "managewiki/delete":
|
||||||
|
content = "🗑️ "+_("[{author}]({author_url}) deleted a wiki *{wiki_name}* ({comment})").format(author=author, author_url=author_url,
|
||||||
|
wiki_name=change["logparams"].get("wiki", {"wiki": _("Unknown")}), comment=parsed_comment)
|
||||||
|
elif action == "managewiki/lock":
|
||||||
|
content = "🔒 "+_("[{author}]({author_url}) locked a wiki *{wiki_name}* ({comment})").format(
|
||||||
|
author=author, author_url=author_url, wiki_name=change["logparams"].get("wiki", {"wiki": _("Unknown")}), comment=parsed_comment)
|
||||||
|
elif action == "managewiki/namespaces":
|
||||||
|
content = "📦 "+_("[{author}]({author_url}) modified a namespace *{namespace_name}* on *{wiki_name}* ({comment})").format(
|
||||||
|
author=author, author_url=author_url, namespace_name=change["logparams"].get("namespace", {"namespace": _("Unknown")}),
|
||||||
|
wiki_name=change["logparams"].get("wiki", {"wiki": _("Unknown")}), comment=parsed_comment)
|
||||||
|
elif action == "managewiki/namespaces-delete":
|
||||||
|
content = "🗑️ " + _(
|
||||||
|
"[{author}]({author_url}) deleted a namespace *{namespace_name}* on *{wiki_name}* ({comment})").format(
|
||||||
|
author=author, author_url=author_url,
|
||||||
|
namespace_name=change["logparams"].get("namespace", {"namespace": _("Unknown")}),
|
||||||
|
wiki_name=change["logparams"].get("wiki", {"wiki": _("Unknown")}), comment=parsed_comment)
|
||||||
|
elif action == "managewiki/rights":
|
||||||
|
content = "🏅 " + _("[{author}]({author_url}) modified user group *{group_name}* ({comment})").format(
|
||||||
|
author=author, author_url=author_url, group_name=change["title"][32:], comment=parsed_comment
|
||||||
|
)
|
||||||
|
elif action == "managewiki/undelete":
|
||||||
|
content = "🏅 " + _("[{author}]({author_url}) restored a wiki *{wiki_name}* ({comment})").format(
|
||||||
|
author=author, author_url=author_url, wiki_name=change["logparams"].get("wiki", {"wiki": _("Unknown")}), comment=parsed_comment
|
||||||
|
)
|
||||||
|
elif action == "managewiki/unlock":
|
||||||
|
content = "🏅 " + _("[{author}]({author_url}) unlocked a wiki *{wiki_name}* ({comment})").format(
|
||||||
|
author=author, author_url=author_url, wiki_name=change["logparams"].get("wiki", {"wiki": _("Unknown")}),
|
||||||
|
comment=parsed_comment
|
||||||
|
)
|
||||||
elif action == "suppressed":
|
elif action == "suppressed":
|
||||||
content = "👁️ "+_("An action has been hidden by administration.")
|
content = "👁️ "+_("An action has been hidden by administration.")
|
||||||
else:
|
else:
|
||||||
|
@ -791,6 +820,36 @@ def embed_formatter(action, change, parsed_comment, categories, recent_changes):
|
||||||
embed["title"] = _("Changed wiki settings")
|
embed["title"] = _("Changed wiki settings")
|
||||||
if change["logparams"].get("changes", ""):
|
if change["logparams"].get("changes", ""):
|
||||||
embed.add_field("Setting", change["logparams"].get("changes"))
|
embed.add_field("Setting", change["logparams"].get("changes"))
|
||||||
|
elif action == "managewiki/delete":
|
||||||
|
embed["title"] = _("Deleted a \"{wiki}\" wiki".format(wiki=change["logparams"].get("wiki", {"wiki": _("Unknown")})))
|
||||||
|
link = create_article_path("")
|
||||||
|
elif action == "managewiki/lock":
|
||||||
|
embed["title"] = _(
|
||||||
|
"Locked a \"{wiki}\" wiki".format(wiki=change["logparams"].get("wiki", {"wiki": _("Unknown")})))
|
||||||
|
link = create_article_path("")
|
||||||
|
elif action == "managewiki/namespaces":
|
||||||
|
embed["title"] = _(
|
||||||
|
"Modified a \"{namespace_name}\" namespace".format(namespace_name=change["logparams"].get("namespace", {"namespace": _("Unknown")})))
|
||||||
|
link = create_article_path("")
|
||||||
|
embed.add_field(_('Wiki'), change["logparams"].get("wiki", {"wiki": _("Unknown")}))
|
||||||
|
elif action == "managewiki/namespaces-delete":
|
||||||
|
embed["title"] = _(
|
||||||
|
"Deleted a \"{namespace_name}\" namespace".format(
|
||||||
|
namespace_name=change["logparams"].get("namespace", {"namespace": _("Unknown")})))
|
||||||
|
link = create_article_path("")
|
||||||
|
embed.add_field(_('Wiki'), change["logparams"].get("wiki", {"wiki": _("Unknown")}))
|
||||||
|
elif action == "managewiki/rights":
|
||||||
|
embed["title"] = _(
|
||||||
|
"Modified \"{usergroup_name}\" usergroup".format(usergroup_name=change["title"][32:]))
|
||||||
|
link = create_article_path("")
|
||||||
|
elif action == "managewiki/undelete":
|
||||||
|
embed["title"] = _(
|
||||||
|
"Restored a \"{wiki}\" wiki".format(wiki=change["logparams"].get("wiki", {"wiki": _("Unknown")})))
|
||||||
|
link = create_article_path("")
|
||||||
|
elif action == "managewiki/unlock":
|
||||||
|
embed["title"] = _(
|
||||||
|
"Unlocked a \"{wiki}\" wiki".format(wiki=change["logparams"].get("wiki", {"wiki": _("Unknown")})))
|
||||||
|
link = create_article_path("")
|
||||||
elif action == "suppressed":
|
elif action == "suppressed":
|
||||||
link = create_article_path("")
|
link = create_article_path("")
|
||||||
embed["title"] = _("Action has been hidden by administration")
|
embed["title"] = _("Action has been hidden by administration")
|
||||||
|
|
Loading…
Reference in a new issue