Merged !110 into testing

This commit is contained in:
Frisk 2022-10-07 00:37:53 +02:00
commit 33e230fb0f
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
3 changed files with 17 additions and 10 deletions

View file

@ -35,7 +35,7 @@ common functions that can be used to interact with the script and the wiki.
### Formatter ### Formatter
**Path**: `src.api.formatter` **Path**: `src.api.formatter`
_Formatter module implements two decorators: `embed` and `compact`. Both of them can take the following keyword arguments:_ _Formatter module implements two decorators: `embed` and `compact`. Both of them can take the following keyword arguments:_
- `event` - string - event type for formatter, in case the event is a [log event](https://www.mediawiki.org/wiki/Manual:Log_actions) it's constructed by taking log_type and combining it with log_action with / character in between (for example `upload/overwrite`). If the event however is not a log event but action like edit, the type will consist only of `type` value. - `event` - string - event type for formatter, in case the event is a [log event](https://www.mediawiki.org/wiki/Manual:Log_actions) it's constructed by taking log_type and combining it with log_action with / character in between (for example `upload/overwrite`). If the event however is not a log event but action like edit, the type will consist only of `type` value. (Pre hooks may receive or set this to an empty string for events that will be ignored.)
- `aliases` - list[str] - list of strings containing all the events given event should alias for, it helps in case you want the same function be used for multiple event types. - `aliases` - list[str] - list of strings containing all the events given event should alias for, it helps in case you want the same function be used for multiple event types.
Both `event` and `aliases` arguments are optional in formatters. However, every formatter needs to have some kind of event specified. If it's not specified in the decorator, a fallback method will be used which constructs event type in format `{func.__module__}/{func.__name__.split("_", 1)[1]}`, in other terms taking the name of the file in which formatter is defined as first part and entire function name after first _ character as second part. Note that this fallback works only for log events. Both `event` and `aliases` arguments are optional in formatters. However, every formatter needs to have some kind of event specified. If it's not specified in the decorator, a fallback method will be used which constructs event type in format `{func.__module__}/{func.__name__.split("_", 1)[1]}`, in other terms taking the name of the file in which formatter is defined as first part and entire function name after first _ character as second part. Note that this fallback works only for log events.

View file

@ -122,12 +122,13 @@ def parse_discussion_post(post, comment_pages):
except KeyError: except KeyError:
discussion_logger.error("Could not parse paths for article comment, here is the content of comment_pages: {}, ignoring...".format(comment_pages)) discussion_logger.error("Could not parse paths for article comment, here is the content of comment_pages: {}, ignoring...".format(comment_pages))
raise ArticleCommentError raise ArticleCommentError
event_type = f"discussion/{post_type.lower()}" context.event = f"discussion/{post_type.lower()}"
context.event = event_type
context.set_comment_page(comment_page) context.set_comment_page(comment_page)
run_hooks(pre_hooks, context, post) run_hooks(pre_hooks, context, post)
if not context.event:
return
try: try:
discord_message = default_message(event_type, formatter_hooks)(context, post) discord_message = default_message(context.event, formatter_hooks)(context, post)
except NoFormatter: except NoFormatter:
return return
except: except:

View file

@ -206,8 +206,10 @@ def rc_processor(change, changed_categories):
if ("actionhidden" in change or "suppressed" in change) and "suppressed" not in settings["ignored"]: # if event is hidden using suppression if ("actionhidden" in change or "suppressed" in change) and "suppressed" not in settings["ignored"]: # if event is hidden using suppression
context.event = "suppressed" context.event = "suppressed"
run_hooks(pre_hooks, context, change) run_hooks(pre_hooks, context, change)
if not context.event:
return
try: try:
discord_message: Optional[DiscordMessage] = default_message("suppressed", formatter_hooks)(context, change) discord_message: Optional[DiscordMessage] = default_message(context.event, formatter_hooks)(context, change)
except NoFormatter: except NoFormatter:
return return
except: except:
@ -243,23 +245,25 @@ def rc_processor(change, changed_categories):
return return
context.event = identification_string context.event = identification_string
run_hooks(pre_hooks, context, change) run_hooks(pre_hooks, context, change)
if not context.event:
return
try: try:
discord_message: Optional[DiscordMessage] = default_message(identification_string, formatter_hooks)(context, change) discord_message: Optional[DiscordMessage] = default_message(context.event, formatter_hooks)(context, change)
except: except:
if settings.get("error_tolerance", 1) > 0: if settings.get("error_tolerance", 1) > 0:
discord_message: Optional[DiscordMessage] = None # It's handled by send_to_discord, we still want other code to run discord_message: Optional[DiscordMessage] = None # It's handled by send_to_discord, we still want other code to run
else: else:
raise raise
if identification_string in ("delete/delete", "delete/delete_redir") and AUTO_SUPPRESSION_ENABLED: # TODO Move it into a hook? if context.event in ("delete/delete", "delete/delete_redir") and AUTO_SUPPRESSION_ENABLED: # TODO Move it into a hook?
delete_messages(dict(pageid=change.get("pageid"))) delete_messages(dict(pageid=change.get("pageid")))
elif identification_string == "delete/event" and AUTO_SUPPRESSION_ENABLED: elif context.event == "delete/event" and AUTO_SUPPRESSION_ENABLED:
logparams = change.get('logparams', {"ids": []}) logparams = change.get('logparams', {"ids": []})
if settings["appearance"]["mode"] == "embed": if settings["appearance"]["mode"] == "embed":
redact_messages(logparams.get("ids", []), 1, logparams.get("new", {})) redact_messages(logparams.get("ids", []), 1, logparams.get("new", {}))
else: else:
for logid in logparams.get("ids", []): for logid in logparams.get("ids", []):
delete_messages(dict(logid=logid)) delete_messages(dict(logid=logid))
elif identification_string == "delete/revision" and AUTO_SUPPRESSION_ENABLED: elif context.event == "delete/revision" and AUTO_SUPPRESSION_ENABLED:
logparams = change.get('logparams', {"ids": []}) logparams = change.get('logparams', {"ids": []})
if logparams.get("type", "") in ("revision", "logging", "oldimage"): if logparams.get("type", "") in ("revision", "logging", "oldimage"):
if settings["appearance"]["mode"] == "embed": if settings["appearance"]["mode"] == "embed":
@ -282,8 +286,10 @@ def abuselog_processing(entry):
context = Context(settings["appearance"]["mode"], "abuselog", settings.get("abuselog_webhookURL", settings["webhookURL"]), client, formatters_i18n, settings) context = Context(settings["appearance"]["mode"], "abuselog", settings.get("abuselog_webhookURL", settings["webhookURL"]), client, formatters_i18n, settings)
context.event = action context.event = action
run_hooks(pre_hooks, context, entry) run_hooks(pre_hooks, context, entry)
if not context.event:
return
try: try:
discord_message: Optional[DiscordMessage] = default_message(action, formatter_hooks)(context, entry) discord_message: Optional[DiscordMessage] = default_message(context.event, formatter_hooks)(context, entry)
except NoFormatter: except NoFormatter:
return return
except: except: