Upload chat.py
Browse files- chatbot/plugins/chat.py +52 -91
chatbot/plugins/chat.py
CHANGED
@@ -199,85 +199,8 @@ Type anything to begin.
|
|
199 |
|
200 |
gen = genai.Client(api_key=GOOGLE_API_KEY)
|
201 |
|
202 |
-
|
203 |
-
async def progress(current, total, message, start, type_of_ps, file_name=None):
|
204 |
-
"""Progress Bar For Showing Progress While Uploading / Downloading File - Normal"""
|
205 |
-
now = time.time()
|
206 |
-
diff = now - start
|
207 |
-
buttons = [
|
208 |
-
[
|
209 |
-
InlineKeyboardButton(
|
210 |
-
text="Cancel",
|
211 |
-
callback_data="cancels"
|
212 |
-
)
|
213 |
-
],
|
214 |
-
]
|
215 |
-
if round(diff % 10.00) == 0 or current == total:
|
216 |
-
percentage = current * 100 / total
|
217 |
-
speed = current / diff
|
218 |
-
elapsed_time = round(diff) * 1000
|
219 |
-
if elapsed_time == 0:
|
220 |
-
return
|
221 |
-
time_to_completion = round((total - current) / speed) * 1000
|
222 |
-
estimated_total_time = elapsed_time + time_to_completion
|
223 |
-
progress_str = f"{''.join(['▰' for i in range(math.floor(percentage / 10))])}"
|
224 |
-
progress_str += (
|
225 |
-
f"{''.join(['▱' for i in range(10 - math.floor(percentage / 10))])}"
|
226 |
-
)
|
227 |
-
progress_str += f"{round(percentage, 2)}%\n"
|
228 |
-
tmp = f"{progress_str}{humanbytes(current)} of {humanbytes(total)}\n"
|
229 |
-
tmp += f"ETA: {time_formatter(estimated_total_time)}"
|
230 |
-
if file_name:
|
231 |
-
try:
|
232 |
-
await message.edit(
|
233 |
-
f"{type_of_ps}\n**File Name:** `{file_name}`\n{tmp}"
|
234 |
-
)
|
235 |
-
except FloodWait as e:
|
236 |
-
await asyncio.sleep(e.x)
|
237 |
-
except MessageNotModified:
|
238 |
-
pass
|
239 |
-
else:
|
240 |
-
try:
|
241 |
-
await message.edit_text(
|
242 |
-
f"{type_of_ps}\n{tmp}",
|
243 |
-
parse_mode=enums.ParseMode.MARKDOWN,
|
244 |
-
reply_markup=InlineKeyboardMarkup(buttons)
|
245 |
-
)
|
246 |
-
except FloodWait as e:
|
247 |
-
await asyncio.sleep(e.x)
|
248 |
-
except MessageNotModified:
|
249 |
-
pass
|
250 |
-
|
251 |
-
def humanbytes(size):
|
252 |
-
"""Convert Bytes To Bytes So That Human Can Read It"""
|
253 |
-
if not size:
|
254 |
-
return ""
|
255 |
-
power = 2**10
|
256 |
-
raised_to_pow = 0
|
257 |
-
dict_power_n = {0: "", 1: "Ki", 2: "Mi", 3: "Gi", 4: "Ti"}
|
258 |
-
while size > power:
|
259 |
-
size /= power
|
260 |
-
raised_to_pow += 1
|
261 |
-
return str(round(size, 2)) + " " + dict_power_n[raised_to_pow] + "B"
|
262 |
-
|
263 |
-
def time_formatter(milliseconds: int) -> str:
|
264 |
-
"""Time Formatter"""
|
265 |
-
seconds, milliseconds = divmod(int(milliseconds), 1000)
|
266 |
-
minutes, seconds = divmod(seconds, 60)
|
267 |
-
hours, minutes = divmod(minutes, 60)
|
268 |
-
days, hours = divmod(hours, 24)
|
269 |
-
tmp = (
|
270 |
-
((str(days) + " day(s), ") if days else "")
|
271 |
-
+ ((str(hours) + " hour(s), ") if hours else "")
|
272 |
-
+ ((str(minutes) + " minute(s), ") if minutes else "")
|
273 |
-
+ ((str(seconds) + " second(s), ") if seconds else "")
|
274 |
-
+ ((str(milliseconds) + " millisecond(s), ") if milliseconds else "")
|
275 |
-
)
|
276 |
-
return tmp[:-2]
|
277 |
-
|
278 |
# Original: @GeminiAIDev_Bot
|
279 |
# Code by @xtdevs
|
280 |
-
|
281 |
def replace_with_markdown_list(text, pattern=r"^\s*\*\s*(.*)$"):
|
282 |
def replace(match):
|
283 |
text = match.group(1)
|
@@ -304,14 +227,56 @@ def split_message(text: str) -> List[str]:
|
|
304 |
text = ""
|
305 |
return parts
|
306 |
|
307 |
-
@Client.on_callback_query(filters.regex("^
|
308 |
-
async def
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
|
316 |
@Client.on_callback_query(filters.regex("^deletemydatagm$"))
|
317 |
async def deletemydata(client, callback):
|
@@ -550,11 +515,6 @@ async def remover_bg(client, callback):
|
|
550 |
reply_markup=None
|
551 |
)
|
552 |
|
553 |
-
|
554 |
-
@Client.on_callback_query(filters.regex("^closedd$"))
|
555 |
-
async def closeed(client, callback):
|
556 |
-
await callback.message.delete()
|
557 |
-
|
558 |
@Client.on_callback_query(filters.regex("^memory_(\d+)_([a-f0-9]{8})$"))
|
559 |
async def memory_updated(client, callback):
|
560 |
user_id, uuidstr = callback.matches[0].groups()
|
@@ -734,6 +694,7 @@ def create_keyboard(
|
|
734 |
[
|
735 |
InlineKeyboardButton(f"♾️", callback_data=f"trmulti_{user_id}_{uuid_str}"),
|
736 |
InlineKeyboardButton(f"🔒", callback_data=f"showchat_{user_id}"),
|
|
|
737 |
InlineKeyboardButton(f"💾", callback_data=f"memory_{user_id}_{uuid_str}")
|
738 |
],
|
739 |
[
|
@@ -1540,4 +1501,4 @@ async def chatbot_talk(client: Client, message: Message):
|
|
1540 |
|
1541 |
except Exception as e:
|
1542 |
LOGS.error(f"Error: message.text: {str(e)}")
|
1543 |
-
return await message.reply_text("Server busy try again later")
|
|
|
199 |
|
200 |
gen = genai.Client(api_key=GOOGLE_API_KEY)
|
201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
# Original: @GeminiAIDev_Bot
|
203 |
# Code by @xtdevs
|
|
|
204 |
def replace_with_markdown_list(text, pattern=r"^\s*\*\s*(.*)$"):
|
205 |
def replace(match):
|
206 |
text = match.group(1)
|
|
|
227 |
text = ""
|
228 |
return parts
|
229 |
|
230 |
+
@Client.on_callback_query(filters.regex("^closedd$"))
|
231 |
+
async def closeed(client, callback):
|
232 |
+
await callback.message.delete()
|
233 |
+
|
234 |
+
@Client.on_callback_query(filters.regex("^modelmenu$"))
|
235 |
+
async def modelgeminimenu(client, callback):
|
236 |
+
keyboard.append([
|
237 |
+
InlineKeyboardButton("Gemini Flash EXP", callback_data="modelset:gemini-2.0-flash-exp"),
|
238 |
+
InlineKeyboardButton("Gemini EXP", callback_data="modelset:gemini-exp-1206")
|
239 |
+
])
|
240 |
+
keyboard.append([
|
241 |
+
InlineKeyboardButton("Gemini Flash 8B", callback_data="modelset:gemini-1.5-flash-8b"),
|
242 |
+
InlineKeyboardButton("Gemini 2.0 Flash ", callback_data="modelset:gemini-2.0-flash-001")
|
243 |
+
])
|
244 |
+
keyboard.append([
|
245 |
+
InlineKeyboardButton("Gemini PRO", callback_data="modelset:gemini-1.5-pro"),
|
246 |
+
InlineKeyboardButton("Gemini Flash", callback_data="modelset:gemini-1.5-flash"),
|
247 |
+
])
|
248 |
+
keyboard.append([
|
249 |
+
InlineKeyboardButton("Close", callback_data="close")
|
250 |
+
])
|
251 |
+
await callback.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup(keyboard))
|
252 |
+
|
253 |
+
@Client.on_callback_query(filters.regex(r"^modelset:(.*)$"))
|
254 |
+
async def gemini_setmodel(client, callback):
|
255 |
+
model = callback.matches[0].group(1)
|
256 |
+
user_id = callback.from_user.id
|
257 |
+
await users_collection.update_one(
|
258 |
+
{"user_id": user_id},
|
259 |
+
{"$set": {"model": model}},
|
260 |
+
upsert=True
|
261 |
+
)
|
262 |
+
await callback.answer(f"Model set to {model}")
|
263 |
+
keyboard = []
|
264 |
+
keyboard.append([
|
265 |
+
InlineKeyboardButton("Gemini Flash EXP", callback_data="modelset:gemini-2.0-flash-exp"),
|
266 |
+
InlineKeyboardButton("Gemini EXP", callback_data="modelset:gemini-exp-1206")
|
267 |
+
])
|
268 |
+
keyboard.append([
|
269 |
+
InlineKeyboardButton("Gemini Flash 8B", callback_data="modelset:gemini-1.5-flash-8b"),
|
270 |
+
InlineKeyboardButton("Gemini 2.0 Flash ", callback_data="modelset:gemini-2.0-flash-001")
|
271 |
+
])
|
272 |
+
keyboard.append([
|
273 |
+
InlineKeyboardButton("Gemini PRO", callback_data="modelset:gemini-1.5-pro"),
|
274 |
+
InlineKeyboardButton("Gemini Flash", callback_data="modelset:gemini-1.5-flash"),
|
275 |
+
])
|
276 |
+
keyboard.append([
|
277 |
+
InlineKeyboardButton("Close", callback_data="close")
|
278 |
+
])
|
279 |
+
await callback.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup(keyboard))
|
280 |
|
281 |
@Client.on_callback_query(filters.regex("^deletemydatagm$"))
|
282 |
async def deletemydata(client, callback):
|
|
|
515 |
reply_markup=None
|
516 |
)
|
517 |
|
|
|
|
|
|
|
|
|
|
|
518 |
@Client.on_callback_query(filters.regex("^memory_(\d+)_([a-f0-9]{8})$"))
|
519 |
async def memory_updated(client, callback):
|
520 |
user_id, uuidstr = callback.matches[0].groups()
|
|
|
694 |
[
|
695 |
InlineKeyboardButton(f"♾️", callback_data=f"trmulti_{user_id}_{uuid_str}"),
|
696 |
InlineKeyboardButton(f"🔒", callback_data=f"showchat_{user_id}"),
|
697 |
+
InlineKeyboardButton(f"⛏️", callback_data=f"modelmenu"),
|
698 |
InlineKeyboardButton(f"💾", callback_data=f"memory_{user_id}_{uuid_str}")
|
699 |
],
|
700 |
[
|
|
|
1501 |
|
1502 |
except Exception as e:
|
1503 |
LOGS.error(f"Error: message.text: {str(e)}")
|
1504 |
+
return await message.reply_text("Server busy try again later")
|