Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 49 additions & 20 deletions apprise/plugins/revolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,19 @@ class NotifyRevolt(NotifyBase):
title_maxlen = 100

# Define object templates
templates = ("{schema}://{bot_token}/{targets}",)
templates = (
"{schema}://{bot_token}/{targets}",
"{schema}://{server_api_url}/{bot_token}/{targets}",
)

# Defile out template tokens
template_tokens = dict(
NotifyBase.template_tokens,
**{
"server_api_url": {
"name": _("Server API URL"),
"type": "string",
},
"bot_token": {
"name": _("Bot Token"),
"type": "string",
Expand Down Expand Up @@ -137,9 +144,19 @@ class NotifyRevolt(NotifyBase):
},
)

def __init__(self, bot_token, targets, icon_url=None, link=None, **kwargs):
def __init__(
self,
bot_token,
targets,
icon_url=None,
link=None,
server_api_url=None,
**kwargs,
):
super().__init__(**kwargs)

if server_api_url:
self.notify_url = server_api_url
# Bot Token
self.bot_token = validate_regex(bot_token)
if not self.bot_token:
Expand Down Expand Up @@ -192,13 +209,17 @@ def send(self, body, title="", notify_type=NotifyType.INFO, **kwargs):
)

if self.notify_format == NotifyFormat.MARKDOWN:
payload["embeds"] = [{
"title": None if not title else title[0 : self.title_maxlen],
"description": body,
# Our color associated with our notification
"colour": self.color(notify_type),
"replies": None,
}]
payload["embeds"] = [
{
"title": None
if not title
else title[0 : self.title_maxlen],
"description": body,
# Our color associated with our notification
"colour": self.color(notify_type),
"replies": None,
}
]

if image_url:
payload["embeds"][0]["icon_url"] = image_url
Expand Down Expand Up @@ -249,9 +270,7 @@ def _send(self, payload, channel_id, retries=1, **kwargs):
# the same allowing this to role smoothly and set our throttle
# accordingly
wait = abs(
(
self.ratelimit_reset - now + self.clock_skew
).total_seconds()
(self.ratelimit_reset - now + self.clock_skew).total_seconds()
)

# Default content response object
Expand Down Expand Up @@ -299,7 +318,6 @@ def _send(self, payload, channel_id, retries=1, **kwargs):
requests.codes.ok,
requests.codes.no_content,
):

# Some details to debug by
self.logger.debug(
f"Response Details:\r\n{content if content else r.content}"
Expand All @@ -324,7 +342,6 @@ def _send(self, payload, channel_id, retries=1, **kwargs):
r.status_code == requests.codes.too_many_requests
and retries > 0
):

# Try again
return self._send(
payload=payload,
Expand Down Expand Up @@ -400,14 +417,26 @@ def parse_url(url):
# We're done early as we couldn't load the results
return results

# Store our bot token
bot_token = NotifyRevolt.unquote(results["host"])
_host = NotifyRevolt.unquote(results["host"])
selfhosted = _host.endswith("/")
if selfhosted:
r = requests.get(f"https://{_host}")
if r.ok:
results["server_api_url"] = f"https://{_host}"

bot_token = NotifyRevolt.split_path(results["fullpath"])[0]
targets = NotifyRevolt.split_path(results["fullpath"])[1:]
results["bot_token"] = bot_token
results["targets"] = targets
else:
# Store our bot token
bot_token = NotifyRevolt.unquote(results["host"])

# Now fetch the Channel IDs
targets = NotifyRevolt.split_path(results["fullpath"])
# Now fetch the Channel IDs
targets = NotifyRevolt.split_path(results["fullpath"])

results["bot_token"] = bot_token
results["targets"] = targets
results["bot_token"] = bot_token
results["targets"] = targets

# Support the 'to' variable so that we can support rooms this way too
# The 'to' makes it easier to use yaml configuration
Expand Down
Loading