mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
Fediverse: Add usernameSnarfer.
This commit is contained in:
parent
76950126b5
commit
e9ff57a1c9
@ -51,9 +51,9 @@ def configure(advanced):
|
||||
|
||||
|
||||
Fediverse = conf.registerPlugin("Fediverse")
|
||||
# This is where your configuration variables (if any) should go. For example:
|
||||
# conf.registerGlobalValue(Fediverse, 'someConfigVariableName',
|
||||
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
|
||||
conf.registerChannelValue(Fediverse, 'usernameSnarfer',
|
||||
registry.Boolean(False, _("""Determines whether the bot will output the
|
||||
profile of @username@hostname accounts it sees in channel messages.""")))
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
@ -46,7 +46,7 @@ importlib.reload(ap)
|
||||
_ = PluginInternationalization("Fediverse")
|
||||
|
||||
|
||||
_username_re = re.compile("@(?P<localuser>[^@]+)@(?P<hostname>[^@]+)")
|
||||
_username_regexp = re.compile("@(?P<localuser>[^@ ]+)@(?P<hostname>[^@ ]+)")
|
||||
|
||||
|
||||
class FediverseHttp(httpserver.SupyHTTPServerCallback):
|
||||
@ -113,10 +113,11 @@ class FediverseHttp(httpserver.SupyHTTPServerCallback):
|
||||
self.wfile.write(json.dumps(actor).encode())
|
||||
|
||||
|
||||
class Fediverse(callbacks.Plugin):
|
||||
class Fediverse(callbacks.PluginRegexp):
|
||||
"""Fetches information from ActivityPub servers."""
|
||||
|
||||
threaded = True
|
||||
regexps = ['usernameSnarfer']
|
||||
|
||||
def __init__(self, irc):
|
||||
super().__init__(irc)
|
||||
@ -138,7 +139,7 @@ class Fediverse(callbacks.Plugin):
|
||||
def _get_actor(self, irc, username):
|
||||
if username in self._actor_cache:
|
||||
return self._actor_cache[username]
|
||||
match = _username_re.match(username)
|
||||
match = _username_regexp.match(username)
|
||||
if not match:
|
||||
irc.errorInvalid("fediverse username", username)
|
||||
localuser = match.group("localuser")
|
||||
@ -185,6 +186,23 @@ class Fediverse(callbacks.Plugin):
|
||||
)
|
||||
)
|
||||
|
||||
def usernameSnarfer(self, irc, msg, match):
|
||||
try:
|
||||
actor = self._get_actor(irc, match.group(0))
|
||||
except ap.ActivityPubError:
|
||||
# Be silent on errors
|
||||
return
|
||||
|
||||
irc.reply(
|
||||
_("\x02%s\x02 (%s): %s")
|
||||
% (
|
||||
actor["name"],
|
||||
self._format_actor_username(actor),
|
||||
utils.web.htmlToText(actor["summary"]),
|
||||
)
|
||||
)
|
||||
usernameSnarfer.__doc__ = _username_regexp.pattern
|
||||
|
||||
@wrap(["somethingWithoutSpaces"])
|
||||
def featured(self, irc, msg, args, username):
|
||||
"""<@user@instance>
|
||||
|
Loading…
Reference in New Issue
Block a user