Created
May 28, 2018 15:59
-
-
Save Bergiu/ab3a4d8f2bedeb2a6cc1e57d63efceca to your computer and use it in GitHub Desktop.
Small Telegram-Bot that removes all /commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# requirements: | |
# - [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot/) | |
# - `pip3 install python-telegram-bot` | |
from telegram.ext import CommandHandler, MessageHandler, Filters, Updater | |
from telegram import Message, Update, Bot | |
from telegram.ext import BaseFilter | |
import logging | |
# TODO: replace with your token from [@botfather](https://t.me/botfather) | |
token = "" | |
class BlueText(BaseFilter): | |
def filter(self, message: Message): | |
if message.text.find("/") == 0: | |
return True | |
return False | |
def remove_bluetext(bot: Bot, update: Update): | |
bot.delete_message( | |
chat_id=update.message.chat_id, | |
message_id=update.message.message_id) | |
# bot | |
updater = Updater(token=token) | |
dispatcher = updater.dispatcher | |
# logging | |
logform = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' | |
logging.basicConfig(format=logform, level=logging.INFO) | |
# Remember to initialize the class. | |
remove_handler = MessageHandler(BlueText(), remove_bluetext) | |
dispatcher.add_handler(remove_handler) | |
# start bot | |
updater.start_polling() | |
print("Bot is running.") | |
# wait till sigint | |
updater.idle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Danke, ich muss mal schauen ob ich das in mein bestehendes Projekt einbauen kann.