def setpoint(author): sql = f"update member set point = 10 where discord_id='{str(author)}'" try: algoalgo_sql.sql_exe(sql) return f"[*] 테스트용 10 포인트세팅" except Exception as ex: return f"[!] setpoint error!\n[INFO]: {ex}"
def random_bj(author, cmd): args = cmd.split() if len(args) != 2: return "[!] Usage : !random_bj <tier>" tier = args[1] # 요청자 BOJ id 및 푼 문제 목록 확인 try: bojid = 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}" solved = get_solved(bojid) # 티어별 시작점 설정 if tier == 'bronze': startfrom = 1 elif tier == 'silver': startfrom = 6 elif tier == 'gold': startfrom = 11 elif tier == 'platinum': startfrom = 16 elif tier == 'diamond': startfrom = 21 elif tier == 'ruby': startfrom = 26 else: return "[!] There is no such tier in solved.ac." # DB에서 해당 티어 문제 목록 가져오기 sql = "SELECT id FROM solved_rank WHERE rank >= %s and rank < %s;" try: result = algoalgo_sql.sql_exe(sql, startfrom, startfrom + 5) except Exception as ex: return f"[!] An error occurs while check db....\n[INFO] error : {ex}" candidate = [] for item in result: candidate.append(item['id']) # 푼 적 없는 랜덤 문제 추천 count = 0 while count != len(candidate): rbj = candidate[randint(0, len(candidate))] if rbj not in solved: break # 결과 반환 if count == len(candidate): return "[!] You've Solved All Problems." else: return f'https://www.acmicpc.net/problem/{rbj}'
def showmap(author): sql = f"select map_location from member where discord_id='{str(author)}'" try: sql_result = algoalgo_sql.sql_exe(sql) Locinfo = sql_result[0]['map_location'] sql_bj_no = f"select baekjoon_no from map where id= {Locinfo}" sql_bj_result = algoalgo_sql.sql_exe(sql_bj_no) bj_no = sql_bj_result[0]['baekjoon_no'] return f"[*] Successfully Inquires data about **{author}** 's location on the map", Locinfo, bj_no except Exception as ex: return f"[!] An error occurs while finding **{author}** 's location on the map in db....\n[INFO] error : {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"
def showuserinfo(author): sql = f"select * from member where discord_id='{str(author)}';" try: sql_result = algoalgo_sql.sql_exe(sql) item_dir = show_items(sql_result[0]['items']) # status : 1, 2, 3에 맞는 값을 각각 문자열로 풀어서 출력 # items : 아이템 보유 개수 정리해서 출력 userinfo = f"""discord_id : {sql_result[0]['discord_id']} name : {sql_result[0]['name']} **- GAME INFO** status : {sql_result[0]['status']} your steps on today : {sql_result[0]['daily_steps']} your point : {sql_result[0]['point']} your location : {sql_result[0]['map_location']} **- items** ``` STEP | {item_dir['STEP']} SNAKE | {item_dir['SNAKE']} STUN | {item_dir['STUN']} ASSASSIN | {item_dir['ASSASSIN']} REDEMPTION | {item_dir['REDEMPTION']} ``` **- BAEKJOON INFO** baekjoon id : {sql_result[0]['baekjoon_id']} Continuous Days of Mission : {sql_result[0]['bj_solv_contd']} """ return f"[*] Successfully Inquires data about {author}", userinfo except Exception as ex: return f"[!] An error occurs while finding user({author}) in db....\n[INFO] error : {ex}", None
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 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 checkMember(person): sql = f"select name from member where discord_id='{str(person)}'" try: sql_result = algoalgo_sql.sql_exe(sql) #print(sql_result) return sql_result except Exception as ex: raise f"[!] error finding '{str(person)}'"
def point_check(author): sql = f"select * from member where discord_id='{str(author)}'" try: sql_result = algoalgo_sql.sql_exe(sql) pointinfo = f"""{sql_result[0]['point']}""" return f"[*] Successfully Inquires data about the feature of the {author}'s point'", pointinfo except Exception as ex: return f"[!] point check error!\n[INFO]: {ex}"
def check_dailystep(author): sql = f"select daily_steps from member where discord_id='{str(author)}'" try: sql_result = algoalgo_sql.sql_exe(sql) daily_step = sql_result[0]['daily_steps'] return daily_step except Exception as ex: raise ex
def getBossLife(): sql = "select life from algoalgo.boss limit 1" try: sql_result = algoalgo_sql.sql_exe(sql) curr_life = sql_result[0]['life'] return curr_life except Exception as ex: raise ex
def testupdate(author): sql = f"update member set items = 'ASSASSIN;STUN;STEP;STEP;ASSASSIN;SNAKE;SNAKE;REDEMPTION;REDEMPTION;STUN;' where discord_id='{str(author)}'" #sql = f"select items from member where discord_id='{str(author)}'" try: result = algoalgo_sql.sql_exe(sql) #return "[+]테스트 10점 넣어줌" return f"[+]db item update '{author}'" except Exception as ex: return "[!]db x."
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 check_items(author, item_name): 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']) return item_dir[item_name] except Exception as ex: raise ex
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
def get_location(author): sql = f"select map_location from member where discord_id='{str(author)}'" try: sql_result = algoalgo_sql.sql_exe(sql) location = sql_result[0]['map_location'] return location except Exception as ex: raise ex
def check_status(author): sql = f"select status from member where discord_id='{str(author)}'" try: sql_result = algoalgo_sql.sql_exe(sql) status = sql_result[0]['status'] return status except Exception as ex: raise ex
def check_feature(author): try: location = get_location(author) sql = f"select * from map where id='{location}'" sql_result = algoalgo_sql.sql_exe(sql) feature = sql_result[0]['feature'] return feature except Exception as ex: raise ex
def snake(author): try: location = get_location(author) sql = f"select ahead_to from map where id='{location}'" sql_result = algoalgo_sql.sql_exe(sql) dst = sql_result[0]['ahead_to'] update_location_dst(author, dst) except Exception as ex: raise ex
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 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 list_achievement(): # DB에서 업적 목록 확인 try: achlist = algoalgo_sql.sql_exe( "SELECT description, points FROM achievement WHERE is_hidden = 0") except Exception as ex: return f"[!] An error occurs while check db....\n[INFO] error : {ex}" # 업적 목록 만들기 printlist = [] for ach in achlist: printlist.append( f"{fill_str_with_space(ach['description'])}{ach['points']} 포인트") return "\n".join(printlist)
def getPlayers(cmd): args = cmd.split() nowLoc = args[1] sql = f"select name from member where map_location='{nowLoc}'" try: sql_result = algoalgo_sql.sql_exe(sql) Locinfo = "" for person in sql_result: Locinfo += person['name'] + "\n" return f"[*] Successfully Inquires data about the users in the {nowLoc} location on the map", Locinfo, nowLoc except Exception as ex: return f"[!] An error occurs while finding the users in the {nowLoc} location on the map in db....\n[INFO] error : {ex}"
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 useitem(author): 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']) # 인덱스. 아이템명 : 소유 개수 형식의 리스트 출력해야함 itemlist = sql_result[0]['items'].split(";") # 중복있는 아이템목록 count = Counter(itemlist) # 유저의 아이템 종류 수 # 인벤토리가 비었다. if len(count) == 1: return 0 return item_dir # 아이템 보유 현황에 대한 dict 반환 except Exception as ex: e_msg = "[!] error finding your info: " raise algoalgo_error.UserDefinedException(e_msg)
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}'"
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 getLocType(cmd): args = cmd.split() nowLoc = args[1] sql = f"select * from map where id='{nowLoc}'" try: sql_result = algoalgo_sql.sql_exe(sql) if sql_result[0]['feature'] == 0: LocFeatureInfo = "**NOMAL**🦶" if sql_result[0]['feature'] == 1: LocFeatureInfo = "**LADDER**👣" if sql_result[0]['feature'] == 2: LocFeatureInfo = "**SNAKE**🐍" if sql_result[0]['feature'] == 3: LocFeatureInfo = "**BOSS**🧟♀️" return f"[*] Successfully Inquires data about the feature of the {nowLoc} location on the map", LocFeatureInfo, nowLoc except Exception as ex: return f"[!] An error occurs while finding the feature of the {nowLoc} location on the map in db....\n[INFO] error : {ex}"
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}"