irc: add AP message relay

This commit is contained in:
William Pitcock 2018-08-17 18:01:44 -05:00
parent 489a01fc9e
commit fd171fb52c
2 changed files with 22 additions and 1 deletions

View File

@ -85,10 +85,15 @@ def strip_html(data):
return cgi.escape(no_tags)
from .authreqs import check_reqs
from .authreqs import check_reqs, get_irc_bot
async def handle_create(actor, data, request):
# for now, we only care about Notes
if data['object']['type'] != Note:
return
# strip the HTML if present
content = strip_html(data['object']['content']).split()
# check if the message is an authorization token for linking identities together
@ -96,6 +101,10 @@ async def handle_create(actor, data, request):
if check_reqs(content, actor):
return
# fetch our IRC bot
bot = get_irc_bot()
bot.relay_message(actor, data['object'], content)
async def handle_follow(actor, data, request):
message = {

View File

@ -204,6 +204,18 @@ class IRCProtocol(asyncio.Protocol):
logging.debug('> %r', m)
self.transport.write(m.to_message().encode('utf-8') + b'\r\n')
def relay_message(self, actor, obj, content):
fmt = "\x02{name}\x02: {content} [{url}]"
msgcontent = content[0:256]
if len(content) > 256:
msgcontent += '...'
message = fmt.format(name=actor['name'], content=msgcontent, url=obj['id'])
target = ','.join(IRC_CONFIG['relay_channels'])
self.say(target, message)
async def irc_bot():
loop = asyncio.get_event_loop()