Fixing Like/Unlike/Retweet buttons, other minor fixes
This commit is contained in:
parent
0edc96940b
commit
0c62833095
|
@ -45,8 +45,9 @@ def callback(bot, update):
|
||||||
status = feature(bot, update, args[1:])
|
status = feature(bot, update, args[1:])
|
||||||
except:
|
except:
|
||||||
status = feature(bot, update)
|
status = feature(bot, update)
|
||||||
except:
|
except Exception as e:
|
||||||
update.callback_query.reply_text(bottools.strings.unknownCommand)
|
logging.exception(e)
|
||||||
|
update.callback_query.message.reply_text(bottools.strings.unknownCommand)
|
||||||
return
|
return
|
||||||
|
|
||||||
if status:
|
if status:
|
||||||
|
@ -134,13 +135,17 @@ def storeLocation(bot, update):
|
||||||
update.message.reply_text(bottools.strings.storeLocation, reply_markup=telegram.ReplyKeyboardRemove())
|
update.message.reply_text(bottools.strings.storeLocation, reply_markup=telegram.ReplyKeyboardRemove())
|
||||||
|
|
||||||
def auth(bot, update):
|
def auth(bot, update):
|
||||||
|
message = update.message or update.callback_query.message
|
||||||
db = dbtools.dbHelper()
|
db = dbtools.dbHelper()
|
||||||
cid = update.message.chat_id
|
cid = message.chat_id
|
||||||
|
|
||||||
auth = tweepy.OAuthHandler(setuptools.cke(), setuptools.cse())
|
auth = tweepy.OAuthHandler(setuptools.cke(), setuptools.cse())
|
||||||
update.message.reply_text(bottools.strings.auth % auth.get_authorization_url())
|
url = auth.get_authorization_url()
|
||||||
dbtools.dbHelper().storeToken(cid, auth.request_token)
|
dbtools.dbHelper().storeToken(cid, auth.request_token)
|
||||||
|
|
||||||
|
rmo = telegram.InlineKeyboardMarkup([[telegram.InlineKeyboardButton("Verify", switch_inline_query_current_chat = "/verify")]])
|
||||||
|
message.reply_text(bottools.strings.auth % url, reply_markup=rmo)
|
||||||
|
|
||||||
def verify(bot, update, args):
|
def verify(bot, update, args):
|
||||||
db = dbtools.dbHelper()
|
db = dbtools.dbHelper()
|
||||||
cid = update.message.chat_id
|
cid = update.message.chat_id
|
||||||
|
@ -203,15 +208,19 @@ def accounts(bot, update):
|
||||||
|
|
||||||
buttons = []
|
buttons = []
|
||||||
|
|
||||||
if len(accounts) != 0:
|
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
buttons += [telegram.InlineKeyboardButton("@%s" % account, callback_data = "/switch %s" % account)]
|
buttons += [telegram.InlineKeyboardButton("@%s" % account, callback_data = "/switch %s" % account)]
|
||||||
|
|
||||||
rmo = telegram.InlineKeyboardMarkup(bottools.methods.makeMenu(buttons, 1))
|
buttons += [telegram.InlineKeyboardButton("Login with Twitter", callback_data = "/login")]
|
||||||
update.message.reply_text(bottools.strings.accounts % getTwo(update.message).whoami(), reply_markup = rmo)
|
|
||||||
|
|
||||||
else:
|
rmo = telegram.InlineKeyboardMarkup(bottools.methods.makeMenu(buttons, 1))
|
||||||
update.message.reply_text(bottools.strings.noauth)
|
|
||||||
|
try:
|
||||||
|
name = getTwo(update.message).whoami()
|
||||||
|
except:
|
||||||
|
name = bottools.strings.accountNobody
|
||||||
|
|
||||||
|
update.message.reply_text(bottools.strings.accounts % name, reply_markup = rmo)
|
||||||
|
|
||||||
# User methods
|
# User methods
|
||||||
|
|
||||||
|
@ -342,7 +351,9 @@ def retweet(bot, update, args):
|
||||||
except tweepy.error.TweepError as e:
|
except tweepy.error.TweepError as e:
|
||||||
bottools.methods.twoExceptions(e, message)
|
bottools.methods.twoExceptions(e, message)
|
||||||
|
|
||||||
return twitools.getTweet(tid)
|
if update.callback_query:
|
||||||
|
time.sleep(0.5)
|
||||||
|
return two.getTweet(tid)
|
||||||
|
|
||||||
def thread(bot, update, args):
|
def thread(bot, update, args):
|
||||||
message = update.message or update.callback_query.message
|
message = update.message or update.callback_query.message
|
||||||
|
@ -384,7 +395,9 @@ def like(bot, update, args):
|
||||||
except tweepy.error.TweepError as e:
|
except tweepy.error.TweepError as e:
|
||||||
bottools.methods.twoExceptions(e, message)
|
bottools.methods.twoExceptions(e, message)
|
||||||
|
|
||||||
return twitools.getTweet(tid)
|
if update.callback_query:
|
||||||
|
time.sleep(0.5)
|
||||||
|
return two.getTweet(tid)
|
||||||
|
|
||||||
def unlike(bot, update, args):
|
def unlike(bot, update, args):
|
||||||
message = update.message or update.callback_query.message
|
message = update.message or update.callback_query.message
|
||||||
|
@ -398,12 +411,16 @@ def unlike(bot, update, args):
|
||||||
except tweepy.error.TweepError as e:
|
except tweepy.error.TweepError as e:
|
||||||
bottools.methods.twoExceptions(e, message)
|
bottools.methods.twoExceptions(e, message)
|
||||||
|
|
||||||
return twitools.getTweet(tid)
|
if update.callback_query:
|
||||||
|
time.sleep(0.5)
|
||||||
|
return two.getTweet(tid)
|
||||||
|
|
||||||
def tweet(bot, update):
|
def tweet(bot, update):
|
||||||
try:
|
try:
|
||||||
if dbtools.dbHelper().getTStatus(update.message.chat_id):
|
if dbtools.dbHelper().getTStatus(update.message.chat_id):
|
||||||
bottools.methods.explicitTweet(bot, update, [update.message.text])
|
bottools.methods.explicitTweet(bot, update, [update.message.text])
|
||||||
|
except ValueError:
|
||||||
|
update.message.reply_text(bottools.strings.noauth)
|
||||||
except tweepy.error.TweepError as e:
|
except tweepy.error.TweepError as e:
|
||||||
bottools.methods.twoExceptions(e, update.message)
|
bottools.methods.twoExceptions(e, update.message)
|
||||||
|
|
||||||
|
@ -438,7 +455,8 @@ def tweetMessage(status, cid, bot, force = False, callback = None, notified = No
|
||||||
buttons = []
|
buttons = []
|
||||||
header = None
|
header = None
|
||||||
|
|
||||||
if notified and notified != dbtools.dbHelper().ato(cid):
|
if notified:
|
||||||
|
if notified != db.ato(cid):
|
||||||
ase = db.aseByAto(notified)
|
ase = db.aseByAto(notified)
|
||||||
oac = twitools.twObject(ato=notified, ase=ase).whoami()
|
oac = twitools.twObject(ato=notified, ase=ase).whoami()
|
||||||
|
|
||||||
|
@ -456,19 +474,18 @@ def tweetMessage(status, cid, bot, force = False, callback = None, notified = No
|
||||||
|
|
||||||
buttons += [
|
buttons += [
|
||||||
telegram.InlineKeyboardButton("Reply", switch_inline_query_current_chat = "/reply %i " % i),
|
telegram.InlineKeyboardButton("Reply", switch_inline_query_current_chat = "/reply %i " % i),
|
||||||
telegram.InlineKeyboardButton("Quote",switch_inline_query_current_chat = "/quote %i " % i)
|
telegram.InlineKeyboardButton("Quote", switch_inline_query_current_chat = "/quote %i " % i)
|
||||||
]
|
]
|
||||||
|
|
||||||
if status.in_reply_to_status_id:
|
if status.in_reply_to_status_id:
|
||||||
buttons += [telegram.InlineKeyboardButton("View Thread", callback_data = "/thread %i" % i)]
|
buttons += [telegram.InlineKeyboardButton("View Thread", callback_data = "/thread %i" % i)]
|
||||||
|
|
||||||
rmu = telegram.InlineKeyboardMarkup(makeMenu(buttons, header = header))
|
rmu = telegram.InlineKeyboardMarkup(makeMenu(buttons, header=header))
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
bot.editMessageReplyMarkup(chat_id=callback.message.chat_id, message_id=callback.message.message_id, reply_markup=rmu)
|
bot.editMessageReplyMarkup(chat_id=callback.message.chat_id, message_id=callback.message.message_id, reply_markup=rmu)
|
||||||
else:
|
else:
|
||||||
|
bot.sendMessage(chat_id = cid or callback.message.chat_id, text = "Tweet %i:\n%s (@%s) at %s:\n%s" % (i, status.author.name, status.author.screen_name, status.created_at, html.unescape(status.text)), reply_markup=rmu)
|
||||||
bot.sendMessage(chat_id = cid, text = "Tweet %i:\n%s (@%s) at %s:\n%s" % (i, status.author.name, status.author.screen_name, status.created_at, html.unescape(status.text)), reply_markup=rmu)
|
|
||||||
|
|
||||||
def trends(bot, update, args):
|
def trends(bot, update, args):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -7,12 +7,7 @@ You will receive a seven-digit PIN. Please send it to me like this:
|
||||||
* /verify 1234567'''
|
* /verify 1234567'''
|
||||||
|
|
||||||
|
|
||||||
authimp = '''You can't currently log in to a new account as you are either already logged in or I'm waiting for your verification code.
|
noauth = '''You are not logged in. Please use /accounts to sign in with Twitter.'''
|
||||||
|
|
||||||
If you wish to log in to a different account or start the login process from the top, please /logout first..'''
|
|
||||||
|
|
||||||
|
|
||||||
noauth = '''You are not logged in. Please use /login to sign in with Twitter.'''
|
|
||||||
|
|
||||||
|
|
||||||
start = '''Hey there!
|
start = '''Hey there!
|
||||||
|
@ -154,3 +149,5 @@ You can use the following accounts:'''
|
||||||
switch = '''You are now logged in as @%s.'''
|
switch = '''You are now logged in as @%s.'''
|
||||||
|
|
||||||
messageSwitch = '''Switch to @%s'''
|
messageSwitch = '''Switch to @%s'''
|
||||||
|
|
||||||
|
accountNobody = '''... Well, actually nobody.'''
|
||||||
|
|
|
@ -43,6 +43,9 @@ class twObject:
|
||||||
|
|
||||||
return self.auth.access_token, self.auth.access_token_secret
|
return self.auth.access_token, self.auth.access_token_secret
|
||||||
|
|
||||||
|
def getTweet(self, tid):
|
||||||
|
return self.api.get_status(tid)
|
||||||
|
|
||||||
def getFollowerIDs(section = setuptools.TWITTER):
|
def getFollowerIDs(section = setuptools.TWITTER):
|
||||||
''' Returns 5,000 follower IDs at most '''
|
''' Returns 5,000 follower IDs at most '''
|
||||||
for id in list(twoHelper(section).api.followers_ids(screen_name=twObject().whoami())):
|
for id in list(twoHelper(section).api.followers_ids(screen_name=twObject().whoami())):
|
||||||
|
|
Loading…
Reference in a new issue