Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -95,44 +95,47 @@ def is_csv_empty(file_path):
|
|
95 |
|
96 |
|
97 |
def blocking_io(member_id):
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
member_name = member.name
|
115 |
-
worksheet.update(values=[[string_member_id, member_name, xp, current_level]], range_name=f'A{length+1}:D{length+1}')
|
116 |
-
# initial role assignment
|
117 |
-
if current_level == 1:
|
118 |
-
if lvl1 not in member.roles:
|
119 |
-
return(1)
|
120 |
-
|
121 |
-
else:
|
122 |
-
print(f"4")
|
123 |
-
if cell:
|
124 |
-
# if so, update that row...
|
125 |
-
xp = worksheet.cell(cell.row, cell.col+2).value
|
126 |
-
xp = int(xp) + XP_PER_MESSAGE
|
127 |
current_level = calculate_level(xp)
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
|
138 |
async def add_exp(member_id):
|
|
|
95 |
|
96 |
|
97 |
def blocking_io(member_id):
|
98 |
+
try:
|
99 |
+
worksheet = gspread_bot.open("levelbot").sheet1
|
100 |
+
|
101 |
+
guild = bot.get_guild(879548962464493619)
|
102 |
+
member = guild.get_member(member_id)
|
103 |
+
print(f" {member}")
|
104 |
+
print(f"2")
|
105 |
+
|
106 |
+
cell = worksheet.find(str(member.id))
|
107 |
+
length = len(worksheet.col_values(1))
|
108 |
+
print(f"3")
|
109 |
+
if cell is None:
|
110 |
+
print(f"creating new record for {member}")
|
111 |
+
# if not, create new record
|
112 |
+
string_member_id = str(member.id)
|
113 |
+
xp = 10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
current_level = calculate_level(xp)
|
115 |
+
member_name = member.name
|
116 |
+
worksheet.update(values=[[string_member_id, member_name, xp, current_level]], range_name=f'A{length+1}:D{length+1}')
|
117 |
+
# initial role assignment
|
118 |
+
if current_level == 1:
|
119 |
+
if lvl1 not in member.roles:
|
120 |
+
return(1)
|
121 |
+
|
122 |
+
else:
|
123 |
+
print(f"4")
|
124 |
+
if cell:
|
125 |
+
# if so, update that row...
|
126 |
+
xp = worksheet.cell(cell.row, cell.col+2).value
|
127 |
+
xp = int(xp) + XP_PER_MESSAGE
|
128 |
+
current_level = calculate_level(xp)
|
129 |
+
print(f"updating record for {member}: {xp} xp")
|
130 |
+
# write with added xp
|
131 |
+
worksheet.update(values=[[xp, current_level]], range_name=f'C{cell.row}:D{cell.row}')
|
132 |
+
# level up
|
133 |
+
print(f"current_level: {current_level}")
|
134 |
+
if current_level >= 2 and current_level <=30:
|
135 |
+
# pass current_level as int?
|
136 |
+
return(current_level)
|
137 |
+
except Exception as e:
|
138 |
+
print(f"blocking_io Error: {e}")
|
139 |
|
140 |
|
141 |
async def add_exp(member_id):
|