Telegram version of schneiderbot
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.

53 lines
1.8 KiB

5 years ago
  1. import twitter
  2. pepito_id = 333923305
  3. last_status = None
  4. pepito_groups = []
  5. def get_twitter_instance():
  6. twitter_config = {}
  7. with open("config/twitter_config") as tmp_file:
  8. for line in tmp_file:
  9. (key, val) = line.split('=')
  10. twitter_config[key] = val.replace('\n', '')
  11. return twitter.Api(consumer_key=twitter_config['consumer_key'],
  12. consumer_secret=twitter_config['consumer_secret'],
  13. access_token_key=twitter_config['access_token_key'],
  14. access_token_secret=twitter_config['access_token_secret'])
  15. def toggle_pepito_for_group(bot, update):
  16. global pepito_groups
  17. chat_id = update.message.chat_id
  18. if chat_id in pepito_groups:
  19. pepito_groups.remove(chat_id)
  20. update.message.reply_text("Pepito is now disabled!")
  21. else:
  22. pepito_groups.append(update.message.chat_id)
  23. update.message.reply_text("Pepito is now enabled!")
  24. def check_pepito_and_post_auto(bot, update):
  25. api = get_twitter_instance()
  26. current_status = api.GetUserTimeline(pepito_id)[0]
  27. global last_status
  28. if last_status is None or last_status.AsDict()['id'] != current_status.AsDict()['id']:
  29. for group_id in pepito_groups:
  30. bot.send_message(chat_id=group_id, text=current_status.AsDict()['text'])
  31. last_status = current_status
  32. def check_pepito_and_post_manually(bot, update):
  33. api = get_twitter_instance()
  34. current_status = api.GetUserTimeline(pepito_id)[0]
  35. global last_status
  36. if last_status.AsDict()['id'] != current_status.AsDict()['id']:
  37. for group_id in pepito_groups:
  38. bot.send_message(chat_id=group_id, text=current_status.AsDict()['text'])
  39. last_status = current_status
  40. else:
  41. update.message.reply_text(current_status.AsDict()['text'])