-
Notifications
You must be signed in to change notification settings - Fork 1
/
algoalgo_step.py
175 lines (138 loc) · 4.66 KB
/
algoalgo_step.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
import algoalgo_sql
import algoalgo_error
import algoalgo_item
import algoalgo_map
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 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
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 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 update_location(author):
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 update_location_dst(author, dst):
sql = f"update member set map_location = {dst} where discord_id='{str(author)}'"
try:
algoalgo_sql.sql_update(sql)
return 0
except Exception as ex:
raise ex
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 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_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 ladder(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 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 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 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 show_items(items_list):
try:
item_dir = {"STEP" : 0,
"SNAKE" : 0,
"STUN" : 0,
"ASSASSIN" : 0,
"REDEMPTION" : 0,
"CAFFEINE" : 0,
"BOMB" : 0,
"RED BULL" : 0
}
if items_list != None:
items_list = items_list.rstrip(';')
items = items_list.split(';')
for item in items:
if len(item) == 0:
continue
item_dir[item] += 1
return item_dir
except Exception as ex:
raise ex