From 70f7dfcc85631fd92345d923d4829b6fd8669bae Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 28 Mar 2017 11:07:33 +0200 Subject: [PATCH] Switch stuff and more --- bottools/methods.py | 30 ++++++++++++++++++++++++------ dbtools/__init__.py | 4 ++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/bottools/methods.py b/bottools/methods.py index 5a505b9..34606a2 100644 --- a/bottools/methods.py +++ b/bottools/methods.py @@ -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)] diff --git a/dbtools/__init__.py b/dbtools/__init__.py index 1ba1f6c..14416ba 100644 --- a/dbtools/__init__.py +++ b/dbtools/__init__.py @@ -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)))