- chatbot/__init__.py +0 -72
- chatbot/__main__.py +0 -151
- chatbot/plugins/__init__ py +0 -0
- chatbot/plugins/chat.py +0 -1850
- chatbot/plugins/myinfo.py +0 -62
- chatbot/plugins/payments.py +0 -90
chatbot/__init__.py
DELETED
@@ -1,72 +0,0 @@
|
|
1 |
-
import asyncio
|
2 |
-
import logging
|
3 |
-
import time
|
4 |
-
import pyrogram
|
5 |
-
import string
|
6 |
-
import random
|
7 |
-
import requests
|
8 |
-
from inspect import getfullargspec
|
9 |
-
from os import path
|
10 |
-
from random import choice
|
11 |
-
import aiohttp
|
12 |
-
import re
|
13 |
-
import os
|
14 |
-
from datetime import datetime as dt
|
15 |
-
from pyrogram import Client
|
16 |
-
from pyrogram.types import *
|
17 |
-
from pyrogram import filters
|
18 |
-
from pyrogram.errors import *
|
19 |
-
from pyrogram.raw.all import layer
|
20 |
-
from pyrogram.handlers import MessageHandler
|
21 |
-
from config import API_HASH, API_ID, BOT_TOKEN
|
22 |
-
from database import db
|
23 |
-
from logger import LOGS
|
24 |
-
from platform import python_version
|
25 |
-
from pyrogram import __version__ as pyrogram_version
|
26 |
-
|
27 |
-
StartTime = time.time()
|
28 |
-
START_TIME = dt.now()
|
29 |
-
|
30 |
-
def send_log(text_log: str):
|
31 |
-
url = "https://private-akeno.randydev.my.id/api/v2/send_message_logs"
|
32 |
-
params = {
|
33 |
-
"text_log": text_log
|
34 |
-
}
|
35 |
-
response = requests.post(url, params=params)
|
36 |
-
if response.status_code != 200:
|
37 |
-
return None
|
38 |
-
return response.json()["message"]
|
39 |
-
|
40 |
-
class Randydev(Client):
|
41 |
-
def __init__(self, loop=None):
|
42 |
-
self.loop = loop or asyncio.get_event_loop()
|
43 |
-
|
44 |
-
super().__init__(
|
45 |
-
"chatbotai",
|
46 |
-
app_version=f"akeno ai latest",
|
47 |
-
api_id=API_ID,
|
48 |
-
api_hash=API_HASH,
|
49 |
-
bot_token=BOT_TOKEN,
|
50 |
-
workers=300,
|
51 |
-
plugins=dict(root="chatbot.plugins"),
|
52 |
-
sleep_threshold=180,
|
53 |
-
)
|
54 |
-
async def start(self):
|
55 |
-
try:
|
56 |
-
await super().start()
|
57 |
-
except FloodWait as e:
|
58 |
-
LOGS.info(e)
|
59 |
-
await asyncio.sleep(e.value)
|
60 |
-
self.start_time = time.time()
|
61 |
-
LOGS.info(
|
62 |
-
"akn running with Pyrogram v%s (Layer %s) started on @%s. Hi!",
|
63 |
-
pyrogram.__version__,
|
64 |
-
layer,
|
65 |
-
self.me.username,
|
66 |
-
)
|
67 |
-
async def stop(self):
|
68 |
-
try:
|
69 |
-
await super().stop()
|
70 |
-
LOGS.warning("akn stopped, Bye!")
|
71 |
-
except ConnectionError:
|
72 |
-
LOGS.warning("akn is already terminated")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chatbot/__main__.py
DELETED
@@ -1,151 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
# -*- coding: utf-8 -*-
|
3 |
-
# Copyright 2020-2023 (c) Randy W @xtdevs, @xtsea
|
4 |
-
#
|
5 |
-
# from : https://github.com/TeamKillerX
|
6 |
-
# Channel : @RendyProjects
|
7 |
-
# This program is free software: you can redistribute it and/or modify
|
8 |
-
# it under the terms of the GNU Affero General Public License as published by
|
9 |
-
# the Free Software Foundation, either version 3 of the License, or
|
10 |
-
# (at your option) any later version.
|
11 |
-
|
12 |
-
# This program is distributed in the hope that it will be useful,
|
13 |
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
-
# GNU Affero General Public License for more details.
|
16 |
-
#
|
17 |
-
# You should have received a copy of the GNU Affero General Public License
|
18 |
-
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
19 |
-
|
20 |
-
import asyncio
|
21 |
-
import logging
|
22 |
-
import sys
|
23 |
-
import traceback
|
24 |
-
from contextlib import closing, suppress
|
25 |
-
from datetime import datetime as dt, timedelta
|
26 |
-
|
27 |
-
from pyrogram import idle
|
28 |
-
from uvloop import install
|
29 |
-
|
30 |
-
from chatbot import Randydev
|
31 |
-
from database import db
|
32 |
-
from logger import LOGS
|
33 |
-
|
34 |
-
logging.basicConfig(
|
35 |
-
level=logging.INFO,
|
36 |
-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
37 |
-
)
|
38 |
-
logging.getLogger("pyrogram.syncer").setLevel(logging.WARNING)
|
39 |
-
logging.getLogger("pyrogram.client").setLevel(logging.WARNING)
|
40 |
-
loop = asyncio.get_event_loop()
|
41 |
-
|
42 |
-
async def startup_tasks(bot_client):
|
43 |
-
task1 = asyncio.create_task(
|
44 |
-
premium_expiry_monitor(bot_client),
|
45 |
-
name="premium_expiry_monitor"
|
46 |
-
)
|
47 |
-
task2 = asyncio.create_task(
|
48 |
-
process_unfreezes(bot_client),
|
49 |
-
name="process_unfreezes"
|
50 |
-
)
|
51 |
-
return [task1, task2]
|
52 |
-
|
53 |
-
async def premium_expiry_monitor(client):
|
54 |
-
while True:
|
55 |
-
try:
|
56 |
-
now = dt.now()
|
57 |
-
expired = db.user_premium.find({
|
58 |
-
"is_premium": True,
|
59 |
-
"premium_expiry": {"$lt": now}
|
60 |
-
})
|
61 |
-
|
62 |
-
async for user in expired:
|
63 |
-
await db.user_premium.update_one(
|
64 |
-
{"user_id": user["user_id"]},
|
65 |
-
{"$set": {"is_premium": False}}
|
66 |
-
)
|
67 |
-
with suppress(Exception):
|
68 |
-
await client.send_message(
|
69 |
-
user["user_id"],
|
70 |
-
"⚠️ Your premium subscription has expired\n"
|
71 |
-
"You've been downgraded to free tier (5 images/day)\n\n"
|
72 |
-
)
|
73 |
-
|
74 |
-
await asyncio.sleep(3600)
|
75 |
-
except asyncio.CancelledError:
|
76 |
-
LOGS.info("Premium monitor stopped gracefully")
|
77 |
-
except Exception as e:
|
78 |
-
LOGS.error(f"Premium monitor error: {e}")
|
79 |
-
await asyncio.sleep(600)
|
80 |
-
|
81 |
-
async def process_unfreezes(client):
|
82 |
-
while True:
|
83 |
-
try:
|
84 |
-
now = dt.now()
|
85 |
-
expired_users = db.user_blacklists.find({
|
86 |
-
"is_frozen": True,
|
87 |
-
"unfreeze_at": {"$lte": now}
|
88 |
-
})
|
89 |
-
|
90 |
-
async for user in expired_users:
|
91 |
-
await db.user_blacklists.update_one(
|
92 |
-
{"_id": user["_id"]},
|
93 |
-
{"$set": {"is_frozen": False}}
|
94 |
-
)
|
95 |
-
LOGS.info(f"Auto-unfrozen user {user['user_id']}")
|
96 |
-
|
97 |
-
with suppress(Exception):
|
98 |
-
await client.send_message(
|
99 |
-
user["user_id"],
|
100 |
-
"✅ Your restrictions have been automatically lifted"
|
101 |
-
)
|
102 |
-
|
103 |
-
await asyncio.sleep(300)
|
104 |
-
|
105 |
-
except asyncio.CancelledError:
|
106 |
-
LOGS.info("Unfreeze monitor stopped gracefully")
|
107 |
-
except Exception as e:
|
108 |
-
LOGS.error(f"Unfreeze task error: {str(e)}")
|
109 |
-
await asyncio.sleep(60)
|
110 |
-
|
111 |
-
async def shutdown(loop):
|
112 |
-
tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]
|
113 |
-
for task in tasks:
|
114 |
-
task.cancel()
|
115 |
-
|
116 |
-
with suppress(asyncio.CancelledError):
|
117 |
-
await asyncio.gather(*tasks, return_exceptions=True)
|
118 |
-
|
119 |
-
LOGS.info("Application shutdown complete")
|
120 |
-
|
121 |
-
async def main():
|
122 |
-
bg_tasks = None
|
123 |
-
try:
|
124 |
-
await db.connect()
|
125 |
-
randydev = Randydev(loop=loop)
|
126 |
-
|
127 |
-
await randydev.start()
|
128 |
-
bg_tasks = await startup_tasks(randydev)
|
129 |
-
LOGS.info("Application startup complete")
|
130 |
-
|
131 |
-
await idle()
|
132 |
-
|
133 |
-
except Exception as e:
|
134 |
-
LOGS.critical(f"Fatal error: {str(e)}")
|
135 |
-
traceback.print_exc()
|
136 |
-
finally:
|
137 |
-
for task in bg_tasks:
|
138 |
-
task.cancel()
|
139 |
-
await asyncio.gather(*bg_tasks, return_exceptions=True)
|
140 |
-
await shutdown(asyncio.get_event_loop())
|
141 |
-
|
142 |
-
if __name__ == "__main__":
|
143 |
-
install()
|
144 |
-
|
145 |
-
with closing(loop):
|
146 |
-
with suppress(asyncio.CancelledError, KeyboardInterrupt):
|
147 |
-
loop.run_until_complete(main())
|
148 |
-
|
149 |
-
loop.run_until_complete(asyncio.sleep(3))
|
150 |
-
if not loop.is_closed():
|
151 |
-
loop.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chatbot/plugins/__init__ py
DELETED
File without changes
|
chatbot/plugins/chat.py
DELETED
@@ -1,1850 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
# -*- coding: utf-8 -*-
|
3 |
-
# Copyright 2019-2025 (c) Randy W @xtdevs, @xtsea
|
4 |
-
#
|
5 |
-
# from : https://github.com/TeamKillerX
|
6 |
-
# Channel : @RendyProjects
|
7 |
-
# This project is proprietary software. Unauthorized redistribution is prohibited.
|
8 |
-
|
9 |
-
import asyncio
|
10 |
-
import base64
|
11 |
-
import json
|
12 |
-
import os
|
13 |
-
import random
|
14 |
-
import re
|
15 |
-
import uuid
|
16 |
-
from datetime import datetime as dt, timedelta
|
17 |
-
from io import BytesIO
|
18 |
-
from typing import List
|
19 |
-
|
20 |
-
import cohere
|
21 |
-
import requests
|
22 |
-
from akenoai import *
|
23 |
-
from akenoai.types import DifferentAPIDefault
|
24 |
-
from google import genai
|
25 |
-
from google.genai import types as ty
|
26 |
-
from gpytranslate import SyncTranslator
|
27 |
-
from PIL import Image
|
28 |
-
from pyrogram import *
|
29 |
-
from pyrogram import Client, enums, filters
|
30 |
-
from pyrogram.errors import *
|
31 |
-
from pyrogram.types import (InlineKeyboardButton, InlineKeyboardMarkup,
|
32 |
-
InlineQuery, InlineQueryResultArticle,
|
33 |
-
InlineQueryResultPhoto, InputMediaPhoto,
|
34 |
-
InputTextMessageContent, Message)
|
35 |
-
|
36 |
-
from config import *
|
37 |
-
from database import db, users_collection
|
38 |
-
from logger import LOGS
|
39 |
-
|
40 |
-
from Ryzenth import ApiKeyFrom, SmallConvertDot
|
41 |
-
from Ryzenth.types import RequestHumanizer
|
42 |
-
|
43 |
-
ryz = ApiKeyFrom(..., True)
|
44 |
-
|
45 |
-
trans = SyncTranslator()
|
46 |
-
js = AkenoXJs(DifferentAPIDefault()).connect()
|
47 |
-
|
48 |
-
message_memory_state = {}
|
49 |
-
DISABLED_COMMANDS = [
|
50 |
-
"/",
|
51 |
-
"/help",
|
52 |
-
"about:",
|
53 |
-
"enabled:",
|
54 |
-
"disabled:",
|
55 |
-
"pro:editimage",
|
56 |
-
"--stream-images",
|
57 |
-
"--edit-images",
|
58 |
-
"--reason",
|
59 |
-
"--deletemydata --reason"
|
60 |
-
]
|
61 |
-
|
62 |
-
def aigen_check(user_id: int, text: str):
|
63 |
-
result = {}
|
64 |
-
try:
|
65 |
-
response = requests.get(
|
66 |
-
f"https://randydev-ryu-js.hf.space/api/v1/ai/akenox/aigen-v2?query={text}",
|
67 |
-
headers={"x-api-key": "akeno_UKQEQMt991kh2Ehh7JqJYKapx8CCyeC"}
|
68 |
-
).json()
|
69 |
-
|
70 |
-
ok = json.loads(response.get("results", "{}"))
|
71 |
-
|
72 |
-
result[user_id] = {
|
73 |
-
"is_image": ok.get("is_image", False),
|
74 |
-
"prompt": ok.get("prompt", ""),
|
75 |
-
"is_anti_porno": ok.get("is_anti_porno", False),
|
76 |
-
"reason": ok.get("reason", "")
|
77 |
-
}
|
78 |
-
return result
|
79 |
-
except (json.decoder.JSONDecodeError, KeyError, TypeError, requests.RequestException) as e:
|
80 |
-
return {user_id: {
|
81 |
-
"is_image": False,
|
82 |
-
"prompt": "",
|
83 |
-
"is_anti_porno": False,
|
84 |
-
"reason": f"Error: {str(e)}"
|
85 |
-
}}
|
86 |
-
|
87 |
-
def is_command_disabled(text):
|
88 |
-
text_lower = text.lower()
|
89 |
-
if text_lower.startswith("/") and not (
|
90 |
-
text_lower.startswith("/setmodel")
|
91 |
-
or text_lower.startswith("/start")
|
92 |
-
or text_lower.startswith("/mypremium")
|
93 |
-
):
|
94 |
-
return True
|
95 |
-
else:
|
96 |
-
return False
|
97 |
-
|
98 |
-
def obfuscate(word):
|
99 |
-
return word.lower()\
|
100 |
-
.replace("a", "[a@4]")\
|
101 |
-
.replace("b", "[b8]")\
|
102 |
-
.replace("e", "[e3]")\
|
103 |
-
.replace("g", "[g69]")\
|
104 |
-
.replace("i", "[i1!|]")\
|
105 |
-
.replace("o", "[o0]")\
|
106 |
-
.replace("s", "[s5$]")\
|
107 |
-
.replace("t", "[t7+]")\
|
108 |
-
.replace("l", "[l1|]")
|
109 |
-
|
110 |
-
def regex_all_blacklist(text):
|
111 |
-
with open("blacklist.txt", "r", encoding="utf-8") as f:
|
112 |
-
words = [obfuscate(w.strip()) for w in f if w.strip()]
|
113 |
-
pattern = r"\b(" + "|".join(words) + r")\b"
|
114 |
-
if re.search(pattern, text, re.IGNORECASE):
|
115 |
-
return True
|
116 |
-
else:
|
117 |
-
return False
|
118 |
-
|
119 |
-
async def geni_files_delete(name: str):
|
120 |
-
url = f"https://generativelanguage.googleapis.com/v1beta/{name}"
|
121 |
-
params = {"key": GOOGLE_API_KEY}
|
122 |
-
response = requests.delete(url, params=params)
|
123 |
-
if response.status_code != 200:
|
124 |
-
return None
|
125 |
-
return response.text
|
126 |
-
|
127 |
-
async def remove_bg_myapi(return_image):
|
128 |
-
with open(return_image, "rb") as image_file:
|
129 |
-
encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
|
130 |
-
payload = {
|
131 |
-
"image_base64": encoded_string
|
132 |
-
}
|
133 |
-
output_bg = "output.png"
|
134 |
-
response = requests.post("https://randydev-meta-ai.hf.space/remove-bg-base64", json=payload)
|
135 |
-
if response.status_code == 200:
|
136 |
-
result_base64 = response.json().get("output_image_base64")
|
137 |
-
with open(output_bg, "wb") as out_file:
|
138 |
-
out_file.write(base64.b64decode(result_base64))
|
139 |
-
return output_bg
|
140 |
-
else:
|
141 |
-
return None
|
142 |
-
|
143 |
-
CREDITS_DEVELOPER = """
|
144 |
-
🗓️ 2 May 2025
|
145 |
-
|
146 |
-
🤖 @GeminiAIDev_Bot — Crafted with passion by @xtdevs
|
147 |
-
|
148 |
-
🧠 Language: Python
|
149 |
-
🔒 Source Code: Not publicly available
|
150 |
-
|
151 |
-
✨ About:
|
152 |
-
You’ve entered a realm where your imagination meets intelligence.
|
153 |
-
From ✍️ text, 🖼️ images etc, to full 🗣️ conversations — Gemini is your AI companion.
|
154 |
-
|
155 |
-
🧾 Credits: Google Devs, OpenAI Engineers
|
156 |
-
"""
|
157 |
-
|
158 |
-
GEMINI_START_TEXT = """
|
159 |
-
Welcome to Gemini AI [Dev]
|
160 |
-
|
161 |
-
Users: `{user}`
|
162 |
-
|
163 |
-
You’ve entered the realm of limitless possibilities.
|
164 |
-
From text, photos, to full conversations — Gemini is your digital partner.
|
165 |
-
|
166 |
-
Speak. Create. Explore. Let your thoughts ignite the machine.
|
167 |
-
|
168 |
-
Type anything to begin.
|
169 |
-
"""
|
170 |
-
|
171 |
-
gen = genai.Client(api_key=GOOGLE_API_KEY)
|
172 |
-
|
173 |
-
async def search_auto_by_cohere(user_id, prompt):
|
174 |
-
COHERE_API_KEY = os.environ.get("COHERE_API_KEY")
|
175 |
-
co = cohere.Client(api_key=COHERE_API_KEY)
|
176 |
-
chat_history = await db._get_cohere_chat_from_db(user_id)
|
177 |
-
chat_history.append({"role": "User", "message": prompt})
|
178 |
-
stream = co.chat_stream(
|
179 |
-
model='command-r-08-2024',
|
180 |
-
message=prompt,
|
181 |
-
temperature=0.3,
|
182 |
-
chat_history=chat_history,
|
183 |
-
prompt_truncation='AUTO',
|
184 |
-
connectors=[{"id":"web-search"}]
|
185 |
-
)
|
186 |
-
data = []
|
187 |
-
output = ""
|
188 |
-
for event in stream:
|
189 |
-
if event.event_type == "search-results":
|
190 |
-
if event.documents:
|
191 |
-
data.extend(event.documents)
|
192 |
-
elif event.event_type == "text-generation":
|
193 |
-
output += event.text
|
194 |
-
|
195 |
-
if not data:
|
196 |
-
data = [{"title": "", "url": ""}]
|
197 |
-
|
198 |
-
reference_dict = {}
|
199 |
-
for item in data:
|
200 |
-
title = item.get("title", "").strip()
|
201 |
-
url = item.get("url", "").strip()
|
202 |
-
if not title or not url:
|
203 |
-
continue
|
204 |
-
if title not in reference_dict:
|
205 |
-
reference_dict[title] = url
|
206 |
-
references = ""
|
207 |
-
for i, (title, url) in enumerate(reference_dict.items()):
|
208 |
-
references += f"{i}. [{title}]({url})\n"
|
209 |
-
|
210 |
-
if not references.strip():
|
211 |
-
references = ""
|
212 |
-
|
213 |
-
if not output:
|
214 |
-
output = "I couldn't generate a response."
|
215 |
-
|
216 |
-
all_answer = f"{output}\n\n{references}"
|
217 |
-
chat_history.append({"role": "Chatbot", "message": all_answer})
|
218 |
-
await db._update_cohere_chat_in_db(user_id, chat_history)
|
219 |
-
return all_answer
|
220 |
-
|
221 |
-
|
222 |
-
# Original: @GeminiAIDev_Bot
|
223 |
-
# Code by @xtdevs
|
224 |
-
def replace_with_markdown_list(text, pattern=r"^\s*\*\s*(.*)$"):
|
225 |
-
def replace(match):
|
226 |
-
text = match.group(1)
|
227 |
-
text = re.sub(r"\b(\w+)\b", r"**\1**", text)
|
228 |
-
return "- " + text
|
229 |
-
return re.sub(pattern, replace, text, flags=re.MULTILINE)
|
230 |
-
|
231 |
-
like_counts = {}
|
232 |
-
unlike_counts = {}
|
233 |
-
TELEGRAM_MAX_LENGTH = 4096
|
234 |
-
|
235 |
-
def split_message(text: str) -> List[str]:
|
236 |
-
if len(text) <= TELEGRAM_MAX_LENGTH:
|
237 |
-
return [text]
|
238 |
-
|
239 |
-
parts = []
|
240 |
-
while len(text) > 0:
|
241 |
-
if len(text) > TELEGRAM_MAX_LENGTH:
|
242 |
-
part = text[:TELEGRAM_MAX_LENGTH]
|
243 |
-
parts.append(part)
|
244 |
-
text = text[TELEGRAM_MAX_LENGTH:]
|
245 |
-
else:
|
246 |
-
parts.append(text)
|
247 |
-
text = ""
|
248 |
-
return parts
|
249 |
-
|
250 |
-
@Client.on_callback_query(filters.regex("^closedd$"))
|
251 |
-
async def closeed(client, callback):
|
252 |
-
await callback.message.delete()
|
253 |
-
|
254 |
-
@Client.on_callback_query(filters.regex("^comode:([a-f0-9]{8})"))
|
255 |
-
async def coheresearch(client, callback):
|
256 |
-
user_id = callback.from_user.id
|
257 |
-
uuidstr = callback.matches[0].group(1)
|
258 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
259 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
260 |
-
await callback.answer("Sorry your account is frozen", True)
|
261 |
-
return
|
262 |
-
keyboard = []
|
263 |
-
keyboard.append([
|
264 |
-
InlineKeyboardButton("Deep Search ON", callback_data=f"deeps_on_{uuidstr}"),
|
265 |
-
InlineKeyboardButton("Deep Search OFF", callback_data=f"deeps_off_{uuidstr}")
|
266 |
-
])
|
267 |
-
keyboard.append([
|
268 |
-
InlineKeyboardButton("Back To Menu", callback_data=f"menu_back:{uuidstr}")
|
269 |
-
])
|
270 |
-
await callback.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup(keyboard))
|
271 |
-
|
272 |
-
@Client.on_callback_query(filters.regex("^human:([a-f0-9]{8})"))
|
273 |
-
async def _humancb(client, callback):
|
274 |
-
user_id = callback.from_user.id
|
275 |
-
uuidstr = callback.matches[0].group(1)
|
276 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
277 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
278 |
-
await callback.answer("Sorry your account is frozen", True)
|
279 |
-
return
|
280 |
-
keyboard = []
|
281 |
-
keyboard.append([
|
282 |
-
InlineKeyboardButton("Humanizer ON", callback_data=f"humanizer_on_{uuidstr}"),
|
283 |
-
InlineKeyboardButton("Humanizer OFF", callback_data=f"humanizer_off_{uuidstr}")
|
284 |
-
])
|
285 |
-
keyboard.append([
|
286 |
-
InlineKeyboardButton("Back To Menu", callback_data=f"menu_back:{uuidstr}")
|
287 |
-
])
|
288 |
-
await callback.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup(keyboard))
|
289 |
-
|
290 |
-
def inline_error(text: str):
|
291 |
-
return [
|
292 |
-
InlineQueryResultArticle(
|
293 |
-
title="❌ Error",
|
294 |
-
input_message_content=InputTextMessageContent(
|
295 |
-
message_text=f"⚠️ {text}"
|
296 |
-
)
|
297 |
-
)
|
298 |
-
]
|
299 |
-
|
300 |
-
@Client.on_inline_query(filters.regex(".*"))
|
301 |
-
async def inline_search(client: Client, inline_query: InlineQuery):
|
302 |
-
user_id = inline_query.from_user.id
|
303 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
304 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
305 |
-
return
|
306 |
-
GOOGLE_CX = "8386c816e6fff4b2a"
|
307 |
-
search_query = inline_query.query.strip()
|
308 |
-
if not search_query:
|
309 |
-
return
|
310 |
-
try:
|
311 |
-
response = requests.get(
|
312 |
-
"https://www.googleapis.com/customsearch/v1",
|
313 |
-
params={
|
314 |
-
"key": GOOGLE_API_SEARCH,
|
315 |
-
"cx": GOOGLE_CX,
|
316 |
-
"q": search_query,
|
317 |
-
"searchType": "image"
|
318 |
-
}
|
319 |
-
)
|
320 |
-
response_json = response.json()
|
321 |
-
|
322 |
-
if "items" in response_json:
|
323 |
-
results = []
|
324 |
-
for i, item in enumerate(response_json["items"]):
|
325 |
-
title = item.get("title", "No Title")
|
326 |
-
description = item["image"].get("contextLink", "No Link")
|
327 |
-
url = item.get("link")
|
328 |
-
|
329 |
-
result = InlineQueryResultPhoto(
|
330 |
-
photo_url=url,
|
331 |
-
id=str(i),
|
332 |
-
title=title,
|
333 |
-
description=description,
|
334 |
-
thumb_url=url,
|
335 |
-
input_message_content=InputTextMessageContent(
|
336 |
-
message_text=f"**Title:** {title}\n\n**Source:** {description}"
|
337 |
-
),
|
338 |
-
reply_markup=InlineKeyboardMarkup(
|
339 |
-
[[InlineKeyboardButton("🔗 Open Link", url=url)]]
|
340 |
-
),
|
341 |
-
)
|
342 |
-
results.append(result)
|
343 |
-
|
344 |
-
await inline_query.answer(results, cache_time=10)
|
345 |
-
|
346 |
-
else:
|
347 |
-
await inline_query.answer(inline_error("No result found."), cache_time=1)
|
348 |
-
except Exception as e:
|
349 |
-
await inline_query.answer(inline_error("Internal error. Try again later."), cache_time=1)
|
350 |
-
LOGS.error(f"[INLINE ERROR] {type(e).__name__}: {e}")
|
351 |
-
|
352 |
-
@Client.on_callback_query(filters.regex("^humanizer_(on|off)_([a-f0-9]{8})$"))
|
353 |
-
async def humanizermode(client, callback):
|
354 |
-
user_id = callback.from_user.id
|
355 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
356 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
357 |
-
await callback.answer("Sorry your account is frozen", True)
|
358 |
-
return
|
359 |
-
check_is_system = await db.backup_chatbot.find_one({"user_id": user_id})
|
360 |
-
if check_is_system and check_is_system.get("is_deepsearch", False):
|
361 |
-
await callback.answer(f"You can OFF in deep search", show_alert=True)
|
362 |
-
return
|
363 |
-
mode, uuidstr = callback.matches[0].groups()
|
364 |
-
try:
|
365 |
-
if mode not in ("on", "off"):
|
366 |
-
await callback.answer("Mode invalid", show_alert=True)
|
367 |
-
return
|
368 |
-
is_human = mode == "on"
|
369 |
-
await db.backup_chatbot.update_one(
|
370 |
-
{"user_id": user_id},
|
371 |
-
{"$set": {"is_humanizer": is_human}},
|
372 |
-
upsert=True
|
373 |
-
)
|
374 |
-
await callback.answer(f"Humanizer mode is set to {mode}.", show_alert=True)
|
375 |
-
keyboard = create_keyboard(
|
376 |
-
user_id=user_id,
|
377 |
-
uuid_str=uuidstr
|
378 |
-
)
|
379 |
-
await callback.edit_message_reply_markup(reply_markup=keyboard)
|
380 |
-
except Exception as e:
|
381 |
-
LOGS.error(f"Humanizer Error: {e}")
|
382 |
-
await callback.answer("Please try again later..", show_alert=True)
|
383 |
-
|
384 |
-
@Client.on_callback_query(filters.regex("^deeps_(on|off)_([a-f0-9]{8})$"))
|
385 |
-
async def deepsearchmode(client, callback):
|
386 |
-
user_id = callback.from_user.id
|
387 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
388 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
389 |
-
await callback.answer("Sorry your account is frozen", True)
|
390 |
-
return
|
391 |
-
check_is_system = await db.backup_chatbot.find_one({"user_id": user_id})
|
392 |
-
if check_is_system and check_is_system.get("is_humanizer", False):
|
393 |
-
await callback.answer(f"You can OFF in humanizer", show_alert=True)
|
394 |
-
return
|
395 |
-
mode, uuidstr = callback.matches[0].groups()
|
396 |
-
try:
|
397 |
-
if mode not in ("on", "off"):
|
398 |
-
await callback.answer("Mode invalid", show_alert=True)
|
399 |
-
return
|
400 |
-
is_deepsearch = mode == "on"
|
401 |
-
await db.backup_chatbot.update_one(
|
402 |
-
{"user_id": user_id},
|
403 |
-
{"$set": {"is_deepsearch": is_deepsearch}},
|
404 |
-
upsert=True
|
405 |
-
)
|
406 |
-
await callback.answer(f"Deep Search mode is set to {mode}.", show_alert=True)
|
407 |
-
keyboard = create_keyboard(
|
408 |
-
user_id=user_id,
|
409 |
-
uuid_str=uuidstr
|
410 |
-
)
|
411 |
-
await callback.edit_message_reply_markup(reply_markup=keyboard)
|
412 |
-
except Exception as e:
|
413 |
-
LOGS.error(f"Cohere Error: {e}")
|
414 |
-
await callback.answer("Please try again later..", show_alert=True)
|
415 |
-
|
416 |
-
@Client.on_callback_query(filters.regex("^modelmenu:([a-f0-9]{8})$"))
|
417 |
-
async def modelgeminimenu(client, callback):
|
418 |
-
uuidstr = callback.matches[0].group(1)
|
419 |
-
user_id = callback.from_user.id
|
420 |
-
check_is_system = await db.backup_chatbot.find_one({"user_id": user_id})
|
421 |
-
if check_is_system and check_is_system.get("is_deepsearch", False):
|
422 |
-
await callback.answer(f"You can OFF in deep search", show_alert=True)
|
423 |
-
return
|
424 |
-
if check_is_system and check_is_system.get("is_humanizer", False):
|
425 |
-
await callback.answer(f"You can OFF in humanizer", show_alert=True)
|
426 |
-
return
|
427 |
-
keyboard = []
|
428 |
-
keyboard.append([
|
429 |
-
InlineKeyboardButton("G Flash EXP", callback_data=f"us:gemini-2.0-flash-exp:{uuidstr}"),
|
430 |
-
InlineKeyboardButton("G EXP 1206", callback_data=f"us:gemini-exp-1206:{uuidstr}")
|
431 |
-
])
|
432 |
-
keyboard.append([
|
433 |
-
InlineKeyboardButton("G 1.5 Flash 8B", callback_data=f"us:gemini-1.5-flash-8b:{uuidstr}"),
|
434 |
-
InlineKeyboardButton("G 2.0 Flash 001", callback_data=f"us:gemini-2.0-flash-001:{uuidstr}")
|
435 |
-
])
|
436 |
-
keyboard.append([
|
437 |
-
InlineKeyboardButton("G 1.5 PRO", callback_data=f"us:gemini-1.5-pro:{uuidstr}"),
|
438 |
-
InlineKeyboardButton("G 1.5 Flash", callback_data=f"us:gemini-1.5-flash:{uuidstr}"),
|
439 |
-
])
|
440 |
-
keyboard.append([
|
441 |
-
InlineKeyboardButton("Back To Menu", callback_data=f"menu_back:{uuidstr}")
|
442 |
-
])
|
443 |
-
await callback.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup(keyboard))
|
444 |
-
|
445 |
-
@Client.on_callback_query(filters.regex(r"^us:(.*):([a-f0-9]{8})$"))
|
446 |
-
async def gemini_setmodel(client, callback):
|
447 |
-
model, uuidstr = callback.matches[0].groups()
|
448 |
-
user_id = callback.from_user.id
|
449 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
450 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
451 |
-
await callback.answer("Sorry your account is frozen", True)
|
452 |
-
return
|
453 |
-
await users_collection.update_one(
|
454 |
-
{"user_id": user_id},
|
455 |
-
{"$set": {"model": model}},
|
456 |
-
upsert=True
|
457 |
-
)
|
458 |
-
await callback.answer(f"Model set to {model}")
|
459 |
-
keyboard = create_keyboard(
|
460 |
-
user_id=user_id,
|
461 |
-
uuid_str=uuidstr
|
462 |
-
)
|
463 |
-
await callback.edit_message_reply_markup(reply_markup=keyboard)
|
464 |
-
|
465 |
-
@Client.on_callback_query(filters.regex("^deletemydatagm$"))
|
466 |
-
async def deletemydata(client, callback):
|
467 |
-
user_id = callback.from_user.id
|
468 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
469 |
-
if user_bl and user_bl.get("is_frozen", False):
|
470 |
-
await callback.answer("Sorry your account is frozen", True)
|
471 |
-
return
|
472 |
-
|
473 |
-
delm = await db._clear_chatbot_database(user_id)
|
474 |
-
if delm:
|
475 |
-
await callback.edit_message_text(delm)
|
476 |
-
else:
|
477 |
-
await callback.answer(delm, True)
|
478 |
-
|
479 |
-
@Client.on_callback_query(filters.regex("^genprompt_(\d+)$"))
|
480 |
-
async def geminigen_prompt(client, callback):
|
481 |
-
user_id = int(callback.matches[0].group(1))
|
482 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
483 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
484 |
-
await callback.answer("Sorry your account is frozen", True)
|
485 |
-
return
|
486 |
-
|
487 |
-
captions = ""
|
488 |
-
file_path = "gemini-native-image.png"
|
489 |
-
try:
|
490 |
-
backup_chat = await db._get_chatbot_chat_from_db(user_id)
|
491 |
-
data = await db.backup_chatbot.find_one({"user_id": user_id})
|
492 |
-
if not data:
|
493 |
-
return await callback.answer("Can't found user", True)
|
494 |
-
get_response = data.get("prompt_image", None)
|
495 |
-
if not get_response:
|
496 |
-
return await callback.answer("Server busy try again later", True)
|
497 |
-
if regex_all_blacklist(get_response):
|
498 |
-
return await callback.answer("Sorry your account is frozen", True)
|
499 |
-
|
500 |
-
await callback.message.edit_text("....")
|
501 |
-
await client.send_chat_action(callback.message.chat.id, enums.ChatAction.UPLOAD_PHOTO)
|
502 |
-
await asyncio.sleep(2.0)
|
503 |
-
backup_chat.append({"role": "user", "parts": [{"text": get_response}]})
|
504 |
-
response = await gen.aio.models.generate_content(
|
505 |
-
model="gemini-2.0-flash-exp-image-generation",
|
506 |
-
contents=get_response,
|
507 |
-
config=ty.GenerateContentConfig(
|
508 |
-
response_modalities=['TEXT', 'IMAGE']
|
509 |
-
)
|
510 |
-
)
|
511 |
-
for part in response.candidates[0].content.parts:
|
512 |
-
if part.text is not None:
|
513 |
-
captions += part.text
|
514 |
-
elif part.inline_data is not None:
|
515 |
-
image = Image.open(BytesIO((part.inline_data.data)))
|
516 |
-
image.save(file_path)
|
517 |
-
|
518 |
-
uuid_code = str(uuid.uuid4())[:8]
|
519 |
-
keyboard = create_keyboard(
|
520 |
-
user_id=user_id,
|
521 |
-
uuid_str=uuid_code
|
522 |
-
)
|
523 |
-
view_button_user = anonymous_user(user_id=user_id)
|
524 |
-
await callback.message.edit_media(
|
525 |
-
media=InputMediaPhoto(
|
526 |
-
media=file_path,
|
527 |
-
caption=captions
|
528 |
-
),
|
529 |
-
reply_markup=keyboard
|
530 |
-
)
|
531 |
-
translation_entry = {
|
532 |
-
"uuid": uuid_code,
|
533 |
-
"text": captions,
|
534 |
-
"timestamp": dt.now().isoformat()
|
535 |
-
}
|
536 |
-
await db.backup_chatbot.update_one(
|
537 |
-
{"user_id": user_id},
|
538 |
-
{"$push": {"translate_history": translation_entry}},
|
539 |
-
upsert=True
|
540 |
-
)
|
541 |
-
backup_chat.append({"role": "model", "parts": [{"text": captions}]})
|
542 |
-
await db._update_chatbot_chat_in_db(user_id, backup_chat)
|
543 |
-
await client.send_chat_action(callback.message.chat.id, enums.ChatAction.CANCEL)
|
544 |
-
return
|
545 |
-
except Exception as e:
|
546 |
-
LOGS.error(f"geminigen_prompt failed: {str(e)}")
|
547 |
-
return await callback.message.edit_media(
|
548 |
-
media=InputMediaPhoto(
|
549 |
-
media="error.png",
|
550 |
-
caption="Server busy try again later"
|
551 |
-
),
|
552 |
-
reply_markup=None
|
553 |
-
)
|
554 |
-
finally:
|
555 |
-
if file_path:
|
556 |
-
try:
|
557 |
-
os.remove(file_path)
|
558 |
-
except:
|
559 |
-
pass
|
560 |
-
|
561 |
-
@Client.on_callback_query(filters.regex("^fluxprompt_(\d+)$"))
|
562 |
-
async def flux_prompt(client, callback):
|
563 |
-
user_id = int(callback.matches[0].group(1))
|
564 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
565 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
566 |
-
await callback.answer("Sorry your account is frozen", True)
|
567 |
-
return
|
568 |
-
|
569 |
-
file_path = None
|
570 |
-
file_photo = None
|
571 |
-
try:
|
572 |
-
backup_chat = await db._get_chatbot_chat_from_db(user_id)
|
573 |
-
data = await db.backup_chatbot.find_one({"user_id": user_id})
|
574 |
-
if not data:
|
575 |
-
return await callback.answer("Can't found user", True)
|
576 |
-
get_response = data.get("prompt_image", None)
|
577 |
-
if not get_response:
|
578 |
-
return await callback.answer("Server busy try again later", True)
|
579 |
-
if regex_all_blacklist(get_response):
|
580 |
-
return await callback.answer("Sorry your account is frozen", True)
|
581 |
-
|
582 |
-
await callback.message.edit_text("....")
|
583 |
-
await client.send_chat_action(callback.message.chat.id, enums.ChatAction.UPLOAD_PHOTO)
|
584 |
-
await asyncio.sleep(2.0)
|
585 |
-
backup_chat.append({"role": "user", "parts": [{"text": get_response}]})
|
586 |
-
response_js = await js.image.create(
|
587 |
-
"black-forest-labs/flux-1-schnell",
|
588 |
-
image_read=True,
|
589 |
-
params_data={"query": get_response},
|
590 |
-
)
|
591 |
-
file_path = "randydev.jpg"
|
592 |
-
with open(file_path, "wb") as f:
|
593 |
-
f.write(response_js)
|
594 |
-
|
595 |
-
file_photo = await gen.aio.files.upload(file=file_path)
|
596 |
-
while file_photo.state.name == "PROCESSING":
|
597 |
-
await client.send_chat_action(callback.message.chat.id, enums.ChatAction.UPLOAD_PHOTO)
|
598 |
-
await asyncio.sleep(10)
|
599 |
-
file_photo = await gen.aio.files.get(name=file_photo.name)
|
600 |
-
if file_photo.state.name == "FAILED":
|
601 |
-
return await callback.message.reply_text(f"Error: {file_photo.state.name}")
|
602 |
-
response = await gen.aio.models.generate_content(
|
603 |
-
model="gemini-2.0-flash",
|
604 |
-
contents=[
|
605 |
-
"You are a picture making a story use small don't be too many",
|
606 |
-
file_photo
|
607 |
-
]
|
608 |
-
)
|
609 |
-
uuid_code = str(uuid.uuid4())[:8]
|
610 |
-
keyboard = create_keyboard(
|
611 |
-
user_id=user_id,
|
612 |
-
uuid_str=uuid_code
|
613 |
-
)
|
614 |
-
view_button_user = anonymous_user(user_id=user_id)
|
615 |
-
await callback.message.edit_media(
|
616 |
-
media=InputMediaPhoto(
|
617 |
-
media=file_path,
|
618 |
-
caption=response.text
|
619 |
-
),
|
620 |
-
reply_markup=keyboard
|
621 |
-
)
|
622 |
-
photo = await client.send_photo(
|
623 |
-
"LicenseAknBotDB",
|
624 |
-
file_path,
|
625 |
-
caption=f"User Mention: {callback.from_user.mention}\n"
|
626 |
-
f"User ID: `{user_id}`",
|
627 |
-
reply_markup=view_button_user
|
628 |
-
)
|
629 |
-
await db.backup_chatbot.update_one(
|
630 |
-
{"user_id": user_id},
|
631 |
-
{"$set": {"file_id": photo.photo.file_id}},
|
632 |
-
upsert=True
|
633 |
-
)
|
634 |
-
translation_entry = {
|
635 |
-
"uuid": uuid_code,
|
636 |
-
"text": response.text,
|
637 |
-
"timestamp": dt.now().isoformat()
|
638 |
-
}
|
639 |
-
await db.backup_chatbot.update_one(
|
640 |
-
{"user_id": user_id},
|
641 |
-
{"$push": {"translate_history": translation_entry}},
|
642 |
-
upsert=True
|
643 |
-
)
|
644 |
-
backup_chat.append({"role": "model", "parts": [{"text": response.text}]})
|
645 |
-
await db._update_chatbot_chat_in_db(user_id, backup_chat)
|
646 |
-
await client.send_chat_action(callback.message.chat.id, enums.ChatAction.CANCEL)
|
647 |
-
return
|
648 |
-
except Exception as e:
|
649 |
-
LOGS.error(f"flux_prompt failed: {str(e)}")
|
650 |
-
return await callback.message.edit_media(
|
651 |
-
media=InputMediaPhoto(
|
652 |
-
media="error.png",
|
653 |
-
caption="Server busy try again later"
|
654 |
-
),
|
655 |
-
reply_markup=None
|
656 |
-
)
|
657 |
-
finally:
|
658 |
-
if file_path and file_photo:
|
659 |
-
try:
|
660 |
-
os.remove(file_path)
|
661 |
-
await gen.aio.files.delete(name=file_photo.name)
|
662 |
-
except:
|
663 |
-
pass
|
664 |
-
|
665 |
-
@Client.on_callback_query(filters.regex("^removerbg$"))
|
666 |
-
async def remover_bg(client, callback):
|
667 |
-
user_id = callback.from_user.id
|
668 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
669 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
670 |
-
await callback.answer("Sorry your account is frozen", True)
|
671 |
-
return
|
672 |
-
try:
|
673 |
-
data = await db.backup_chatbot.find_one({"user_id": user_id})
|
674 |
-
if not data:
|
675 |
-
return await callback.answer("Can't found user", True)
|
676 |
-
get_response = data.get("background_file_id", None)
|
677 |
-
if not get_response:
|
678 |
-
return await callback.answer("Server busy try again later", True)
|
679 |
-
media = await client.download_media(get_response)
|
680 |
-
await callback.message.edit_text(".....")
|
681 |
-
output_bg = await remove_bg_myapi(media)
|
682 |
-
if not output_bg:
|
683 |
-
return await callback.answer("Server busy try again later", True)
|
684 |
-
await callback.message.edit_media(
|
685 |
-
media=InputMediaPhoto(
|
686 |
-
media=output_bg,
|
687 |
-
caption="Uploaded now"
|
688 |
-
)
|
689 |
-
)
|
690 |
-
await callback.answer()
|
691 |
-
except Exception as e:
|
692 |
-
LOGS.error(f"remover_bg failed: {str(e)}")
|
693 |
-
return await callback.message.edit_media(
|
694 |
-
media=InputMediaPhoto(
|
695 |
-
media="error.png",
|
696 |
-
caption="Server busy try again later"
|
697 |
-
),
|
698 |
-
reply_markup=None
|
699 |
-
)
|
700 |
-
|
701 |
-
@Client.on_callback_query(filters.regex("^memory_([a-f0-9]{8})$"))
|
702 |
-
async def memory_updated(client, callback):
|
703 |
-
uuidstr = callback.matches[0].group(1)
|
704 |
-
user_id = callback.from_user.id
|
705 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
706 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
707 |
-
await callback.answer("Sorry your account is frozen", True)
|
708 |
-
return
|
709 |
-
|
710 |
-
translate_result = ""
|
711 |
-
if message_memory_state.get(callback.message.id, False):
|
712 |
-
return await callback.answer("Memory already updated!", show_alert=False)
|
713 |
-
try:
|
714 |
-
if user_id == 0:
|
715 |
-
return await callback.answer("Server busy, try again later", show_alert=True)
|
716 |
-
|
717 |
-
data_tr = await db.backup_chatbot.find_one({"user_id": user_id})
|
718 |
-
if not data_tr:
|
719 |
-
return await callback.answer("User data not found", show_alert=True)
|
720 |
-
|
721 |
-
backup_chat = await db._get_chatbot_chat_from_db(user_id)
|
722 |
-
if not backup_chat:
|
723 |
-
backup_chat = []
|
724 |
-
|
725 |
-
if not data_tr or "translate_history" not in data_tr:
|
726 |
-
return await callback.answer("translate history not found")
|
727 |
-
|
728 |
-
for translations in data_tr["translate_history"]:
|
729 |
-
if translations.get("uuid") == uuidstr:
|
730 |
-
translate_result += translations.get("text", "no translation")
|
731 |
-
break
|
732 |
-
|
733 |
-
backup_chat.append({
|
734 |
-
"role": "model",
|
735 |
-
"parts": [{"text": translate_result}]
|
736 |
-
})
|
737 |
-
await asyncio.gather(
|
738 |
-
db._update_chatbot_chat_in_db(user_id, backup_chat),
|
739 |
-
callback.answer("Memory updated successfully!")
|
740 |
-
)
|
741 |
-
message_memory_state[callback.message.id] = True
|
742 |
-
except Exception as e:
|
743 |
-
LOGS.error(f"Memory update failed: {str(e)}")
|
744 |
-
await callback.answer("Server error", show_alert=True)
|
745 |
-
|
746 |
-
@Client.on_callback_query(filters.regex("^tr_(\w+)_([a-f0-9]{8})$"))
|
747 |
-
async def terjemahkan(client, callback):
|
748 |
-
targetlang, uuidstr = callback.matches[0].groups()
|
749 |
-
user_id = callback.from_user.id
|
750 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
751 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
752 |
-
await callback.answer("Sorry your account is disabled", True)
|
753 |
-
return
|
754 |
-
|
755 |
-
translate_result = ""
|
756 |
-
try:
|
757 |
-
if user_id == 0:
|
758 |
-
return await callback.answer("Server busy try again later", True)
|
759 |
-
data_tr = await db.backup_chatbot.find_one({"user_id": user_id})
|
760 |
-
if not data_tr:
|
761 |
-
return await callback.answer("Can't found user", True)
|
762 |
-
if not data_tr or "translate_history" not in data_tr:
|
763 |
-
return await callback.answer("translate history not found")
|
764 |
-
|
765 |
-
for translations in data_tr["translate_history"]:
|
766 |
-
if translations.get("uuid") == uuidstr:
|
767 |
-
translate_result += translations.get("text", "no translation")
|
768 |
-
break
|
769 |
-
|
770 |
-
translation = trans(
|
771 |
-
translate_result,
|
772 |
-
sourcelang="auto",
|
773 |
-
targetlang=str(targetlang)
|
774 |
-
)
|
775 |
-
keyboard = create_keyboard(
|
776 |
-
user_id=user_id,
|
777 |
-
uuid_str=uuidstr
|
778 |
-
)
|
779 |
-
await callback.edit_message_text(
|
780 |
-
translation.text,
|
781 |
-
reply_markup=keyboard
|
782 |
-
)
|
783 |
-
await callback.answer("Translate Updated Now", False)
|
784 |
-
except Exception as e:
|
785 |
-
LOGS.error(f"Exception translate: {str(e)}")
|
786 |
-
await callback.answer("Server busy try again later", True)
|
787 |
-
|
788 |
-
@Client.on_callback_query(filters.regex("^showchat$"))
|
789 |
-
async def createchat_cb(client, callback):
|
790 |
-
user_id = callback.from_user.id
|
791 |
-
data = await db.backup_chatbot.find_one({"user_id": user_id})
|
792 |
-
if not data:
|
793 |
-
await callback.answer("Can't found user", True)
|
794 |
-
return
|
795 |
-
create_chat_uuid = data.get("create_chat_uuid", None)
|
796 |
-
if not create_chat_uuid:
|
797 |
-
await callback.answer("You can reset chat, this no chat found", True)
|
798 |
-
return
|
799 |
-
await callback.answer(f"Created Chat: {create_chat_uuid}", True)
|
800 |
-
|
801 |
-
@Client.on_callback_query(filters.regex("^trmulti_([a-f0-9]{8})$"))
|
802 |
-
async def multiple_langagues(client, callback):
|
803 |
-
uuidstr = callback.matches[0].group(1)
|
804 |
-
user_id = callback.from_user.id
|
805 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
806 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
807 |
-
await callback.answer("Sorry your account is frozen", True)
|
808 |
-
return
|
809 |
-
|
810 |
-
keyboard = []
|
811 |
-
keyboard.append([
|
812 |
-
InlineKeyboardButton("🇦🇪", callback_data=f"tr_ar_{uuidstr}"),
|
813 |
-
InlineKeyboardButton("🇦🇿", callback_data=f"tr_az_{uuidstr}")
|
814 |
-
])
|
815 |
-
keyboard.append([
|
816 |
-
InlineKeyboardButton("🇧🇾", callback_data=f"tr_be_{uuidstr}"),
|
817 |
-
InlineKeyboardButton("🇪🇸", callback_data=f"tr_es_{uuidstr}")
|
818 |
-
])
|
819 |
-
keyboard.append([
|
820 |
-
InlineKeyboardButton("🇹🇷", callback_data=f"tr_tr_{uuidstr}"),
|
821 |
-
InlineKeyboardButton("🇻🇳", callback_data=f"tr_vi_{uuidstr}")
|
822 |
-
])
|
823 |
-
keyboard.append([
|
824 |
-
InlineKeyboardButton("🇮🇩", callback_data=f"tr_id_{uuidstr}"),
|
825 |
-
InlineKeyboardButton("🇺🇸", callback_data=f"tr_en_{uuidstr}")
|
826 |
-
])
|
827 |
-
keyboard.append([
|
828 |
-
InlineKeyboardButton("🇮🇳", callback_data=f"tr_hi_{uuidstr}"),
|
829 |
-
InlineKeyboardButton("🇯🇵", callback_data=f"tr_ja_{uuidstr}")
|
830 |
-
])
|
831 |
-
keyboard.append([
|
832 |
-
InlineKeyboardButton("🇲🇾", callback_data=f"tr_ms_{uuidstr}"),
|
833 |
-
InlineKeyboardButton("🇷🇺", callback_data=f"tr_ru_{uuidstr}"),
|
834 |
-
])
|
835 |
-
keyboard.append([
|
836 |
-
InlineKeyboardButton("Back To Menu", callback_data=f"menu_back:{uuidstr}")
|
837 |
-
])
|
838 |
-
try:
|
839 |
-
await callback.edit_message_reply_markup(
|
840 |
-
reply_markup=InlineKeyboardMarkup(keyboard)
|
841 |
-
)
|
842 |
-
await callback.answer("Translate List Now", False)
|
843 |
-
except Exception as e:
|
844 |
-
LOGS.error(f"Exception multiple_langagues: {str(e)}")
|
845 |
-
await callback.answer("Server busy try again later", True)
|
846 |
-
|
847 |
-
def anonymous_user(user_id: int = None):
|
848 |
-
keyboard = InlineKeyboardMarkup(
|
849 |
-
[
|
850 |
-
[
|
851 |
-
InlineKeyboardButton(f"👀 View", url=f"tg://user?id={user_id}"),
|
852 |
-
]
|
853 |
-
]
|
854 |
-
)
|
855 |
-
return keyboard
|
856 |
-
|
857 |
-
@Client.on_callback_query(filters.regex("^menu_back:([a-f0-9]{8})$"))
|
858 |
-
async def menu_back(client, callback):
|
859 |
-
uuidstr = callback.matches[0].group(1)
|
860 |
-
user_id = callback.from_user.id
|
861 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
862 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
863 |
-
await callback.answer("Sorry your account is frozen", True)
|
864 |
-
return
|
865 |
-
|
866 |
-
keyboard = create_keyboard(
|
867 |
-
user_id=user_id,
|
868 |
-
uuid_str=uuidstr
|
869 |
-
)
|
870 |
-
try:
|
871 |
-
await callback.edit_message_reply_markup(reply_markup=keyboard)
|
872 |
-
except MessageNotModified:
|
873 |
-
pass
|
874 |
-
|
875 |
-
def create_keyboard(
|
876 |
-
likes: int = 0,
|
877 |
-
unlikes: int = 0,
|
878 |
-
user_id: int = None,
|
879 |
-
uuid_str: str = None,
|
880 |
-
is_menu: bool = False
|
881 |
-
):
|
882 |
-
if is_menu:
|
883 |
-
keyboard = InlineKeyboardMarkup(
|
884 |
-
[
|
885 |
-
[
|
886 |
-
InlineKeyboardButton(f"♾️", callback_data=f"trmulti_{uuid_str}"),
|
887 |
-
InlineKeyboardButton(f"💾", callback_data=f"memory_{uuid_str}"),
|
888 |
-
],
|
889 |
-
[
|
890 |
-
InlineKeyboardButton(f"👍 {likes}", callback_data="vote:like"),
|
891 |
-
InlineKeyboardButton(f"👎 {unlikes}", callback_data="vote:unlike")
|
892 |
-
]
|
893 |
-
]
|
894 |
-
)
|
895 |
-
else:
|
896 |
-
keyboard = InlineKeyboardMarkup(
|
897 |
-
[
|
898 |
-
[
|
899 |
-
InlineKeyboardButton(f"♾️", callback_data=f"trmulti_{uuid_str}"),
|
900 |
-
InlineKeyboardButton(f"🔒", callback_data=f"showchat"),
|
901 |
-
InlineKeyboardButton(f"⛏️", callback_data=f"modelmenu:{uuid_str}"),
|
902 |
-
InlineKeyboardButton(f"💡", callback_data=f"comode:{uuid_str}"),
|
903 |
-
InlineKeyboardButton(f"🚶♀️", callback_data=f"human:{uuid_str}"),
|
904 |
-
InlineKeyboardButton(f"💾", callback_data=f"memory_{uuid_str}")
|
905 |
-
],
|
906 |
-
[
|
907 |
-
InlineKeyboardButton(f"👍 {likes}", callback_data="vote:like"),
|
908 |
-
InlineKeyboardButton(f"👎 {unlikes}", callback_data="vote:unlike"),
|
909 |
-
]
|
910 |
-
]
|
911 |
-
)
|
912 |
-
return keyboard
|
913 |
-
|
914 |
-
@Client.on_callback_query(filters.regex(r"^vote:(like|unlike)$"))
|
915 |
-
async def votes(client, callback_query):
|
916 |
-
message_id = callback_query.message.id
|
917 |
-
user_id = callback_query.from_user.id
|
918 |
-
action = callback_query.matches[0].group(1)
|
919 |
-
|
920 |
-
like_counts.setdefault(message_id, set())
|
921 |
-
unlike_counts.setdefault(message_id, set())
|
922 |
-
|
923 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
924 |
-
if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
|
925 |
-
await callback_query.answer("Sorry, your account is frozen.", show_alert=True)
|
926 |
-
return
|
927 |
-
|
928 |
-
if action == "like":
|
929 |
-
if user_id in like_counts[message_id]:
|
930 |
-
like_counts[message_id].remove(user_id)
|
931 |
-
else:
|
932 |
-
like_counts[message_id].add(user_id)
|
933 |
-
unlike_counts[message_id].discard(user_id)
|
934 |
-
await callback_query.answer("Thank you for your feedback!", show_alert=False)
|
935 |
-
|
936 |
-
elif action == "unlike":
|
937 |
-
if user_id in unlike_counts[message_id]:
|
938 |
-
unlike_counts[message_id].remove(user_id)
|
939 |
-
else:
|
940 |
-
unlike_counts[message_id].add(user_id)
|
941 |
-
like_counts[message_id].discard(user_id)
|
942 |
-
await callback_query.answer("Got it, thank you!", show_alert=False)
|
943 |
-
|
944 |
-
likes = len(like_counts[message_id])
|
945 |
-
unlikes = len(unlike_counts[message_id])
|
946 |
-
updated_keyboard = create_keyboard(likes=likes, unlikes=unlikes)
|
947 |
-
|
948 |
-
try:
|
949 |
-
await callback_query.edit_message_reply_markup(reply_markup=updated_keyboard)
|
950 |
-
except MessageNotModified:
|
951 |
-
pass
|
952 |
-
await callback_query.answer()
|
953 |
-
|
954 |
-
@Client.on_message(
|
955 |
-
~filters.scheduled
|
956 |
-
& filters.command(["block"])
|
957 |
-
& filters.user(6477856957)
|
958 |
-
& ~filters.forwarded
|
959 |
-
)
|
960 |
-
async def blacklist_user(c, m):
|
961 |
-
if m.chat.type.value != "supergroup":
|
962 |
-
return await m.reply_text("You can only use this in public supergroups.")
|
963 |
-
try:
|
964 |
-
if m.reply_to_message:
|
965 |
-
getuser = m.reply_to_message.from_user.id
|
966 |
-
else:
|
967 |
-
if len(m.command) < 2:
|
968 |
-
return await m.reply_text("Reply to a user or pass a user_id to blacklist.")
|
969 |
-
getuser = int(m.command[1])
|
970 |
-
except Exception as e:
|
971 |
-
return await m.reply_text(f"⚠️ Invalid user ID: `{str(e)}`")
|
972 |
-
|
973 |
-
try:
|
974 |
-
unfreeze_at = dt.now() + timedelta(days=30)
|
975 |
-
await db.user_blacklists.update_one(
|
976 |
-
{"user_id": getuser},
|
977 |
-
{"$set": {
|
978 |
-
"is_frozen": True,
|
979 |
-
"reason": "abusive_language",
|
980 |
-
"frozen_at": dt.now(),
|
981 |
-
"unfreeze_at": unfreeze_at
|
982 |
-
}},
|
983 |
-
upsert=True
|
984 |
-
)
|
985 |
-
await c.send_message(
|
986 |
-
getuser,
|
987 |
-
"⚠️ Pengguna telah dibekukan selama 30 hari.\n"
|
988 |
-
f"⚠️ UserID: `{getuser}`.\n"
|
989 |
-
f"🕒 Expire: `{unfreeze_at.strftime('%Y-%m-%d %H:%M')}`",
|
990 |
-
reply_markup=InlineKeyboardMarkup([[
|
991 |
-
InlineKeyboardButton("⏳ Understood", callback_data="closedd")
|
992 |
-
]])
|
993 |
-
)
|
994 |
-
await m.reply_text(
|
995 |
-
"⚠️ Pengguna telah dibekukan selama 30 hari.\n"
|
996 |
-
f"⚠️ UserID: `{getuser}`.\n"
|
997 |
-
f"🕒 Expire: `{unfreeze_at.strftime('%Y-%m-%d %H:%M')}`",
|
998 |
-
reply_markup=InlineKeyboardMarkup([[
|
999 |
-
InlineKeyboardButton("⏳ Understood", callback_data="closedd")
|
1000 |
-
]])
|
1001 |
-
)
|
1002 |
-
except Exception as e:
|
1003 |
-
await m.reply_text(f"❌ Terjadi error saat memproses: `{e}`")
|
1004 |
-
|
1005 |
-
@Client.on_message(
|
1006 |
-
~filters.scheduled
|
1007 |
-
& filters.command(["start"])
|
1008 |
-
& ~filters.forwarded
|
1009 |
-
)
|
1010 |
-
async def startbot(client: Client, message: Message):
|
1011 |
-
user_bl = await db.user_blacklists.find_one({"user_id": message.from_user.id})
|
1012 |
-
if user_bl and user_bl.get("is_frozen", False) and message.from_user.id not in [6477856957]:
|
1013 |
-
return
|
1014 |
-
users_all = await db.backup_chatbot.find_one({"bot_id": client.me.id})
|
1015 |
-
users_count = len(users_all["broadcast"])
|
1016 |
-
buttons = [
|
1017 |
-
[
|
1018 |
-
InlineKeyboardButton(
|
1019 |
-
text="Developer",
|
1020 |
-
url=f"https://t.me/xtdevs"
|
1021 |
-
),
|
1022 |
-
InlineKeyboardButton(
|
1023 |
-
text="Channel",
|
1024 |
-
url='https://t.me/RendyProjects'
|
1025 |
-
),
|
1026 |
-
]
|
1027 |
-
]
|
1028 |
-
await db.backup_chatbot.update_one(
|
1029 |
-
{"bot_id": client.me.id},
|
1030 |
-
{"$addToSet": {"broadcast": message.from_user.id}},
|
1031 |
-
upsert=True
|
1032 |
-
)
|
1033 |
-
await message.reply_text(
|
1034 |
-
text=GEMINI_START_TEXT.format(
|
1035 |
-
user=f"{users_count * random.randint(0, 999999)}"
|
1036 |
-
),
|
1037 |
-
disable_web_page_preview=True,
|
1038 |
-
reply_markup=InlineKeyboardMarkup(buttons)
|
1039 |
-
)
|
1040 |
-
|
1041 |
-
@Client.on_message(
|
1042 |
-
filters.incoming
|
1043 |
-
& (
|
1044 |
-
filters.text
|
1045 |
-
| filters.photo
|
1046 |
-
| filters.video
|
1047 |
-
| filters.audio
|
1048 |
-
| filters.voice
|
1049 |
-
| filters.sticker
|
1050 |
-
| filters.document
|
1051 |
-
)
|
1052 |
-
& filters.private
|
1053 |
-
& ~filters.command(["start", "setmodel", "mypremium"])
|
1054 |
-
& ~filters.forwarded
|
1055 |
-
)
|
1056 |
-
async def chatbot_talk(client: Client, message: Message):
|
1057 |
-
user = await users_collection.find_one({"user_id": message.from_user.id})
|
1058 |
-
model_ = user.get("model") if user else "gemini-2.0-flash"
|
1059 |
-
|
1060 |
-
if message.reply_to_message and message.reply_to_message.from_user:
|
1061 |
-
if message.reply_to_message.from_user.id != client.me.id:
|
1062 |
-
return
|
1063 |
-
|
1064 |
-
if message.photo:
|
1065 |
-
file_photo = None
|
1066 |
-
captions = ""
|
1067 |
-
file_path = "gemini-native-image.png"
|
1068 |
-
try:
|
1069 |
-
user_bl = await db.user_blacklists.find_one({"user_id": message.from_user.id})
|
1070 |
-
if user_bl and user_bl.get("is_frozen", False) and message.from_user.id not in [6477856957]:
|
1071 |
-
return
|
1072 |
-
|
1073 |
-
caption = message.caption or "What this?"
|
1074 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_PHOTO)
|
1075 |
-
await asyncio.sleep(1.5)
|
1076 |
-
|
1077 |
-
if regex_all_blacklist(caption):
|
1078 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1079 |
-
return
|
1080 |
-
|
1081 |
-
if caption in ["--stream-images", "--edit-images"] or len(caption) > 350:
|
1082 |
-
return await message.reply_text(
|
1083 |
-
"You can't type (error 404: creativity not found)"
|
1084 |
-
)
|
1085 |
-
|
1086 |
-
stream_image_now = re.match(r"--stream-images\s*(.*)", caption, re.IGNORECASE)
|
1087 |
-
if stream_image_now:
|
1088 |
-
STREAM_IMAGE_PATH = await message.download()
|
1089 |
-
uuid_code = str(uuid.uuid4())[:8]
|
1090 |
-
try:
|
1091 |
-
backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
|
1092 |
-
backup_chat.append({"role": "user", "parts": [{"text": caption}]})
|
1093 |
-
with open(STREAM_IMAGE_PATH, 'rb') as f:
|
1094 |
-
image_bytes = f.read()
|
1095 |
-
async for chunk in await gen.aio.models.generate_content_stream(
|
1096 |
-
model="gemini-1.5-flash",
|
1097 |
-
contents=[
|
1098 |
-
str(stream_image_now.group(1)),
|
1099 |
-
ty.Part.from_bytes(data=image_bytes, mime_type="image/jpeg")
|
1100 |
-
]
|
1101 |
-
):
|
1102 |
-
captions += chunk.text
|
1103 |
-
|
1104 |
-
if captions == "":
|
1105 |
-
return await message.reply_text("Server busy try again later")
|
1106 |
-
|
1107 |
-
keyboard = create_keyboard(
|
1108 |
-
user_id=message.from_user.id,
|
1109 |
-
uuid_str=uuid_code
|
1110 |
-
)
|
1111 |
-
await message.reply_text(
|
1112 |
-
captions,
|
1113 |
-
disable_web_page_preview=True,
|
1114 |
-
reply_markup=keyboard
|
1115 |
-
)
|
1116 |
-
|
1117 |
-
translation_entry = {
|
1118 |
-
"uuid": uuid_code,
|
1119 |
-
"text": captions,
|
1120 |
-
"timestamp": dt.now().isoformat()
|
1121 |
-
}
|
1122 |
-
await db.backup_chatbot.update_one(
|
1123 |
-
{"user_id": message.from_user.id},
|
1124 |
-
{"$push": {"translate_history": translation_entry}},
|
1125 |
-
upsert=True
|
1126 |
-
)
|
1127 |
-
backup_chat.append({"role": "model", "parts": [{"text": captions}]})
|
1128 |
-
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
1129 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1130 |
-
return
|
1131 |
-
except Exception as e:
|
1132 |
-
return await message.reply_text("Server busy try again later")
|
1133 |
-
finally:
|
1134 |
-
if STREAM_IMAGE_PATH:
|
1135 |
-
try:
|
1136 |
-
os.remove(STREAM_IMAGE_PATH)
|
1137 |
-
except:
|
1138 |
-
pass
|
1139 |
-
|
1140 |
-
edit_image_now = re.match(r"--edit-images\s*(.*)", caption, re.IGNORECASE)
|
1141 |
-
if edit_image_now:
|
1142 |
-
try:
|
1143 |
-
user_data = await db.user_premium.find_one({"user_id": message.from_user.id}) or {
|
1144 |
-
"user_id": message.from_user.id,
|
1145 |
-
"credits_used": 0,
|
1146 |
-
"last_reset": dt.now(),
|
1147 |
-
"is_premium": False,
|
1148 |
-
"premium_expiry": None
|
1149 |
-
}
|
1150 |
-
if dt.now() - user_data["last_reset"] > timedelta(days=1):
|
1151 |
-
await db.user_premium.update_one(
|
1152 |
-
{"user_id": message.from_user.id},
|
1153 |
-
{"$set": {"credits_used": 0, "last_reset": dt.now()}}
|
1154 |
-
)
|
1155 |
-
user_data["credits_used"] = 0
|
1156 |
-
|
1157 |
-
if user_data.get("is_premium") and user_data["premium_expiry"] < dt.now():
|
1158 |
-
await db.user_premium.update_one(
|
1159 |
-
{"user_id": message.from_user.id},
|
1160 |
-
{"$set": {"is_premium": False}}
|
1161 |
-
)
|
1162 |
-
user_data["is_premium"] = False
|
1163 |
-
|
1164 |
-
credit_limit = 50 if user_data["is_premium"] else 5
|
1165 |
-
remaining = credit_limit - user_data["credits_used"]
|
1166 |
-
if remaining <= 0:
|
1167 |
-
time_left = (user_data["last_reset"] + timedelta(days=1) - dt.now())
|
1168 |
-
hours = int(time_left.total_seconds() // 3600)
|
1169 |
-
return await message.reply_text(
|
1170 |
-
f"🚫 Credit Limit Reached\n\n"
|
1171 |
-
f"• Used: {user_data['credits_used']}/{credit_limit} images today\n"
|
1172 |
-
f"• Resets in: {hours} hours\n\n"
|
1173 |
-
f"💎 Upgrade to Premium for 50 daily credits!",
|
1174 |
-
reply_markup=InlineKeyboardMarkup([[
|
1175 |
-
InlineKeyboardButton("Get Premium", callback_data="get_premium")
|
1176 |
-
]])
|
1177 |
-
)
|
1178 |
-
|
1179 |
-
backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
|
1180 |
-
backup_chat.append({"role": "user", "parts": [{"text": caption}]})
|
1181 |
-
images = Image.open(await message.download())
|
1182 |
-
response = await gen.aio.models.generate_content(
|
1183 |
-
model="gemini-2.0-flash-exp-image-generation",
|
1184 |
-
contents=[str(edit_image_now.group(1)), images],
|
1185 |
-
config=ty.GenerateContentConfig(
|
1186 |
-
response_modalities=['TEXT', 'IMAGE']
|
1187 |
-
)
|
1188 |
-
)
|
1189 |
-
for part in response.candidates[0].content.parts:
|
1190 |
-
if part.text is not None:
|
1191 |
-
captions += part.text
|
1192 |
-
elif part.inline_data is not None:
|
1193 |
-
image = Image.open(BytesIO(part.inline_data.data))
|
1194 |
-
image.save(file_path)
|
1195 |
-
keyboard_like = create_keyboard(user_id=message.from_user.id)
|
1196 |
-
await message.reply_photo(
|
1197 |
-
file_path,
|
1198 |
-
caption=captions,
|
1199 |
-
reply_markup=keyboard_like
|
1200 |
-
)
|
1201 |
-
await db.backup_chatbot.update_one(
|
1202 |
-
{"user_id": message.from_user.id},
|
1203 |
-
{"$set": {"translate_text": captions}},
|
1204 |
-
upsert=True
|
1205 |
-
)
|
1206 |
-
backup_chat.append({"role": "model", "parts": [{"text": captions}]})
|
1207 |
-
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
1208 |
-
is_active_premium = (
|
1209 |
-
user_data.get("is_premium", False) and
|
1210 |
-
user_data.get("premium_expiry", dt.min) > dt.now()
|
1211 |
-
)
|
1212 |
-
new_credits_used = user_data.get("credits_used", 0) + 1
|
1213 |
-
should_reset = (dt.now() - user_data.get("last_reset", dt.now())) > timedelta(days=1)
|
1214 |
-
update = {
|
1215 |
-
"$set": {
|
1216 |
-
"credits_used": 1 if should_reset else new_credits_used,
|
1217 |
-
"last_reset": dt.now() if should_reset else user_data["last_reset"],
|
1218 |
-
"is_premium": is_active_premium
|
1219 |
-
}
|
1220 |
-
}
|
1221 |
-
if "premium_expiry" not in user_data:
|
1222 |
-
update["$set"]["premium_expiry"] = None
|
1223 |
-
|
1224 |
-
await db.user_premium.update_one(
|
1225 |
-
{"user_id": message.from_user.id},
|
1226 |
-
update,
|
1227 |
-
upsert=True
|
1228 |
-
)
|
1229 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1230 |
-
return
|
1231 |
-
except Exception as e:
|
1232 |
-
LOGS.error(f"Error: Gemini Edit Image: {str(e)}")
|
1233 |
-
return await message.reply_text("Server busy try again later")
|
1234 |
-
finally:
|
1235 |
-
if file_path:
|
1236 |
-
try:
|
1237 |
-
os.remove(file_path)
|
1238 |
-
except:
|
1239 |
-
pass
|
1240 |
-
|
1241 |
-
if re.findall(r"\b(pro:editimage)\b", caption, re.IGNORECASE):
|
1242 |
-
await db.backup_chatbot.update_one(
|
1243 |
-
{"user_id": message.from_user.id},
|
1244 |
-
{"$set": {"background_file_id": message.photo.file_id}},
|
1245 |
-
upsert=True
|
1246 |
-
)
|
1247 |
-
buttons = [
|
1248 |
-
[
|
1249 |
-
InlineKeyboardButton(
|
1250 |
-
text="✂️ Background Remover",
|
1251 |
-
callback_data="removerbg"
|
1252 |
-
)
|
1253 |
-
],
|
1254 |
-
[
|
1255 |
-
InlineKeyboardButton(
|
1256 |
-
text="❌ Cancel",
|
1257 |
-
callback_data="closedd"
|
1258 |
-
)
|
1259 |
-
]
|
1260 |
-
]
|
1261 |
-
await message.reply_photo(
|
1262 |
-
message.photo.file_id,
|
1263 |
-
caption="Are you sure you want to image this edit image?",
|
1264 |
-
reply_markup=InlineKeyboardMarkup(buttons)
|
1265 |
-
)
|
1266 |
-
return
|
1267 |
-
|
1268 |
-
backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
|
1269 |
-
backup_chat.append({"role": "user", "parts": [{"text": caption}]})
|
1270 |
-
file_photo = await gen.aio.files.upload(file=await message.download())
|
1271 |
-
while file_photo.state.name == "PROCESSING":
|
1272 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_PHOTO)
|
1273 |
-
await asyncio.sleep(10)
|
1274 |
-
file_photo = await gen.aio.files.get(name=file_photo.name)
|
1275 |
-
if file_photo.state.name == "FAILED":
|
1276 |
-
return await message.reply_text(f"Error: {file_photo.state.name}")
|
1277 |
-
response = await gen.aio.models.generate_content(
|
1278 |
-
model="gemini-1.5-flash",
|
1279 |
-
contents=[str(caption), file_photo]
|
1280 |
-
)
|
1281 |
-
uuid_code = str(uuid.uuid4())[:8]
|
1282 |
-
if len(response.text) > 4096:
|
1283 |
-
text_parts = split_message(response.text)
|
1284 |
-
for part in text_parts:
|
1285 |
-
await message.reply_text(part)
|
1286 |
-
else:
|
1287 |
-
keyboard_like = create_keyboard(
|
1288 |
-
user_id=message.from_user.id,
|
1289 |
-
uuid_str=uuid_code
|
1290 |
-
)
|
1291 |
-
await message.reply_text(
|
1292 |
-
response.text,
|
1293 |
-
disable_web_page_preview=True,
|
1294 |
-
reply_markup=keyboard_like
|
1295 |
-
)
|
1296 |
-
translation_entry = {
|
1297 |
-
"uuid": uuid_code,
|
1298 |
-
"text": response.text,
|
1299 |
-
"timestamp": dt.now().isoformat()
|
1300 |
-
}
|
1301 |
-
await db.backup_chatbot.update_one(
|
1302 |
-
{"user_id": message.from_user.id},
|
1303 |
-
{"$push": {"translate_history": translation_entry}},
|
1304 |
-
upsert=True
|
1305 |
-
)
|
1306 |
-
backup_chat.append({"role": "model", "parts": [{"text": response.text}]})
|
1307 |
-
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
1308 |
-
LOGS.info(f"Response Upload Photo: {message.from_user.first_name} | {message.from_user.id}\n\nText: {caption}")
|
1309 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1310 |
-
return
|
1311 |
-
|
1312 |
-
except Exception as e:
|
1313 |
-
LOGS.error(f"Error: message.text: {str(e)}")
|
1314 |
-
return await message.reply_text("Server busy try again later")
|
1315 |
-
finally:
|
1316 |
-
if file_photo:
|
1317 |
-
await gen.aio.files.delete(name=file_photo.name)
|
1318 |
-
|
1319 |
-
if message.video:
|
1320 |
-
video_file = None
|
1321 |
-
try:
|
1322 |
-
user_bl = await db.user_blacklists.find_one({"user_id": message.from_user.id})
|
1323 |
-
if user_bl and user_bl.get("is_frozen", False) and message.from_user.id not in [6477856957]:
|
1324 |
-
return
|
1325 |
-
|
1326 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_VIDEO)
|
1327 |
-
await asyncio.sleep(2.0)
|
1328 |
-
caption = message.caption or "What this?"
|
1329 |
-
if regex_all_blacklist(caption):
|
1330 |
-
return
|
1331 |
-
|
1332 |
-
backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
|
1333 |
-
backup_chat.append({"role": "user", "parts": [{"text": caption}]})
|
1334 |
-
video_file = await gen.aio.files.upload(file=await message.download())
|
1335 |
-
while video_file.state.name == "PROCESSING":
|
1336 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_VIDEO)
|
1337 |
-
await asyncio.sleep(10)
|
1338 |
-
video_file = await gen.aio.files.get(name=video_file.name)
|
1339 |
-
if video_file.state.name == "FAILED":
|
1340 |
-
return await message.reply_text(f"Error: {video_file.state.name}")
|
1341 |
-
response = await gen.aio.models.generate_content(
|
1342 |
-
model="gemini-1.5-flash",
|
1343 |
-
contents=[str(caption), video_file]
|
1344 |
-
)
|
1345 |
-
uuid_code = str(uuid.uuid4())[:8]
|
1346 |
-
if len(response.text) > 4096:
|
1347 |
-
text_parts = split_message(response.text)
|
1348 |
-
for part in text_parts:
|
1349 |
-
await message.reply_text(part)
|
1350 |
-
else:
|
1351 |
-
keyboard_like = create_keyboard(
|
1352 |
-
user_id=message.from_user.id,
|
1353 |
-
uuid_str=uuid_code
|
1354 |
-
)
|
1355 |
-
await message.reply_text(
|
1356 |
-
response.text,
|
1357 |
-
disable_web_page_preview=True,
|
1358 |
-
reply_markup=keyboard_like
|
1359 |
-
)
|
1360 |
-
translation_entry = {
|
1361 |
-
"uuid": uuid_code,
|
1362 |
-
"text": response.text,
|
1363 |
-
"timestamp": dt.now().isoformat()
|
1364 |
-
}
|
1365 |
-
await db.backup_chatbot.update_one(
|
1366 |
-
{"user_id": message.from_user.id},
|
1367 |
-
{"$push": {"translate_history": translation_entry}},
|
1368 |
-
upsert=True
|
1369 |
-
)
|
1370 |
-
backup_chat.append({"role": "model", "parts": [{"text": response.text}]})
|
1371 |
-
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
1372 |
-
LOGS.info(f"Response Upload Video: {message.from_user.first_name} | {message.from_user.id}\n\nText: {caption}")
|
1373 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1374 |
-
return
|
1375 |
-
|
1376 |
-
except Exception as e:
|
1377 |
-
LOGS.error(f"Error: message.text: {str(e)}")
|
1378 |
-
return await message.reply_text("Server busy try again later")
|
1379 |
-
finally:
|
1380 |
-
if video_file:
|
1381 |
-
await gen.aio.files.delete(name=video_file.name)
|
1382 |
-
|
1383 |
-
if message.sticker:
|
1384 |
-
sticker_file = None
|
1385 |
-
media = None
|
1386 |
-
try:
|
1387 |
-
user_bl = await db.user_blacklists.find_one({"user_id": message.from_user.id})
|
1388 |
-
if user_bl and user_bl.get("is_frozen", False) and message.from_user.id not in [6477856957]:
|
1389 |
-
return
|
1390 |
-
|
1391 |
-
f = message.sticker.file_id
|
1392 |
-
backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
|
1393 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CHOOSE_STICKER)
|
1394 |
-
await asyncio.sleep(2.5)
|
1395 |
-
media = await client.download_media(f, file_name=f"{str(uuid.uuid4())[:8]}.jpg")
|
1396 |
-
if media.endswith(".jpg"):
|
1397 |
-
sticker_file = await gen.aio.files.upload(file=media)
|
1398 |
-
while sticker_file.state.name == "PROCESSING":
|
1399 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CHOOSE_STICKER)
|
1400 |
-
await asyncio.sleep(10)
|
1401 |
-
sticker_file = await gen.aio.files.get(name=sticker_file.name)
|
1402 |
-
if sticker_file.state.name == "FAILED":
|
1403 |
-
return await message.reply_text(f"Error: {sticker_file.state.name}")
|
1404 |
-
response = await gen.aio.models.generate_content(
|
1405 |
-
model="gemini-1.5-flash",
|
1406 |
-
contents=["funny random meme sticker words", sticker_file]
|
1407 |
-
)
|
1408 |
-
uuid_code = str(uuid.uuid4())[:8]
|
1409 |
-
if len(response.text) > 4096:
|
1410 |
-
text_parts = split_message(response.text)
|
1411 |
-
for part in text_parts:
|
1412 |
-
await message.reply_text(part)
|
1413 |
-
else:
|
1414 |
-
keyboard_like = create_keyboard(
|
1415 |
-
user_id=message.from_user.id,
|
1416 |
-
uuid_str=uuid_code
|
1417 |
-
)
|
1418 |
-
await message.reply_text(
|
1419 |
-
response.text,
|
1420 |
-
disable_web_page_preview=True,
|
1421 |
-
reply_markup=keyboard_like
|
1422 |
-
)
|
1423 |
-
|
1424 |
-
translation_entry = {
|
1425 |
-
"uuid": uuid_code,
|
1426 |
-
"text": response.text,
|
1427 |
-
"timestamp": dt.now().isoformat()
|
1428 |
-
}
|
1429 |
-
await db.backup_chatbot.update_one(
|
1430 |
-
{"user_id": message.from_user.id},
|
1431 |
-
{"$push": {"translate_history": translation_entry}},
|
1432 |
-
upsert=True
|
1433 |
-
)
|
1434 |
-
backup_chat.append({"role": "model", "parts": [{"text": response.text}]})
|
1435 |
-
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
1436 |
-
LOGS.info(f"Response Upload Sticker: {message.from_user.first_name} | {message.from_user.id}")
|
1437 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1438 |
-
return
|
1439 |
-
|
1440 |
-
except Exception as e:
|
1441 |
-
LOGS.error(f"Error: message.text: {str(e)}")
|
1442 |
-
return await message.reply_text("Server busy try again later")
|
1443 |
-
finally:
|
1444 |
-
if sticker_file:
|
1445 |
-
await gen.aio.files.delete(name=sticker_file.name)
|
1446 |
-
try:
|
1447 |
-
os.remove(media)
|
1448 |
-
except:
|
1449 |
-
pass
|
1450 |
-
|
1451 |
-
if message.text:
|
1452 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.TYPING)
|
1453 |
-
await asyncio.sleep(1.5)
|
1454 |
-
query = message.text.strip()
|
1455 |
-
query_base = query
|
1456 |
-
captions = ""
|
1457 |
-
file_path = "gemini-native-image.png"
|
1458 |
-
try:
|
1459 |
-
user_bl = await db.user_blacklists.find_one({"user_id": message.from_user.id})
|
1460 |
-
if user_bl and user_bl.get("is_frozen", False) and message.from_user.id not in [6477856957]:
|
1461 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1462 |
-
return
|
1463 |
-
|
1464 |
-
if is_command_disabled(query_base):
|
1465 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1466 |
-
return
|
1467 |
-
|
1468 |
-
if regex_all_blacklist(query_base):
|
1469 |
-
unfreeze_at = dt.now() + timedelta(days=2)
|
1470 |
-
await db.user_blacklists.update_one(
|
1471 |
-
{"user_id": message.from_user.id},
|
1472 |
-
{"$set": {
|
1473 |
-
"is_frozen": True,
|
1474 |
-
"reason": "abusive_language",
|
1475 |
-
"frozen_at": dt.now(),
|
1476 |
-
"unfreeze_at": unfreeze_at
|
1477 |
-
}},
|
1478 |
-
upsert=True
|
1479 |
-
)
|
1480 |
-
await message.reply_text(
|
1481 |
-
"⚠️ You've been restricted for 2 days\n"
|
1482 |
-
f"Expires: {unfreeze_at.strftime('%Y-%m-%d %H:%M')}",
|
1483 |
-
reply_markup=InlineKeyboardMarkup([[
|
1484 |
-
InlineKeyboardButton(
|
1485 |
-
"⏳ Understood",
|
1486 |
-
callback_data="closedd"
|
1487 |
-
)
|
1488 |
-
]])
|
1489 |
-
)
|
1490 |
-
return
|
1491 |
-
|
1492 |
-
if query_base in DISABLED_COMMANDS:
|
1493 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1494 |
-
return
|
1495 |
-
|
1496 |
-
all_regex_disabled = re.match(r"(--stream-images|--edit-images)\s*(.*)", query_base, re.IGNORECASE)
|
1497 |
-
if all_regex_disabled:
|
1498 |
-
await message.reply_text(
|
1499 |
-
"Use upload your photo and caption instead of text is disabled"
|
1500 |
-
)
|
1501 |
-
return
|
1502 |
-
|
1503 |
-
if re.findall(r"\b(about:developer)\b", query_base, re.IGNORECASE):
|
1504 |
-
await message.reply_text(CREDITS_DEVELOPER)
|
1505 |
-
return
|
1506 |
-
|
1507 |
-
check_data = aigen_check(message.from_user.id, query_base)
|
1508 |
-
user_result = check_data.get(message.from_user.id, {})
|
1509 |
-
if user_result.get("is_anti_porno"):
|
1510 |
-
return await message.reply_text(user_result["reason"])
|
1511 |
-
|
1512 |
-
if user_result.get("is_image"):
|
1513 |
-
try:
|
1514 |
-
buttons = [
|
1515 |
-
[
|
1516 |
-
InlineKeyboardButton(
|
1517 |
-
text="🎨 Gemini AI Generate Image",
|
1518 |
-
callback_data=f"genprompt_{message.from_user.id}"
|
1519 |
-
)
|
1520 |
-
],
|
1521 |
-
[
|
1522 |
-
InlineKeyboardButton(
|
1523 |
-
text="🖌️ FLUX AI Generate Image",
|
1524 |
-
callback_data=f"fluxprompt_{message.from_user.id}"
|
1525 |
-
)
|
1526 |
-
],
|
1527 |
-
[
|
1528 |
-
InlineKeyboardButton(
|
1529 |
-
text="❌ Cancel",
|
1530 |
-
callback_data="closedd"
|
1531 |
-
)
|
1532 |
-
]
|
1533 |
-
]
|
1534 |
-
await db.backup_chatbot.update_one(
|
1535 |
-
{"user_id": message.from_user.id},
|
1536 |
-
{"$set": {"prompt_image": user_result["prompt"]}},
|
1537 |
-
upsert=True
|
1538 |
-
)
|
1539 |
-
LOGS.info(f"Response Image Generate: {message.from_user.first_name} | {message.from_user.id}\n\nText: {query_base}")
|
1540 |
-
await message.reply_photo(
|
1541 |
-
photo="loading.jpg",
|
1542 |
-
caption="Are you sure you want to prompt this Image generate?",
|
1543 |
-
reply_markup=InlineKeyboardMarkup(buttons)
|
1544 |
-
)
|
1545 |
-
return
|
1546 |
-
except Exception as e:
|
1547 |
-
LOGS.error(f"Error: Gemini Image: {str(e)}")
|
1548 |
-
return await message.reply_text("Server busy try again later")
|
1549 |
-
|
1550 |
-
|
1551 |
-
if re.findall(r"\b(disabled:callusers)\b", query_base, re.IGNORECASE):
|
1552 |
-
if message.from_user.id != 6477856957:
|
1553 |
-
return
|
1554 |
-
try:
|
1555 |
-
data = await db.backup_chatbot.find({"is_system": True}).to_list(length=None)
|
1556 |
-
for user in data:
|
1557 |
-
await db.backup_chatbot.update_one(
|
1558 |
-
{"_id": user["_id"]},
|
1559 |
-
{"$set": {"is_system": False}},
|
1560 |
-
)
|
1561 |
-
await message.reply_text("All Users streaming is disabled now")
|
1562 |
-
return
|
1563 |
-
except Exception as e:
|
1564 |
-
await message.reply_text(f"Error {str(e)}")
|
1565 |
-
|
1566 |
-
if re.findall(r"\b(enabled:chatstream)\b", query_base, re.IGNORECASE):
|
1567 |
-
await db.backup_chatbot.update_one(
|
1568 |
-
{"user_id": message.from_user.id},
|
1569 |
-
{"$set": {"is_system": True}},
|
1570 |
-
upsert=True
|
1571 |
-
)
|
1572 |
-
await message.reply_text(
|
1573 |
-
"Ok successfully streaming is enabled"
|
1574 |
-
)
|
1575 |
-
return
|
1576 |
-
|
1577 |
-
if re.findall(r"\b(disabled:chatstream)\b", query_base, re.IGNORECASE):
|
1578 |
-
await db.backup_chatbot.update_one(
|
1579 |
-
{"user_id": message.from_user.id},
|
1580 |
-
{"$set": {"is_system": False}},
|
1581 |
-
upsert=True
|
1582 |
-
)
|
1583 |
-
await message.reply_text(
|
1584 |
-
"Ok successfully streaming is disabled"
|
1585 |
-
)
|
1586 |
-
return
|
1587 |
-
|
1588 |
-
check_is_system = await db.backup_chatbot.find_one({"user_id": message.from_user.id})
|
1589 |
-
if not check_is_system:
|
1590 |
-
uuid_create = str(uuid.uuid4())[:8]
|
1591 |
-
await db.backup_chatbot.update_one(
|
1592 |
-
{"user_id": message.from_user.id},
|
1593 |
-
{"$set": {"is_system": False, "create_chat_uuid": uuid_create}},
|
1594 |
-
upsert=True
|
1595 |
-
)
|
1596 |
-
await message.reply_text(
|
1597 |
-
"Ok Updated Now Type anything to begin."
|
1598 |
-
)
|
1599 |
-
return
|
1600 |
-
|
1601 |
-
uuid_human = str(uuid.uuid4())[:8]
|
1602 |
-
if check_is_system.get("is_humanizer", False):
|
1603 |
-
backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
|
1604 |
-
backup_chat.append({"role": "user", "parts": [{"text": query_base}]})
|
1605 |
-
response = await ryz.aio.humanizer.rewrite(
|
1606 |
-
RequestHumanizer(
|
1607 |
-
text=str(query_base),
|
1608 |
-
writing_style="alay",
|
1609 |
-
author_id=str(message.from_user.id),
|
1610 |
-
timestamp=str(dt.now())
|
1611 |
-
),
|
1612 |
-
pickle_json=True
|
1613 |
-
)
|
1614 |
-
data = SmallConvertDot(response).to_dot()
|
1615 |
-
if len(data.text) > 4096:
|
1616 |
-
text_parts = split_message(data.text)
|
1617 |
-
for part in text_parts:
|
1618 |
-
await message.reply_text(part)
|
1619 |
-
else:
|
1620 |
-
keyboard_like = create_keyboard(
|
1621 |
-
user_id=message.from_user.id,
|
1622 |
-
uuid_str=uuid_human
|
1623 |
-
)
|
1624 |
-
await message.reply_text(
|
1625 |
-
data.text,
|
1626 |
-
disable_web_page_preview=True,
|
1627 |
-
reply_markup=keyboard_like
|
1628 |
-
)
|
1629 |
-
translation_entry = {
|
1630 |
-
"uuid": uuid_human,
|
1631 |
-
"text": data.text,
|
1632 |
-
"timestamp": dt.now().isoformat()
|
1633 |
-
}
|
1634 |
-
await db.backup_chatbot.update_one(
|
1635 |
-
{"user_id": message.from_user.id},
|
1636 |
-
{"$push": {"translate_history": translation_entry}},
|
1637 |
-
upsert=True
|
1638 |
-
)
|
1639 |
-
backup_chat.append({"role": "model", "parts": [{"text": data.text}]})
|
1640 |
-
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
1641 |
-
LOGS.info(f"Response Humanizer: {message.from_user.first_name} | {message.from_user.id}\n\nText: {query_base}")
|
1642 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1643 |
-
return
|
1644 |
-
|
1645 |
-
|
1646 |
-
uuid_cohere = str(uuid.uuid4())[:8]
|
1647 |
-
if check_is_system.get("is_deepsearch", False):
|
1648 |
-
backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
|
1649 |
-
backup_chat.append({"role": "user", "parts": [{"text": query_base}]})
|
1650 |
-
results = await search_auto_by_cohere(message.from_user.id, query_base)
|
1651 |
-
if len(results) > 4096:
|
1652 |
-
text_parts = split_message(results)
|
1653 |
-
for part in text_parts:
|
1654 |
-
await message.reply_text(part)
|
1655 |
-
else:
|
1656 |
-
keyboard_like = create_keyboard(
|
1657 |
-
user_id=message.from_user.id,
|
1658 |
-
uuid_str=uuid_cohere
|
1659 |
-
)
|
1660 |
-
await message.reply_text(
|
1661 |
-
results,
|
1662 |
-
disable_web_page_preview=True,
|
1663 |
-
reply_markup=keyboard_like
|
1664 |
-
)
|
1665 |
-
translation_entry = {
|
1666 |
-
"uuid": uuid_cohere,
|
1667 |
-
"text": results,
|
1668 |
-
"timestamp": dt.now().isoformat()
|
1669 |
-
}
|
1670 |
-
await db.backup_chatbot.update_one(
|
1671 |
-
{"user_id": message.from_user.id},
|
1672 |
-
{"$push": {"translate_history": translation_entry}},
|
1673 |
-
upsert=True
|
1674 |
-
)
|
1675 |
-
backup_chat.append({"role": "model", "parts": [{"text": results}]})
|
1676 |
-
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
1677 |
-
LOGS.info(f"Response Deep Search: {message.from_user.first_name} | {message.from_user.id}\n\nText: {query_base}")
|
1678 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1679 |
-
return
|
1680 |
-
|
1681 |
-
if check_is_system.get("is_system", False):
|
1682 |
-
_deletemydata_match = re.match(r"^--deletemydata\s+--reason\s+(.+)$", query_base, re.IGNORECASE)
|
1683 |
-
if _deletemydata_match:
|
1684 |
-
reasons = _deletemydata_match.group(1).strip()
|
1685 |
-
if not reasons:
|
1686 |
-
return await message.reply_text("Reason cannot be empty")
|
1687 |
-
if len(reasons) < 15:
|
1688 |
-
return await message.reply_text("Reason is too short (minimum 15 characters).")
|
1689 |
-
buttons = [
|
1690 |
-
[
|
1691 |
-
InlineKeyboardButton(
|
1692 |
-
text="💀 Delete my data history",
|
1693 |
-
callback_data="deletemydatagm"
|
1694 |
-
)
|
1695 |
-
],
|
1696 |
-
[
|
1697 |
-
InlineKeyboardButton(
|
1698 |
-
text="❌ Cancel",
|
1699 |
-
callback_data="closedd"
|
1700 |
-
)
|
1701 |
-
]
|
1702 |
-
]
|
1703 |
-
LOGS.info(f"Response info data system: {message.from_user.first_name} | {message.from_user.id}\n\nText: {query_base}")
|
1704 |
-
await message.reply_text(
|
1705 |
-
"Are you sure you want to delete this data history?",
|
1706 |
-
reply_markup=InlineKeyboardMarkup(buttons)
|
1707 |
-
)
|
1708 |
-
return
|
1709 |
-
|
1710 |
-
test_result = ""
|
1711 |
-
uuid_code = str(uuid.uuid4())[:8]
|
1712 |
-
backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
|
1713 |
-
backup_chat.append({"role": "user", "parts": [{"text": query_base}]})
|
1714 |
-
async for chunk in await gen.aio.models.generate_content_stream(
|
1715 |
-
model=model_,
|
1716 |
-
contents=backup_chat,
|
1717 |
-
config=ty.GenerateContentConfig(
|
1718 |
-
system_instruction="You are my name Randy Dev and friends coding language Indonesia and English",
|
1719 |
-
response_mime_type="text/plain",
|
1720 |
-
temperature=0,
|
1721 |
-
top_p=0.95,
|
1722 |
-
top_k=20,
|
1723 |
-
candidate_count=1,
|
1724 |
-
seed=5,
|
1725 |
-
max_output_tokens=4096,
|
1726 |
-
stop_sequences=['STOP!'],
|
1727 |
-
presence_penalty=0.0,
|
1728 |
-
frequency_penalty=0.0,
|
1729 |
-
)
|
1730 |
-
):
|
1731 |
-
test_result += chunk.text
|
1732 |
-
|
1733 |
-
if test_result == "":
|
1734 |
-
return await message.reply_text("Server busy try again later")
|
1735 |
-
|
1736 |
-
if len(test_result) > 4096:
|
1737 |
-
text_parts = split_message(test_result)
|
1738 |
-
for part in text_parts:
|
1739 |
-
await message.reply_text(part)
|
1740 |
-
else:
|
1741 |
-
keyboard_like = create_keyboard(
|
1742 |
-
user_id=message.from_user.id,
|
1743 |
-
uuid_str=uuid_code
|
1744 |
-
)
|
1745 |
-
await message.reply_text(
|
1746 |
-
test_result,
|
1747 |
-
disable_web_page_preview=True,
|
1748 |
-
reply_markup=keyboard_like
|
1749 |
-
)
|
1750 |
-
translation_entry = {
|
1751 |
-
"uuid": uuid_code,
|
1752 |
-
"text": test_result,
|
1753 |
-
"timestamp": dt.now().isoformat()
|
1754 |
-
}
|
1755 |
-
await db.backup_chatbot.update_one(
|
1756 |
-
{"user_id": message.from_user.id},
|
1757 |
-
{"$push": {"translate_history": translation_entry}},
|
1758 |
-
upsert=True
|
1759 |
-
)
|
1760 |
-
backup_chat.append({"role": "model", "parts": [{"text": test_result}]})
|
1761 |
-
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
1762 |
-
LOGS.info(f"Response Gemini System: {message.from_user.first_name} | {message.from_user.id}\n\nText: {query_base}")
|
1763 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1764 |
-
return
|
1765 |
-
|
1766 |
-
_deletemydata_match = re.match(r"^--deletemydata\s+--reason\s+(.+)$", query_base, re.IGNORECASE)
|
1767 |
-
if _deletemydata_match:
|
1768 |
-
reasons = _deletemydata_match.group(1).strip()
|
1769 |
-
if not reasons:
|
1770 |
-
await message.reply_text("Reason cannot be empty")
|
1771 |
-
return
|
1772 |
-
if len(reasons) < 15:
|
1773 |
-
return await message.reply_text("Reason is too short (minimum 15 characters).")
|
1774 |
-
buttons = [
|
1775 |
-
[
|
1776 |
-
InlineKeyboardButton(
|
1777 |
-
text="💀 Delete my data history",
|
1778 |
-
callback_data="deletemydatagm"
|
1779 |
-
)
|
1780 |
-
],
|
1781 |
-
[
|
1782 |
-
InlineKeyboardButton(
|
1783 |
-
text="❌ Cancel",
|
1784 |
-
callback_data="closedd"
|
1785 |
-
)
|
1786 |
-
]
|
1787 |
-
]
|
1788 |
-
LOGS.info(f"Response info data: {message.from_user.first_name} | {message.from_user.id}\n\nText: {query_base}")
|
1789 |
-
await message.reply_text(
|
1790 |
-
"Are you sure you want to delete this data history?",
|
1791 |
-
reply_markup=InlineKeyboardMarkup(buttons)
|
1792 |
-
)
|
1793 |
-
return
|
1794 |
-
|
1795 |
-
backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
|
1796 |
-
backup_chat.append({"role": "user", "parts": [{"text": query_base}]})
|
1797 |
-
chat_session = gen.aio.chats.create(
|
1798 |
-
model=model_,
|
1799 |
-
history=backup_chat,
|
1800 |
-
config=ty.GenerateContentConfig(
|
1801 |
-
system_instruction="You are my name Randy Dev and friends coding language Indonesia and English",
|
1802 |
-
temperature=0,
|
1803 |
-
top_p=0.95,
|
1804 |
-
top_k=20,
|
1805 |
-
candidate_count=1,
|
1806 |
-
seed=5,
|
1807 |
-
max_output_tokens=4096,
|
1808 |
-
stop_sequences=['STOP!'],
|
1809 |
-
presence_penalty=0.0,
|
1810 |
-
frequency_penalty=0.0,
|
1811 |
-
)
|
1812 |
-
)
|
1813 |
-
response_data = await chat_session.send_message(query_base)
|
1814 |
-
output = response_data.text
|
1815 |
-
uuid_code = str(uuid.uuid4())[:8]
|
1816 |
-
if len(output) > 4096:
|
1817 |
-
text_parts = split_message(output)
|
1818 |
-
for part in text_parts:
|
1819 |
-
await message.reply_text(part)
|
1820 |
-
else:
|
1821 |
-
keyboard_like = create_keyboard(
|
1822 |
-
user_id=message.from_user.id,
|
1823 |
-
uuid_str=uuid_code
|
1824 |
-
)
|
1825 |
-
await message.reply_text(
|
1826 |
-
output,
|
1827 |
-
disable_web_page_preview=True,
|
1828 |
-
reply_markup=keyboard_like
|
1829 |
-
)
|
1830 |
-
translation_entry = {
|
1831 |
-
"uuid": uuid_code,
|
1832 |
-
"text": output,
|
1833 |
-
"timestamp": dt.now().isoformat()
|
1834 |
-
}
|
1835 |
-
await db.backup_chatbot.update_one(
|
1836 |
-
{"user_id": message.from_user.id},
|
1837 |
-
{"$push": {"translate_history": translation_entry}},
|
1838 |
-
upsert=True
|
1839 |
-
)
|
1840 |
-
backup_chat.append({"role": "model", "parts": [{"text": output}]})
|
1841 |
-
await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
|
1842 |
-
LOGS.info(f"Response Gemini: {message.from_user.first_name} | {message.from_user.id}\n\nText: {query_base}")
|
1843 |
-
await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
|
1844 |
-
return
|
1845 |
-
|
1846 |
-
except Exception as e:
|
1847 |
-
LOGS.error(f"Error: message.text: {str(e)}")
|
1848 |
-
return await message.reply_text("Server busy try again later")
|
1849 |
-
|
1850 |
-
# Developer by @xtdevs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
chatbot/plugins/myinfo.py
DELETED
@@ -1,62 +0,0 @@
|
|
1 |
-
import time
|
2 |
-
import os
|
3 |
-
from pyrogram import *
|
4 |
-
from pyrogram.types import *
|
5 |
-
|
6 |
-
from logger import LOGS
|
7 |
-
from database import db
|
8 |
-
from datetime import datetime as dt, timedelta
|
9 |
-
|
10 |
-
@Client.on_message(filters.command("mypremium"))
|
11 |
-
async def check_premium_status(client, message):
|
12 |
-
user_id = message.from_user.id
|
13 |
-
|
14 |
-
try:
|
15 |
-
user_data = await db.user_premium.find_one({"user_id": user_id}) or {
|
16 |
-
"is_premium": False,
|
17 |
-
"credits_used": 0,
|
18 |
-
"last_reset": dt.now(),
|
19 |
-
"premium_expiry": None
|
20 |
-
}
|
21 |
-
|
22 |
-
credit_limit = 50 if user_data["is_premium"] else 5
|
23 |
-
remaining_credits = max(0, credit_limit - user_data.get("credits_used", 0))
|
24 |
-
|
25 |
-
is_active = user_data["is_premium"] and (
|
26 |
-
user_data.get("premium_expiry") is None or
|
27 |
-
user_data["premium_expiry"] > dt.now()
|
28 |
-
)
|
29 |
-
|
30 |
-
reset_time = user_data["last_reset"] + timedelta(days=1)
|
31 |
-
time_left = reset_time - dt.now()
|
32 |
-
hours_left = int(time_left.total_seconds() // 3600)
|
33 |
-
|
34 |
-
status = "ACTIVE ✅" if is_active else "INACTIVE ❌"
|
35 |
-
premium_expiry = (
|
36 |
-
f"\n⌛ Expires: {user_data['premium_expiry'].strftime('%Y-%m-%d %H:%M')}"
|
37 |
-
if user_data.get("premium_expiry")
|
38 |
-
else ""
|
39 |
-
)
|
40 |
-
|
41 |
-
text = (
|
42 |
-
f"💎 <b>**Your Premium Status:**</b>\n\n"
|
43 |
-
f"• Status: **{status}{premium_expiry}**\n"
|
44 |
-
f"• Credits: `{remaining_credits}/{credit_limit}` images\n"
|
45 |
-
f"• Reset in: `{hours_left}` hours\n"
|
46 |
-
f"• Plan: `{'Premium' if is_active else 'Free Tier'}`\n\n"
|
47 |
-
)
|
48 |
-
|
49 |
-
markup = None
|
50 |
-
if not is_active:
|
51 |
-
markup = InlineKeyboardMarkup([[
|
52 |
-
InlineKeyboardButton("✨ Upgrade Premium", callback_data="get_premium")
|
53 |
-
]])
|
54 |
-
|
55 |
-
await message.reply_text(
|
56 |
-
text,
|
57 |
-
reply_markup=markup,
|
58 |
-
disable_web_page_preview=True
|
59 |
-
)
|
60 |
-
except Exception as e:
|
61 |
-
LOGS.error(f"Premium check error: {str(e)}")
|
62 |
-
await message.reply_text("❌ Error checking your status. Please try again later.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chatbot/plugins/payments.py
DELETED
@@ -1,90 +0,0 @@
|
|
1 |
-
import time
|
2 |
-
import os
|
3 |
-
from pyrogram import *
|
4 |
-
from pyrogram.types import *
|
5 |
-
from database import db
|
6 |
-
from datetime import datetime as dt, timedelta
|
7 |
-
|
8 |
-
PLAN_PREMIUM = """
|
9 |
-
**✨ Premium Subscription Plans**
|
10 |
-
|
11 |
-
**🔹 Free Tier**:
|
12 |
-
(For new users and testing)
|
13 |
-
- **🖼️ Image Credits**: 5/day (resets at midnight UTC)
|
14 |
-
- **⚡ Features**: Basic generation only
|
15 |
-
- **⚠️ Restrictions**:
|
16 |
-
=> Blacklist keyword scanning enabled
|
17 |
-
=> Account freeze possible for violations
|
18 |
-
|
19 |
-
**💎 Monthly Premium**:
|
20 |
-
**Rp 50,000** (~$3.50/month)
|
21 |
-
- **🖼️ Credits**: 50/day (10× free tier)
|
22 |
-
- **🎨 Advanced Tools**:
|
23 |
-
=> `--edit-images` full access
|
24 |
-
- **🛡️ Protection**:
|
25 |
-
=> Anti-freeze guarantee
|
26 |
-
=> Whitelisted from blacklists
|
27 |
-
|
28 |
-
**🚀 Yearly Premium**:
|
29 |
-
**Rp 825,854** (~$58/year - **35% discount**)
|
30 |
-
✅ **All Monthly benefits PLUS**:
|
31 |
-
- **👨💻 VIP Support**: Direct developer contact
|
32 |
-
- **🔐 Early Access**: Beta features
|
33 |
-
- **💸 Best Value**: Only Rp 68,821/month
|
34 |
-
|
35 |
-
"""
|
36 |
-
|
37 |
-
@Client.on_callback_query(filters.regex(r"^get_premium$"))
|
38 |
-
async def get_premiums(client, callback):
|
39 |
-
keyboard = InlineKeyboardMarkup(
|
40 |
-
[
|
41 |
-
[
|
42 |
-
InlineKeyboardButton("💳 Buy Monthly", callback_data="buy_premium_monthly"),
|
43 |
-
InlineKeyboardButton("🚀 Buy Yearly", callback_data="buy_premium_yearly"),
|
44 |
-
],
|
45 |
-
[
|
46 |
-
InlineKeyboardButton("☎️ Contact Support", url="https://t.me/xpushz"),
|
47 |
-
],
|
48 |
-
[
|
49 |
-
InlineKeyboardButton(f"❌ Closed", callback_data="closedd")
|
50 |
-
]
|
51 |
-
]
|
52 |
-
)
|
53 |
-
return await callback.message.edit_text(
|
54 |
-
PLAN_PREMIUM,
|
55 |
-
reply_markup=keyboard
|
56 |
-
)
|
57 |
-
|
58 |
-
@Client.on_callback_query(filters.regex(r"^buy_premium_(monthly|yearly)$"))
|
59 |
-
async def premium_purchase(client, callback):
|
60 |
-
plan = callback.matches[0].group(1)
|
61 |
-
user_id = callback.from_user.id
|
62 |
-
if user_id != 6477856957:
|
63 |
-
return await callback.answer("Only Developer test")
|
64 |
-
|
65 |
-
if plan == "monthly":
|
66 |
-
expiry = dt.now() + timedelta(days=30)
|
67 |
-
price = "$4.99"
|
68 |
-
else:
|
69 |
-
expiry = dt.now() + timedelta(days=365)
|
70 |
-
price = "$49.99"
|
71 |
-
|
72 |
-
await db.user_premium.update_one(
|
73 |
-
{"user_id": user_id},
|
74 |
-
{
|
75 |
-
"$set": {
|
76 |
-
"is_premium": True,
|
77 |
-
"premium_expiry": expiry,
|
78 |
-
"subscription_plan": plan
|
79 |
-
},
|
80 |
-
"$inc": {"credits_used": -50}
|
81 |
-
},
|
82 |
-
upsert=True
|
83 |
-
)
|
84 |
-
await callback.message.edit_text(
|
85 |
-
f"💎 Premium {plan.capitalize()} Activated!\n"
|
86 |
-
f"∙ Expires: {expiry.strftime('%Y-%m-%d')}\n"
|
87 |
-
f"∙ Daily credits: 50 images\n\n"
|
88 |
-
f"Thanks for your support!",
|
89 |
-
reply_markup=None
|
90 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|