From 5f78254e63b4ab1ceb80061d839dd734273fddf1 Mon Sep 17 00:00:00 2001 From: jan6 Date: Tue, 11 Jan 2022 19:29:42 +0200 Subject: [PATCH] youtube links in /me messages work now (or other ctcp messages) --- commands.py | 4 ++-- config.py | 6 +++--- stuff.py | 40 +++++++++++++++++++++++++++++----------- youtube.py | 1 + 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/commands.py b/commands.py index e146b74..83606d1 100644 --- a/commands.py +++ b/commands.py @@ -104,14 +104,14 @@ class Command: command = "dbg" elif cmd == "dbg2" or cmd.startswith("dbg2 "): command = "dbg2" - elif cmd.startswith("\x01"): - command = "ctcp" elif ( "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" + elif cmd.startswith("\x01") or self.is_ctcp: + command = "ctcp" else: # self.mesg(cmd) return diff --git a/config.py b/config.py index 9885b20..3a04eed 100644 --- a/config.py +++ b/config.py @@ -1,7 +1,7 @@ class config: class self: nick = "bot6" - username = "jan6_bot" + username = "jan6_bot" #you can set it to your username realname = "jan6's bot" source = "https://tildegit.org/jan6/bot6" @@ -11,7 +11,7 @@ class config: port = 6697 ssl = True channel = "##jan6" - autojoin = ["##sharing"] + autojoin = ["##share","#1337331"] class admin: accounts = ["jan6"] @@ -19,7 +19,7 @@ class config: class cmd: prefixes = ["6", "'"] - # disabled commands, won't run via normal means + # disabled commands, won't run via normal means, probably disabled = [] # admin-only override, # useful for testing broken commands which should still be normal-user accessible diff --git a/stuff.py b/stuff.py index 6ec13c6..d3ca040 100755 --- a/stuff.py +++ b/stuff.py @@ -20,6 +20,7 @@ def stuff(bot, sock): wanted_caps = config.capabilities chan = config.server.channel # main channel autojoin_done = False + is_ctcp = False is_pm = False mode = "init" @@ -43,9 +44,16 @@ def stuff(bot, sock): admin_only, ) - command, command.util, config, util, prefixes, admin_accounts, admin_users, admin_only = ( - configure() - ) + ( + command, + command.util, + config, + util, + prefixes, + admin_accounts, + admin_users, + admin_only, + ) = configure() send = util.send send(irctokens.build("NICK", [config.self.nick]).format()) @@ -106,26 +114,28 @@ def stuff(bot, sock): elif line.command == "PRIVMSG": if line.tags == None or "batch" not in line.tags: is_pm = False + is_ctcp = False target = line.params[0] if target == self_nick: target = line.source.split("!")[0] is_pm = True util.target = target command.util.target = target + cmd = line.params[1] + if ( is_pm - or line.params[1].startswith(self_nick) - or line.params[1][0] in prefixes - or line.params[1].startswith("https://") + or cmd.startswith(self_nick) + or cmd[0] in prefixes + or cmd.startswith("https://") or ( "https://www.youtube.com/watch?v=" or "https://m.youtube.com/watch?v=" or "https://youtu.be/" ) - in line.params[1] + in cmd ): try: - cmd = line.params[1] # if message in a channel, remove prefixes if is_pm: command.prefix = None @@ -164,6 +174,7 @@ def stuff(bot, sock): # update command module's info dynamically for line info command.util.target = target command._line = line + command.is_ctcp = is_ctcp command.pm = is_pm command.line = cmd command.admin = is_adm @@ -172,9 +183,16 @@ def stuff(bot, sock): command.prefix = prefix if is_adm and cmd.startswith("reload"): - command, command.util, config, util, prefixes, admin_accounts, admin_users, admin_only = ( - configure() - ) + ( + command, + command.util, + config, + util, + prefixes, + admin_accounts, + admin_users, + admin_only, + ) = configure() util.target = target send = util.send command._line = line diff --git a/youtube.py b/youtube.py index 33d6e8e..f054689 100644 --- a/youtube.py +++ b/youtube.py @@ -33,6 +33,7 @@ class YouTube: return f"{m}m {s}s" def yt(self, url): + url=url.rstrip("\x01") global y, z y, z = {}, {} p = self.parseprop()