Stuff
This commit is contained in:
commit
1e6e84fdf1
2 changed files with 72 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
config.py
|
||||
*.pyc
|
||||
__pycache__/
|
||||
user.txt
|
68
run.py
Normal file
68
run.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
from telegram.ext import CommandHandler
|
||||
import logging
|
||||
import json
|
||||
from config import updater
|
||||
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.INFO)
|
||||
|
||||
|
||||
|
||||
|
||||
def hello(bot, update):
|
||||
print(update)
|
||||
update.message.reply_text(
|
||||
'Hello {}'.format(update.message.from_user.first_name))
|
||||
|
||||
def start(bot, update):
|
||||
update.message.reply_text("Du möchtest auch jeden morgen Motiviert in den Tag starten?")
|
||||
update.message.reply_text("Dann abonniere jetzt diesen motivierenden Bot der dir jeden Morgen um 6 perfekt für deinen Tag vorbereitet")
|
||||
update.message.reply_text("Schreibe dafür einen /subscribe .... wenn du irgendwan genug motiviert bist kannst du dich mit /unsubscribe wieder abmleden")
|
||||
|
||||
def subscribe(bot, update):
|
||||
users = getAllUsers()
|
||||
for user in users:
|
||||
if user["chatId"] == update["message"]["chat"]["id"]:
|
||||
update.message.reply_text("Du willst wohl besonders motiviert in den Tag starten, dabei hast du doch schon aboniert");
|
||||
return;
|
||||
|
||||
users.append({"chatId": update["message"]["chat"]["id"]})
|
||||
saveUser(users)
|
||||
update.message.reply_text("Danke, ab jetzt wirst du jeden morgen motiviert!");
|
||||
|
||||
def unsubscribe(bot, update):
|
||||
users = getAllUsers()
|
||||
newUserList = []
|
||||
unsubscribed = False
|
||||
for user in users:
|
||||
if user["chatId"] == update["message"]["chat"]["id"]:
|
||||
unsubscribed = True
|
||||
else:
|
||||
newUserList.append(user)
|
||||
|
||||
if unsubscribed:
|
||||
saveUser(newUserList)
|
||||
update.message.reply_text("Schade das du uns verlassen hast, ich weiß nicht ob ich so morgen weiter motivieren kann :'(")
|
||||
else:
|
||||
update.message.reply_text("Du stehst nicht in meiner Abonenten liste, aboniere einfach mit einem /subscribe")
|
||||
|
||||
def getAllUsers():
|
||||
f = open("user.txt")
|
||||
content = f.read();
|
||||
f.close()
|
||||
return json.loads(content)
|
||||
|
||||
def saveUser(users):
|
||||
j = json.dumps(users)
|
||||
f = open("user.txt", "w")
|
||||
f.write(j)
|
||||
f.close()
|
||||
|
||||
updater.dispatcher.add_handler(CommandHandler('hello', hello))
|
||||
updater.dispatcher.add_handler(CommandHandler('subscribe', subscribe))
|
||||
updater.dispatcher.add_handler(CommandHandler('unsubscribe', unsubscribe))
|
||||
updater.dispatcher.add_handler(CommandHandler('start', start))
|
||||
|
||||
|
||||
updater.start_polling()
|
||||
updater.idle()
|
Reference in a new issue