forked from SilentDemonSD/WZML-X
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7097eab
commit bea75ed
Showing
1 changed file
with
55 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,65 @@ | ||
from pymongo import MongoClient | ||
from telegram.ext import CommandHandler, Filters | ||
from random import choice as rchoice | ||
from telegram.ext import CommandHandler | ||
|
||
from bot import bot, dispatcher, LOGGER, config_dict | ||
from bot import config_dict, dispatcher, OWNER_ID | ||
from bot.helper.telegram_helper.filters import CustomFilters | ||
from bot.helper.telegram_helper.message_utils import sendMessage | ||
|
||
def broadcast(update, context): | ||
reply_to = update.message.reply_to_message | ||
from bot.helper.telegram_helper.message_utils import sendMessage, sendPhoto | ||
from bot.helper.telegram_helper.bot_commands import BotCommands | ||
|
||
def dbusers(update, context): | ||
if not config_dict['DATABASE_URL']: | ||
context.bot.send_message(chat_id=update.effective_chat.id, text=f"DATABASE_URL not provided") | ||
else: | ||
conn = MongoClient(config_dict['DATABASE_URL']) | ||
db = conn.mltb | ||
users_collection = db.users | ||
users_count = db.users.count_documents({}) | ||
|
||
chat_ids = [str(user["_id"]) for user in users_collection.find({}, {"_id": 1})] | ||
success = 0 | ||
|
||
for chat_id in chat_ids: | ||
try: | ||
context.bot.copy_message(chat_id=chat_id, from_chat_id=update.message.chat.id, message_id=reply_to.message_id) | ||
success += 1 | ||
except Exception as err: | ||
LOGGER.error(err) | ||
|
||
msg = f"<b>Broadcasting Completed</b>\n" | ||
msg += f"<b>Total {users_count} users in Database</b>\n" | ||
msg += f"<b>Sucess: </b>{success} users\n" | ||
msg += f"<b>Failed: </b>{users_count - success} users" | ||
return sendMessage(msg, context.bot, update.message) | ||
|
||
broadcast_handler = CommandHandler("broadcast", broadcast, filters=CustomFilters.owner_filter) | ||
dispatcher.add_handler(broadcast_handler) | ||
context.bot.send_message(chat_id=update.effective_chat.id, text=f"Total users in database: {users_count}") | ||
|
||
def get_id(update, context): | ||
chat_id = update.effective_chat.id | ||
if update.effective_chat.type == 'private': | ||
user_id = update.message.from_user.id | ||
context.bot.send_message(chat_id=user_id, text=f"Your user ID is: <code>{user_id}</code>") | ||
else: | ||
context.bot.send_message(chat_id=chat_id, text=f"This group's ID is: <code>{chat_id}</code>") | ||
|
||
def bot_limit(update, context): | ||
TORRENT_DIRECT_LIMIT = config_dict['TORRENT_DIRECT_LIMIT'] | ||
CLONE_LIMIT = config_dict['CLONE_LIMIT'] | ||
MEGA_LIMIT = config_dict['MEGA_LIMIT'] | ||
LEECH_LIMIT = config_dict['LEECH_LIMIT'] | ||
ZIP_UNZIP_LIMIT = config_dict['ZIP_UNZIP_LIMIT'] | ||
TOTAL_TASKS_LIMIT = config_dict['TOTAL_TASKS_LIMIT'] | ||
USER_TASKS_LIMIT = config_dict['USER_TASKS_LIMIT'] | ||
|
||
torrent_direct = 'No Limit Set' if TORRENT_DIRECT_LIMIT == '' else f'{TORRENT_DIRECT_LIMIT}GB/Link' | ||
clone_limit = 'No Limit Set' if CLONE_LIMIT == '' else f'{CLONE_LIMIT}GB/Link' | ||
mega_limit = 'No Limit Set' if MEGA_LIMIT == '' else f'{MEGA_LIMIT}GB/Link' | ||
leech_limit = 'No Limit Set' if LEECH_LIMIT == '' else f'{LEECH_LIMIT}GB/Link' | ||
zip_unzip = 'No Limit Set' if ZIP_UNZIP_LIMIT == '' else f'{ZIP_UNZIP_LIMIT}GB/Link' | ||
total_task = 'No Limit Set' if TOTAL_TASKS_LIMIT == '' else f'{TOTAL_TASKS_LIMIT} Total Tasks/Time' | ||
user_task = 'No Limit Set' if USER_TASKS_LIMIT == '' else f'{USER_TASKS_LIMIT} Tasks/user' | ||
|
||
limit = f"<b>🔢 Bot Limitations </b>\n\n"\ | ||
f"Torrent/Direct: {torrent_direct}\n"\ | ||
f"Zip/Unzip: {zip_unzip}\n"\ | ||
f"Leech: {leech_limit}\n"\ | ||
f"Clone: {clone_limit}\n"\ | ||
f"Mega: {mega_limit}\n"\ | ||
f"Total Tasks: {total_task}\n"\ | ||
f"User Tasks: {user_task}\n\n" | ||
|
||
if config_dict['PICS']: | ||
sendPhoto(limit, context.bot, update.message, rchoice(config_dict['PICS'])) | ||
else: | ||
sendMessage(limit, context.bot, update.message) | ||
|
||
dbusers_handler = CommandHandler("dbusers", dbusers, filters=CustomFilters.owner_filter | CustomFilters.sudo_user) | ||
id_handler = CommandHandler("id", get_id) | ||
limit_handler = CommandHandler(BotCommands.LimitCommand, bot_limit, | ||
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user) | ||
|
||
dispatcher.add_handler(dbusers_handler) | ||
dispatcher.add_handler(id_handler) | ||
dispatcher.add_handler(limit_handler) |