Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,6 @@ from telegram.ext import Application, CommandHandler, MessageHandler, CallbackQu
|
|
9 |
from pydub import AudioSegment
|
10 |
from io import BytesIO
|
11 |
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
12 |
-
from datetime import datetime, timedelta
|
13 |
|
14 |
# تنظیمات اولیه
|
15 |
TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
|
@@ -85,7 +84,7 @@ MESSAGES = {
|
|
85 |
'membership_required': "برای ادامه کار با ربات و استفاده نامحدود، لطفاً ابتدا عضو کانالهای زیر شوید:",
|
86 |
'btn_join_channel': "عضو شدن 🤝",
|
87 |
'btn_check_membership': "بررسی عضویت ✅",
|
88 |
-
'membership_success': "✅ عضویت شما تأیید شد! اکنون میتوانید به صورت نامحدود از ربات استفاده
|
89 |
'membership_failed': "❌ متاسفم، شما هنوز عضو تمام کانالهای مورد نیاز نیستید. لطفاً ابتدا عضو شوید و سپس دوباره 'بررسی عضویت' را بزنید.",
|
90 |
'not_admin': "شما اجازه دسترسی به این بخش را ندارید.",
|
91 |
'admin_menu_prompt': "به پنل مدیریت لینکها خوش آمدید:",
|
@@ -100,7 +99,14 @@ MESSAGES = {
|
|
100 |
'channel_removed': "✅ کانال '{channel_id}' با موفقیت حذف شد.",
|
101 |
'channel_not_found': "❗️ کانال مورد نظر یافت نشد.",
|
102 |
'invalid_channel_id': "آیدی/لینک کانال نامعتبر است. لطفاً @username یا آیدی عددی (مانند -1001234567890) را ارسال کنید.",
|
103 |
-
'bot_not_admin_in_channel': "ربات ادمین کانال '{channel_id}' نیست یا مجوزهای کافی برای بررسی عضویت را ندارد. لطفاً ربات را به عنوان ادمین با مجوز 'بررسی وضعیت اعضا' در کانال اضافه کنید."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
},
|
105 |
'en': {
|
106 |
'start_welcome': "Hello! I am an audio and video format conversion bot.\n\nTo start, select a feature from the menu below.",
|
@@ -154,7 +160,14 @@ MESSAGES = {
|
|
154 |
'channel_removed': "✅ Channel '{channel_id}' successfully removed.",
|
155 |
'channel_not_found': "❗️ Channel not found.",
|
156 |
'invalid_channel_id': "Invalid channel ID/link. Please send @username or numeric ID (e.g., -1001234567890).",
|
157 |
-
'bot_not_admin_in_channel': "The bot is not an admin in channel '{channel_id}' or does not have sufficient permissions to check membership. Please add the bot as an admin with 'Check members' permission in the channel."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
}
|
159 |
}
|
160 |
|
@@ -586,7 +599,7 @@ async def admin_handle_remove_channel(update: Update, context):
|
|
586 |
await query.edit_message_text(get_message(context, 'channel_not_found'))
|
587 |
return await admin_link_command(update, context)
|
588 |
|
589 |
-
# قابلیت
|
590 |
scheduler = AsyncIOScheduler()
|
591 |
scheduler.start()
|
592 |
|
@@ -615,19 +628,19 @@ async def run_command(update: Update, context):
|
|
615 |
chat_id = update.effective_chat.id
|
616 |
user_id = update.effective_user.id
|
617 |
if update.effective_chat.type not in ['group', 'supergroup']:
|
618 |
-
await update.message.reply_text(
|
619 |
return
|
620 |
try:
|
621 |
chat_member = await context.bot.get_chat_member(chat_id=chat_id, user_id=user_id)
|
622 |
-
if chat_member.status not in ['administrator', 'creator']:
|
623 |
-
|
624 |
-
|
625 |
except Exception as e:
|
626 |
print(f"Error checking admin status: {e}", file=sys.stderr)
|
627 |
-
await update.message.reply_text(
|
628 |
return
|
629 |
if chat_id in group_jobs:
|
630 |
-
await update.message.reply_text(
|
631 |
return
|
632 |
initial_interval = random.randint(21, 180)
|
633 |
job = scheduler.add_job(
|
@@ -640,31 +653,30 @@ if chat_member.status not in ['administrator', 'creator']:
|
|
640 |
)
|
641 |
group_jobs[chat_id] = job
|
642 |
await update.message.reply_text(
|
643 |
-
|
644 |
-
f"پیام بعدی {format_interval(initial_interval)} دیگر ارسال میشود."
|
645 |
)
|
646 |
|
647 |
async def stop_command(update: Update, context):
|
648 |
chat_id = update.effective_chat.id
|
649 |
user_id = update.effective_user.id
|
650 |
if update.effective_chat.type not in ['group', 'supergroup']:
|
651 |
-
await update.message.reply_text(
|
652 |
return
|
653 |
try:
|
654 |
chat_member = await context.bot.get_chat_member(chat_id=chat_id, user_id=user_id)
|
655 |
if chat_member.status not in ['administrator', 'creator']:
|
656 |
-
await update.message.reply_text(
|
657 |
return
|
658 |
except Exception as e:
|
659 |
print(f"Error checking admin status: {e}", file=sys.stderr)
|
660 |
-
await update.message.reply_text(
|
661 |
return
|
662 |
if chat_id not in group_jobs:
|
663 |
-
await update.message.reply_text(
|
664 |
return
|
665 |
job = group_jobs.pop(chat_id)
|
666 |
job.remove()
|
667 |
-
await update.message.reply_text(
|
668 |
|
669 |
def main():
|
670 |
application = Application.builder().token(TOKEN).build()
|
|
|
9 |
from pydub import AudioSegment
|
10 |
from io import BytesIO
|
11 |
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
|
12 |
|
13 |
# تنظیمات اولیه
|
14 |
TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
|
|
|
84 |
'membership_required': "برای ادامه کار با ربات و استفاده نامحدود، لطفاً ابتدا عضو کانالهای زیر شوید:",
|
85 |
'btn_join_channel': "عضو شدن 🤝",
|
86 |
'btn_check_membership': "بررسی عضویت ✅",
|
87 |
+
'membership_success': "✅ عضویت شما تأیید شد! اکنون میتوانید به صورت نامحدود از ربات استفاده کنید.",
|
88 |
'membership_failed': "❌ متاسفم، شما هنوز عضو تمام کانالهای مورد نیاز نیستید. لطفاً ابتدا عضو شوید و سپس دوباره 'بررسی عضویت' را بزنید.",
|
89 |
'not_admin': "شما اجازه دسترسی به این بخش را ندارید.",
|
90 |
'admin_menu_prompt': "به پنل مدیریت لینکها خوش آمدید:",
|
|
|
99 |
'channel_removed': "✅ کانال '{channel_id}' با موفقیت حذف شد.",
|
100 |
'channel_not_found': "❗️ کانال مورد نظر یافت نشد.",
|
101 |
'invalid_channel_id': "آیدی/لینک کانال نامعتبر است. لطفاً @username یا آیدی عددی (مانند -1001234567890) را ارسال کنید.",
|
102 |
+
'bot_not_admin_in_channel': "ربات ادمین کانال '{channel_id}' نیست یا مجوزهای کافی برای بررسی عضویت را ندارد. لطفاً ربات را به عنوان ادمین با مجوز 'بررسی وضعیت اعضا' در کانال اضافه کنید.",
|
103 |
+
'group_only_command': "❌ این دستور فقط در گروهها قابل اجراست.",
|
104 |
+
'not_group_admin': "❌ شما ادمین این گروه نیستید و نمیتوانید این دستور را اجرا کنید.",
|
105 |
+
'random_message_already_active': "❗️ ارسال پیامهای تصادفی در این گروه قبلاً فعال شده است.",
|
106 |
+
'random_message_not_active': "❗️ ارسال پیامهای تصادفی در این گروه فعال نیست.",
|
107 |
+
'random_message_started': "✅ ارسال پیامهای تصادفی در گروه فعال شد.\nپیام بعدی {interval} دیگر ارسال میشود.",
|
108 |
+
'random_message_stopped': "✅ ارسال پیامهای تصادفی در گروه متوقف شد.",
|
109 |
+
'admin_check_error': "❌ خطا در بررسی وضعیت ادمین."
|
110 |
},
|
111 |
'en': {
|
112 |
'start_welcome': "Hello! I am an audio and video format conversion bot.\n\nTo start, select a feature from the menu below.",
|
|
|
160 |
'channel_removed': "✅ Channel '{channel_id}' successfully removed.",
|
161 |
'channel_not_found': "❗️ Channel not found.",
|
162 |
'invalid_channel_id': "Invalid channel ID/link. Please send @username or numeric ID (e.g., -1001234567890).",
|
163 |
+
'bot_not_admin_in_channel': "The bot is not an admin in channel '{channel_id}' or does not have sufficient permissions to check membership. Please add the bot as an admin with 'Check members' permission in the channel.",
|
164 |
+
'group_only_command': "❌ This command can only be used in groups.",
|
165 |
+
'not_group_admin': "❌ You are not an admin of this group and cannot execute this command.",
|
166 |
+
'random_message_already_active': "❗️ Random message sending is already active in this group.",
|
167 |
+
'random_message_not_active': "❗️ Random message sending is not active in this group.",
|
168 |
+
'random_message_started': "✅ Random message sending activated in the group.\nNext message will be sent in {interval}.",
|
169 |
+
'random_message_stopped': "✅ Random message sending stopped in the group.",
|
170 |
+
'admin_check_error': "❌ Error checking admin status."
|
171 |
}
|
172 |
}
|
173 |
|
|
|
599 |
await query.edit_message_text(get_message(context, 'channel_not_found'))
|
600 |
return await admin_link_command(update, context)
|
601 |
|
602 |
+
# قابلیت ارسال پیامهای تصادفی در گروهها
|
603 |
scheduler = AsyncIOScheduler()
|
604 |
scheduler.start()
|
605 |
|
|
|
628 |
chat_id = update.effective_chat.id
|
629 |
user_id = update.effective_user.id
|
630 |
if update.effective_chat.type not in ['group', 'supergroup']:
|
631 |
+
await update.message.reply_text(get_message(context, 'group_only_command'))
|
632 |
return
|
633 |
try:
|
634 |
chat_member = await context.bot.get_chat_member(chat_id=chat_id, user_id=user_id)
|
635 |
+
if chat_member.status not in ['administrator', 'creator']:
|
636 |
+
await update.message.reply_text(get_message(context, 'not_group_admin'))
|
637 |
+
return
|
638 |
except Exception as e:
|
639 |
print(f"Error checking admin status: {e}", file=sys.stderr)
|
640 |
+
await update.message.reply_text(get_message(context, 'admin_check_error'))
|
641 |
return
|
642 |
if chat_id in group_jobs:
|
643 |
+
await update.message.reply_text(get_message(context, 'random_message_already_active'))
|
644 |
return
|
645 |
initial_interval = random.randint(21, 180)
|
646 |
job = scheduler.add_job(
|
|
|
653 |
)
|
654 |
group_jobs[chat_id] = job
|
655 |
await update.message.reply_text(
|
656 |
+
get_message(context, 'random_message_started', interval=format_interval(initial_interval))
|
|
|
657 |
)
|
658 |
|
659 |
async def stop_command(update: Update, context):
|
660 |
chat_id = update.effective_chat.id
|
661 |
user_id = update.effective_user.id
|
662 |
if update.effective_chat.type not in ['group', 'supergroup']:
|
663 |
+
await update.message.reply_text(get_message(context, 'group_only_command'))
|
664 |
return
|
665 |
try:
|
666 |
chat_member = await context.bot.get_chat_member(chat_id=chat_id, user_id=user_id)
|
667 |
if chat_member.status not in ['administrator', 'creator']:
|
668 |
+
await update.message.reply_text(get_message(context, 'not_group_admin'))
|
669 |
return
|
670 |
except Exception as e:
|
671 |
print(f"Error checking admin status: {e}", file=sys.stderr)
|
672 |
+
await update.message.reply_text(get_message(context, 'admin_check_error'))
|
673 |
return
|
674 |
if chat_id not in group_jobs:
|
675 |
+
await update.message.reply_text(get_message(context, 'random_message_not_active'))
|
676 |
return
|
677 |
job = group_jobs.pop(chat_id)
|
678 |
job.remove()
|
679 |
+
await update.message.reply_text(get_message(context, 'random_message_stopped'))
|
680 |
|
681 |
def main():
|
682 |
application = Application.builder().token(TOKEN).build()
|