Switch stuff and more

This commit is contained in:
Klaus-Uwe Mitterer 2017-03-28 11:07:33 +02:00
parent 0c62833095
commit 70f7dfcc85
2 changed files with 28 additions and 6 deletions

View file

@ -61,7 +61,6 @@ def mentionHelper(bot, update):
try:
feature(bot, update, args[2:])
except:
print(e)
feature(bot, update)
except Exception as e:
logging.exception(e)
@ -163,6 +162,19 @@ def verify(bot, update, args):
db.deleteToken(update.message.chat_id)
update.message.reply_text(bottools.strings.verifyfail)
found = None
for a in dbtools.dbHelper().accounts(cid):
try:
if twitools.twObject(ato=a[0], ase=a[1]).whoami().strip("@").lower() == args[0].strip("@").lower():
found = a
break
except:
pass
if found:
dbtools.dbHelper().deleteUserByAto(found[0])
except:
update.message.reply_text(bottools.strings.verifyimp)
@ -193,6 +205,11 @@ def switch(bot, update, args):
if found:
dbtools.dbHelper().setActive(cid, a[0])
message.reply_text(bottools.strings.switch % bottools.methods.getTwo(message).whoami().strip("@"))
try:
return getTwo(message).getTweet(getTweetID(args[1], cid))
except Exception as e:
logging.exception(e)
else:
message.reply_text(bottools.strings.noauth)
@ -288,7 +305,7 @@ def reply(bot, update, args):
try:
reply = bottools.methods.getTweetID(args[0], update.message.chat_id)
two = bottools.methods.getTwo(update.message)
otweet = twitools.getTweet(reply)
otweet = two.getTweet(reply)
sender = otweet.user.screen_name
if not ("@%s" % sender.strip("@")) in [("@%s" % a.strip("@")) for a in args]:
@ -329,7 +346,7 @@ def quote(bot, update, args):
try:
reply = bottools.methods.getTweetID(args[0], update.message.chat_id)
two = bottools.methods.getTwo(update.message)
otweet = twitools.getTweet(reply)
otweet = two.getTweet(reply)
sender = otweet.user.screen_name
args += ["https://twitter.com/%s/status/%i" % (sender, int(reply))]
@ -358,6 +375,7 @@ def retweet(bot, update, args):
def thread(bot, update, args):
message = update.message or update.callback_query.message
tid = bottools.methods.getTweetID(args[0], message.chat_id)
two = getTwo(message.chat_id)
i = 0
@ -366,13 +384,13 @@ def thread(bot, update, args):
except:
count = 5
tweets = [twitools.getTweet(tid)]
tweets = [two.getTweet(tid)]
if tweets[-1].in_reply_to_status_id:
nexttid = tweets[-1].in_reply_to_status_id
while i < count:
tweets += [twitools.getTweet(nexttid)]
tweets += [two.getTweet(nexttid)]
if not tweets[-1].in_reply_to_status_id:
break
nexttid = tweets[-1].in_reply_to_status_id
@ -460,7 +478,7 @@ def tweetMessage(status, cid, bot, force = False, callback = None, notified = No
ase = db.aseByAto(notified)
oac = twitools.twObject(ato=notified, ase=ase).whoami()
header = [telegram.InlineKeyboardButton(bottools.strings.messageSwitch % oac, callback_data = "/switch %s" % oac)]
header = [telegram.InlineKeyboardButton(bottools.strings.messageSwitch % oac, callback_data = "/switch %s %i" % (oac, i))]
if status.favorited:
buttons += [telegram.InlineKeyboardButton("Unlike", callback_data = "/unlike %i" % i)]

View file

@ -111,6 +111,10 @@ class dbObject:
self.executeQuery("DELETE FROM tokens WHERE cid = %i AND active;" % int(cid))
self.commit()
def deleteUserByAto(self, ato):
self.executeQuery("DELETE FROM tokens WHERE ato = '%s';" % ato)
self.commit()
def storeUser(self, cid, ato, ase):
self.executeQuery("UPDATE tokens SET active = 0 WHERE cid = %i;" % int(cid))
self.executeQuery("UPDATE tokens SET ato = '%s', ase = '%s', active = 1 WHERE cid = %i AND ase IS NULL;" % (ato, ase, int(cid)))