Compare commits
2 Commits
24eb9571fb
...
e3b7f076ae
Author | SHA1 | Date |
---|---|---|
Lephenixnoir | e3b7f076ae | |
Lephenixnoir | c2ad050502 |
|
@ -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
22
irc.py
|
@ -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)
|
||||
|
|
|
@ -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']
|
||||
|
|
Loading…
Reference in New Issue