Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Synced repo using 'sync_with_huggingface' Github Action
Browse files- app.py +136 -147
- requirements.txt +0 -1
app.py
CHANGED
@@ -19,8 +19,8 @@ bot = commands.Bot(command_prefix='!', intents=intents)
|
|
19 |
|
20 |
""""""
|
21 |
XP_PER_MESSAGE = 10 # 100k messages = 1M exp = lvl 100
|
22 |
-
data_file_path = '/data/xp_data.json'
|
23 |
-
xp_data = {}
|
24 |
""""""
|
25 |
service_account = json.loads(os.environ.get('KEY'))
|
26 |
file_path = 'service_account.json'
|
@@ -29,46 +29,26 @@ with open(file_path, 'w') as json_file:
|
|
29 |
gspread_bot = gspread.service_account(filename='service_account.json')
|
30 |
worksheet = gspread_bot.open("levelbot").sheet1
|
31 |
""""""
|
32 |
-
|
33 |
API_URL = "https://api-inference.huggingface.co/models/mariagrandury/roberta-base-finetuned-sms-spam-detection"
|
34 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
35 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
36 |
-
|
37 |
-
|
38 |
def query(payload):
|
39 |
response = requests.post(API_URL, headers=headers, json=payload)
|
40 |
return response.json()
|
41 |
-
|
42 |
|
43 |
@bot.event
|
44 |
async def on_ready():
|
45 |
print(f'Logged in as {bot.user.name}')
|
46 |
print(f"XP_PER_MESSAGE: {XP_PER_MESSAGE}")
|
47 |
-
global xp_data
|
48 |
-
xp_data = load_xp_data()
|
49 |
-
#print('XP data loaded:', xp_data)
|
50 |
-
print('XP data loaded')
|
51 |
-
print(xp_data)
|
52 |
-
|
53 |
-
"""
|
54 |
-
try:
|
55 |
-
with open('xp_data.json', 'r') as f:
|
56 |
-
xp_data = json.load(f)
|
57 |
-
except FileNotFoundError:
|
58 |
-
xp_data = {}
|
59 |
-
|
60 |
-
"""
|
61 |
-
|
62 |
-
def save_xp_data():
|
63 |
-
with open(data_file_path, 'w') as f:
|
64 |
-
json.dump(xp_data, f)
|
65 |
|
66 |
|
67 |
-
def
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
72 |
|
73 |
|
74 |
@bot.event
|
@@ -78,16 +58,6 @@ async def on_message(message):
|
|
78 |
|
79 |
#output = query({"inputs": f"{message.content}",})
|
80 |
#print(output)
|
81 |
-
|
82 |
-
"""AWAIT LEVEL ALGORITHM OR SOMETHING (MULTIPLE FILES?)"""
|
83 |
-
author_id = str(message.author.id) # dictionary pairs (ID -> TOTAL XP)
|
84 |
-
xp_data.setdefault(author_id, 0) # default if it doesn't already exist
|
85 |
-
|
86 |
-
xp_data[author_id] += XP_PER_MESSAGE
|
87 |
-
print(f"{message.author} = {xp_data[author_id]}")
|
88 |
-
#print(f"xp_data: {xp_data}")
|
89 |
-
save_xp_data()
|
90 |
-
|
91 |
bot_ids = [1166392942387265536, 1158038249835610123, 1130774761031610388, 1155489509518098565, 1155169841276260546, 1152238037355474964, 1154395078735953930]
|
92 |
|
93 |
try:
|
@@ -95,8 +65,6 @@ async def on_message(message):
|
|
95 |
#if message.author.id == 811235357663297546:
|
96 |
# get level
|
97 |
guild = bot.get_guild(879548962464493619)
|
98 |
-
current_level = calculate_level(xp_data[author_id])
|
99 |
-
|
100 |
lvl1 = guild.get_role(1171861537699397733)
|
101 |
lvl2 = guild.get_role(1171861595115245699)
|
102 |
lvl3 = guild.get_role(1171861626715115591)
|
@@ -112,123 +80,144 @@ async def on_message(message):
|
|
112 |
lvl13 = guild.get_role(1171525021928263791)
|
113 |
lvl14 = guild.get_role(1171525062201966724)
|
114 |
lvl15 = guild.get_role(1171525098465918996)
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
if
|
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 |
-
|
183 |
-
|
184 |
-
await message.author.remove_roles(lvl10)
|
185 |
-
print(f"Removed {lvl10} from {message.author}")
|
186 |
-
|
187 |
-
if current_level == 12:
|
188 |
-
if lvl12 not in message.author.roles:
|
189 |
-
await message.author.add_roles(lvl12)
|
190 |
-
print(f"Gave {message.author} {lvl12}")
|
191 |
-
await message.author.remove_roles(lvl11)
|
192 |
-
print(f"Removed {lvl11} from {message.author}")
|
193 |
-
|
194 |
-
if current_level == 13:
|
195 |
-
if lvl13 not in message.author.roles:
|
196 |
-
await message.author.add_roles(lvl13)
|
197 |
-
print(f"Gave {message.author} {lvl13}")
|
198 |
-
await message.author.remove_roles(lvl12)
|
199 |
-
print(f"Removed {lvl12} from {message.author}")
|
200 |
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
|
216 |
|
217 |
except Exception as e:
|
218 |
print(f"Error: {e}")
|
219 |
|
220 |
await bot.process_commands(message)
|
|
|
221 |
except Exception as e:
|
222 |
print(f"Error: {e}")
|
223 |
|
224 |
|
225 |
-
def calculate_level(xp):
|
226 |
-
return int(xp ** (1.0 / 3.0))
|
227 |
|
228 |
|
229 |
-
def calculate_xp(level):
|
230 |
-
return (int(level ** 3))
|
231 |
-
|
232 |
|
233 |
@bot.command()
|
234 |
async def restore_exp(ctx):
|
@@ -284,7 +273,7 @@ async def restore_exp(ctx):
|
|
284 |
|
285 |
|
286 |
# does a record already exist?
|
287 |
-
|
288 |
|
289 |
|
290 |
|
@@ -301,7 +290,7 @@ async def restore_exp(ctx):
|
|
301 |
worksheet.update_cell(length+1, 4, string_level)
|
302 |
"""
|
303 |
|
304 |
-
|
305 |
else:
|
306 |
if cell:
|
307 |
continue
|
@@ -313,7 +302,7 @@ async def restore_exp(ctx):
|
|
313 |
|
314 |
#worksheet.update_cell(cell.row, cell.col+2, xp)
|
315 |
#worksheet.update_cell(cell.row, cell.col+3, level)
|
316 |
-
|
317 |
|
318 |
|
319 |
"""
|
|
|
19 |
|
20 |
""""""
|
21 |
XP_PER_MESSAGE = 10 # 100k messages = 1M exp = lvl 100
|
22 |
+
#data_file_path = '/data/xp_data.json'
|
23 |
+
#xp_data = {}
|
24 |
""""""
|
25 |
service_account = json.loads(os.environ.get('KEY'))
|
26 |
file_path = 'service_account.json'
|
|
|
29 |
gspread_bot = gspread.service_account(filename='service_account.json')
|
30 |
worksheet = gspread_bot.open("levelbot").sheet1
|
31 |
""""""
|
|
|
32 |
API_URL = "https://api-inference.huggingface.co/models/mariagrandury/roberta-base-finetuned-sms-spam-detection"
|
33 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
34 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
|
|
|
|
35 |
def query(payload):
|
36 |
response = requests.post(API_URL, headers=headers, json=payload)
|
37 |
return response.json()
|
38 |
+
""""""
|
39 |
|
40 |
@bot.event
|
41 |
async def on_ready():
|
42 |
print(f'Logged in as {bot.user.name}')
|
43 |
print(f"XP_PER_MESSAGE: {XP_PER_MESSAGE}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
|
46 |
+
def calculate_level(xp):
|
47 |
+
return int(xp ** (1.0 / 3.0))
|
48 |
+
|
49 |
+
|
50 |
+
def calculate_xp(level):
|
51 |
+
return (int(level ** 3))
|
52 |
|
53 |
|
54 |
@bot.event
|
|
|
58 |
|
59 |
#output = query({"inputs": f"{message.content}",})
|
60 |
#print(output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
bot_ids = [1166392942387265536, 1158038249835610123, 1130774761031610388, 1155489509518098565, 1155169841276260546, 1152238037355474964, 1154395078735953930]
|
62 |
|
63 |
try:
|
|
|
65 |
#if message.author.id == 811235357663297546:
|
66 |
# get level
|
67 |
guild = bot.get_guild(879548962464493619)
|
|
|
|
|
68 |
lvl1 = guild.get_role(1171861537699397733)
|
69 |
lvl2 = guild.get_role(1171861595115245699)
|
70 |
lvl3 = guild.get_role(1171861626715115591)
|
|
|
80 |
lvl13 = guild.get_role(1171525021928263791)
|
81 |
lvl14 = guild.get_role(1171525062201966724)
|
82 |
lvl15 = guild.get_role(1171525098465918996)
|
83 |
+
|
84 |
+
# does a record already exist?
|
85 |
+
cell = worksheet.find(str(message.author.id))
|
86 |
+
length = len(worksheet.col_values(1))
|
87 |
+
if cell is None:
|
88 |
+
print(f"creating new record for {member}")
|
89 |
+
# if not, create new record
|
90 |
+
xp = 10
|
91 |
+
worksheet.update(values=[[string_member_id, member.name, xp, level]], range_name=f'A{length+1}:D{length+1}')
|
92 |
+
else:
|
93 |
+
if cell:
|
94 |
+
print(f"updating record for {member}")
|
95 |
+
# if so, update that row...
|
96 |
+
# update exp, can only be in a positive direction
|
97 |
+
# read
|
98 |
+
xp = worksheet.cell(cell.row, cell.col+2).value
|
99 |
+
xp += XP_PER_MESSAGE
|
100 |
+
current_level = calculate_level(xp)
|
101 |
+
# write with added xp
|
102 |
+
worksheet.update(values=[[xp, current_level]], range_name=f'C{cell.row}:D{cell.row}')
|
103 |
+
|
104 |
+
if current_level == 2:
|
105 |
+
if lvl2 not in message.author.roles:
|
106 |
+
await message.author.add_roles(lvl2)
|
107 |
+
print(f"Gave {message.author} {lvl2}")
|
108 |
+
await message.author.remove_roles(lvl1)
|
109 |
+
print(f"Removed {lvl1} from {message.author}")
|
110 |
+
|
111 |
+
if current_level == 3:
|
112 |
+
if lvl3 not in message.author.roles:
|
113 |
+
await message.author.add_roles(lvl3)
|
114 |
+
print(f"Gave {message.author} {lvl3}")
|
115 |
+
await message.author.remove_roles(lvl2)
|
116 |
+
print(f"Removed {lvl2} from {message.author}")
|
117 |
+
|
118 |
+
if current_level == 4:
|
119 |
+
if lvl4 not in message.author.roles:
|
120 |
+
await message.author.add_roles(lvl4)
|
121 |
+
print(f"Gave {message.author} {lvl4}")
|
122 |
+
await message.author.remove_roles(lvl3)
|
123 |
+
print(f"Removed {lvl3} from {message.author}")
|
124 |
+
|
125 |
+
if current_level == 5:
|
126 |
+
if lvl5 not in message.author.roles:
|
127 |
+
await message.author.add_roles(lvl5)
|
128 |
+
print(f"Gave {message.author} {lvl5}")
|
129 |
+
await message.author.remove_roles(lvl4)
|
130 |
+
print(f"Removed {lvl4} from {message.author}")
|
131 |
+
|
132 |
+
if current_level == 6:
|
133 |
+
if lvl6 not in message.author.roles:
|
134 |
+
await message.author.add_roles(lvl6)
|
135 |
+
print(f"Gave {message.author} {lvl6}")
|
136 |
+
await message.author.remove_roles(lvl5)
|
137 |
+
print(f"Removed {lvl5} from {message.author}")
|
138 |
+
|
139 |
+
if current_level == 7:
|
140 |
+
if lvl7 not in message.author.roles:
|
141 |
+
await message.author.add_roles(lvl7)
|
142 |
+
print(f"Gave {message.author} {lvl7}")
|
143 |
+
await message.author.remove_roles(lvl6)
|
144 |
+
print(f"Removed {lvl6} from {message.author}")
|
145 |
+
|
146 |
+
if current_level == 8:
|
147 |
+
if lvl8 not in message.author.roles:
|
148 |
+
await message.author.add_roles(lvl8)
|
149 |
+
print(f"Gave {message.author} {lvl8}")
|
150 |
+
await message.author.remove_roles(lvl7)
|
151 |
+
print(f"Removed {lvl7} from {message.author}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
+
if current_level == 9:
|
154 |
+
if lvl9 not in message.author.roles:
|
155 |
+
await message.author.add_roles(lvl9)
|
156 |
+
print(f"Gave {message.author} {lvl9}")
|
157 |
+
await message.author.remove_roles(lvl8)
|
158 |
+
print(f"Removed {lvl8} from {message.author}")
|
159 |
|
160 |
+
if current_level == 10:
|
161 |
+
if lvl10 not in message.author.roles:
|
162 |
+
await message.author.add_roles(lvl10)
|
163 |
+
print(f"Gave {message.author} {lvl10}")
|
164 |
+
await message.author.remove_roles(lvl9)
|
165 |
+
print(f"Removed {lvl9} from {message.author}")
|
166 |
+
|
167 |
+
if current_level == 11:
|
168 |
+
if lvl11 not in message.author.roles:
|
169 |
+
await message.author.add_roles(lvl11)
|
170 |
+
print(f"Gave {message.author} {lvl11}")
|
171 |
+
await message.author.remove_roles(lvl10)
|
172 |
+
print(f"Removed {lvl10} from {message.author}")
|
173 |
+
|
174 |
+
if current_level == 12:
|
175 |
+
if lvl12 not in message.author.roles:
|
176 |
+
await message.author.add_roles(lvl12)
|
177 |
+
print(f"Gave {message.author} {lvl12}")
|
178 |
+
await message.author.remove_roles(lvl11)
|
179 |
+
print(f"Removed {lvl11} from {message.author}")
|
180 |
+
|
181 |
+
if current_level == 13:
|
182 |
+
if lvl13 not in message.author.roles:
|
183 |
+
await message.author.add_roles(lvl13)
|
184 |
+
print(f"Gave {message.author} {lvl13}")
|
185 |
+
await message.author.remove_roles(lvl12)
|
186 |
+
print(f"Removed {lvl12} from {message.author}")
|
187 |
+
|
188 |
+
if current_level == 14:
|
189 |
+
if lvl14 not in message.author.roles:
|
190 |
+
await message.author.add_roles(lvl14)
|
191 |
+
print(f"Gave {message.author} {lvl14}")
|
192 |
+
await message.author.remove_roles(lvl13)
|
193 |
+
print(f"Removed {lvl13} from {message.author}")
|
194 |
+
|
195 |
+
if current_level == 15:
|
196 |
+
if lvl15 not in message.author.roles:
|
197 |
+
await message.author.add_roles(lvl15)
|
198 |
+
print(f"Gave {message.author} {lvl15}")
|
199 |
+
await message.author.remove_roles(lvl14)
|
200 |
+
print(f"Removed {lvl14} from {message.author}")
|
201 |
+
|
202 |
+
|
203 |
+
"""
|
204 |
+
value = cell.value
|
205 |
+
row_number = cell.row
|
206 |
+
column_number = cell.col
|
207 |
+
"""
|
208 |
|
209 |
|
210 |
except Exception as e:
|
211 |
print(f"Error: {e}")
|
212 |
|
213 |
await bot.process_commands(message)
|
214 |
+
|
215 |
except Exception as e:
|
216 |
print(f"Error: {e}")
|
217 |
|
218 |
|
|
|
|
|
219 |
|
220 |
|
|
|
|
|
|
|
221 |
|
222 |
@bot.command()
|
223 |
async def restore_exp(ctx):
|
|
|
273 |
|
274 |
|
275 |
# does a record already exist?
|
276 |
+
cell = worksheet.find(string_member_id)
|
277 |
|
278 |
|
279 |
|
|
|
290 |
worksheet.update_cell(length+1, 4, string_level)
|
291 |
"""
|
292 |
|
293 |
+
|
294 |
else:
|
295 |
if cell:
|
296 |
continue
|
|
|
302 |
|
303 |
#worksheet.update_cell(cell.row, cell.col+2, xp)
|
304 |
#worksheet.update_cell(cell.row, cell.col+3, level)
|
305 |
+
|
306 |
|
307 |
|
308 |
"""
|
requirements.txt
CHANGED
@@ -1,3 +1,2 @@
|
|
1 |
discord.py
|
2 |
gradio
|
3 |
-
gspread
|
|
|
1 |
discord.py
|
2 |
gradio
|
|