add 關鍵字 訊息
刪除 關鍵字
團購
關鍵字 @Display_name +1
關鍵字 刪除 @Display_name
手動新增團購者跟手動刪除團購者
if(event.message.text[:event.message.text.find(" "):] in keywords and len(event.message.text)>event.message.text.find(" ")):
    text=event.message.text
    lastLength=text.find(" ")
    if(text[lastLength+1:lastLength+2:]=='@'):            
        key=text[:lastLength:]
        name=text[lastLength+2:text.find(" ",lastLength+1):]
        uid=""
        if not event.message.mention is None:
            for user in event.message.mention.mentionees:
                uid=user.user_id
        quantity=text[text.find(" ",lastLength+1)+1:len(text):]
        cursor=conn.cursor()
        cursor.execute(f"DO $do$ BEGIN IF EXISTS(SELECT uid FROM group_buying_user WHERE mid=(SELECT mid FROM group_buying_message WHERE keyword='{key}') AND uid='{uid}' ) THEN UPDATE group_buying_user SET name='{name}',quantity='{quantity}' WHERE mid=(SELECT mid FROM group_buying_message WHERE keyword='{key}') AND uid='{uid}'; ELSE INSERT INTO group_buying_user (mid ,uid ,name, quantity) VALUES ((SELECT mid FROM group_buying_message WHERE keyword='{key}'),'{uid}','{name}','{quantity}'); END IF; END $do$")
        conn.commit()
        message=text
        message=TextSendMessage(message)
    elif(text[lastLength+1:text.find(" ",lastLength+1):]=="刪除" and text[text.find(" ",lastLength+1)+1:text.find(" ",lastLength+1)+2:]=='@'):
        if not event.message.mention is None:
            for user in event.message.mention.mentionees:
                uid=user.user_id
        cursor=conn.cursor()
        cursor.execute(f"DELETE FROM group_buying_user WHERE uid='{uid}'")
        conn.commit()
        message=TextSendMessage("從"+text[:event.message.text.find(" "):]+"中移除"+text[text.find(" ",lastLength+1)+2:len(text):])
    else:
        key=text[:lastLength:]
        profile = line_bot_api.get_profile(event.source.user_id)
        cursor=conn.cursor()
        cursor.execute(f"DO $do$ BEGIN IF EXISTS(SELECT uid FROM group_buying_user WHERE mid=(SELECT mid FROM group_buying_message WHERE keyword='{key}') AND uid='{profile.user_id}' ) THEN UPDATE group_buying_user SET name='{profile.display_name}',quantity='{text[lastLength+1::]}' WHERE mid=(SELECT mid FROM group_buying_message WHERE keyword='{key}' AND uid='{profile.user_id}'); ELSE INSERT INTO group_buying_user (mid, uid, name, quantity) VALUES ((SELECT mid FROM group_buying_message WHERE keyword='{key}'),'{profile.user_id}','{profile.display_name}','{text[lastLength+1::]}'); END IF; END $do$")
        conn.commit()
        message=key+" "+profile.display_name+" "+text[lastLength+1::]
        message=TextSendMessage(message)
    line_bot_api.reply_message(event.reply_token,message)
group_right:
aid|uid|add_message_right|delete_message_right|view_right|add_buyer_right|delete_buyer_right|allow_changeright_right
---|---
cursor.execute(f"SELECT add_message_right,delete_message_right,view_right,add_buyer_right,delete_buyer_right,allow_changeright_right FROM group_right WHERE uid='{event.source.user_id}';")
rows = cursor.fetchone()