-
Notifications
You must be signed in to change notification settings - Fork 1
/
algoalgo_map.py
185 lines (125 loc) · 6.68 KB
/
algoalgo_map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import pymysql
import os
import algoalgo_sql
import algoalgo_error
# getPlayers() #해당 칸에 위치한 플레이어
# getItems() #해당 칸에 위치한 아이템
# getFloorType() #해당 칸이 어떤 칸인지. 문제 칸 or 사다리 or 뱀
# id : 칸 순서
# feature: 칸 종류 :: 일반 칸 사다리 뱀 보스
# ahead_to : 사다리나 뱀일 경우 이동할 칸의 번호
# 맵 설정
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..."
# nowLoc의 속성 반환
#<normal: 0, ladder: 1, snake: 2, boss: 3>
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}"
# nowLoc에 있는 플레이어들의 이름 출력
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}"
# player's loc 반환
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}"
# SNAKE
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}"
# STEP
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
#step - initialize status
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)