recorderbashingbot/main.py
2020-10-02 03:55:30 +02:00

43 lines
1.1 KiB
Python

import os
import random
import difflib
import telegram
from telegram import Update
from telegram.ext import Updater, MessageHandler, Filters, CallbackContext
POSSIBLE_TEXTS = [
"\U0001F92C", # "serious face with symbols covering mouth"
]
def on_message(update: Update, context: CallbackContext):
for word in update.message.text.split():
if difflib.get_close_matches(word.lower(), ["blockflöte"]):
context.bot.send_message(
chat_id=update.effective_chat.id, text=random.choice(POSSIBLE_TEXTS)
)
break
message_handler = MessageHandler(Filters.text & ~Filters.command, on_message)
if __name__ == "__main__":
TOKEN = os.environ.get("TOKEN")
if not TOKEN:
print("Please provide a bot token using the TOKEN environment variable")
exit(1)
try:
updater = Updater(token=TOKEN, use_context=True)
except telegram.error.InvalidToken:
print("The provided token appears to be invalid")
exit(1)
dispatcher = updater.dispatcher
dispatcher.add_handler(message_handler)
updater.start_polling()