Ejemplo n.º 1
0
def update_weee(update, context):
    global update_time
    uid = update.effective_user.id
    if (auth.check_user_premission(uid) and
        (datetime.datetime.now()-update_time).seconds > 10):
        zip2uid = weee_db.get_zip2uid()
        uzip = weee_db.get_user_info(uid)["zip"]
        if (auth.check_admin_premission(uid) and 
            len(context.args) == 2 and 
            re.match(r"^[0-9]{5}$", context.args[1])):
            uzip = context.args[1]
        priv_time, priv_dict = weee_db.get_time_and_product(uzip)

        now_time = datetime.datetime.now().isoformat()
        weee_dic = weee_lib.get_weee_now(uzip)

        if len(context.args) >= 1 and context.args[0] == "all":
            sent_dic_to_user(context, uid, weee_dic, uzip=uzip)

        if len(context.args) >= 1 and context.args[0] == "filter":
            f_dic = weee_lib.filter_dic(weee_dic, weee_db.get_filter(uid))
            sent_dic_to_user(context, uid, f_dic, uzip=uzip)

        sent_newdic_to_user(context, zip2uid[uzip], 
            priv_time, priv_dict, now_time, weee_dic, reply_uid=uid)

        weee_db.set_time_and_product(uzip, now_time, weee_dic)
        update_time = datetime.datetime.now()
    else:
        info_text = auth.get_premission_error_message()
        context.bot.send_message(chat_id=update.effective_chat.id, text=info_text)
Ejemplo n.º 2
0
def delete_user(update, context):
    info_text = ""
    if auth.check_admin_premission(update.effective_user.id):
        weee_db.delete_user(context.args[0])
        info_text = str(weee_db.get_user_list())
    else:
        info_text = auth.get_premission_error_message()
    context.bot.send_message(chat_id=update.effective_chat.id, text=info_text)
Ejemplo n.º 3
0
def check_premission_info(uid):
    if auth.check_admin_premission(uid):
        info_text = "喵!是铲屎官!"
    elif auth.check_user_premission(uid):
        info_text = "二虎亲热的蹭了蹭你!"
    else:
        info_text = auth.get_premission_error_message()
    return info_text
Ejemplo n.º 4
0
def clear_filter(update, context):
    uid = update.effective_user.id
    if auth.check_user_premission(uid):
        weee_db.clear_filter(uid)
        info_text = "二虎知道你不挑食~"
    else:
        info_text = auth.get_premission_error_message()
    context.bot.send_message(chat_id=uid, text=info_text)
Ejemplo n.º 5
0
def check_user_list(update, context):
    info_text = ""
    if auth.check_admin_premission(update.effective_user.id):
        ulist = weee_db.get_user_list()
        info_text = ""
        for u in ulist:
            info_text += u + " " + str(weee_db.get_user_info(u))
            info_text += "\n"
    else:
        info_text = auth.get_premission_error_message()
    context.bot.send_message(chat_id=update.effective_chat.id, text=info_text)
Ejemplo n.º 6
0
def get_filter(update, context):
    uid = update.effective_user.id
    if auth.check_user_premission(uid):
        fl = [w.encode('utf8') for w in weee_db.get_filter(uid)]
        if fl:
            info_text = "二虎知道你喜欢吃:" + ", ".join(fl)
        else:
            info_text = "二虎知道你不挑食~"
    else:
        info_text = auth.get_premission_error_message()
    context.bot.send_message(chat_id=uid, text=info_text)
Ejemplo n.º 7
0
def delete_filter(update, context):
    uid = update.effective_user.id
    if auth.check_user_premission(uid):
        if len(context.args) != 0:
            weee_db.delete_filter(uid, context.args)
            fl = [w.encode('utf8') for w in weee_db.get_filter(uid)]
            info_text = "二虎知道你喜欢吃:" + ", ".join(fl)
        else:
            info_text = "快告诉二虎你吃腻了啥~"
    else:
        info_text = auth.get_premission_error_message()
    context.bot.send_message(chat_id=uid, text=info_text)
Ejemplo n.º 8
0
def add_user(update, context):
    info_text = ""
    if auth.check_admin_premission(update.effective_user.id):
        if len(context.args) != 2:
            info_text = "Please enter uid and zipcode"
        else:
            uid, zipcode = context.args[0], context.args[1]
            weee_db.add_user(uid)
            weee_db.add_user_info(uid, {"zip": zipcode})
            info_text = str(weee_db.get_user_info(uid))
    else:
        info_text = auth.get_premission_error_message()
    context.bot.send_message(chat_id=update.effective_chat.id, text=info_text)
Ejemplo n.º 9
0
def update_zipcode(update, context):
    def set_zipcode(uid, set_uid, zipcode):
        if not re.match(r"^[0-9]{5}$", zipcode):
            info_text = "请输入正确的 zipcode 喔。"
        elif not auth.check_user_premission(set_uid):
            info_text = "请输入正确的 user id 喔。"
        else:
            weee_db.add_user_info(set_uid, {"zip": zipcode})
            info_text = "更新成功~"
        return info_text
    uid = update.effective_user.id
    if auth.check_admin_premission(uid) and len(context.args) == 2:
        info_text = set_zipcode(uid, context.args[0], context.args[1])
    elif auth.check_user_premission(uid) and len(context.args) == 1:
        info_text = set_zipcode(uid, uid, context.args[0])
    else:
        info_text = auth.get_premission_error_message()
    context.bot.send_message(chat_id=uid, text=info_text)