2024-05-25 07:05:14 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from telegram import Update
|
2024-05-25 07:10:59 +00:00
|
|
|
from telegram.ext import (
|
|
|
|
ApplicationBuilder,
|
|
|
|
CommandHandler,
|
2024-05-25 07:58:57 +00:00
|
|
|
ContextTypes,
|
2024-05-25 07:10:59 +00:00
|
|
|
MessageHandler,
|
|
|
|
filters,
|
|
|
|
)
|
2024-05-25 07:05:14 +00:00
|
|
|
|
2024-05-25 07:58:57 +00:00
|
|
|
from nlp import is_noun_follows_verb
|
2024-05-25 07:05:14 +00:00
|
|
|
from settings import Settings
|
|
|
|
|
2024-05-25 07:58:57 +00:00
|
|
|
# Load environment variables
|
2024-05-25 07:05:14 +00:00
|
|
|
settings = Settings()
|
|
|
|
|
2024-05-25 07:58:57 +00:00
|
|
|
# Set the log level
|
|
|
|
log_level = logging.getLevelNamesMapping().get(settings.log_level, logging.INFO)
|
2024-05-25 07:05:14 +00:00
|
|
|
logging.basicConfig(
|
|
|
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=log_level
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
|
|
await context.bot.send_message(
|
|
|
|
chat_id=update.effective_chat.id, text="Hello, deez nuts on yo chin!"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-05-25 07:10:59 +00:00
|
|
|
async def message_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
2024-05-25 07:58:57 +00:00
|
|
|
# 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
|
2024-05-25 07:10:59 +00:00
|
|
|
|
|
|
|
|
2024-05-25 07:05:14 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
app = ApplicationBuilder().token(settings.bot_token).build()
|
|
|
|
start_handler = CommandHandler("start", start)
|
2024-05-25 07:10:59 +00:00
|
|
|
message_handler = MessageHandler(filters.ALL, message_handler)
|
|
|
|
|
2024-05-25 07:05:14 +00:00
|
|
|
app.add_handler(start_handler)
|
2024-05-25 07:10:59 +00:00
|
|
|
app.add_handler(message_handler)
|
2024-05-25 07:05:14 +00:00
|
|
|
|
|
|
|
app.run_polling()
|