Spaces:
Sleeping
Sleeping
Aleksey Khlopkov
commited on
Commit
·
0efd01c
1
Parent(s):
8730736
fixed bug
Browse files
main.py
CHANGED
|
@@ -24,8 +24,8 @@ bezumtsi_gif_id = "CgACAgIAAxkBAAE4zMtojLmiH_CGW5cT7G0QVXHR7D4g6wAC53UAApkBmEmM-
|
|
| 24 |
|
| 25 |
last_maxim_insult = 1.0
|
| 26 |
last_gif_sent = 1.0
|
| 27 |
-
maxim_insult_cooldown =
|
| 28 |
-
gif_sent_cooldown =
|
| 29 |
|
| 30 |
torch.manual_seed(0)
|
| 31 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
@@ -42,20 +42,21 @@ def handle_response(text: str) -> Optional[str]:
|
|
| 42 |
return None
|
| 43 |
|
| 44 |
|
| 45 |
-
def edit_response(text: str) -> str:
|
|
|
|
|
|
|
| 46 |
text = re.sub(r'\s+([,.!?;])\s+', r'\1 ', text)
|
| 47 |
-
|
| 48 |
return text
|
| 49 |
|
| 50 |
|
| 51 |
async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 52 |
if update.message.chat_id == CHAT_ID:
|
| 53 |
-
response: Optional[str] = ""
|
| 54 |
global last_maxim_insult, last_gif_sent
|
| 55 |
if update.message.from_user.username == "WhoReadThisWillDie" and \
|
| 56 |
time.time() - last_maxim_insult >= maxim_insult_cooldown:
|
| 57 |
-
response = "Максим, иди нахуй"
|
| 58 |
last_maxim_insult = time.time()
|
|
|
|
| 59 |
elif "роман" in update.message.text.lower() and \
|
| 60 |
time.time() - last_gif_sent >= gif_sent_cooldown:
|
| 61 |
await context.bot.send_animation( chat_id=update.message.chat_id, animation=romantiki_gif_id)
|
|
@@ -67,9 +68,8 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
| 67 |
else:
|
| 68 |
text = update.message.text.replace(BOT_USERNAME, '').strip().lower()
|
| 69 |
response = edit_response(handle_response(text))
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
await context.bot.sendMessage(update.message.chat_id, response, reply_to_message_id=update.message.id)
|
| 73 |
|
| 74 |
|
| 75 |
async def error(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
@@ -85,7 +85,7 @@ def main() -> None:
|
|
| 85 |
application = Application.builder().token(TOKEN).build()
|
| 86 |
|
| 87 |
application.add_handler(MessageHandler(filters.TEXT, handle_message))
|
| 88 |
-
application.add_error_handler(error)
|
| 89 |
|
| 90 |
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
| 91 |
|
|
|
|
| 24 |
|
| 25 |
last_maxim_insult = 1.0
|
| 26 |
last_gif_sent = 1.0
|
| 27 |
+
maxim_insult_cooldown = 180.0
|
| 28 |
+
gif_sent_cooldown = 180.0
|
| 29 |
|
| 30 |
torch.manual_seed(0)
|
| 31 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
| 42 |
return None
|
| 43 |
|
| 44 |
|
| 45 |
+
def edit_response(text: Optional[str]) -> Optional[str]:
|
| 46 |
+
if text is None:
|
| 47 |
+
return None
|
| 48 |
text = re.sub(r'\s+([,.!?;])\s+', r'\1 ', text)
|
|
|
|
| 49 |
return text
|
| 50 |
|
| 51 |
|
| 52 |
async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 53 |
if update.message.chat_id == CHAT_ID:
|
| 54 |
+
# response: Optional[str] = ""
|
| 55 |
global last_maxim_insult, last_gif_sent
|
| 56 |
if update.message.from_user.username == "WhoReadThisWillDie" and \
|
| 57 |
time.time() - last_maxim_insult >= maxim_insult_cooldown:
|
|
|
|
| 58 |
last_maxim_insult = time.time()
|
| 59 |
+
await context.bot.sendMessage(update.message.chat_id, "Максим, иди нахуй", reply_to_message_id=update.message.id)
|
| 60 |
elif "роман" in update.message.text.lower() and \
|
| 61 |
time.time() - last_gif_sent >= gif_sent_cooldown:
|
| 62 |
await context.bot.send_animation( chat_id=update.message.chat_id, animation=romantiki_gif_id)
|
|
|
|
| 68 |
else:
|
| 69 |
text = update.message.text.replace(BOT_USERNAME, '').strip().lower()
|
| 70 |
response = edit_response(handle_response(text))
|
| 71 |
+
if response:
|
| 72 |
+
await context.bot.sendMessage(update.message.chat_id, response, reply_to_message_id=update.message.id)
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
async def error(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
|
|
| 85 |
application = Application.builder().token(TOKEN).build()
|
| 86 |
|
| 87 |
application.add_handler(MessageHandler(filters.TEXT, handle_message))
|
| 88 |
+
# application.add_error_handler(error)
|
| 89 |
|
| 90 |
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
| 91 |
|