Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nubuki-all committed Dec 12, 2023
1 parent 65667d2 commit 4cba9ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
13 changes: 13 additions & 0 deletions bot/utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
tgp_client,
time,
)
from bot.config import CMD_SUFFIX as suffix


class Var_list:
Expand Down Expand Up @@ -261,6 +262,18 @@ def replace_proxy(url):
return url


def check_cmds(command: str, *matches: str):
def check_cmd(command: str, match: str):
match += suffix
c = command.split(match, maxsplit=1)
return len(c) == 2 and not c[1]

for match in matches:
if check_cmd(command, match):
return True
return False


def gfn(fn):
"gets module path"
return ".".join([fn.__module__, fn.__qualname__])
Expand Down
15 changes: 1 addition & 14 deletions bot/utils/rss_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
from feedparser import parse as feedparse

from bot import pyro, rss_dict_lock
from bot.config import CMD_SUFFIX as suffix
from bot.config import RSS_CHAT as rss_chat
from bot.config import RSS_DELAY as rss_delay
from bot.workers.auto.schedule import addjob, scheduler
from bot.workers.handlers.queue import enleech, enleech2

from .bot_utils import RSS_DICT as rss_dict
from .bot_utils import get_html
from .bot_utils import check_cmds, get_html
from .db_utils import save2db2
from .log_utils import log
from .msg_utils import send_rss
Expand Down Expand Up @@ -99,18 +98,6 @@ async def rss_monitor():
log(e="No active rss feed\nRss Monitor has been paused!")


def check_cmds(command: str, *matches: str):
def check_cmd(command: str, match: str):
match += suffix
c = command.split(match, maxsplit=1)
return len(c) == 2 and not c[1]

for match in matches:
if check_cmd(command, match):
return True
return False


async def fake_event_handler(event):
"""
Passes the rss message to the bot as a new event.
Expand Down
20 changes: 11 additions & 9 deletions bot/workers/handlers/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from bot.utils.batch_utils import batch_preview, clean_batch
from bot.utils.bot_utils import (
bot_is_paused,
check_cmds,
get_bqueue,
get_f,
get_filename,
Expand Down Expand Up @@ -759,7 +760,8 @@ async def addqueue(event, args, client):
"""
Add replied video to queue with args
Accepts the same argument as /l
can also be used to reuse a leech command
can also be used to reuse a leech command
if user is OWNER
"""
user_id = event.sender_id
if not user_is_allowed(user_id):
Expand All @@ -774,15 +776,15 @@ async def addqueue(event, args, client):
return await event.reply("Try again!")
await pencode(media, args, user_id)
return
if event_2.text.startswith("/l"):
args = (
event_2.text.split(maxsplit=1)[1].strip()
if len(event_2.text.split()) > 1
else None
)
await enleech(event_2, args, client)
if not user_is_owner(user_id):
return
await event.reply(addqueue.__doc__)
command, args = event_2.text.split(maxsplit=1) if (event_2.text and len(event_2.text.split()) > 1) else (event_2.text, None)
if not (command and check_cmds(command, "/l", "/ql", "/qbleech", "/leech")):
return await event.reply(addqueue.__doc__)
if check_cmds(command, "/l", "/leech"):
asyncio.create_task(enleech(event_2, args, client, True))
elif check_cmds(command, "/ql", "/qbleech"):
asyncio.create_task(enleech2(event_2, args, client, True))
except Exception:
await logger(Exception)
finally:
Expand Down

0 comments on commit 4cba9ed

Please sign in to comment.