youtube auto-titling now works inline too, and for multiple urls also
This commit is contained in:
parent
fb01696636
commit
baa107fdfa
27
commands.py
27
commands.py
|
@ -107,11 +107,10 @@ 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)
|
||||||
|
@ -126,7 +125,8 @@ class Command:
|
||||||
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"):
|
||||||
|
@ -151,9 +151,20 @@ 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]
|
||||||
|
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:
|
try:
|
||||||
a = YouTube.yt(YouTube, cmd)
|
a = YouTube.yt(YouTube, video)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
a = e
|
a = e
|
||||||
mesg(a)
|
mesg(a)
|
||||||
|
|
15
stuff.py
15
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)
|
||||||
|
@ -93,7 +94,8 @@ def stuff(bot, sock):
|
||||||
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:
|
||||||
|
True
|
||||||
autojoin_done = True
|
autojoin_done = True
|
||||||
elif mode == "normal":
|
elif mode == "normal":
|
||||||
if line.command == "433":
|
if line.command == "433":
|
||||||
|
@ -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
|
||||||
|
|
11
util.py
11
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