Compare commits

...

2 Commits

Author SHA1 Message Date
Lephenixnoir e3b7f076ae
Get IRC formatting from the v4 server 2023-08-08 21:14:10 +02:00
Lephenixnoir c2ad050502
Revert fab79f5d2, 44e4d20ce, 84a65d9cb and 24eb9571f
Reverts changes related to passing around BBCode. This idea has been
scrapped in favor of having the v4 server directly output IRC formatting
from the BBCode in TextOut. Something similar will have to be used on
the v5 server in order to support Markdown formatting in the shoutbox.
2023-08-08 21:12:02 +02:00
3 changed files with 6 additions and 23 deletions

View File

@ -30,7 +30,7 @@ def handle_irc(m):
@shoutbox.on(lambda m: m.channel in channels)
def handle_shoutbox(m):
author = Shoutbox.normalize(m.author)
shoutbox.irc_clients[author][0].send(f"#{m.channel}", f"{m.text}", bbcode=m.bbcode)
shoutbox.irc_clients[author][0].send(f"#{m.channel}", f"{m.text}")
irc.start(f"Shoutbox[{nick}]", password, nick)

22
irc.py
View File

@ -37,9 +37,6 @@ class IRC(object):
self._send(f"USER {nick} * * :{nick}")
self._send(f"NICK {nick}")
self._send(f"CAP REQ :message-tags")
self._waitfor(lambda m: "CAP" in m and "ACK" in m)
self._send(f"CAP END")
self._waitfor(lambda m: "NOTICE" in m and "/AUTH" in m)
for i in range(3):
@ -79,13 +76,9 @@ class IRC(object):
logging.info(f"matched {event.__name__}")
callback(message)
def send(self, target, message, bbcode=None):
def send(self, target, message):
""" Send a message to the specified target (channel or user) """
if bbcode is not None:
bbcode = self._escapetag(bbcode)
self._send(f"@planet-casio.com/v4-bbcode={bbcode} PRIVMSG {target} :{message}")
else:
self._send(f"PRIVMSG {target} :{message}")
self._send(f"PRIVMSG {target} :{message}")
def receive(self):
""" Receive a private message """
@ -163,18 +156,9 @@ class IRC(object):
msg = self._recv()
return msg
def _escapetag(self, text):
""" Escape text as an IRC tag """
text = text.replace("\\", "\\\\")
text = text.replace(";", "\\:")
text = text.replace(" ", "\\s")
text = text.replace("\r", "\\r")
text = text.replace("\n", "\\n")
return text
class IRCMessage(object):
r = re.compile("^(?:@[^ ]+ *)?:(?P<author>[\w.~|\[\]]+)(?:!(?P<host>\S+))? PRIVMSG (?P<to>\S+) :(?P<text>.+)")
r = re.compile("^:(?P<author>[\w.~|\[\]]+)(?:!(?P<host>\S+))? PRIVMSG (?P<to>\S+) :(?P<text>.+)")
def __init__(self, raw):
match = re.search(IRCMessage.r, raw)

View File

@ -22,7 +22,7 @@ class Shoutbox(object):
self._handler = Thread(target=self._handle)
for channel, last_id in self.channels.items():
messages = json.loads(r.get(f"https://www.planet-casio.com/Fr/shoutbox/api/read?since={last_id}&channel={channel}&format=textbbcode").text)['messages']
messages = json.loads(r.get(f"https://www.planet-casio.com/Fr/shoutbox/api/read?since={last_id}&channel={channel}&format=irc").text)['messages']
for m in messages:
self.channels[channel] = m['id']
@ -82,7 +82,7 @@ class Shoutbox(object):
for channel, last_id in self.channels.items():
# Do not spam with logs
logging.getLogger().setLevel(logging.INFO)
messages = json.loads(r.get(f"https://www.planet-casio.com/Fr/shoutbox/api/read?since={last_id}&channel={channel}&format=textbbcode").text)['messages']
messages = json.loads(r.get(f"https://www.planet-casio.com/Fr/shoutbox/api/read?since={last_id}&channel={channel}&format=irc").text)['messages']
logging.getLogger().setLevel(logging.DEBUG)
for m in messages:
logging.debug(m)
@ -134,4 +134,3 @@ class SBMessage(object):
self.author = raw['author']
self.channel = channel
self.text = raw['content']
self.bbcode = raw['bbcode']