diff --git a/commands.py b/commands.py index d370748..e146b74 100644 --- a/commands.py +++ b/commands.py @@ -107,14 +107,13 @@ class Command: elif cmd.startswith("\x01"): command = "ctcp" elif ( - cmd.startswith("yt ") - or cmd.startswith("https://www.youtube.com/watch?v=") - or cmd.startswith("https://m.youtube.com/watch?v=") - or cmd.startswith("https://youtu.be/") - ): + "https://www.youtube.com/watch?v=" + or "https://m.youtube.com/watch?v=" + or "https://youtu.be/" + ) in cmd or cmd.startswith("yt "): command = "yt" else: - #self.mesg(cmd) + # self.mesg(cmd) return if command not in self.config.cmd.disabled: eval(f"self.{command}()") @@ -123,14 +122,15 @@ class Command: @cmd def ctcp(self, prefix, cmd, pm, line, admin, mesg): """CTCP responses""" - notice=self.notice + notice = self.notice ctcp = cmd[1:] if ctcp.startswith("PING"): - if not ctcp.endswith("\x01"): ctcp=ctcp+"\x01" + if not ctcp.endswith("\x01"): + ctcp = ctcp + "\x01" print(ctcp) self.notice(ctcp) elif ctcp.startswith("SOURCE"): - self.notice("\x01SOURCE "+self.config.self.source+"\x01") + self.notice("\x01SOURCE " + self.config.self.source + "\x01") elif ctcp.startswith("CLIENTINFO"): self.notice("\x01CLIENTINFO PING SOURCE\x01") @@ -151,12 +151,23 @@ class Command: """youtube""" if cmd.startswith("yt "): cmd = cmd[3:] - cmd=cmd.split()[0] - try: - a = YouTube.yt(YouTube, cmd) - except Exception as e: - a = e - mesg(a) + # cmd=cmd.split()[0] + urls = [ + i + for i in cmd.split() + if i.startswith( + "https://www.youtube.com/watch?v=" + or "https://m.youtube.com/watch?v=" + or "https://youtu.be/" + ) + ] + # mesg(urls) + for video in urls: + try: + a = YouTube.yt(YouTube, video) + except Exception as e: + a = e + mesg(a) @cmd def echo(self, prefix, cmd, pm, line, admin, mesg): diff --git a/stuff.py b/stuff.py index 40e92d3..6ec13c6 100755 --- a/stuff.py +++ b/stuff.py @@ -4,6 +4,7 @@ from util import Util from commands import Command import sys, importlib, time + def stuff(bot, sock): config = Config util = Util(config, sock) @@ -18,7 +19,7 @@ def stuff(bot, sock): server_caps = [] wanted_caps = config.capabilities chan = config.server.channel # main channel - autojoin_done=False + autojoin_done = False is_pm = False mode = "init" @@ -88,13 +89,14 @@ def stuff(bot, sock): elif mode == "boot": send(irctokens.build("JOIN", [chan]).format()) mode = "normal" - elif mode == "normal" and autojoin_done==False: + elif mode == "normal" and autojoin_done == False: try: for channel in config.server.autojoin: - send("JOIN "+channel) + send("JOIN " + channel) time.sleep(0.25) - except Exception: True - autojoin_done=True + except Exception: + True + autojoin_done = True elif mode == "normal": if line.command == "433": mesg("nick in use!", chan) @@ -115,6 +117,12 @@ def stuff(bot, sock): or line.params[1].startswith(self_nick) or line.params[1][0] in prefixes or line.params[1].startswith("https://") + or ( + "https://www.youtube.com/watch?v=" + or "https://m.youtube.com/watch?v=" + or "https://youtu.be/" + ) + in line.params[1] ): try: cmd = line.params[1] @@ -147,7 +155,10 @@ def stuff(bot, sock): line.tags["account"] in admin_accounts or line.source in admin_users ) - except (KeyError, TypeError): #either no account tag, or no tags at all + except ( + KeyError, + TypeError, + ): # either no account tag, or no tags at all is_adm = line.source in admin_users # update command module's info dynamically for line info diff --git a/util.py b/util.py index d2e0f02..0ebbad5 100644 --- a/util.py +++ b/util.py @@ -1,6 +1,7 @@ import irctokens import time + class Util: def __init__(self, config, sock): self.sock = sock @@ -62,18 +63,24 @@ class Util: self.send("NICK " + nick) def _m(self, msg: str, t=None): - if t == None: t = self.target + 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 + return t, msg + def mesg(self, msg: str, t=None): - t,msg=self._m(msg,t) + t, msg = self._m(msg, t) self.send(irctokens.build("PRIVMSG", [t, str(msg)]).format()) + def action(self, msg: str, t=None): - t,msg=self._m(msg,t) - self.send(irctokens.build("PRIVMSG", [t, "\x01ACTION "+str(msg)+"\x01"]).format()) + t, msg = self._m(msg, t) + self.send( + irctokens.build("PRIVMSG", [t, "\x01ACTION " + str(msg) + "\x01"]).format() + ) + def notice(self, msg: str, t=None): - t,msg=self._m(msg,t) + t, msg = self._m(msg, t) self.send(irctokens.build("NOTICE", [t, str(msg)]).format())