Exemplo n.º 1
0
 def get_secret(hash_to_find):
     db = peewee.SqliteDatabase("task_db.db")
     db.connect()
     query = Secret.select().where(Secret.hash == hash_to_find)
     current_time = datetime.datetime.today()
     if query.scalar() is None:
         db.close()
         return False
     else:
         query[0].remaining_views -= 1
         query[0].save()
         if query[0].remaining_views == -1:
             return False
         elif query[0].remaining_views == 0:
             new_query = Secret.delete().where(Secret.hash == hash_to_find)
             new_query.execute()
             db.close()
         # probably secrets after expiration date should by deleted automatically,
         # but I decided to delete them on request
         elif query[0].expires_at != query[0].created_at and (
                 query[0].expires_at - current_time).total_seconds() < 0:
             new_query = Secret.delete().where(Secret.hash == hash_to_find)
             new_query.execute()
             db.close()
             return False
         return query[0]
Exemplo n.º 2
0
def github_history_token(bot, update, user_data):
    user = update.message.from_user
    logger.debug("User %s getting history", user.first_name)
    c = 1
    user_data['tokens'] = {}
    message = u"روی هرکدوم که بزنی پاک میشه!!!!! برای بازگشت کنسل رو بزن \n"
    entities = []
    for _secret in Secret.select().where(Secret.owner_id == user_data['id']):
        entity = MessageEntity(
            'code',
            len(message) + 1 + len(str(c)) + 1 + len(_secret.user_name) + 1,
            17)
        entities.append(entity)
        message += u"/%d %s %s....%s\n" % (
            c, _secret.user_name, _secret.secret[:9], _secret.secret[-4:])
        user_data['tokens'][c] = _secret.id
        c += 1
    message += u"/cancel"
    bot.sendMessage(user.id, message, reply_markup=ReplyKeyboardRemove())
    return State.GITHUB_HISTORY
Exemplo n.º 3
0
def get_github_link(bot, update, user_data, job_queue):
    user = update.message.from_user
    logger.debug("user: %s  bye bye! after submit a github link",
                 user.first_name)
    update.message.reply_text(
        u' با تشکر بعد از بررسی لینک داخل کانال @channel گذاشته میشه\n'
        u'و همچنین برای تمای کاربرا ارسال میشه تا بعد از تاییدشون ستاره بگیری برای شر.ع دوباره /start رو بزن',
        reply_markup=ReplyKeyboardRemove())

    message = update.message.text
    logger.debug("message %s", message)

    if "github.com" in message:
        link = message
        temp_list = message.split("/")
        logger.debug("temp %s", temp_list)
        if temp_list[-1] == "":
            temp_list.pop()
        logger.debug("temp %s", temp_list)

        repo_name = temp_list[-1]
        repo_owner = temp_list[-2]

        logger.debug("github_obj.repo_name %s", repo_name)
        logger.debug("github_obj.repo_owner %s", repo_owner)

        logger.info("user: %s send a github link: %s", user.first_name,
                    message)

    else:
        repo_owner, repo_name = message.split(":")
        link = SitePrefix.GITHUB + "/" + repo_owner + "/" + repo_name
        logger.info("user: %s send a github owner: %s repo: %s",
                    user.first_name, repo_owner, repo_name)

    github_obj = Github.get_or_none(owner_id=user_data['id'],
                                    link=link,
                                    repo_name=repo_name,
                                    repo_owner=repo_owner)
    if not github_obj:
        github_obj = Github.create(owner_id=user_data['id'],
                                   link=link,
                                   repo_name=repo_name,
                                   repo_owner=repo_owner)
    github_obj.save()
    logger.debug("github object saved")

    after = 1
    user_data['jobs'] = []
    for _secret in Secret.select().where(Secret.permitted == True):
        context = {
            "token": _secret.secret,
            "chat_id": user.id,
            "secret_owner_chat_id": _secret.owner.uid,
            "repo_name": repo_name,
            "repo_owner": repo_owner,
            "try": 0
        }
        job = job_queue.run_once(set_star, after, context=context)

        user_data['jobs'].append({"job": job, "context": context})
        after += Const.REQUEST_DELAY

        logger.info("secret owner name: %s staring owner: %s repo: %s",
                    _secret.owner.first_name, github_obj.repo_owner,
                    github_obj.repo_name)

    return ConversationHandler.END