Пример #1
0
def go_back(author, dst):
    sql = f"update member set map_location = map_location - 1 where discord_id='{str(author)}'"
    try:
        algoalgo_sql.sql_update(sql)
        return 0
    except Exception as ex:
        raise ex
def refresh():
    try:
        algoalgo_sql.sql_update(
            "UPDATE member SET daily_steps = 0")  # 일일 문제풀이 가능 횟수
        algoalgo_sql.sql_update(
            "UPDATE member SET status = 0 WHERE status = -1")  # Stun 초기화

        # 연속 업적 달성 확인
        algoalgo_sql.sql_update(
            "UPDATE member SET bj_solv_contd = bj_solv_contd+1 WHERE bj_today <> 0"
        )
        algoalgo_sql.sql_update(
            "UPDATE member SET bj_solv_contd = 0 WHERE bj_today = 0")
        algoalgo_sql.sql_update("UPDATE member SET bj_today = 0")

        # 연속 업적 달성자 업적 반영
        sids = algoalgo_sql.sql_exe(
            "SELECT student_id, bj_solv_contd FROM member WHERE bj_solv_contd IN (5, 14, 30)"
        )
        for sid in sids:
            # 달성 업적 확인
            if sid['bj_solv_contd'] == 5:
                aid = 12
            elif sid['bj_solv_contd'] == 14:
                aid = 13
            else:
                aid = 14

            addpoint(f"!addpoint {aid} {sid['student_id']}")
    except Exception as ex:
        return f"[!] An error occurs while refresh db....\n[INFO] error : {ex}"

    print('refresh done')
    return f"[+] Refresh Done"
Пример #3
0
def update_dailystep(author):
    sql = f"update member set daily_steps = daily_steps + 1 where discord_id='{str(author)}'"
    try:
        algoalgo_sql.sql_update(sql)
        return 0
    except Exception as ex:
        raise ex
Пример #4
0
def update_status(author):
    sql = f"update member set status = 0 where discord_id='{str(author)}'"
    try:
        algoalgo_sql.sql_update(sql)
        return 0
    except Exception as ex:
        raise ex
def setRedemption(author):
    sql = f"update member set status = 1 where discord_id='{str(author)}'"
    try:
        algoalgo_sql.sql_update(sql)
        print("[+] success Redemption")
        return f"[+] success Redemption '{str(author)}'"
    except Exception as ex:
        raise f"[!] error Redemption '{str(author)}'"
def setStun(person):
    sql = f"update member set status = -1 where discord_id='{str(person)}'"
    try:
        algoalgo_sql.sql_update(sql)
        print("[+] success stun")
        return f"[+] success stun '{str(person)}'"
    except Exception as ex:
        raise f"[!] error stun '{str(person)}'"
def init_status(author):
    sql = "update member set status = 0 where discord_id = %s;"

    try:
        algoalgo_sql.sql_update(sql, str(author))
        print(f"[*] Successfully init status data about {author}")

    except Exception as ex:
        e_msg = f"[!] An error occurs while initializing status about {author} in db....\n[INFO] error : {ex}"
        raise algoalgo_error.UserDefinedException(e_msg)
def setAssassin(person):
    sql = f"select map_location from member where discord_id='{str(person)}'"
    try:
        sql_result = algoalgo_sql.sql_exe(sql)
    except Exception as ex:
        return f"[!] error select '{str(person)}' DB"

    sql2 = f"update member set map_location = {int(sql_result[0]['map_location'])-1} where discord_id='{str(person)}'"
    try:
        algoalgo_sql.sql_update(sql2)
    except Exception as ex:
        raise f"[!] error update '{str(person)}' DB"
    return f"[+] success use item '{person}', Assasin"
def unlock(author):
    try:
        memberinfo = algoalgo_sql.sql_exe(
            "SELECT status, map_location, baekjoon_id, bj_solved FROM member WHERE discord_id = %s",
            author)[0]
    except Exception as ex:
        return f"[!] An error occurs while check db....\n[INFO] error : {ex}"

    # 이미 잠금 해제된 경우
    if memberinfo['status'] == 1:
        return "[!] Already Unlocked."

    # 스턴에 걸린 경우
    if memberinfo['status'] == -1:
        return "[!] You've got Stunned. Try Again Tomorrow."

    if memberinfo['status'] == 0:
        # 풀어야 하는 문제 확인
        try:
            pid = algoalgo_sql.sql_exe(
                "SELECT baekjoon_no FROM map WHERE id = %s",
                memberinfo['map_location'])[0]['baekjoon_no']
        except Exception as ex:
            return f"[!] An error occurs while check db....\n[INFO] error : {ex}"

        # 정상 해제 시도
        if pid in get_solved(memberinfo['baekjoon_id']):
            try:
                algoalgo_sql.sql_update(
                    "UPDATE member SET status = 1 WHERE baekjoon_id = %s",
                    memberinfo['baekjoon_id'])
            except Exception as ex:
                return f"[!] An error occurs while update status into db....\n[INFO] error : {ex}"

            # DB에 인증되지 않았을 경우 인증 진행
            if pid not in memberinfo['bj_solved'].split(';')[:-1]:
                memberinfo['bj_solved'] += (str(pid) + ';')

            return "[*] Successfully Unlocked."

        # 문제를 풀지 않은 경우
        else:
            return "[!] You haven't Solved The Problem."

    # 그 외의 에러
    else:
        return "[!] Status Error: Call the Admins"
def daily_baekjoon(author, cmd):
    args = cmd.split()
    if len(args) != 2:
        return "[!] Usage : !daily_baekjoon <Problem id>"

    # 입력된 문제 번호
    pid = args[1]

    # 인증된 푼 문제 목록
    try:
        solvedlist = algoalgo_sql.sql_exe(
            "SELECT bj_solved FROM member WHERE discord_id = %s",
            author)[0]['bj_solved']
    except Exception as ex:
        return f"[!] An error occurs while check db....\n[INFO] error : {ex}"

    if solvedlist == None:
        solvedlist = ""

    # 이미 인증된 문제
    if pid in solvedlist.split(';')[:-1]:
        return "[!] Already Registered Problem"

    # 아직 풀지 않은 문제
    try:
        solvedlist_db = get_solved(
            algoalgo_sql.sql_exe(
                "SELECT baekjoon_id FROM member WHERE discord_id = %s",
                author)[0]['baekjoon_id'])
    except Exception as ex:
        return f"[!] An error occurs while check db....\n[INFO] error : {ex}"
    if pid not in solvedlist_db:
        return "[!] You Haven't Solved the Problem Yet."

    # 신규 1일 1백준 인증 및 add point
    solvedlist += (str(pid) + ';')
    try:
        algoalgo_sql.sql_update(
            "UPDATE member SET bj_solved = %s WHERE discord_id = %s",
            solvedlist, author)
        addpoint(f"!addpoint 11 {author}")
        algoalgo_sql.sql_update(
            "UPDATE member SET bj_today = 1 WHERE discord_id = %s", author)
    except Exception as ex:
        return f"[!] An error occurs while update certification into db....\n[INFO] error : {ex}"

    return "[+] Successfully Certified."
def setmap(cmd):
    args = cmd.split()
    if len(args) != 4:
        return "Usage : !set_map <id> <feature> <ahead_to>"
    # !set_map <칸 순서> <normal: 0, ladder: 1, snake: 2, boss: 3> <이동할 위치>

    id = args[1]
    feature = args[2]
    ahead_to = args[3]

    sql = "insert into map (id, feature, ahead_to) value (%s, %s, %s);"
    try:
        algoalgo_sql.sql_update(sql, int(id), int(feature), int(ahead_to))
    except Exception as ex:
        return f"[!] An error occurs while adding map data into db....\n[INFO] error : {ex}"

    return f"[+] success adding map data into db..."
def buy_item(author, cmd): #!buy_item <아이템> <개수>
    args = cmd.split()

    if len(args) != 3:
        return "Usage: !buyitem <item name> <number>"
        
    # if str(type(args[1])) != "<class 'str'>":
    #     return "Usage: !buyitem <item name> <number>"
        
    # if str(type(args[2])) != "<class 'int'>":
    #     return "Usage: !buyitem <item name> <number>"
    
    # if str(type(args[1])) != "<class 'str'>":
    #     return "Usage: !buyitem <item name> <number>"

    # if str(type(args[2])) != "<class 'int'>":
    #     return "Usage: !buyitem <item name> <number>"

    item = args[1]
    cnt = int(args[2])

    # error ouccurs -> ValueError: 'REDEMTION' is not in list
    item_price = int(PRICE[ITEMS.index(item)])*cnt

    sql = f"select * from member where discord_id='{str(author)}'"
    sql_result = algoalgo_sql.sql_exe(sql)
    pointinfo = f"""{sql_result[0]['point']}"""

    if item not in ITEMS:
        return "Please enter the item name correctly"
    
    if item_price > int(pointinfo):
        return "You don't have enough points"
    
    gogo=''
    for i in range(cnt):
        gogo+=item+';'
    
    sql = f"update member set items = CONCAT_WS(';', items, %s) where discord_id='{str(author)}'"
    sql2 = f"update member set point = point-{item_price} where discord_id='{str(author)}'"
    try:
        algoalgo_sql.sql_update(sql, gogo)
        algoalgo_sql.sql_update(sql2)
    except Exception as ex:
        return f"[!] buy item error!\n[INFO]: {ex}"
    return f"[+] success updating item into db: {author}\n구매 성공! {item_price} 포인트 차감되었습니다"
def snake(discord_id):
    #STEP 6-2 는 메세지로 알려주기
    sql = f"select * from member where discord_id='{str(discord_id)}'"

    try:
        sql_result = algoalgo_sql.sql_exe(sql)

        map_sql = f"select * from map where id='{sql_result[0]['map_location']}'"
        map_sql_result = algoalgo_sql.sql_exe(map_sql)

        #STEP 6-2 는 메세지로 알려주기

        map_location_sql2 = f"update member set map_location ='{map_sql_result[0]['ahead_to']}' where discord_id='{str(discord_id)}'"
        algoalgo_sql.sql_update(map_location_sql2)
        return f"[*] Successfully updataed data about **{discord_id}** 's location on the snake map"

    except Exception as ex:
        return f"[!] An error occurs while finding **{discord_id}** 's location on the map in db....\n[INFO] error : {ex}"
def updateitem(author, item):
    sql = f"select items from member where discord_id='{str(author)}'"
    try:
        sql_result = algoalgo_sql.sql_exe(sql)

        sql_result2 = sql_result[0]['items'].replace(item, "", 1)

    except Exception as ex:
        e_msg = f"[!] error select '{str(author)}' DB"
        raise algoalgo_error.UserDefinedException(e_msg)

    sql2 = f"update member set items ='{str(sql_result2)}' where discord_id='{str(author)}'"
    try:
        algoalgo_sql.sql_update(sql2)
    except Exception as ex:
        e_msg = f"[!] error update '{str(author)}' DB"
        raise algoalgo_error.UserDefinedException(e_msg)

    return f"[+] success use item '{author}', '{item}'"
Пример #15
0
def use_items(author, item):
    sql = f"select items from member where discord_id='{str(author)}'"
    try:
        sql_result = algoalgo_sql.sql_exe(sql)
        item_dir = show_items(sql_result[0]['items'])
        item_dir[item] -= 1
        if item_dir[item] < 0:
            e_msg = "You tried to use item you don't have.\n보유하지 않은 아이템을 사용하려 하셨습니다. 스탭에게 문의주세요."
            raise algoalgo_error.UserDefinedException(e_msg)

        item_str = ""
        for k, v in item_dir.items():
            if v <= 0:
                continue
            item_str += (k + ';') * v

        update_query = f"update member set items = %s where discord_id=%s;"
        algoalgo_sql.sql_update(update_query, item_str, str(author))

    except Exception as ex:
        raise ex
def adduser(author, cmd):
    args = cmd.split()
    if author == "admin" and len(args) != 5:
        return "[!] Usage : !adduser <name> <student_id> <baekjoon_id> <discord_id>"
    elif author != "admin" and len(args) != 4:
        return "[!] Usage : !adduser <name> <student_id> <baekjoon_id>"
    # !adduser <이름> <학번> <백준 아이디>

    dc_id = author if author != "admin" else args[4]
    name = args[1]
    s_id = args[2]
    bj_id = args[3]
    bj_solved = algoalgo_bj_crawling.getBJSolved(bj_id)

    sql = "insert into member (discord_id, student_id, name, baekjoon_id, bj_solved) value (%s, %s, %s, %s, %s);"
    try:
        algoalgo_sql.sql_update(sql, dc_id, s_id, name, bj_id, bj_solved)
    except Exception as ex:
        return f"[!] An error occurs while adding user({author}) into db....\n[INFO] error : {ex}"

    return f"[+] success adding user into db...{author}"
def addpoint(cmd):
    args = cmd.split(' ')
    if len(args) != 3:
        return "[!] Usage : !addpoint <archivement id> <student_id or discord_id>"
    # !addpoint <업적 번호> <학번 또는 디스코드 닉네임>

    # 업적 정보 확인
    try:
        result = algoalgo_sql.sql_exe(
            "SELECT points, achive_name FROM achievement WHERE id = %s",
            args[1])[0]
    except Exception as ex:
        return f"[!] An error occurs while check the db....\n[INFO] error : {ex}"

    point = result['points']
    achname = result['achive_name']

    # 포인트 업데이트
    if args[2].find('#') == -1:  # 학번 입력시
        sql = "UPDATE member SET point = point+%s WHERE student_id = %s;"
        try:
            algoalgo_sql.sql_update(sql, point, args[2])
            name = algoalgo_sql.sql_exe(
                "SELECT discord_id FROM member WHERE student_id = %s",
                args[2])[0]['discord_id']
        except Exception as ex:
            return f"[!] An error occurs while update the point into db....\n[INFO] error : {ex}"

    else:  # 디스코드 닉네임 입력시
        name = args[2]
        try:
            sql = "UPDATE member SET point = point+%s WHERE discord_id = %s;"
            algoalgo_sql.sql_update(sql, point, name)
        except Exception as ex:
            return f"[!] An error occurs while update the point into db....\n[INFO] error : {ex}"

    return f"[+] Mission Accomplished: {achname} by {name}"
def step(discord_id):
    try:
        sql = f"select * from member where discord_id='{str(discord_id)}'"
        sql_result = algoalgo_sql.sql_exe(sql)

        #STEP-2
        daily_step_sql = f"update member set daily_steps ='{sql_result[0]['daily_steps'] + 1}' where discord_id='{str(discord_id)}'"
        algoalgo_sql.sql_update(daily_step_sql)

        #STEP-3
        if sql_result[0]['status'] == 1:

            #STEP-4
            map_location_sql = f"update member set map_location ='{sql_result[0]['map_location'] + 1}' where discord_id='{str(discord_id)}'"
            algoalgo_sql.sql_update(map_location_sql)

            #STEP-5
            map_sql = f"select * from map where id='{int(sql_result[0]['map_location'])+1}'"
            map_sql_result = algoalgo_sql.sql_exe(map_sql)

            if map_sql_result[0]['feature'] == 1:
                map_location_sql2 = f"update member set map_location ='{map_sql_result[0]['ahead_to']}' where discord_id='{str(discord_id)}'"
                algoalgo_sql.sql_update(map_location_sql2)
                return f"[*] Successfully updated data about **{discord_id}** 's location on the map", map_sql_result[
                    0]['feature'], 3 - (sql_result[0]['daily_steps'] + 1)

            # if map_sql_result[0]['feature'] == 2 :
            #     # LocFeatureInfo = "**SNAKE**🐍"
            #     return f"[*] Successfully updated data about **{discord_id}** 's location on the map", map_sql_result[0]['feature'], 3 - (sql_result[0]['daily_steps'] + 1)

            # if map_sql_result[0]['feature'] == 3 :
            #     # LocFeatureInfo = "**BOSS**🧟‍♀️"
            #     return f"[*] Successfully updated data about **{discord_id}** 's location on the map", map_sql_result[0]['feature'], 3 - (sql_result[0]['daily_steps'] + 1)

            return f"[*] Successfully updated data about **{discord_id}** 's location on the map", map_sql_result[
                0]['feature'], 3 - (sql_result[0]['daily_steps'] + 1)

        else:
            # raise 해야함
            return f"[*] 문제를 푸셔야합니다.", 0, 0

    except Exception as ex:
        #raise 해야함
        return f"[!] An error occurs while finding **{discord_id}** 's location on the map in db....\n[INFO] error : {ex}", 0, 0
Пример #19
0
def attackBoss(author, cmd):
    args = cmd.split()
    if len(args) != 2:
        return "[!] Usage : !attackBoss <Problem id>"

    # 입력된 문제 번호
    pid = args[1]

    # 인증된 푼 문제 목록
    try:
        solvedlist = algoalgo_sql.sql_exe(
            "SELECT bj_solved FROM member WHERE discord_id = %s",
            author)[0]['bj_solved']
    except Exception as ex:
        return f"[!] An error occurs while check db....\n[INFO] error : {ex}"

    if solvedlist == None:
        solvedlist = ""

    # 이미 인증된 문제
    if pid in solvedlist.split(';')[:-1]:
        return "[!] Already Registered Problem"

    # 아직 풀지 않은 문제
    try:
        solvedlist_db = algoalgo_member.get_solved(
            algoalgo_sql.sql_exe(
                "SELECT baekjoon_id FROM member WHERE discord_id = %s",
                author)[0]['baekjoon_id'])
    except Exception as ex:
        return f"[!] An error occurs while check db....\n[INFO] error : {ex}"
    if pid not in solvedlist_db:
        return "[!] You Haven't Solved the Problem Yet."

    # 문제풀이 인증 및 add point
    solvedlist += (str(pid) + ';')
    try:
        algoalgo_sql.sql_update(
            "UPDATE member SET bj_solved = %s WHERE discord_id = %s",
            solvedlist, author)
    except Exception as ex:
        return f"[!] An error occurs while update certification into db....\n[INFO] error : {ex}"

    # 문제 계수 설정
    rank = algoalgo_sql.sql_exe(
        "SELECT rank FROM algoalgo.solved_rank where id = %s", pid)[0]['rank']
    dmg = 0
    if rank <= 5:
        dmg = 1
    elif rank <= 10:
        dmg = 3
    elif rank <= 15:
        dmg = 8
    else:
        dmg = 15

    dmg *= (rank - 1) % 5 + 1

    # 보스 체력 날리기
    try:
        algoalgo_sql.sql_update(
            "UPDATE boss SET life = life - %s where season = 1;", dmg)
    except Exception as ex:
        return f"[!] An error occurs while updating boss life into db....\n[INFO] error : {ex}"

    # 멤버당 보스 공격한 누적 뎀 정리
    try:
        algoalgo_sql.sql_update(
            "UPDATE member_boss SET attack = attack + 1 where discord_id = %s;",
            author)
        algoalgo_sql.sql_update(
            "UPDATE member_boss SET total_dmg = total_dmg + %s where discord_id = %s;",
            dmg, author)
    except Exception as ex:
        return f"[!] An error occurs while updating boss life into db....\n[INFO] error : {ex}"

    return f"[+] 공격 성공, 데미지 : {dmg}"