output "santization" and ping list fix

This commit is contained in:
HAV0X 2025-02-05 11:50:18 +08:00
parent a04fe9e7a7
commit d9c157cfab
1 changed files with 13 additions and 7 deletions

20
bot.py
View File

@ -60,7 +60,13 @@ def remove_ping(term, user_id):
elif user_id not in ping_terms[term]:
return False
else:
ping_terms[term].remove(user_id)
#if there is only one remaining person in the ping term list, delete the whole term
if len(ping_terms[term]) == 1 and ping_terms[term][0] == user_id:
del ping_terms[term]
#if there is more than on person in the ping term list, delete only that user_id
else:
ping_terms[term].remove(user_id)
config["ping_terms"] = ping_terms
save_config("config.json", config)
return True
@ -225,28 +231,28 @@ async def myLoop():
@bot.slash_command(description="Pings you when auction name contains the given term")
async def ping_me(interaction: nextcord.Interaction, term: str):
if add_ping(term, interaction.user.id):
await interaction.response.send_message(f"Success! You will be pinged for {term}", ephemeral=False)
await interaction.response.send_message(f"Success! You will be pinged for `{term}`", ephemeral=False)
else:
pings = get_user_pings(interaction.user.id)
if len(pings) > 0:
await interaction.response.send_message(f"Failed to add {term}. You are pinged for {', '.join(pings)}",
await interaction.response.send_message(f"Failed to add `{term}`. You are pinged for `{', '.join(pings)}`",
ephemeral=True)
else:
await interaction.response.send_message(f"Failed to add {term}. You are not pinged for anything",
await interaction.response.send_message(f"Failed to add `{term}`. You are not pinged for anything",
ephemeral=True)
@bot.slash_command(description="No longer pings you when auction name contains the given term")
async def unping_me(interaction: nextcord.Interaction, term: str):
if remove_ping(term, interaction.user.id):
await interaction.response.send_message(f"Success! You will no longer be pinged for {term}", ephemeral=False)
await interaction.response.send_message(f"Success! You will no longer be pinged for `{term}`", ephemeral=False)
else:
pings = get_user_pings(interaction.user.id)
if len(pings) > 0:
await interaction.response.send_message(f"Failed to remove {term}. You are pinged for {', '.join(pings)}",
await interaction.response.send_message(f"Failed to remove `{term}`. You are pinged for `{', '.join(pings)}`",
ephemeral=True)
else:
await interaction.response.send_message(f"Failed to remove {term}. You are not pinged for anything",
await interaction.response.send_message(f"Failed to remove `{term}`. You are not pinged for anything",
ephemeral=True)