示例#1
0
def get_my_id(update, context):
    uid = update.effective_user.id
    text = "喵!你的UID是 %s 喔!"%(uid)
    if auth.check_user_premission(uid):
        text += "\n"
        text += str(weee_db.get_user_info(uid))
    context.bot.send_message(chat_id=update.effective_chat.id, text=text)
示例#2
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)
示例#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
示例#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)
示例#5
0
 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
示例#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)
示例#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)
示例#8
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)