mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-24 23:41:09 +00:00
irc: add AP message relay
This commit is contained in:
parent
489a01fc9e
commit
fd171fb52c
|
@ -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 = {
|
||||
|
|
12
viera/irc.py
12
viera/irc.py
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue