File size: 39,936 Bytes
21bc372 7575d98 23de1c5 7575d98 23de1c5 21bc372 |
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 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 |
import datetime
import time
import markdown
import smtplib
from motor import motor_asyncio
from motor.core import AgnosticClient
from motor.motor_asyncio import AsyncIOMotorClient
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from config import *
from akn.utils.logger import LOGS
client_tiktok = AsyncIOMotorClient(MONGO_URL)
db_tiktok = client_tiktok["tiktokbot"]
otp_collection = db_tiktok["otps"]
async def send_check_otp_email(receiver_email, text):
try:
smtp_server = "smtp.gmail.com"
port = 587
sender_email = ME_GMAIL
password = ME_GMAIL_PASSWORD
msg = MIMEMultipart()
msg['From'] = 'Akeno AI <[email protected]>'
msg['To'] = receiver_email
msg['Subject'] = "Verified OTP- Akeno AI API"
html = markdown.markdown(text)
msg.attach(MIMEText(html, 'html'))
server = smtplib.SMTP(smtp_server, port)
server.starttls()
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, msg.as_string())
server.quit()
LOGS.info("Email sent successfully!")
except Exception:
pass
class Database:
def __init__(self, uri: str) -> None:
self.client: AgnosticClient = motor_asyncio.AsyncIOMotorClient(uri)
self.db = self.client["Akeno"]
# tiktok bot
self.db_tiktok = self.client["tiktokbot"]
self.magic_bot = self.db_tiktok["magicbot"]
self.gemini_bot = self.db_tiktok["geminibot"]
self.gpt_4_bot = self.db_tiktok["gpt_4_bot"]
self.meta_bot = self.db_tiktok["metabot"]
self.youtube_bot = self.db_tiktok["youtubebot"]
self.session_bot = self.db_tiktok["sessionbot"]
self.captcha_bot = self.db_tiktok["captchabot"]
self.alldl_bot = self.db_tiktok["alldlbot"]
self.privary_bot = self.db_tiktok["privarybot"]
self.maintance_bot = self.db_tiktok["maintancebot"]
# akeno
self.afk = self.db["afk"]
self.antiflood = self.db["antiflood"]
self.autopost = self.db["autopost"]
self.blacklist = self.db["blacklist"]
self.echo = self.db["echo"]
self.env = self.db["env"]
self.filter = self.db["filter"]
self.forcesub = self.db["forcesub"]
self.gachabots = self.db["gachabots"]
self.cohere = self.db["cohere"]
self.chatbot = self.db["chatbot"]
self.backup_chatbot = self.db["backupchatbot"]
self.antiarabic = self.db["antiarabic"]
self.gban = self.db["gban"]
self.gmute = self.db["gmute"]
self.greetings = self.db["greetings"]
self.mute = self.db["mute"]
self.pmpermit = self.db["pmpermit"]
self.session = self.db["session"]
self.snips = self.db["snips"]
self.stan_users = self.db["stan_users"]
self.expired_users = self.db["expired_users"]
async def connect(self):
try:
await self.client.admin.command("ping")
LOGS.info(f"Database Connection Established!")
except Exception as e:
LOGS.info(f"DatabaseErr: {e} ")
quit(1)
async def _close(self):
await self.client.close()
def get_datetime(self) -> str:
return datetime.datetime.now().strftime("%d/%m/%Y - %H:%M")
async def claim_privacy_policy(self, user_id):
return await self.privary_bot.update_one(
{"user_id": user_id},
{"$set": {"is_claimed": True}},
upsert=True
)
async def set_pic_in_allbot(self, id, link, is_pic):
return await self.privary_bot.update_one(
{"bot_id": id},
{"$set": {"link_pic": link, "is_pic": is_pic}},
upsert=True
)
async def get_pic_in_allbot(self, id):
user_data = await self.privary_bot.find_one({"bot_id": id})
if user_data:
return user_data.get("is_pic"), user_data.get("link_pic")
return False, None
async def fixed_maintance(self, is_maintance):
return await self.maintance_bot.update_one(
{"bot_id": 1},
{"$set": {"is_maintance": is_maintance}},
upsert=True
)
async def get_maintance(self):
user_data = await self.maintance_bot.find_one({"bot_id": 1})
return user_data.get("is_maintance") if user_data else False
async def get_privacy_policy(self, user_id):
user_data = await self.privary_bot.find_one({"user_id": user_id})
return user_data.get("is_claimed") if user_data else None
async def remove_bot_token_magic(self, user_id):
remove_bot_clone = {
"bot_token": None,
"user_id": user_id
}
return await self.magic_bot.update_one({"user_id": user_id}, {"$unset": remove_bot_clone})
async def remove_expired_date(self, user_id):
remove_filter = {"expire_date": None}
return await self.expired_users.update_one({"user_id": user_id}, {"$unset": remove_filter})
async def get_expired_date(self, user_id):
user = await self.expired_users.find_one({"user_id": user_id})
if user:
return user
else:
return None
async def set_expired_date(
self,
user_id,
first_name,
username,
expire_date,
bot_token,
client_name,
disconnected: bool = False
):
add_expired = {
"expire_date": expire_date,
"first_name": first_name,
"username": username,
"user_id": user_id,
"user_client": {
"bot_token": bot_token,
"client_name": client_name,
"disconnected": disconnected
}
}
return await self.expired_users.update_one(
{"user_id": user_id},
{"$set": add_expired},
upsert=True
)
async def set_env(self, name: str, value: str) -> None:
await self.env.update_one(
{"name": name}, {"$set": {"value": value}}, upsert=True
)
async def get_env(self, name: str) -> str | None:
if await self.is_env(name):
data = await self.env.find_one({"name": name})
return data["value"]
return None
async def rm_env(self, name: str) -> None:
await self.env.delete_one({"name": name})
async def is_env(self, name: str) -> bool:
if await self.env.find_one({"name": name}):
return True
return False
async def get_all_env(self) -> list:
return [i async for i in self.env.find({})]
async def is_stan(self, client: int, user_id: int) -> bool:
if await self.stan_users.find_one({"client": client, "user_id": user_id}):
return True
return False
async def add_stan(self, client: int, user_id: int) -> bool:
if await self.is_stan(client, user_id):
return False
await self.stan_users.insert_one(
{"client": client, "user_id": user_id, "date": self.get_datetime()}
)
return True
async def rm_stan(self, client: int, user_id: int) -> bool:
if not await self.is_stan(client, user_id):
return False
await self.stan_users.delete_one({"client": client, "user_id": user_id})
return True
async def get_stans(self, client: int) -> list:
return [i async for i in self.stan_users.find({"client": client})]
async def get_all_stans(self) -> list:
return [i async for i in self.stan_users.find({})]
async def is_session(self, user_id: int) -> bool:
if await self.session.find_one({"user_id": user_id}):
return True
return False
async def update_session(
self,
user_id: int,
api_id: int,
api_hash: str,
session: str,
email: str,
phone_number: str,
verified_password=None
) -> None:
await self.session.update_one(
{"user_id": user_id},
{"$set": {
"session": session,
"api_id": api_id,
"api_hash": api_hash,
"email": email,
"phone_number": phone_number,
"verified_password": verified_password,
"date": self.get_datetime()}
},
upsert=True
)
async def rm_session(self, user_id: int) -> None:
await self.session.delete_one({"user_id": user_id})
async def get_session(self, user_id: int):
if not await self.is_session(user_id):
return False
data = await self.session.find_one({"user_id": user_id})
return data
async def add_bot_token_meta(self, user_id, bot_token):
add_bot_clone = {
"bot_token": bot_token,
"user_id": user_id
}
return await self.meta_bot.update_one({"user_id": user_id}, {"$set": add_bot_clone}, upsert=True)
async def get_all_sessions(self) -> list:
return [i async for i in self.session.find({})]
async def get_all_meta_bot(self) -> list:
return [i async for i in self.meta_bot.find({})]
async def get_all_magic_bot(self) -> list:
return [i async for i in self.magic_bot.find({})]
async def get_all_gemini_bot(self) -> list:
return [i async for i in self.gemini_bot.find({})]
async def get_all_youtube_bot(self) -> list:
return [i async for i in self.youtube_bot.find({})]
async def get_all_session_bot(self) -> list:
return [i async for i in self.session_bot.find({})]
async def get_all_captcha_bot(self) -> list:
return [i async for i in self.captcha_bot.find({})]
async def get_all_alldl_bot(self) -> list:
return [i async for i in self.alldl_bot.find({})]
async def get_alldlbot_by_user_id(self, user_id, id):
user_data = await self.alldl_bot.find_one({
"user_id": user_id,
"bot_id": int(id)
})
LOGS.info(user_data)
return True if user_data else False
async def get_alldlbot_by_no_button(self, id):
user_data = await self.alldl_bot.find_one({"bot_id": id})
if not user_data:
return False
return user_data.get("is_rm_button", False)
#############################################
async def remove_strings_userv(self, user: int) -> bool:
if not user:
LOGS.error(f"Invalid session User format: {type(user)}")
return False
try:
result = await self.session.delete_one({"user_id": user})
if result.deleted_count == 1:
LOGS.info(f"Session User deleted: {user}")
return True
LOGS.warning(f"Session User not found: {user}...")
return False
except Exception as e:
LOGS.critical(f"Deletion failed for {user}...: {str(e)}")
return False
async def remove_bot_token_meta(self, bot_token: str) -> bool:
if not bot_token or not isinstance(bot_token, str):
LOGS.error(f"Invalid token format: {type(bot_token)}")
return False
try:
result = await self.meta_bot.delete_one({"bot_token": bot_token})
if result.deleted_count == 1:
LOGS.info(f"Token deleted: {bot_token[:6]}...{bot_token[-3:]}")
return True
LOGS.warning(f"Token not found: {bot_token[:6]}...")
return False
except Exception as e:
LOGS.critical(f"Deletion failed for {bot_token[:6]}...: {str(e)}")
return False
async def remove_bot_token_magic(self, bot_token: str) -> bool:
if not bot_token or not isinstance(bot_token, str):
LOGS.error(f"Invalid token format: {type(bot_token)}")
return False
try:
result = await self.magic_bot.delete_one({"bot_token": bot_token})
if result.deleted_count == 1:
LOGS.info(f"Token deleted: {bot_token[:6]}...{bot_token[-3:]}")
return True
LOGS.warning(f"Token not found: {bot_token[:6]}...")
return False
except Exception as e:
LOGS.critical(f"Deletion failed for {bot_token[:6]}...: {str(e)}")
return False
async def remove_bot_token_youtube(self, bot_token: str) -> bool:
if not bot_token or not isinstance(bot_token, str):
LOGS.error(f"Invalid token format: {type(bot_token)}")
return False
try:
result = await self.youtube_bot.delete_one({"bot_token": bot_token})
if result.deleted_count == 1:
LOGS.info(f"Token deleted: {bot_token[:6]}...{bot_token[-3:]}")
return True
LOGS.warning(f"Token not found: {bot_token[:6]}...")
return False
except Exception as e:
LOGS.critical(f"Deletion failed for {bot_token[:6]}...: {str(e)}")
return False
async def remove_bot_token_sessionbot(self, bot_token: str) -> bool:
if not bot_token or not isinstance(bot_token, str):
LOGS.error(f"Invalid token format: {type(bot_token)}")
return False
try:
result = await self.session_bot.delete_one({"bot_token": bot_token})
if result.deleted_count == 1:
LOGS.info(f"Token deleted: {bot_token[:6]}...{bot_token[-3:]}")
return True
LOGS.warning(f"Token not found: {bot_token[:6]}...")
return False
except Exception as e:
LOGS.critical(f"Deletion failed for {bot_token[:6]}...: {str(e)}")
return False
async def remove_bot_token_gemini(self, bot_token: str) -> bool:
if not bot_token or not isinstance(bot_token, str):
LOGS.error(f"Invalid token format: {type(bot_token)}")
return False
try:
result = await self.gemini_bot.delete_one({"bot_token": bot_token})
if result.deleted_count == 1:
LOGS.info(f"Token deleted: {bot_token[:6]}...{bot_token[-3:]}")
return True
LOGS.warning(f"Token not found: {bot_token[:6]}...")
return False
except Exception as e:
LOGS.critical(f"Deletion failed for {bot_token[:6]}...: {str(e)}")
return False
async def remove_bot_token_alldlbot(self, bot_token: str) -> bool:
if not bot_token or not isinstance(bot_token, str):
LOGS.error(f"Invalid token format: {type(bot_token)}")
return False
try:
result = await self.alldl_bot.delete_one({"bot_token": bot_token})
if result.deleted_count == 1:
LOGS.info(f"Token deleted: {bot_token[:6]}...{bot_token[-3:]}")
return True
LOGS.warning(f"Token not found: {bot_token[:6]}...")
return False
except Exception as e:
LOGS.critical(f"Deletion failed for {bot_token[:6]}...: {str(e)}")
return False
#############################################
async def update_alldlbot_broadcast(self, id, user_id, action):
if action == "add":
update_query = {"$addToSet": {"stats_bc": user_id}}
elif action == "remove":
update_query = {"$pull": {"stats_bc": user_id}}
else:
raise ValueError("Invalid action. Use 'add' or 'remove'.")
return await self.alldl_bot.update_one(
{"bot_id": id},
update_query,
upsert=True if action == "add" else False
)
async def update_alldlbot_sudouser(self, id, user, action):
if action == "add":
update_query = {"$addToSet": {"sudo_user": user}}
elif action == "remove":
update_query = {"$pull": {"sudo_user": user}}
else:
raise ValueError("Invalid action. Use 'add' or 'remove'.")
return await self.alldl_bot.update_one(
{"bot_id": id},
update_query,
upsert=True if action == "add" else False
)
async def get_alldlbot_sudouser(self, id, user_id):
user_data = await self.alldl_bot.find_one({"bot_id": id})
if not user_data or "sudo_user" not in user_data:
return []
return user_id in user_data["sudo_user"]
async def get_alldlbot_allsudouser(self, id: int):
y = await self.alldl_bot.find_one({"bot_id": id})
if not y or "sudo_user" not in y:
return []
return y["blacklist_chat"]
async def update_alldlbot_broadcast_in_group(self, id, chat, action):
if action == "add":
update_query = {"$addToSet": {"stats_gc": chat}}
elif action == "remove":
update_query = {"$pull": {"stats_gc": chat}}
else:
raise ValueError("Invalid action. Use 'add' or 'remove'.")
return await self.alldl_bot.update_one(
{"bot_id": id},
update_query,
upsert=True if action == "add" else False
)
async def alldlbot_broadcast_stats(self, id):
user_data = await self.alldl_bot.find_one({"bot_id": id})
return len(user_data["stats_bc"]) if user_data and "stats_bc" in user_data else 0
async def alldlbot_all_broadcast(self, id):
user_data = await self.alldl_bot.find_one({"bot_id": id})
return user_data["stats_bc"]
async def alldlbot_all_broadcast_group(self, id):
user_data = await self.alldl_bot.find_one({"bot_id": id})
return user_data["stats_gc"]
async def alldlbot_blacklist_stats(self, id):
user_data = await self.alldl_bot.find_one({"bot_id": id})
return len(user_data["blacklist_user"]) if user_data and "blacklist_user" in user_data else 0
async def get_alldlbot_is_blacklist_user(self, id: int, user_id: int) -> bool:
data = await self.get_alldlbot_blacklist_user(id)
if not data or "blacklist_user" not in data:
return False
return user_id in data["blacklist_user"]
async def get_alldlbot_blacklist_user(self, id: int):
return await self.alldl_bot.find_one({"bot_id": id})
async def get_alldlbot_allblacklist_user(self, id: int):
data = await self.get_alldlbot_blacklist_user(id)
if not data or "blacklist_user" not in data:
return []
return data["blacklist_user"]
async def add_alldlbot_blacklist_user(self, id, user_id):
return await self.alldl_bot.update_one(
{"bot_id": id},
{"$push": {"blacklist_user": user_id}},
upsert=True
)
async def add_alldlbot_unblacklist_user(self, id, user_id):
return await self.alldl_bot.update_one(
{"bot_id": id},
{"$pull": {"blacklist_user": user_id}}
)
async def add_alldlbot_blacklist_chat(self, id, chat):
return await self.alldl_bot.update_one(
{"bot_id": id},
{"$push": {"blacklist_chat": chat}},
upsert=True
)
async def get_alldlbot_blacklist_chat(self, id: int):
chat = await self.alldl_bot.find_one({"bot_id": id})
if not chat or "blacklist_chat" not in chat:
return []
return chat["blacklist_chat"]
async def get_alldlbot_is_blacklist_chat(self, id: int, chat_id: int) -> bool:
data = await self.get_alldlbot_blacklist_chat(id)
return chat_id in data
async def alldlbot_whitelist_chat(self, id: int, chat_id: int) -> bool:
chat = await self.alldl_bot.find_one({"bot_id": id})
if chat and "blacklist_chat" in chat and chat_id in chat["blacklist_chat"]:
await self.alldl_bot.update_one(
{"bot_id": id},
{"$pull": {"blacklist_chat": chat_id}}
)
return True
return False
async def add_alldlbot_by_no_button(self, id, is_rm_button=False):
_ups = {"is_rm_button": is_rm_button}
return await self.alldl_bot.update_one({"bot_id": id}, {"$set": _ups}, upsert=True)
async def is_gbanned(self, user_id: int) -> bool:
if await self.gban.find_one({"user_id": user_id}):
return True
return False
async def add_gban(self, user_id: int, reason: str) -> bool:
if await self.is_gbanned(user_id):
return False
await self.gban.insert_one(
{"user_id": user_id, "reason": reason, "date": self.get_datetime()}
)
return True
async def rm_gban(self, user_id: int):
if not await self.is_gbanned(user_id):
return None
reason = (await self.gban.find_one({"user_id": user_id}))["reason"]
await self.gban.delete_one({"user_id": user_id})
return reason
async def get_gban(self) -> list:
return [i async for i in self.gban.find({})]
async def get_gban_user(self, user_id: int) -> dict | None:
if not await self.is_gbanned(user_id):
return None
return await self.gban.find_one({"user_id": user_id})
async def is_gmuted(self, user_id: int) -> bool:
if await self.gmute.find_one({"user_id": user_id}):
return True
return False
async def add_gmute(self, user_id: int, reason: str) -> bool:
if await self.is_gmuted(user_id):
return False
await self.gmute.insert_one(
{"user_id": user_id, "reason": reason, "date": self.get_datetime()}
)
return True
async def rm_gmute(self, user_id: int):
if not await self.is_gmuted(user_id):
return None
reason = (await self.gmute.find_one({"user_id": user_id}))["reason"]
await self.gmute.delete_one({"user_id": user_id})
return reason
async def get_gmute(self) -> list:
return [i async for i in self.gmute.find({})]
async def add_mute(self, client: int, user_id: int, chat_id: int, reason: str):
await self.mute.update_one(
{"client": client, "user_id": user_id, "chat_id": chat_id},
{"$set": {"reason": reason, "date": self.get_datetime()}},
upsert=True,
)
async def rm_mute(self, client: int, user_id: int, chat_id: int) -> str:
reason = (await self.get_mute(client, user_id, chat_id))["reason"]
await self.mute.delete_one({"client": client, "user_id": user_id, "chat_id": chat_id})
return reason
async def is_muted(self, client: int, user_id: int, chat_id: int) -> bool:
if await self.get_mute(client, user_id, chat_id):
return True
return False
async def get_mute(self, client: int, user_id: int, chat_id: int):
data = await self.mute.find_one({"client": client, "user_id": user_id, "chat_id": chat_id})
return data
async def set_afk(
self, user_id: int, reason: str, media: int, media_type: str
) -> None:
await self.afk.update_one(
{"user_id": user_id},
{
"$set": {
"reason": reason,
"time": time.time(),
"media": media,
"media_type": media_type,
}
},
upsert=True,
)
async def get_afk(self, user_id: int):
data = await self.afk.find_one({"user_id": user_id})
return data
async def is_afk(self, user_id: int) -> bool:
if await self.afk.find_one({"user_id": user_id}):
return True
return False
async def rm_afk(self, user_id: int) -> None:
await self.afk.delete_one({"user_id": user_id})
async def set_flood(self, client_chat: tuple[int, int], settings: dict):
await self.antiflood.update_one(
{"client": client_chat[0], "chat": client_chat[1]},
{"$set": settings},
upsert=True,
)
async def get_flood(self, client_chat: tuple[int, int]):
data = await self.antiflood.find_one(
{"client": client_chat[0], "chat": client_chat[1]}
)
return data or {}
async def is_flood(self, client_chat: tuple[int, int]) -> bool:
data = await self.get_flood(client_chat)
if not data:
return False
if data["limit"] == 0:
return False
return True
async def get_all_floods(self) -> list:
return [i async for i in self.antiflood.find({})]
async def set_autopost(self, client: int, from_channel: int, to_channel: int):
await self.autopost.update_one(
{"client": client},
{
"$push": {
"autopost": {
"from_channel": from_channel,
"to_channel": to_channel,
"date": self.get_datetime(),
}
}
},
upsert=True,
)
async def get_autopost(self, client: int, from_channel: int):
data = await self.autopost.find_one(
{
"client": client,
"autopost": {"$elemMatch": {"from_channel": from_channel}},
}
)
return data
async def is_autopost(
self, client: int, from_channel: int, to_channel: int = None
) -> bool:
if to_channel:
data = await self.autopost.find_one(
{
"client": client,
"autopost": {
"$elemMatch": {
"from_channel": from_channel,
"to_channel": to_channel,
}
},
}
)
else:
data = await self.autopost.find_one(
{
"client": client,
"autopost": {"$elemMatch": {"from_channel": from_channel}},
}
)
return True if data else False
async def rm_autopost(self, client: int, from_channel: int, to_channel: int):
await self.autopost.update_one(
{"client": client},
{
"$pull": {
"autopost": {
"from_channel": from_channel,
"to_channel": to_channel,
}
}
},
)
async def get_all_autoposts(self, client: int) -> list:
return [i async for i in self.autopost.find({"client": client})]
async def add_blacklist(self, client: int, chat: int, blacklist: str):
await self.blacklist.update_one(
{"client": client, "chat": chat},
{"$push": {"blacklist": blacklist}},
upsert=True,
)
async def rm_blacklist(self, client: int, chat: int, blacklist: str):
await self.blacklist.update_one(
{"client": client, "chat": chat},
{"$pull": {"blacklist": blacklist}},
)
async def is_blacklist(self, client: int, chat: int, blacklist: str) -> bool:
blacklists = await self.get_all_blacklists(client, chat)
if blacklist in blacklists:
return True
return False
async def get_all_blacklists(self, client: int, chat: int) -> list:
data = await self.blacklist.find_one({"client": client, "chat": chat})
if not data:
return []
return data["blacklist"]
async def get_blacklist_clients(self) -> list:
return [i async for i in self.blacklist.find({})]
async def set_echo(self, client: int, chat: int, user: int):
await self.echo.update_one(
{"client": client, "chat": chat},
{"$push": {"echo": user}},
upsert=True,
)
async def rm_echo(self, client: int, chat: int, user: int):
await self.echo.update_one(
{"client": client, "chat": chat},
{"$pull": {"echo": user}},
)
async def is_echo(self, client: int, chat: int, user: int) -> bool:
data = await self.get_all_echo(client, chat)
if user in data:
return True
return False
async def get_all_echo(self, client: int, chat: int) -> list:
data = await self.echo.find_one({"client": client, "chat": chat})
if not data:
return []
return data["echo"]
async def set_filter(self, client: int, chat: int, keyword: str, msgid: int):
await self.filter.update_one(
{"client": client, "chat": chat},
{"$push": {"filter": {"keyword": keyword, "msgid": msgid}}},
upsert=True,
)
async def rm_filter(self, client: int, chat: int, keyword: str):
await self.filter.update_one(
{"client": client, "chat": chat},
{"$pull": {"filter": {"keyword": keyword}}},
)
async def rm_all_filters(self, client: int, chat: int):
await self.filter.delete_one({"client": client, "chat": chat})
async def is_filter(self, client: int, chat: int, keyword: str) -> bool:
data = await self.get_filter(client, chat, keyword)
return True if data else False
async def get_filter(self, client: int, chat: int, keyword: str):
data = await self.filter.find_one(
{
"client": client,
"chat": chat,
"filter": {"$elemMatch": {"keyword": keyword}},
}
)
return data
async def get_all_filters(self, client: int, chat: int) -> list:
data = await self.filter.find_one({"client": client, "chat": chat})
if not data:
return []
return data["filter"]
async def set_snip(self, client: int, chat: int, keyword: str, msgid: int):
await self.snips.update_one(
{"client": client, "chat": chat},
{"$push": {"snips": {"keyword": keyword, "msgid": msgid}}},
upsert=True,
)
async def rm_snip(self, client: int, chat: int, keyword: str):
await self.snips.update_one(
{"client": client, "chat": chat},
{"$pull": {"snips": {"keyword": keyword}}},
)
async def rm_all_snips(self, client: int, chat: int):
await self.snips.delete_one({"client": client, "chat": chat})
async def is_snip(self, client: int, chat: int, keyword: str) -> bool:
data = await self.get_snip(client, chat, keyword)
return True if data else False
async def get_snip(self, client: int, chat: int, keyword: str):
data = await self.snips.find_one(
{
"client": client,
"chat": chat,
"snips": {"$elemMatch": {"keyword": keyword}},
}
)
return data
async def get_all_snips(self, client: int, chat: int) -> list:
data = await self.snips.find_one({"client": client, "chat": chat})
if not data:
return []
return data["snips"]
async def add_pmpermit(self, client: int, user: int):
await self.pmpermit.update_one(
{"client": client, "user": user},
{"$set": {"date": self.get_datetime()}},
upsert=True,
)
async def rm_pmpermit(self, client: int, user: int):
await self.pmpermit.delete_one({"client": client, "user": user})
async def is_pmpermit(self, client: int, user: int) -> bool:
data = await self.get_pmpermit(client, user)
return True if data else False
async def get_pmpermit(self, client: int, user: int):
data = await self.pmpermit.find_one({"client": client, "user": user})
return data
async def get_all_pmpermits(self, client: int) -> list:
return [i async for i in self.pmpermit.find({"client": client})]
async def set_welcome(self, client: int, chat: int, message: int):
await self.greetings.update_one(
{"client": client, "chat": chat, "welcome": True},
{"$set": {"message": message}},
upsert=True,
)
async def rm_welcome(self, client: int, chat: int):
await self.greetings.delete_one(
{"client": client, "chat": chat, "welcome": True}
)
async def is_welcome(self, client: int, chat: int) -> bool:
data = await self.get_welcome(client, chat)
return True if data else False
async def get_welcome(self, client: int, chat: int):
data = await self.greetings.find_one(
{"client": client, "chat": chat, "welcome": True}
)
return data
async def set_goodbye(self, client: int, chat: int, message: int):
await self.greetings.update_one(
{"client": client, "chat": chat, "welcome": False},
{"$set": {"message": message}},
upsert=True,
)
async def rm_goodbye(self, client: int, chat: int):
await self.greetings.delete_one(
{"client": client, "chat": chat, "welcome": False}
)
async def is_goodbye(self, client: int, chat: int) -> bool:
data = await self.get_goodbye(client, chat)
return True if data else False
async def get_goodbye(self, client: int, chat: int):
data = await self.greetings.find_one(
{"client": client, "chat": chat, "welcome": False}
)
return data
async def get_all_greetings(self, client: int) -> list:
return [i async for i in self.greetings.find({"client": client})]
async def add_forcesub_only_bot(self, id: int, must_join: str):
await self.forcesub.update_one(
{"bot_id": id},
{"$set": {"must_join": must_join}},
upsert=True,
)
async def get_forcesub_only_bot(self, id: int):
data = await self.forcesub.find_one({"bot_id": id})
if data:
return data.get("must_join")
return None
async def add_forcesub(self, chat: int, must_join: int):
await self.forcesub.update_one(
{"chat": chat},
{"$push": {"must_join": must_join}},
upsert=True,
)
async def rm_forcesub(self, chat: int, must_join: int) -> int:
await self.forcesub.update_one(
{"chat": chat},
{"$pull": {"must_join": must_join}},
)
data = await self.forcesub.find_one({"chat": chat})
return len(data["must_join"])
async def rm_all_forcesub(self, in_chat: int):
await self.forcesub.delete_one({"chat": in_chat})
async def is_forcesub(self, chat: int, must_join: int) -> bool:
data = await self.get_forcesub(chat)
if must_join in data["must_join"]:
return True
return False
async def get_forcesub(self, in_chat: int):
data = await self.forcesub.find_one({"chat": in_chat})
return data
async def get_all_forcesubs(self) -> list:
return [i async for i in self.forcesub.find({})]
async def add_gachabot(
self, client: int, bot: tuple[int, str], catch_command: str, chat_id: int
):
await self.gachabots.update_one(
{"client": client, "bot": bot[0]},
{
"$set": {
"username": bot[1],
"catch_command": catch_command,
"chat_id": chat_id,
"date": self.get_datetime(),
}
},
upsert=True,
)
async def rm_gachabot(self, client: int, bot: int, chat_id: int = None):
if chat_id:
await self.gachabots.delete_one(
{"client": client, "bot": bot, "chat_id": chat_id}
)
else:
await self.gachabots.delete_one({"client": client, "bot": bot})
async def is_gachabot(self, client: int, bot: int, chat_id: int) -> bool:
data = await self.get_gachabot(client, bot, chat_id)
return True if data else False
async def get_gachabot(self, client: int, bot: int, chat_id: int):
data = await self.gachabots.find_one(
{"client": client, "bot": bot, "chat_id": chat_id}
)
return data
async def get_all_gachabots(self, client: int) -> list:
return [i async for i in self.gachabots.find({"client": client})]
async def get_all_gachabots_id(self) -> list:
data = await self.gachabots.distinct("bot")
return data
async def _get_cohere_chat_from_db(self, user_id):
user_data = await self.cohere.find_one({"user_id": user_id})
return user_data.get("cohere_chat", []) if user_data else []
async def _update_cohere_chat_in_db(self, user_id, cohere_chat):
await self.cohere.update_one(
{"user_id": user_id},
{"$set": {"cohere_chat": cohere_chat}},
upsert=True
)
async def _clear_history_in_db(self, user_id):
unset_clear = {"cohere_chat": None}
return await self.cohere.update_one({"user_id": user_id}, {"$unset": unset_clear})
async def clear_database(self, user_id):
"""Clear the cohere history for the current user."""
result = await self._clear_history_in_db(user_id)
if result.modified_count > 0:
return "Chat history cleared successfully."
else:
return "No chat history found to clear."
async def set_chat_setting(self, chat_id, isboolean):
await self.antiarabic.update_one(
{"chat_id": chat_id},
{"$set": {"arabic": isboolean}},
upsert=True
)
async def chat_antiarabic(self, chat_id):
user_data = await self.antiarabic.find_one({"chat_id": chat_id})
if user_data:
return user_data.get("arabic", False)
return False
async def add_chatbot(self, chat_id, user_id):
await self.chatbot.update_one(
{"chat_id": chat_id},
{"$set": {"user_id": user_id}},
upsert=True
)
async def add_gpt_plan(self, user_id):
await self.gpt_4_bot.update_one(
{"user_id": user_id},
{"$set": {"is_payment": True}},
upsert=True
)
async def is_gpt_plan(self, user_id):
user_data = await self.gpt_4_bot.find_one({"user_id": user_id})
return user_data.get("is_payment") if user_data else None
async def get_chatbot(self, chat_id):
user_data = await self.chatbot.find_one({"chat_id": chat_id})
return user_data.get("user_id") if user_data else None
async def remove_chatbot(self, chat_id):
unset_data = {"user_id": None}
return await self.chatbot.update_one({"chat_id": chat_id}, {"$unset": unset_data})
async def _update_chatbot_chat_in_db(self, user_id, chatbot_chat):
await self.backup_chatbot.update_one(
{"user_id": user_id},
{"$set": {"chatbot_chat": chatbot_chat}},
upsert=True
)
async def _get_chatbot_chat_from_db(self, user_id):
user_data = await self.backup_chatbot.find_one({"user_id": user_id})
return user_data.get("chatbot_chat", []) if user_data else []
async def _clear_chatbot_history_in_db(self, user_id):
unset_clear = {"chatbot_chat": None}
return await self.backup_chatbot.update_one({"user_id": user_id}, {"$unset": unset_clear})
async def _clear_chatbot_database(self, user_id):
result = await self._clear_chatbot_history_in_db(user_id)
if result.modified_count > 0:
return "Chat history cleared successfully."
else:
return "No chat history found to clear."
db = Database(MONGO_URL)
|