Spaces:
Runtime error
Runtime error
add timestamp and author id
Browse files
bot.py
CHANGED
@@ -3,6 +3,7 @@ from discord import Option, commands
|
|
3 |
import redis
|
4 |
import os
|
5 |
import random
|
|
|
6 |
|
7 |
# Function to generate auto-incremented IDs
|
8 |
def generate_id(key):
|
@@ -26,26 +27,26 @@ r = redis.from_url(redis_url)
|
|
26 |
|
27 |
r.set('species_identified', 0)
|
28 |
|
29 |
-
def improve_player_stats_image(ctx):
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
|
46 |
-
|
47 |
|
48 |
-
|
49 |
|
50 |
|
51 |
bot = discord.Bot()
|
@@ -137,10 +138,13 @@ def get_conf_score(confidence: str):
|
|
137 |
])
|
138 |
async def identify_image(ctx, id:int, label:str, confidence: str):
|
139 |
|
|
|
|
|
|
|
140 |
role = "Hobbyist"
|
141 |
role_names = [role.name for role in ctx.author.roles]
|
142 |
if "Expert" in role_names:
|
143 |
-
|
144 |
|
145 |
label_cnt = generate_id(f'cnt:label:image:{id}')
|
146 |
r.hset(f'label:image:{id}:{label_cnt}'.encode('utf-8'), b'label', label.encode('utf-8'))
|
@@ -148,6 +152,8 @@ async def identify_image(ctx, id:int, label:str, confidence: str):
|
|
148 |
conf_score = get_conf_score(confidence)
|
149 |
r.hset(f'label:image:{id}:{label_cnt}'.encode('utf-8'), b'confidence', conf_score)
|
150 |
r.hset(f'label:image:{id}:{label_cnt}'.encode('utf-8'), b'role', role)
|
|
|
|
|
151 |
|
152 |
r.hset(f'image:{id}'.encode('utf-8'), b'label', label.encode('utf-8'))
|
153 |
r.hset(f'image:{id}'.encode('utf-8'), b'author', ctx.author.mention.encode('utf-8'))
|
@@ -202,10 +208,13 @@ async def sound(ctx, id): # a slash command will be created with the name "ping"
|
|
202 |
])
|
203 |
async def identify_sound(ctx, id:int, label:str, timestamp:str, confidence: str):
|
204 |
|
|
|
|
|
|
|
205 |
role = "Hobbyist"
|
206 |
role_names = [role.name for role in ctx.author.roles]
|
207 |
if "Expert" in role_names:
|
208 |
-
|
209 |
|
210 |
label_cnt = generate_id(f'cnt:label:sound:{id}')
|
211 |
r.hset(f'label:sound:{id}:{label_cnt}'.encode('utf-8'), b'label', label.encode('utf-8'))
|
@@ -214,6 +223,8 @@ async def identify_sound(ctx, id:int, label:str, timestamp:str, confidence: str)
|
|
214 |
r.hset(f'label:sound:{id}:{label_cnt}'.encode('utf-8'), b'label_at', timestamp.encode('utf-8'))
|
215 |
conf_score = get_conf_score(confidence)
|
216 |
r.hset(f'label:sound:{id}:{label_cnt}'.encode('utf-8'), b'confidence', conf_score)
|
|
|
|
|
217 |
|
218 |
r.hset(f'sound:{id}'.encode('utf-8'), b'label', label.encode('utf-8'))
|
219 |
r.hset(f'sound:{id}'.encode('utf-8'), b'label_at', timestamp.encode('utf-8'))
|
@@ -241,7 +252,11 @@ async def identify_sound(ctx, id:int, label:str, timestamp:str, confidence: str)
|
|
241 |
)
|
242 |
async def next_image(ctx):
|
243 |
total_images = r.get(b'cnt:image').decode('utf-8')
|
244 |
-
|
|
|
|
|
|
|
|
|
245 |
await image(ctx, id)
|
246 |
|
247 |
@bot.command(
|
@@ -249,32 +264,41 @@ async def next_image(ctx):
|
|
249 |
)
|
250 |
async def next_sound(ctx):
|
251 |
total_sound = r.get(b'cnt:sound').decode('utf-8')
|
252 |
-
|
|
|
|
|
|
|
|
|
253 |
await sound(ctx, id)
|
254 |
|
255 |
@bot.command(
|
256 |
description="Check your profile"
|
257 |
)
|
258 |
async def profile(ctx):
|
259 |
-
xp_key = f'{ctx.author.name}:XP'.encode('utf-8')
|
260 |
-
if not r.exists(xp_key):
|
261 |
-
|
262 |
|
263 |
-
img_oc_key = f'{ctx.author.name}:image'.encode('utf-8')
|
264 |
-
if not r.exists(img_oc_key):
|
265 |
-
|
266 |
|
267 |
-
s_oc_key = f'{ctx.author.name}:sound'.encode('utf-8')
|
268 |
-
if not r.exists(s_oc_key):
|
269 |
-
|
270 |
|
271 |
# Create an embed
|
|
|
|
|
|
|
|
|
|
|
272 |
embed = discord.Embed(color=discord.Colour.blurple())
|
273 |
embed.set_author(name=f"{ctx.author.name} - Profile", icon_url=ctx.author.display_avatar.url)
|
274 |
-
embed.add_field(name="**PROGRESS**", value=f"**Level**: 1\n**XP**: {r.get(xp_key).decode()}/1000\n", inline=False)
|
275 |
-
embed.add_field(name="**STATS**", value=f"**π± Images labeled**: {r.get(img_oc_key).decode()}", inline=False)
|
276 |
embed.set_thumbnail(url=ctx.author.display_avatar.url)
|
277 |
-
|
278 |
await ctx.respond(embed=embed)
|
279 |
|
280 |
bot.run('MTA5NzMzMDI2MDI4NDAzNTEyMg.GNFiQP.hZC_2HLTvVAROlKKUmnVQjviT0G4wHeQq23-rs')
|
|
|
3 |
import redis
|
4 |
import os
|
5 |
import random
|
6 |
+
import time
|
7 |
|
8 |
# Function to generate auto-incremented IDs
|
9 |
def generate_id(key):
|
|
|
27 |
|
28 |
r.set('species_identified', 0)
|
29 |
|
30 |
+
# def improve_player_stats_image(ctx):
|
31 |
+
# # add 1 to the number of species identified
|
32 |
+
# value = r.get(b'species_identified').decode('utf-8')
|
33 |
+
# r.set(b'species_identified', int(value) + 1)
|
34 |
|
35 |
+
# xp_key = f'{ctx.author.name}:XP'.encode('utf-8')
|
36 |
+
# if not r.exists(xp_key):
|
37 |
+
# r.set(xp_key, 0)
|
38 |
|
39 |
+
# role_key = f'{ctx.author.name}:role'.encode('utf-8')
|
40 |
+
# if not r.exists(role_key):
|
41 |
+
# r.set(role_key, 'Naturalist')
|
42 |
|
43 |
+
# img_oc_key = f'{ctx.author.name}:image'.encode('utf-8')
|
44 |
+
# if not r.exists(img_oc_key):
|
45 |
+
# r.set(img_oc_key, 0)
|
46 |
|
47 |
+
# r.set(xp_key, int(r.get(xp_key)) + 10)
|
48 |
|
49 |
+
# r.set(img_oc_key, int(r.get(img_oc_key)) + 1)
|
50 |
|
51 |
|
52 |
bot = discord.Bot()
|
|
|
138 |
])
|
139 |
async def identify_image(ctx, id:int, label:str, confidence: str):
|
140 |
|
141 |
+
timestamp = str(time.time())
|
142 |
+
author_id = str(ctx.author_id)
|
143 |
+
|
144 |
role = "Hobbyist"
|
145 |
role_names = [role.name for role in ctx.author.roles]
|
146 |
if "Expert" in role_names:
|
147 |
+
role = "Expert"
|
148 |
|
149 |
label_cnt = generate_id(f'cnt:label:image:{id}')
|
150 |
r.hset(f'label:image:{id}:{label_cnt}'.encode('utf-8'), b'label', label.encode('utf-8'))
|
|
|
152 |
conf_score = get_conf_score(confidence)
|
153 |
r.hset(f'label:image:{id}:{label_cnt}'.encode('utf-8'), b'confidence', conf_score)
|
154 |
r.hset(f'label:image:{id}:{label_cnt}'.encode('utf-8'), b'role', role)
|
155 |
+
r.hset(f'label:image:{id}:{label_cnt}'.encode('utf-8'), b'authorid', author_id)
|
156 |
+
r.hset(f'label:image:{id}:{label_cnt}'.encode('utf-8'), b'timestamp', timestamp)
|
157 |
|
158 |
r.hset(f'image:{id}'.encode('utf-8'), b'label', label.encode('utf-8'))
|
159 |
r.hset(f'image:{id}'.encode('utf-8'), b'author', ctx.author.mention.encode('utf-8'))
|
|
|
208 |
])
|
209 |
async def identify_sound(ctx, id:int, label:str, timestamp:str, confidence: str):
|
210 |
|
211 |
+
timestamp = str(time.time())
|
212 |
+
author_id = str(ctx.author_id)
|
213 |
+
|
214 |
role = "Hobbyist"
|
215 |
role_names = [role.name for role in ctx.author.roles]
|
216 |
if "Expert" in role_names:
|
217 |
+
role = "Expert"
|
218 |
|
219 |
label_cnt = generate_id(f'cnt:label:sound:{id}')
|
220 |
r.hset(f'label:sound:{id}:{label_cnt}'.encode('utf-8'), b'label', label.encode('utf-8'))
|
|
|
223 |
r.hset(f'label:sound:{id}:{label_cnt}'.encode('utf-8'), b'label_at', timestamp.encode('utf-8'))
|
224 |
conf_score = get_conf_score(confidence)
|
225 |
r.hset(f'label:sound:{id}:{label_cnt}'.encode('utf-8'), b'confidence', conf_score)
|
226 |
+
r.hset(f'label:sound:{id}:{label_cnt}'.encode('utf-8'), b'authorid', author_id)
|
227 |
+
r.hset(f'label:sound:{id}:{label_cnt}'.encode('utf-8'), b'timestamp', timestamp)
|
228 |
|
229 |
r.hset(f'sound:{id}'.encode('utf-8'), b'label', label.encode('utf-8'))
|
230 |
r.hset(f'sound:{id}'.encode('utf-8'), b'label_at', timestamp.encode('utf-8'))
|
|
|
252 |
)
|
253 |
async def next_image(ctx):
|
254 |
total_images = r.get(b'cnt:image').decode('utf-8')
|
255 |
+
numbers = list(range(1, int(total_images)))
|
256 |
+
exclude_redis = r.lrange('image:accept', 0, -1)
|
257 |
+
exclude = set(int(num.decode('utf-8')) for num in exclude_redis)
|
258 |
+
numbers = [num for num in numbers if num not in exclude]
|
259 |
+
id = random.choice(numbers)
|
260 |
await image(ctx, id)
|
261 |
|
262 |
@bot.command(
|
|
|
264 |
)
|
265 |
async def next_sound(ctx):
|
266 |
total_sound = r.get(b'cnt:sound').decode('utf-8')
|
267 |
+
numbers = list(range(1, int(total_sound)))
|
268 |
+
exclude_redis = r.lrange('image:accept', 0, -1)
|
269 |
+
exclude = set(int(num.decode('utf-8')) for num in exclude_redis)
|
270 |
+
numbers = [num for num in numbers if num not in exclude]
|
271 |
+
id = random.choice(numbers)
|
272 |
await sound(ctx, id)
|
273 |
|
274 |
@bot.command(
|
275 |
description="Check your profile"
|
276 |
)
|
277 |
async def profile(ctx):
|
278 |
+
# xp_key = f'{ctx.author.name}:XP'.encode('utf-8')
|
279 |
+
# if not r.exists(xp_key):
|
280 |
+
# r.set(xp_key, 0)
|
281 |
|
282 |
+
# img_oc_key = f'{ctx.author.name}:image'.encode('utf-8')
|
283 |
+
# if not r.exists(img_oc_key):
|
284 |
+
# r.set(img_oc_key, 0)
|
285 |
|
286 |
+
# s_oc_key = f'{ctx.author.name}:sound'.encode('utf-8')
|
287 |
+
# if not r.exists(s_oc_key):
|
288 |
+
# r.set(s_oc_key, 0)
|
289 |
|
290 |
# Create an embed
|
291 |
+
role = "Hobbyist"
|
292 |
+
role_names = [role.name for role in ctx.author.roles]
|
293 |
+
if "Expert" in role_names:
|
294 |
+
role = "Expert"
|
295 |
+
|
296 |
embed = discord.Embed(color=discord.Colour.blurple())
|
297 |
embed.set_author(name=f"{ctx.author.name} - Profile", icon_url=ctx.author.display_avatar.url)
|
298 |
+
# embed.add_field(name="**PROGRESS**", value=f"**Level**: 1\n**XP**: {r.get(xp_key).decode()}/1000\n", inline=False)
|
299 |
+
# embed.add_field(name="**STATS**", value=f"**π± Images labeled**: {r.get(img_oc_key).decode()}", inline=False)
|
300 |
embed.set_thumbnail(url=ctx.author.display_avatar.url)
|
301 |
+
embed.set_footer(text=f"π Role: {r.get(role).decode()}")
|
302 |
await ctx.respond(embed=embed)
|
303 |
|
304 |
bot.run('MTA5NzMzMDI2MDI4NDAzNTEyMg.GNFiQP.hZC_2HLTvVAROlKKUmnVQjviT0G4wHeQq23-rs')
|