randydev commited on
Commit
3facba9
ยท
verified ยท
1 Parent(s): 4bf15e7

Update chatbot/plugins/chat.py

Browse files
Files changed (1) hide show
  1. chatbot/plugins/chat.py +31 -5
chatbot/plugins/chat.py CHANGED
@@ -266,19 +266,23 @@ async def memory_updated(client, callback):
266
  LOGS.error(f"Memory update failed: {str(e)}")
267
  await callback.answer("Server error", show_alert=True)
268
 
269
- @Client.on_callback_query(filters.regex("^tr_(\d+)$"))
270
  async def terjemahkan(client, callback):
271
- user_id = int(callback.matches[0].group(1))
272
  try:
273
  if user_id == 0:
274
  return await callback.answer("Server busy try again later", True)
275
- data_tr = await db.backup_chatbot.find_one({"user_id": user_id})
276
  if not data_tr:
277
  return await callback.answer("Can't found user", True)
278
  get_response = data_tr.get("translate_text", None)
279
  if not get_response:
280
  return await callback.answer("Server busy try again later", True)
281
- translation = trans(get_response, sourcelang="auto", targetlang="id")
 
 
 
 
282
  keyboard = create_keyboard()
283
  await callback.edit_message_text(
284
  translation.text,
@@ -289,13 +293,35 @@ async def terjemahkan(client, callback):
289
  LOGS.error(f"Exception translate: {str(e)}")
290
  await callback.answer("Server busy try again later", True)
291
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
  def create_keyboard(likes: int = 0, unlikes: int = 0, user_id: int = None):
293
  keyboard = InlineKeyboardMarkup(
294
  [
295
  [
296
  InlineKeyboardButton(f"๐Ÿ‘ {likes}", callback_data="like"),
297
  InlineKeyboardButton(f"๐Ÿ‘Ž {unlikes}", callback_data="unlike"),
298
- InlineKeyboardButton(f"๐Ÿ‡ฎ๐Ÿ‡ฉ", callback_data=f"tr_{user_id}"),
299
  InlineKeyboardButton(f"๐Ÿ”", callback_data="refreshch"),
300
  InlineKeyboardButton(f"๐Ÿ’พ", callback_data=f"memory_{user_id}"),
301
  ]
 
266
  LOGS.error(f"Memory update failed: {str(e)}")
267
  await callback.answer("Server error", show_alert=True)
268
 
269
+ @Client.on_callback_query(filters.regex("^tr_(\d+)_(\w+)$"))
270
  async def terjemahkan(client, callback):
271
+ user_id, targetlang = callback.matches[0].group()
272
  try:
273
  if user_id == 0:
274
  return await callback.answer("Server busy try again later", True)
275
+ data_tr = await db.backup_chatbot.find_one({"user_id": int(user_id)})
276
  if not data_tr:
277
  return await callback.answer("Can't found user", True)
278
  get_response = data_tr.get("translate_text", None)
279
  if not get_response:
280
  return await callback.answer("Server busy try again later", True)
281
+ translation = trans(
282
+ get_response,
283
+ sourcelang="auto",
284
+ targetlang=str(targetlang)
285
+ )
286
  keyboard = create_keyboard()
287
  await callback.edit_message_text(
288
  translation.text,
 
293
  LOGS.error(f"Exception translate: {str(e)}")
294
  await callback.answer("Server busy try again later", True)
295
 
296
+ @Client.on_callback_query(filters.regex("^trmulti_(\d+)$"))
297
+ async def multiple_langagues(client, callback):
298
+ user_id = int(callback.matches[0].group(1))
299
+ keyboard = InlineKeyboardMarkup(
300
+ [
301
+ [
302
+ InlineKeyboardButton(f"๐Ÿ‡ฎ๐Ÿ‡ณ", callback_data=f"tr_{user_id}_in"),
303
+ InlineKeyboardButton(f"๐Ÿ‡ฎ๐Ÿ‡ฉ", callback_data=f"tr_{user_id}_id"),
304
+ InlineKeyboardButton(f"๐Ÿ”", callback_data="refreshch"),
305
+ InlineKeyboardButton(f"๐Ÿ’พ", callback_data=f"memory_{user_id}"),
306
+ ]
307
+ ]
308
+ )
309
+ try:
310
+ await callback.edit_message_reply_markup(
311
+ reply_markup=keyboard
312
+ )
313
+ await callback.answer("Translate List Now", False)
314
+ except Exception as e:
315
+ LOGS.error(f"Exception multiple_langagues: {str(e)}")
316
+ await callback.answer("Server busy try again later", True)
317
+
318
  def create_keyboard(likes: int = 0, unlikes: int = 0, user_id: int = None):
319
  keyboard = InlineKeyboardMarkup(
320
  [
321
  [
322
  InlineKeyboardButton(f"๐Ÿ‘ {likes}", callback_data="like"),
323
  InlineKeyboardButton(f"๐Ÿ‘Ž {unlikes}", callback_data="unlike"),
324
+ InlineKeyboardButton(f"๐Ÿ‡ฎ๐Ÿ‡ฉ", callback_data=f"tr_{user_id}_id"),
325
  InlineKeyboardButton(f"๐Ÿ”", callback_data="refreshch"),
326
  InlineKeyboardButton(f"๐Ÿ’พ", callback_data=f"memory_{user_id}"),
327
  ]