added general notice support, switched to libera.chat, handle messages without tags

This commit is contained in:
jan6 2021-10-07 22:22:45 +03:00
parent 5bc9edd5c6
commit 5412493052
4 changed files with 23 additions and 16 deletions

View File

@ -1,4 +1,6 @@
from functools import wraps
from irctokens import build
from youtube import YouTube
@ -10,6 +12,9 @@ class Command:
def mesg(self, msg):
self.util.mesg(msg)
def notice(self, msg):
self.util.notice(msg)
def send(self, msg):
self.util.send(msg)
@ -113,19 +118,16 @@ class Command:
@cmd
def ctcp(self, prefix, cmd, pm, line, admin, mesg):
"""CTCP responses"""
notice=self.notice
ctcp = cmd[1:]
if ctcp.startswith("PING"):
if not ctcp.endswith("\x01"):
ctcp = ctcp + "\x01"
self.send(f"NOTICE {self.util.target} \x01" + ctcp)
if not ctcp.endswith("\x01"): ctcp=ctcp+"\x01"
print(ctcp)
self.notice(ctcp)
elif ctcp.startswith("SOURCE"):
self.send(
f"NOTICE {self.util.target} \x01SOURCE "
+ self.config.self.source
+ "\x01"
)
self.notice("\x01SOURCE "+self.config.self.source+"\x01")
elif ctcp.startswith("CLIENTINFO"):
self.send(f"NOTICE {self.util.target} \x01CLIENTINFO PING SOURCE\x01")
self.notice("\x01CLIENTINFO PING SOURCE\x01")
@adm
def quit(self, prefix, cmd, pm, line, admin, mesg):

View File

@ -6,11 +6,11 @@ class config:
source = "https://tildegit.org/jan6/bot6"
class server:
name = "tilde.chat"
host = "tilde.chat"
name = "libera"
host = "irc.libera.chat"
port = 6697
ssl = True
channel = "#botsix"
channel = "##jan6"
capabilities = [
"message-tags",

View File

@ -95,7 +95,7 @@ def stuff(bot, sock):
if line.command == "INVITE":
send(irctokens.build("JOIN", [line.params[1]]).format())
elif line.command == "PRIVMSG":
if not "batch" in line.tags:
if line.tags == None or "batch" not in line.tags:
is_pm = False
target = line.params[0]
if target == self_nick:

11
util.py
View File

@ -61,11 +61,16 @@ class Util:
else:
self.send("NICK " + nick)
def mesg(self, msg: str, t=None):
if t == None:
t = self.target
def _m(self, msg: str, t=None):
if t == None: t = self.target
msg = str(msg).partition("\n")[0]
if len(msg) >= 900:
msg = msg[:900]
self.mesg("message too long!")
return t,msg
def mesg(self, msg: str, t=None):
t,msg=self._m(msg,t)
self.send(irctokens.build("PRIVMSG", [t, str(msg)]).format())
def notice(self, msg: str, t=None):
t,msg=self._m(msg,t)
self.send(irctokens.build("NOTICE", [t, str(msg)]).format())