aboutsummaryrefslogtreecommitdiff
path: root/modules/fediverse/__init__.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-10-04 13:06:29 +0100
committerGravatar jesopo2019-10-04 13:06:29 +0100
commit472b5ba9f0f8d04fb65140b5ed66ac0044753765 (patch)
tree756180de52ab1f20638b58c3db2fbb8a807314c9 /modules/fediverse/__init__.py
parentexpand `apikey` command to list, add, remove and info (diff)
support !fedi with a URL to a Note
Diffstat (limited to 'modules/fediverse/__init__.py')
-rw-r--r--modules/fediverse/__init__.py51
1 files changed, 36 insertions, 15 deletions
diff --git a/modules/fediverse/__init__.py b/modules/fediverse/__init__.py
index d3a634fa..bbf29110 100644
--- a/modules/fediverse/__init__.py
+++ b/modules/fediverse/__init__.py
@@ -53,8 +53,11 @@ class Module(ModuleManager.BaseModule):
@utils.kwarg("usage", "@<user>@<instance>")
def fedi(self, event):
account = None
+ url = None
if not event["args"]:
account = event["user"].get_setting("fediverse", None)
+ elif utils.http.REGEX_URL.match(event["args_split"][0]):
+ url = event["args_split"][0]
elif not "@" in event["args"]:
target = event["args_split"][0]
if event["server"].has_user_id(target):
@@ -63,14 +66,40 @@ class Module(ModuleManager.BaseModule):
else:
account = event["args_split"][0]
- username = None
- instance = None
- if account:
- username, instance = ap_utils.split_username(account)
+ note = None
+ type = "Create"
+ if not url == None:
+ note_page = ap_utils.activity_request(url)
+ if not note_page.content_type == ap_utils.ACTIVITY_TYPE:
+ raise utils.EventError("That's not a fediverse URL")
+
+ note = note_page.data
+ actor = ap_actor.Actor(note["attributedTo"])
+ actor.load()
+ else:
+ username = None
+ instance = None
+ if account:
+ username, instance = ap_utils.split_username(account)
+
+ if not username or not instance:
+ raise utils.EventError("Please provide @<user>@<instance>")
+ actor, note = self._get_from_outbox(username, instance)
+ type = note["type"]
+ note = note["object"]
+
+ cw, out, url = ap_utils.format_note(actor, note, type)
+ shorturl = self.exports.get_one("shorturl")(event["server"], url,
+ context=event["target"])
+
+ if cw:
+ out = "CW: %s - %s" % (cw, shorturl)
+ else:
+ out = "%s - %s" % (out, shorturl)
+ event["stdout"].write(out)
- if not username or not instance:
- raise utils.EventError("Please provide @<user>@<instance>")
+ def _get_from_outbox(self, username, instance):
actor_url = ap_utils.find_actor(username, instance)
if not actor_url:
@@ -89,12 +118,4 @@ class Module(ModuleManager.BaseModule):
if not first_item:
raise utils.EventError("No toots found")
- cw, out, url = ap_utils.format_note(actor, first_item)
- shorturl = self.exports.get_one("shorturl")(event["server"], url,
- context=event["target"])
-
- if cw:
- out = "CW: %s - %s" % (cw, shorturl)
- else:
- out = "%s - %s" % (out, shorturl)
- event["stdout"].write(out)
+ return actor, first_item