youtube auto-titling now works inline too, and for multiple urls also
This commit is contained in:
parent
fb01696636
commit
baa107fdfa
41
commands.py
41
commands.py
|
@ -107,14 +107,13 @@ class Command:
|
||||||
elif cmd.startswith("\x01"):
|
elif cmd.startswith("\x01"):
|
||||||
command = "ctcp"
|
command = "ctcp"
|
||||||
elif (
|
elif (
|
||||||
cmd.startswith("yt ")
|
"https://www.youtube.com/watch?v="
|
||||||
or cmd.startswith("https://www.youtube.com/watch?v=")
|
or "https://m.youtube.com/watch?v="
|
||||||
or cmd.startswith("https://m.youtube.com/watch?v=")
|
or "https://youtu.be/"
|
||||||
or cmd.startswith("https://youtu.be/")
|
) in cmd or cmd.startswith("yt "):
|
||||||
):
|
|
||||||
command = "yt"
|
command = "yt"
|
||||||
else:
|
else:
|
||||||
#self.mesg(cmd)
|
# self.mesg(cmd)
|
||||||
return
|
return
|
||||||
if command not in self.config.cmd.disabled:
|
if command not in self.config.cmd.disabled:
|
||||||
eval(f"self.{command}()")
|
eval(f"self.{command}()")
|
||||||
|
@ -123,14 +122,15 @@ class Command:
|
||||||
@cmd
|
@cmd
|
||||||
def ctcp(self, prefix, cmd, pm, line, admin, mesg):
|
def ctcp(self, prefix, cmd, pm, line, admin, mesg):
|
||||||
"""CTCP responses"""
|
"""CTCP responses"""
|
||||||
notice=self.notice
|
notice = self.notice
|
||||||
ctcp = cmd[1:]
|
ctcp = cmd[1:]
|
||||||
if ctcp.startswith("PING"):
|
if ctcp.startswith("PING"):
|
||||||
if not ctcp.endswith("\x01"): ctcp=ctcp+"\x01"
|
if not ctcp.endswith("\x01"):
|
||||||
|
ctcp = ctcp + "\x01"
|
||||||
print(ctcp)
|
print(ctcp)
|
||||||
self.notice(ctcp)
|
self.notice(ctcp)
|
||||||
elif ctcp.startswith("SOURCE"):
|
elif ctcp.startswith("SOURCE"):
|
||||||
self.notice("\x01SOURCE "+self.config.self.source+"\x01")
|
self.notice("\x01SOURCE " + self.config.self.source + "\x01")
|
||||||
elif ctcp.startswith("CLIENTINFO"):
|
elif ctcp.startswith("CLIENTINFO"):
|
||||||
self.notice("\x01CLIENTINFO PING SOURCE\x01")
|
self.notice("\x01CLIENTINFO PING SOURCE\x01")
|
||||||
|
|
||||||
|
@ -151,12 +151,23 @@ class Command:
|
||||||
"""youtube"""
|
"""youtube"""
|
||||||
if cmd.startswith("yt "):
|
if cmd.startswith("yt "):
|
||||||
cmd = cmd[3:]
|
cmd = cmd[3:]
|
||||||
cmd=cmd.split()[0]
|
# cmd=cmd.split()[0]
|
||||||
try:
|
urls = [
|
||||||
a = YouTube.yt(YouTube, cmd)
|
i
|
||||||
except Exception as e:
|
for i in cmd.split()
|
||||||
a = e
|
if i.startswith(
|
||||||
mesg(a)
|
"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
|
@cmd
|
||||||
def echo(self, prefix, cmd, pm, line, admin, mesg):
|
def echo(self, prefix, cmd, pm, line, admin, mesg):
|
||||||
|
|
23
stuff.py
23
stuff.py
|
@ -4,6 +4,7 @@ from util import Util
|
||||||
from commands import Command
|
from commands import Command
|
||||||
import sys, importlib, time
|
import sys, importlib, time
|
||||||
|
|
||||||
|
|
||||||
def stuff(bot, sock):
|
def stuff(bot, sock):
|
||||||
config = Config
|
config = Config
|
||||||
util = Util(config, sock)
|
util = Util(config, sock)
|
||||||
|
@ -18,7 +19,7 @@ def stuff(bot, sock):
|
||||||
server_caps = []
|
server_caps = []
|
||||||
wanted_caps = config.capabilities
|
wanted_caps = config.capabilities
|
||||||
chan = config.server.channel # main channel
|
chan = config.server.channel # main channel
|
||||||
autojoin_done=False
|
autojoin_done = False
|
||||||
is_pm = False
|
is_pm = False
|
||||||
mode = "init"
|
mode = "init"
|
||||||
|
|
||||||
|
@ -88,13 +89,14 @@ def stuff(bot, sock):
|
||||||
elif mode == "boot":
|
elif mode == "boot":
|
||||||
send(irctokens.build("JOIN", [chan]).format())
|
send(irctokens.build("JOIN", [chan]).format())
|
||||||
mode = "normal"
|
mode = "normal"
|
||||||
elif mode == "normal" and autojoin_done==False:
|
elif mode == "normal" and autojoin_done == False:
|
||||||
try:
|
try:
|
||||||
for channel in config.server.autojoin:
|
for channel in config.server.autojoin:
|
||||||
send("JOIN "+channel)
|
send("JOIN " + channel)
|
||||||
time.sleep(0.25)
|
time.sleep(0.25)
|
||||||
except Exception: True
|
except Exception:
|
||||||
autojoin_done=True
|
True
|
||||||
|
autojoin_done = True
|
||||||
elif mode == "normal":
|
elif mode == "normal":
|
||||||
if line.command == "433":
|
if line.command == "433":
|
||||||
mesg("nick in use!", chan)
|
mesg("nick in use!", chan)
|
||||||
|
@ -115,6 +117,12 @@ def stuff(bot, sock):
|
||||||
or line.params[1].startswith(self_nick)
|
or line.params[1].startswith(self_nick)
|
||||||
or line.params[1][0] in prefixes
|
or line.params[1][0] in prefixes
|
||||||
or line.params[1].startswith("https://")
|
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:
|
try:
|
||||||
cmd = line.params[1]
|
cmd = line.params[1]
|
||||||
|
@ -147,7 +155,10 @@ def stuff(bot, sock):
|
||||||
line.tags["account"] in admin_accounts
|
line.tags["account"] in admin_accounts
|
||||||
or line.source in admin_users
|
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
|
is_adm = line.source in admin_users
|
||||||
|
|
||||||
# update command module's info dynamically for line info
|
# update command module's info dynamically for line info
|
||||||
|
|
19
util.py
19
util.py
|
@ -1,6 +1,7 @@
|
||||||
import irctokens
|
import irctokens
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
class Util:
|
class Util:
|
||||||
def __init__(self, config, sock):
|
def __init__(self, config, sock):
|
||||||
self.sock = sock
|
self.sock = sock
|
||||||
|
@ -62,18 +63,24 @@ class Util:
|
||||||
self.send("NICK " + nick)
|
self.send("NICK " + nick)
|
||||||
|
|
||||||
def _m(self, msg: str, t=None):
|
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]
|
msg = str(msg).partition("\n")[0]
|
||||||
if len(msg) >= 900:
|
if len(msg) >= 900:
|
||||||
msg = msg[:900]
|
msg = msg[:900]
|
||||||
self.mesg("message too long!")
|
self.mesg("message too long!")
|
||||||
return t,msg
|
return t, msg
|
||||||
|
|
||||||
def mesg(self, msg: str, t=None):
|
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())
|
self.send(irctokens.build("PRIVMSG", [t, str(msg)]).format())
|
||||||
|
|
||||||
def action(self, msg: str, t=None):
|
def action(self, msg: str, t=None):
|
||||||
t,msg=self._m(msg,t)
|
t, msg = self._m(msg, t)
|
||||||
self.send(irctokens.build("PRIVMSG", [t, "\x01ACTION "+str(msg)+"\x01"]).format())
|
self.send(
|
||||||
|
irctokens.build("PRIVMSG", [t, "\x01ACTION " + str(msg) + "\x01"]).format()
|
||||||
|
)
|
||||||
|
|
||||||
def notice(self, msg: str, t=None):
|
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())
|
self.send(irctokens.build("NOTICE", [t, str(msg)]).format())
|
||||||
|
|
Loading…
Reference in New Issue