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"):
|
||||
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)
|
||||
|
@ -126,7 +125,8 @@ class Command:
|
|||
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"):
|
||||
|
@ -151,9 +151,20 @@ class Command:
|
|||
"""youtube"""
|
||||
if cmd.startswith("yt "):
|
||||
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:
|
||||
a = YouTube.yt(YouTube, cmd)
|
||||
a = YouTube.yt(YouTube, video)
|
||||
except Exception as e:
|
||||
a = e
|
||||
mesg(a)
|
||||
|
|
15
stuff.py
15
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)
|
||||
|
@ -93,7 +94,8 @@ def stuff(bot, sock):
|
|||
for channel in config.server.autojoin:
|
||||
send("JOIN " + channel)
|
||||
time.sleep(0.25)
|
||||
except Exception: True
|
||||
except Exception:
|
||||
True
|
||||
autojoin_done = True
|
||||
elif mode == "normal":
|
||||
if line.command == "433":
|
||||
|
@ -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
|
||||
|
|
11
util.py
11
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
|
||||
|
||||
def mesg(self, msg: str, t=None):
|
||||
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())
|
||||
self.send(
|
||||
irctokens.build("PRIVMSG", [t, "\x01ACTION " + str(msg) + "\x01"]).format()
|
||||
)
|
||||
|
||||
def notice(self, msg: str, t=None):
|
||||
t, msg = self._m(msg, t)
|
||||
self.send(irctokens.build("NOTICE", [t, str(msg)]).format())
|
||||
|
|
Loading…
Reference in New Issue