You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/python3
  2. import time
  3. import telepot
  4. from telepot.loop import MessageLoop
  5. import redis
  6. import os
  7. if 'TOKEN' in os.environ:
  8. TOKEN = os.environ.get('TOKEN')
  9. else:
  10. TOKEN = ""
  11. r = redis.Redis(host='localhost', port=6379, db=0)
  12. def handle(msg):
  13. content_type, chat_type, chat_id = telepot.glance(msg)
  14. print(content_type, chat_type, chat_id)
  15. try:
  16. if msg["text"] == "/start":
  17. bot.sendMessage(chat_id, "Hello. You can add this bot to the group to greet anyone who comes back to the group and increase the group's activity.")
  18. except:
  19. pass
  20. goal = int(time.time()) + 86400
  21. if r.get(str(chat_id)) == None:
  22. r.set(str(chat_id), str(goal))
  23. else:
  24. if int(r.get(str(chat_id))) < int(time.time()):
  25. try:
  26. bot.sendMessage(chat_id, "Welcome back, @" + msg["from"]["username"] + "!")
  27. r.set(str(chat_id), str(goal))
  28. except:
  29. bot.sendMessage(chat_id, "Welcome back!")
  30. r.set(str(chat_id), str(goal))
  31. bot = telepot.Bot(TOKEN)
  32. MessageLoop(bot, handle).run_as_thread()
  33. print ('Listening ...')
  34. # Keep the program running.
  35. while 1:
  36. time.sleep(10)