Skip to content

Commit

Permalink
broadcast and minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Jan 4, 2025
1 parent ab6073f commit 7e1c9ab
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
5 changes: 5 additions & 0 deletions bot/core/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ def add_handlers():
BotCommands.SpeedTest,
CustomFilters.authorized,
),
"broadcast": (
broadcast,
BotCommands.BroadcastCommand,
CustomFilters.owner,
),
}

for handler_func, command_name, custom_filter in command_filters.values():
Expand Down
17 changes: 17 additions & 0 deletions bot/helper/ext_utils/db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,23 @@ async def add_incomplete_task(self, cid, link, tag):
{"_id": link, "cid": cid, "tag": tag},
)

async def get_pm_uids(self):
if self._return:
return None
return [doc["_id"] async for doc in self._db.pm_users[TgClient.ID].find({})]

async def update_pm_users(self, user_id):
if self._return:
return
if not bool(await self._db.pm_users[TgClient.ID].find_one({"_id": user_id})):
await self._db.pm_users[TgClient.ID].insert_one({"_id": user_id})
LOGGER.info(f"New PM User Added : {user_id}")

async def rm_pm_user(self, user_id):
if self._return:
return
await self._db.pm_users[TgClient.ID].delete_one({"_id": user_id})

async def update_user_tdata(self, user_id, token, time):
if self._return:
return
Expand Down
1 change: 1 addition & 0 deletions bot/helper/telegram_helper/bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self):
self.BotSetCommand = f"botsettings{i}"
self.UserSetCommand = f"settings{i}"
self.SpeedTest = f"speedtest{i}"
self.BroadcastCommand = [f"broadcast{i}", "broadcastall"]
self.SelectCommand = f"sel{i}"
self.RssCommand = f"rss{i}"

Expand Down
2 changes: 2 additions & 0 deletions bot/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .bot_settings import edit_bot_settings, send_bot_settings
from .broadcast import broadcast
from .cancel_task import cancel, cancel_all_buttons, cancel_all_update, cancel_multi
from .chat_permission import add_sudo, authorize, remove_sudo, unauthorize
from .clone import clone_node
Expand Down Expand Up @@ -41,6 +42,7 @@
"authorize",
"bot_help",
"bot_stats",
"broadcast",
"cancel",
"cancel_all_buttons",
"cancel_all_update",
Expand Down
14 changes: 3 additions & 11 deletions bot/modules/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from bot import bot
from bot.helper.ext_utils.bot_utils import new_task
from bot.helper.ext_utils.db_handler import Database
from bot.helper.ext_utils.db_handler import database
from bot.helper.ext_utils.status_utils import get_readable_time
from bot.helper.telegram_helper.bot_commands import BotCommands
from bot.helper.telegram_helper.filters import CustomFilters
Expand All @@ -28,7 +28,7 @@ async def broadcast(_, message):
updater = time()
broadcast_message = await send_message(message, "Broadcast in progress...")

for uid in await Database.get_pm_uids():
for uid in await database.get_pm_uids():
try:
await message.reply_to_message.copy(uid)
successful += 1
Expand All @@ -37,7 +37,7 @@ async def broadcast(_, message):
await message.reply_to_message.copy(uid)
successful += 1
except (UserIsBlocked, InputUserDeactivated):
await Database.rm_pm_user(uid)
await database.rm_pm_user(uid)
blocked += 1
except Exception:
unsuccessful += 1
Expand All @@ -63,11 +63,3 @@ def generate_status(total, successful, blocked, unsuccessful, elapsed_time=""):
if elapsed_time:
status += f"\n\n<b>Elapsed Time:</b> {elapsed_time}"
return status


bot.add_handler(
MessageHandler(
broadcast,
filters=command(BotCommands.BroadcastCommand) & CustomFilters.owner,
),
)
11 changes: 9 additions & 2 deletions bot/modules/mirror_leech.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,15 @@ async def new_event(self):
file_ = None

if (
self.link and (is_magnet(self.link) or self.link.endswith(".torrent"))
) or (file_ and file_.file_name.endswith(".torrent")):
self.link
and (
is_magnet(self.link)
or self.link.endswith(".torrent")
)
) or (
file_
and getattr(file_, "file_name", "").endswith(".torrent")
):
self.is_qbit = True

if (
Expand Down
3 changes: 2 additions & 1 deletion bot/modules/speedtest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from speedtest import Speedtest

from bot import LOGGER
from bot.core.aeon_client import TgClient
from bot.helper.ext_utils.bot_utils import new_task
from bot.helper.ext_utils.status_utils import get_readable_file_size
from bot.helper.telegram_helper.message_utils import (
Expand All @@ -21,7 +22,7 @@ def get_speedtest_results():
test.upload()
return test.results

result = get_speedtest_results()
result = await TgClient.bot.loop.run_in_executor(None, get_speedtest_results)

if not result:
await edit_message(speed, "Speedtest failed to complete.")
Expand Down

0 comments on commit 7e1c9ab

Please sign in to comment.