Last active
June 14, 2018 22:47
-
-
Save Bergiu/dec876b0974d4ae1313dcd5382967211 to your computer and use it in GitHub Desktop.
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 | |
# License: | |
# https://www.gnu.org/licenses/gpl-3.0.en.html | |
# 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 | |
# vars | |
# TODO: replace with your token from [@botfather](https://t.me/botfather) | |
token = "" | |
personid = 0 | |
personname = "" | |
phrase = "xd" | |
# static | |
counter = 0 | |
class PersonPhraseFilter(BaseFilter): | |
def filter(self, message: Message): | |
if message.text.lower().find(phrase.lower()) >= 0 and message.from_user.id == personid: | |
return True | |
return False | |
def count(bot: Bot, update: Update): | |
global counter | |
counter += 1 | |
def get_count(bot: Bot, update: Update): | |
global counter | |
text = "{} hat bis jetzt schon {} mal {} geschrieben".format(personname, counter, phrase) | |
bot.send_message(update.message.chat.id, text=text) | |
def license(bot: Bot, update: Update): | |
global counter | |
text = 'Welcome!\nThis bot is a program which is available under the <b>GNU GPLv3</b> license at <a href="https://gist.github.com/Bergiu/dec876b0974d4ae1313dcd5382967211">github.com</a>' | |
bot.send_message(update.message.chat.id, text=text) | |
# 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. | |
handler1 = MessageHandler(PersonPhraseFilter(), count) | |
dispatcher.add_handler(handler1) | |
handler2 = CommandHandler('get_count', get_count) | |
dispatcher.add_handler(handler2) | |
handler3 = CommandHandler('license', license) | |
dispatcher.add_handler(handler3) | |
# 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