def callback(token, data): try: update = json.loads(data) except Exception as err: return Log.w("Not JSON data (%s) (%s)" % (err, data)) if token not in BotCache.bots: Log.w("This token is not in the cache!") if token not in token_black_list: if len(token) == 45: HTTPLL.deleteWebhook(token) else: Log.w("Invalid token!! (%s) blacklist." % token) token_black_list.append(token) return if token not in offsets: offsets[token] = 0 last_id = offsets[token] bot = BotCache.bots[token] if update["update_id"] > last_id: offsets[token] = update["update_id"] try: update_handler(bot, update) except Exception as err: Log.e("UNHANDLED EXCEPTION IN THE UPDATE HANDLER: %s" % str(err))
def detach_bot(token, bid=None): if bid: token = Manager.get_token_from_bot_id(bid) if not token: return Log.w("Empty token.") if token not in BotCache.bots: return Log.w("This token is not running.") HTTPLL.deleteWebhook(token) del BotCache.bots[token] Log.i("Bot with %s token stopped." % token) return True
def bot_init(token, clean): ok = False try: BotCache.bots[token] = HTTPLL.getMe(token) ok = True LowLevel.check_files(Manager.get_botid_from_token(token)) if clean: HTTPLL.deleteWebhook(token) clean_updates(token) HTTPLL.setWebhook(token, certfile) except Unauthorized: if ok: Log.w("getMe ok but unauth.") Log.w("Bot with token '%s' unauthorized." % token) Utils.warn_token(token) except Exception as error: Log.e(error)