Add follow and unfollow methods, fix reply method

This commit is contained in:
Klaus-Uwe Mitterer 2017-03-20 21:40:02 +01:00
parent 003183ed0d
commit 59b4bcd548
2 changed files with 23 additions and 3 deletions

View file

@ -27,6 +27,7 @@ After authentication, you will be able to tweet from your account. Just drop me
Additionally, you will be able to use the following commands: Additionally, you will be able to use the following commands:
* /follow USER - Follow a user.
* /like TWEET - Like a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline. * /like TWEET - Like a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline.
* /reply TWEET TEXT - Reply TEXT to a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline. * /reply TWEET TEXT - Reply TEXT to a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline.
* /retweet TWEET - Retweet a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline. * /retweet TWEET - Retweet a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline.
@ -34,6 +35,7 @@ Additionally, you will be able to use the following commands:
* /toggletweet - Turn automatic tweeting of messages on/off. Useful in groups. * /toggletweet - Turn automatic tweeting of messages on/off. Useful in groups.
* /tweet TEXT - Explicitly tweet TEXT even if automatic tweeting is off (/toggletweet). * /tweet TEXT - Explicitly tweet TEXT even if automatic tweeting is off (/toggletweet).
* /unauth - Revoke your authenticaton and stop using %s. * /unauth - Revoke your authenticaton and stop using %s.
* /unfollow USER - Unfollow a user.
Have fun!''' Have fun!'''

View file

@ -20,6 +20,7 @@ def twoExceptions(e, message):
131: strings.twitterError, 131: strings.twitterError,
161: strings.followLimit, 161: strings.followLimit,
185: strings.tweetLimit, 185: strings.tweetLimit,
186: strings.tweetLimit,
187: strings.dupTweet, 187: strings.dupTweet,
205: strings.rateLimit, 205: strings.rateLimit,
226: strings.automatedTweet, 226: strings.automatedTweet,
@ -86,6 +87,22 @@ def fish(bot, update):
dbtools.dbHelper().addFish(update.message.chat_id) dbtools.dbHelper().addFish(update.message.chat_id)
update.message.reply_text(strings.fishThanks) update.message.reply_text(strings.fishThanks)
def follow(bot, update, args):
try:
two = getTwo(update.message)
for user in args:
two.api.create_friendship(screen_name = user)
except tweepy.error.TweepError as e:
twoExceptions(e, update.message)
def unfollow(bot, update, args):
try:
two = getTwo(update.message)
for user in args:
two.api.destroy_friendship(screen_name = user)
except tweepy.error.TweepError as e:
twoExceptions(e, update.message)
def getTweetID(tlid, cid): def getTweetID(tlid, cid):
try: try:
db = dbtools.dbHelper() db = dbtools.dbHelper()
@ -125,12 +142,11 @@ def explicitTweet(bot, update, args, reply = None):
else: else:
out = mobj out = mobj
two.api.update_with_media(filename, update.message.caption, reply, file=out)
two.api.update_with_media(filename, update.message.caption, file=out)
out.close() out.close()
else: else:
two.tweet(' '.join(args)) two.tweet(' '.join(args), reply)
except tweepy.error.TweepError as e: except tweepy.error.TweepError as e:
logging.exception("Meh.") logging.exception("Meh.")
@ -215,6 +231,7 @@ if __name__ == "__main__":
updater.dispatcher.add_handler(telegram.ext.CommandHandler("auth", auth)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("auth", auth))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("fish", fish)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("fish", fish))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("follow", follow, pass_args=True))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("help", start)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("help", start))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("like", like, pass_args=True)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("like", like, pass_args=True))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("reply", reply, pass_args=True)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("reply", reply, pass_args=True))
@ -225,6 +242,7 @@ if __name__ == "__main__":
updater.dispatcher.add_handler(telegram.ext.CommandHandler("toggletweet", toggleTweet)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("toggletweet", toggleTweet))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("tweet", explicitTweet, pass_args=True)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("tweet", explicitTweet, pass_args=True))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("unauth", unauth)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("unauth", unauth))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("unfollow", unfollow, pass_args=True))
updater.dispatcher.add_handler(telegram.ext.CommandHandler("verify", verify, pass_args=True)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("verify", verify, pass_args=True))
updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.text, tweet)) updater.dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.text, tweet))