File size: 39,100 Bytes
056f521 82e775f 056f521 d81ce4e 056f521 d81ce4e 056f521 134d2fa 056f521 d81ce4e 056f521 d81ce4e 056f521 d81ce4e 056f521 d81ce4e 056f521 d81ce4e 056f521 7268842 056f521 7268842 056f521 7268842 056f521 82e775f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 |
# https://github.com/Infamous-Hydra/YaeMiko
# https://github.com/Team-ProjectCodeX
# <============================================== IMPORTS =========================================================>
import asyncio
import contextlib
import importlib
import json
import re
import time
import traceback
from platform import python_version
from random import choice
import asyncio
from . import initialize
import psutil
import pyrogram
import telegram
import telethon
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.constants import ParseMode
from telegram.error import (
BadRequest,
ChatMigrated,
Forbidden,
NetworkError,
TelegramError,
TimedOut,
)
from telegram.ext import (
ApplicationHandlerStop,
CallbackQueryHandler,
CommandHandler,
ContextTypes,
MessageHandler,
filters,
)
from telegram.helpers import escape_markdown
from Infamous.karma import *
from Mikobot import (
BOT_NAME,
LOGGER,
OWNER_ID,
SUPPORT_CHAT,
TOKEN,
StartTime,
app,
dispatcher,
function,
loop,
tbot,
)
from Mikobot.plugins import ALL_MODULES
from Mikobot.plugins.helper_funcs.chat_status import is_user_admin
from Mikobot.plugins.helper_funcs.misc import paginate_modules
# <=======================================================================================================>
PYTHON_VERSION = python_version()
PTB_VERSION = telegram.__version__
PYROGRAM_VERSION = pyrogram.__version__
TELETHON_VERSION = telethon.__version__
# <============================================== FUNCTIONS =========================================================>
def get_readable_time(seconds: int) -> str:
count = 0
ping_time = ""
time_list = []
time_suffix_list = ["s", "m", "h", "days"]
while count < 4:
count += 1
remainder, result = divmod(seconds, 60) if count < 3 else divmod(seconds, 24)
if seconds == 0 and remainder == 0:
break
time_list.append(int(result))
seconds = int(remainder)
for x in range(len(time_list)):
time_list[x] = str(time_list[x]) + time_suffix_list[x]
if len(time_list) == 4:
ping_time += time_list.pop() + ", "
time_list.reverse()
ping_time += ":".join(time_list)
return ping_time
IMPORTED = {}
MIGRATEABLE = []
HELPABLE = {}
STATS = []
USER_INFO = []
DATA_IMPORT = []
DATA_EXPORT = []
CHAT_SETTINGS = {}
USER_SETTINGS = {}
for module_name in ALL_MODULES:
imported_module = importlib.import_module("Mikobot.plugins." + module_name)
if not hasattr(imported_module, "__mod_name__"):
imported_module.__mod_name__ = imported_module.__name__
if imported_module.__mod_name__.lower() not in IMPORTED:
IMPORTED[imported_module.__mod_name__.lower()] = imported_module
else:
raise Exception("Can't have two modules with the same name! Please change one")
if hasattr(imported_module, "__help__") and imported_module.__help__:
HELPABLE[imported_module.__mod_name__.lower()] = imported_module
# Chats to migrate on chat_migrated events
if hasattr(imported_module, "__migrate__"):
MIGRATEABLE.append(imported_module)
if hasattr(imported_module, "__stats__"):
STATS.append(imported_module)
if hasattr(imported_module, "__user_info__"):
USER_INFO.append(imported_module)
if hasattr(imported_module, "__import_data__"):
DATA_IMPORT.append(imported_module)
if hasattr(imported_module, "__export_data__"):
DATA_EXPORT.append(imported_module)
if hasattr(imported_module, "__chat_settings__"):
CHAT_SETTINGS[imported_module.__mod_name__.lower()] = imported_module
if hasattr(imported_module, "__user_settings__"):
USER_SETTINGS[imported_module.__mod_name__.lower()] = imported_module
# do not async
async def send_help(chat_id, text, keyboard=None):
if not keyboard:
keyboard = InlineKeyboardMarkup(paginate_modules(0, HELPABLE, "help"))
await dispatcher.bot.send_message(
chat_id=chat_id,
text=text,
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True,
reply_markup=keyboard,
)
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
args = context.args
message = update.effective_message
uptime = get_readable_time((time.time() - StartTime))
if update.effective_chat.type == "private":
if len(args) >= 1:
if args[0].lower() == "help":
await send_help(update.effective_chat.id, HELP_STRINGS)
elif args[0].lower().startswith("ghelp_"):
mod = args[0].lower().split("_", 1)[1]
if not HELPABLE.get(mod, False):
return
await send_help(
update.effective_chat.id,
HELPABLE[mod].__help__,
InlineKeyboardMarkup(
[[InlineKeyboardButton(text="โ", callback_data="help_back")]]
),
)
elif args[0].lower() == "markdownhelp":
IMPORTED["exแดสแดs"].markdown_help_sender(update)
elif args[0].lower().startswith("stngs_"):
match = re.match("stngs_(.*)", args[0].lower())
chat = dispatcher.bot.getChat(match.group(1))
if is_user_admin(chat, update.effective_user.id):
send_settings(match.group(1), update.effective_user.id, False)
else:
send_settings(match.group(1), update.effective_user.id, True)
elif args[0][1:].isdigit() and "rules" in IMPORTED:
await IMPORTED["rules"].send_rules(update, args[0], from_pm=True)
else:
first_name = update.effective_user.first_name
lol = await message.reply_photo(
photo=str(choice(START_IMG)),
caption=FIRST_PART_TEXT.format(escape_markdown(first_name)),
parse_mode=ParseMode.MARKDOWN,
)
await asyncio.sleep(0.2)
guu = await update.effective_message.reply_text("๐พ")
await asyncio.sleep(1.8)
await guu.delete() # Await this line
await update.effective_message.reply_text(
PM_START_TEXT,
reply_markup=InlineKeyboardMarkup(START_BTN),
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=False,
)
else:
await message.reply_photo(
photo=str(choice(START_IMG)),
reply_markup=InlineKeyboardMarkup(GROUP_START_BTN),
caption="<b>I am Alive!</b>\n\n<b>Sinceโ:</b> <code>{}</code>".format(
uptime
),
parse_mode=ParseMode.HTML,
)
async def extra_command_handlered(update: Update, context: ContextTypes.DEFAULT_TYPE):
keyboard = [
[
InlineKeyboardButton("MANAGEMENT", callback_data="help_back"),
InlineKeyboardButton("AI", callback_data="ai_command_handler"),
],
[
InlineKeyboardButton("ANIME", callback_data="anime_command_handler"),
InlineKeyboardButton("GENSHIN", callback_data="genshin_command_handler"),
],
[
InlineKeyboardButton("HOME", callback_data="Miko_back"),
],
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(
"๐๐๐ก๐๐๐ฉ ๐ฉ๐๐ [๐จ๐๐๐ฉ๐๐ค๐ฃ](https://files.catbox.moe/e7upyx.jpg) ๐ฉ๐๐๐ฉ ๐ฎ๐ค๐ช ๐ฌ๐๐ฃ๐ฉ ๐ฉ๐ค ๐ค๐ฅ๐๐ฃ",
reply_markup=reply_markup,
parse_mode="Markdown",
)
async def extra_command_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
if query.data == "extra_command_handler":
await query.answer() # Use 'await' for asynchronous calls
await query.message.edit_text(
"๐๐๐ก๐๐๐ฉ ๐ฉ๐๐ [๐จ๐๐๐ฉ๐๐ค๐ฃ](https://files.catbox.moe/e7upyx.jpg) ๐ฉ๐๐๐ฉ ๐ฎ๐ค๐ช ๐ฌ๐๐ฃ๐ฉ ๐ฉ๐ค ๐ค๐ฅ๐๐ฃ",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton("MANAGEMENT", callback_data="help_back"),
InlineKeyboardButton("AI", callback_data="ai_command_handler"),
],
[
InlineKeyboardButton(
"ANIME", callback_data="anime_command_handler"
),
InlineKeyboardButton(
"GENSHIN", callback_data="genshin_command_handler"
),
],
[
InlineKeyboardButton("HOME", callback_data="Miko_back"),
],
]
),
parse_mode="Markdown", # Added this line to explicitly specify Markdown parsing
)
async def ai_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
keyboard = [
[
InlineKeyboardButton("AI", callback_data="ai_handler"),
InlineKeyboardButton("IMAGEGEN", callback_data="more_aihandlered"),
],
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(
"*Here are the options for* [๐ง๐๐จ๐ค๐ก๐ช๐ฉ๐ ๐๐๐๐๐ฃ๐๐๐ง](https://files.catbox.moe/e7upyx.jpg):",
reply_markup=reply_markup,
parse_mode="Markdown",
)
async def ai_command_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
if query.data == "ai_command_handler":
await query.answer()
await query.message.edit_text(
"*Here are the options for* [๐ง๐๐จ๐ค๐ก๐ช๐ฉ๐ ๐๐๐๐๐ฃ๐๐๐ง](https://files.catbox.moe/e7upyx.jpg):",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton("AI", callback_data="ai_handler"),
InlineKeyboardButton(
"IMAGEGEN", callback_data="more_aihandlered"
),
],
[
InlineKeyboardButton(
"ยป ๐ฝ๐ผ๐พ๐ ยซ", callback_data="extra_command_handler"
),
],
]
),
parse_mode="Markdown",
)
async def ai_handler_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
if query.data == "ai_handler":
await query.answer()
await query.message.edit_text(
"[๐๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ถ๐ฎ๐น ๐๐ป๐๐ฒ๐น๐น๐ถ๐ด๐ฒ๐ป๐ ๐๐๐ป๐ฐ๐๐ถ๐ผ๐ป๐](https://files.catbox.moe/e7upyx.jpg):\n\n"
"All Commands:\n"
"โฝ /askgpt <write query>: A chatbot using GPT for responding to user queries.\n\n"
"โฝ /palm <write prompt>: Performs a Palm search using a chatbot.\n\n"
"โฝ /upscale <reply to image>: Upscales your image quality.",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"More Image Gen โช", callback_data="more_ai_handler"
),
],
[
InlineKeyboardButton(
"โฆ BACK", callback_data="ai_command_handler"
),
],
],
),
parse_mode="Markdown",
)
async def more_ai_handler_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
if query.data == "more_ai_handler":
await query.answer()
await query.message.edit_text(
"*Here's more image gen related commands*:\n\n"
"Command: /meinamix\n"
" โข Description: Generates an image using the meinamix model.\n\n"
"Command: /darksushi\n"
" โข Description: Generates an image using the darksushi model.\n\n"
"Command: /meinahentai\n"
" โข Description: Generates an image using the meinahentai model.\n\n"
"Command: /darksushimix\n"
" โข Description: Generates an image using the darksushimix model.\n\n"
"Command: /anylora\n"
" โข Description: Generates an image using the anylora model.\n\n"
"Command: /cetsumix\n"
" โข Description: Generates an image using the cetsumix model.\n\n"
"Command: /anything\n"
" โข Description: Generates an image using the anything model.\n\n"
"Command: /absolute\n"
" โข Description: Generates an image using the absolute model.\n\n"
"Command: /darkv2\n"
" โข Description: Generates an image using the darkv2 model.\n\n"
"Command: /creative\n"
" โข Description: Generates an image using the creative model.",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton("โฆ BACK", callback_data="ai_handler"),
],
],
),
)
async def more_aihandlered_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
if query.data == "more_aihandlered":
await query.answer()
await query.message.edit_text(
"*Here's more image gen related commands*:\n\n"
"*Command*: /meinamix\n"
" โข Description: Generates an image using the meinamix model.\n\n"
"*Command*: /darksushi\n"
" โข Description: Generates an image using the darksushi model.\n\n"
"*Command*: /meinahentai\n"
" โข Description: Generates an image using the meinahentai model.\n\n"
"*Command*: /darksushimix\n"
" โข Description: Generates an image using the darksushimix model.\n\n"
"*Command*: /anylora\n"
" โข Description: Generates an image using the anylora model.\n\n"
"*Command*: /cetsumix\n"
" โข Description: Generates an image using the cetsumix model.\n\n"
"*Command*: /anything\n"
" โข Description: Generates an image using the anything model.\n\n"
"*Command*: /absolute\n"
" โข Description: Generates an image using the absolute model.\n\n"
"*Command*: /darkv2\n"
" โข Description: Generates an image using the darkv2 model.\n\n"
"*Command*: /creative\n"
" โข Description: Generates an image using the creative model.",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"โฆ BACK", callback_data="ai_command_handler"
),
],
],
),
)
async def anime_command_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
if query.data == "anime_command_handler":
await query.answer()
await query.message.edit_text(
"โฉ[๐๐ป๐ถ๐บ๐ฒ ๐จ๐ฝ๐ฑ๐ฎ๐๐ฒ๐](https://files.catbox.moe/lmfwck.jpg) :\n\n"
"**โ /anime: **fetches info on single anime (includes buttons to look up for prequels and sequels)\n"
"**โ /character: **fetches info on multiple possible characters related to query\n"
"**โ /manga: **fetches info on multiple possible mangas related to query\n"
"**โ /airing: **fetches info on airing data for anime\n"
"**โ /studio: **fetches info on multiple possible studios related to query\n"
"**โ /schedule: **fetches scheduled animes\n"
"**โ /browse: **get popular, trending or upcoming animes\n"
"**โ /top: **to retrieve top animes for a genre or tag\n"
"**โ /watch: **fetches watch order for anime series\n"
"**โ /fillers: **to get a list of anime fillers\n"
"**โ /gettags: **get a list of available tags\n"
"**โ /animequotes: **get random anime quotes\n"
"**โ /getgenres: **Get list of available Genres\n\n"
"**โ๏ธ Group Settings:**\n"
"**โ**\n"
"**โ /anisettings: **to toggle NSFW lock and airing notifications and other settings in groups (anime news)\n"
"**โ**",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton("More Info", url="https://anilist.co/"),
InlineKeyboardButton(
"ใflash", url="https://t.me/SERENE_SPEARMAN"
),
],
[
InlineKeyboardButton(
"ยป ๐ฝ๐ผ๐พ๐ ยซ", callback_data="extra_command_handler"
),
],
]
),
parse_mode="Markdown", # Added this line to explicitly specify Markdown parsing
)
async def genshin_command_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
if query.data == "genshin_command_handler":
await query.answer()
await query.message.edit_text(
"โฉ [๐๐ฒ๐ป๐๐ต๐ถ๐ป ๐๐บ๐ฝ๐ฎ๐ฐ๐](https://files.catbox.moe/lmfwck.jpg) โฉ\n\n"
"*UNDER DEVELOPMENT*",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"More Info", url="https://genshin.mihoyo.com/"
),
],
[
InlineKeyboardButton(
"ยป ๐ฝ๐ผ๐พ๐ ยซ", callback_data="extra_command_handler"
),
],
]
),
parse_mode="Markdown", # Added this line to explicitly specify Markdown parsing
)
async def error_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Log the error and send a telegram message to notify the developer."""
# Log the error before we do anything else, so we can see it even if something breaks.
LOGGER.error(msg="Exception while handling an update:", exc_info=context.error)
# traceback.format_exception returns the usual python message about an exception, but as a
# list of strings rather than a single string, so we have to join them together.
tb_list = traceback.format_exception(
None, context.error, context.error.__traceback__
)
tb = "".join(tb_list)
# Build the message with some markup and additional information about what happened.
message = (
"An exception was raised while handling an update\n"
"<pre>update = {}</pre>\n\n"
"<pre>{}</pre>"
).format(
html.escape(json.dumps(update.to_dict(), indent=2, ensure_ascii=False)),
html.escape(tb),
)
if len(message) >= 4096:
message = message[:4096]
# Finally, send the message
await context.bot.send_message(
chat_id=OWNER_ID, text=message, parse_mode=ParseMode.HTML
)
# for test purposes
async def error_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
error = context.error
try:
raise error
except Forbidden:
print("no nono1")
print(error)
# remove update.message.chat_id from conversation list
except BadRequest:
print("no nono2")
print("BadRequest caught")
print(error)
# handle malformed requests - read more below!
except TimedOut:
print("no nono3")
# handle slow connection problems
except NetworkError:
print("no nono4")
# handle other connection problems
except ChatMigrated as err:
print("no nono5")
print(err)
# the chat_id of a group has changed, use e.new_chat_id instead
except TelegramError:
print(error)
# handle all other telegram related errors
async def help_button(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
mod_match = re.match(r"help_module\((.+?)\)", query.data)
prev_match = re.match(r"help_prev\((.+?)\)", query.data)
next_match = re.match(r"help_next\((.+?)\)", query.data)
back_match = re.match(r"help_back", query.data)
print(query.message.chat.id)
try:
if mod_match:
module = mod_match.group(1)
text = (
"โฒ *HELP SECTION OF* *{}* :\n".format(HELPABLE[module].__mod_name__)
+ HELPABLE[module].__help__
)
await query.message.edit_text(
text=text,
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton(text="โ", callback_data="help_back")]]
),
)
elif prev_match:
curr_page = int(prev_match.group(1))
await query.message.edit_text(
text=HELP_STRINGS,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(
paginate_modules(curr_page - 1, HELPABLE, "help")
),
)
elif next_match:
next_page = int(next_match.group(1))
await query.message.edit_text(
text=HELP_STRINGS,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(
paginate_modules(next_page + 1, HELPABLE, "help")
),
)
elif back_match:
await query.message.edit_text(
text=HELP_STRINGS,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(
paginate_modules(0, HELPABLE, "help")
),
)
await context.bot.answer_callback_query(query.id)
except BadRequest:
pass
async def stats_back(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
if query.data == "insider_":
uptime = get_readable_time((time.time() - StartTime))
cpu = psutil.cpu_percent(interval=0.5)
mem = psutil.virtual_memory().percent
disk = psutil.disk_usage("/").percent
text = f"""
๐๐ฎ๐จ๐ฉ๐๐ข ๐จ๐ฉ๐๐ฉ๐จ
โโโโโโ
UPTIME โผ {uptime}
CPU โผ {cpu}%
RAM โผ {mem}%
DISK โผ {disk}%
PYTHON โผ {PYTHON_VERSION}
PTB โผ {PTB_VERSION}
TELETHON โผ {TELETHON_VERSION}
PYROGRAM โผ {PYROGRAM_VERSION}
"""
await query.answer(text=text, show_alert=True)
async def gitsource_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
await query.answer()
if query.data == "git_source":
source_link = "https://github.com/Infamous-Hydra/YaeMiko"
message_text = (
f"*Here is the link for the public source repo*:\n\n{source_link}"
)
# Adding the inline button
keyboard = [[InlineKeyboardButton(text="โ", callback_data="Miko_back")]]
reply_markup = InlineKeyboardMarkup(keyboard)
await query.edit_message_text(
message_text,
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=False,
reply_markup=reply_markup,
)
async def repo(update: Update, context: ContextTypes.DEFAULT_TYPE):
source_link = "https://www.youtube.com/"
message_text = f"*Here is the link for the public source repo*:\n\n{source_link}"
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=message_text,
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=False,
)
async def Miko_about_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
if query.data == "Miko_":
uptime = get_readable_time((time.time() - StartTime))
message_text = (
f"โฒ <b>Ai integration.</b>"
f"\nโฒ <b>Advance management capability.</b>"
f"\nโฒ <b>Anime bot functionality.</b>"
f"\n\n<b>Click on the buttons below for getting help and info about</b> {BOT_NAME}."
)
await query.message.edit_text(
text=message_text,
disable_web_page_preview=True,
parse_mode=ParseMode.HTML,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text="ABOUT", callback_data="Miko_support"
),
InlineKeyboardButton(text="COMMAND", callback_data="help_back"),
],
[
InlineKeyboardButton(text="INSIDER", callback_data="insider_"),
],
[
InlineKeyboardButton(text="โ", callback_data="Miko_back"),
],
]
),
)
elif query.data == "Miko_support":
message_text = (
"*Our bot leverages SQL, MongoDB, Telegram, MTProto for secure and efficient operations. It resides on a high-speed server, integrates numerous APIs, ensuring quick and versatile responses to user queries.*"
f"\n\n*If you find any bug in {BOT_NAME} Please report it at the support chat.*"
)
await query.message.edit_text(
text=message_text,
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text="SUPPORT", url=f"https://t.me/{SUPPORT_CHAT}"
),
InlineKeyboardButton(
text="DEVELOPER", url=f"tg://user?id={OWNER_ID}"
),
],
[
InlineKeyboardButton(text="โ", callback_data="Miko_"),
],
]
),
)
elif query.data == "Miko_back":
first_name = update.effective_user.first_name
await query.message.edit_text(
PM_START_TEXT.format(escape_markdown(first_name), BOT_NAME),
reply_markup=InlineKeyboardMarkup(START_BTN),
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True,
)
async def get_help(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat = update.effective_chat # type: Optional[Chat]
args = update.effective_message.text.split(None, 1)
# ONLY send help in PM
if chat.type != chat.PRIVATE:
if len(args) >= 2 and any(args[1].lower() == x for x in HELPABLE):
module = args[1].lower()
await update.effective_message.reply_text(
f"Contact me in PM to get help of {module.capitalize()}",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text="HELP",
url="https://t.me/{}?start=ghelp_{}".format(
context.bot.username, module
),
)
]
]
),
)
return
await update.effective_message.reply_text(
"ยป *Choose an option for getting* [๐ต๐ฒ๐น๐ฝ](https://files.catbox.moe/lmfwck.jpg)",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text="OPEN IN PM",
url="https://t.me/{}?start=help".format(
context.bot.username
),
)
],
[
InlineKeyboardButton(
text="OPEN HERE",
callback_data="extra_command_handler",
)
],
]
),
parse_mode="Markdown", # Added this line to explicitly specify Markdown parsing
)
return
elif len(args) >= 2 and any(args[1].lower() == x for x in HELPABLE):
module = args[1].lower()
text = (
"Here is the available help for the *{}* module:\n".format(
HELPABLE[module].__mod_name__
)
+ HELPABLE[module].__help__
)
await send_help(
chat.id,
text,
InlineKeyboardMarkup(
[[InlineKeyboardButton(text="โ", callback_data="help_back")]]
),
)
else:
await send_help(chat.id, HELP_STRINGS)
async def send_settings(chat_id, user_id, user=False):
if user:
if USER_SETTINGS:
settings = "\n\n".join(
"*{}*:\n{}".format(mod.__mod_name__, mod.__user_settings__(user_id))
for mod in USER_SETTINGS.values()
)
await dispatcher.bot.send_message(
user_id,
"These are your current settings:" + "\n\n" + settings,
parse_mode=ParseMode.MARKDOWN,
)
else:
await dispatcher.bot.send_message(
user_id,
"Seems like there aren't any user specific settings available :'(",
parse_mode=ParseMode.MARKDOWN,
)
else:
if CHAT_SETTINGS:
chat_name = dispatcher.bot.getChat(chat_id).title
await dispatcher.bot.send_message(
user_id,
text="Which module would you like to check {}'s settings for?".format(
chat_name
),
reply_markup=InlineKeyboardMarkup(
paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id)
),
)
else:
await dispatcher.bot.send_message(
user_id,
"Seems like there aren't any chat settings available :'(\nSend this "
"in a group chat you're admin in to find its current settings!",
parse_mode=ParseMode.MARKDOWN,
)
async def settings_button(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
user = update.effective_user
bot = context.bot
mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data)
prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data)
next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data)
back_match = re.match(r"stngs_back\((.+?)\)", query.data)
try:
if mod_match:
chat_id = mod_match.group(1)
module = mod_match.group(2)
chat = bot.get_chat(chat_id)
text = "*{}* has the following settings for the *{}* module:\n\n".format(
escape_markdown(chat.title), CHAT_SETTINGS[module].__mod_name__
) + CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id)
await query.message.reply_text(
text=text,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text="โ",
callback_data="stngs_back({})".format(chat_id),
)
]
]
),
)
elif prev_match:
chat_id = prev_match.group(1)
curr_page = int(prev_match.group(2))
chat = bot.get_chat(chat_id)
await query.message.reply_text(
"Hi there! There are quite a few settings for {} - go ahead and pick what "
"you're interested in.".format(chat.title),
reply_markup=InlineKeyboardMarkup(
paginate_modules(
curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id
)
),
)
elif next_match:
chat_id = next_match.group(1)
next_page = int(next_match.group(2))
chat = bot.get_chat(chat_id)
await query.message.reply_text(
"Hi there! There are quite a few settings for {} - go ahead and pick what "
"you're interested in.".format(chat.title),
reply_markup=InlineKeyboardMarkup(
paginate_modules(
next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id
)
),
)
elif back_match:
chat_id = back_match.group(1)
chat = bot.get_chat(chat_id)
await query.message.reply_text(
text="Hi there! There are quite a few settings for {} - go ahead and pick what "
"you're interested in.".format(escape_markdown(chat.title)),
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(
paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id)
),
)
# ensure no spinny white circle
bot.answer_callback_query(query.id)
await query.message.delete()
except BadRequest as excp:
if excp.message not in [
"Message is not modified",
"Query_id_invalid",
"Message can't be deleted",
]:
LOGGER.exception("Exception in settings buttons. %s", str(query.data))
async def get_settings(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat = update.effective_chat # type: Optional[Chat]
user = update.effective_user # type: Optional[User]
msg = update.effective_message # type: Optional[Message]
# ONLY send settings in PM
if chat.type != chat.PRIVATE:
if is_user_admin(chat, user.id):
text = "Click here to get this chat's settings, as well as yours."
await msg.reply_text(
text,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text="SETTINGS",
url="t.me/{}?start=stngs_{}".format(
context.bot.username, chat.id
),
)
]
]
),
)
else:
text = "Click here to check your settings."
else:
await send_settings(chat.id, user.id, True)
async def migrate_chats(update: Update, context: ContextTypes.DEFAULT_TYPE):
msg = update.effective_message # type: Optional[Message]
if msg.migrate_to_chat_id:
old_chat = update.effective_chat.id
new_chat = msg.migrate_to_chat_id
elif msg.migrate_from_chat_id:
old_chat = msg.migrate_from_chat_id
new_chat = update.effective_chat.id
else:
return
LOGGER.info("Migrating from %s, แดแด %s", str(old_chat), str(new_chat))
for mod in MIGRATEABLE:
with contextlib.suppress(KeyError, AttributeError):
mod.__migrate__(old_chat, new_chat)
LOGGER.info("Successfully Migrated!")
raise ApplicationHandlerStop
# <=======================================================================================================>
# <=================================================== MAIN ====================================================>
def main():
function(CommandHandler("start", start))
function(CommandHandler("help", extra_command_handlered))
function(CallbackQueryHandler(help_button, pattern=r"help_.*"))
function(CommandHandler("settings", get_settings))
function(CallbackQueryHandler(settings_button, pattern=r"stngs_"))
function(CommandHandler("repo", repo))
function(CallbackQueryHandler(Miko_about_callback, pattern=r"Miko_"))
function(CallbackQueryHandler(gitsource_callback, pattern=r"git_source"))
function(CallbackQueryHandler(stats_back, pattern=r"insider_"))
function(MessageHandler(filters.StatusUpdate.MIGRATE, migrate_chats))
function(CallbackQueryHandler(ai_handler_callback, pattern=r"ai_handler"))
function(CallbackQueryHandler(more_ai_handler_callback, pattern=r"more_ai_handler"))
function(CallbackQueryHandler(ai_command_callback, pattern="ai_command_handler"))
function(
CallbackQueryHandler(anime_command_callback, pattern="anime_command_handler")
)
function(
CallbackQueryHandler(more_aihandlered_callback, pattern="more_aihandlered")
)
function(
CallbackQueryHandler(extra_command_callback, pattern="extra_command_handler")
)
function(CommandHandler("ai", ai_command))
function(
CallbackQueryHandler(
genshin_command_callback, pattern="genshin_command_handler"
)
)
dispatcher.add_error_handler(error_callback)
LOGGER.info("Mikobot is starting >> Using long polling.")
dispatcher.run_polling(timeout=15, drop_pending_updates=True)
if __name__ == "__main__":
try:
LOGGER.info("Successfully loaded modules: " + str(ALL_MODULES))
tbot.start(bot_token=TOKEN)
app.start()
main()
except KeyboardInterrupt:
pass
except Exception:
err = traceback.format_exc()
LOGGER.info(err)
finally:
try:
if loop.is_running():
loop.stop()
finally:
loop.close()
LOGGER.info(
"------------------------ Stopped Services ------------------------"
)
# <==================================================== END ===================================================>
if __name__ == '__main__':
asyncio.run(initialize()) |