feat: implement nlp

Signed-off-by: Sphericalkat <me@kat.bio>
This commit is contained in:
sphericalkat committed 2024-05-25 13:28:57 +05:30
1 parent 98809e62a4
commit d8ca41ed3f
4 files changed
+90 -7

No files matched your search

+22 -7
View File
@@ -2,19 +2,21 @@ import logging
from telegram import Update
from telegram.ext import (
ContextTypes,
ApplicationBuilder,
CommandHandler,
ContextTypes,
MessageHandler,
filters,
)
from nlp import is_noun_follows_verb
from settings import Settings
# Load environment variables
settings = Settings()
# Set the log level
log_level = logging.getLevelNamesMapping().get(settings.log_level, logging.INFO)
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=log_level
)
@@ -27,10 +29,23 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
async def message_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(
chat_id=update.effective_chat.id,
text="I'm sorry, I'm a bot and I can't understand that.",
)
# Get the message text content
msg_content = update.effective_message.text
# Ignore messages without text
if not msg_content:
return
# Check that the message doesn't have more than 5 words
if len(msg_content.split()) > 5:
return
# Check if a noun immediately follows a verb
is_follows_verb, verb = is_noun_follows_verb(msg_content)
if is_follows_verb:
await update.effective_message.reply_text(f"{verb} deez")
return
if __name__ == "__main__":