Added ping terms slash commands
This commit is contained in:
parent
d78900d076
commit
d7d371a999
47
bot.py
47
bot.py
|
@ -42,17 +42,32 @@ def add_ping(term, user_id):
|
|||
ping_terms[term].append(user_id)
|
||||
else:
|
||||
print(f"{user_id} is already being pinged for {term}")
|
||||
return
|
||||
return False
|
||||
|
||||
config["ping_terms"] = ping_terms
|
||||
save_config("config.json", config)
|
||||
return True
|
||||
|
||||
async def ping_users(auction_name):
|
||||
def remove_ping(term, user_id):
|
||||
if term not in ping_terms:
|
||||
return False
|
||||
elif user_id not in ping_terms[term]:
|
||||
return False
|
||||
else:
|
||||
ping_terms[term].remove(user_id)
|
||||
config["ping_terms"] = ping_terms
|
||||
save_config("config.json", config)
|
||||
return True
|
||||
|
||||
def get_user_pings(user_id):
|
||||
return [term for term in ping_terms.keys() if user_id in ping_terms[term]]
|
||||
|
||||
async def ping_users(auction_name_jp, auction_name_en):
|
||||
"""If the name of the listing is particularly interesting, ping some people
|
||||
- HAV0X"""
|
||||
users_to_ping = []
|
||||
for term in ping_terms.keys():
|
||||
if term in auction_name:
|
||||
if term in auction_name_jp or term in auction_name_en:
|
||||
for user in ping_terms[term]:
|
||||
if user not in users_to_ping:
|
||||
users_to_ping.append(user)
|
||||
|
@ -120,7 +135,7 @@ async def check_yahoo_fleamarket(search_term: str, page: int, notify: bool):
|
|||
name_en = translate(name)
|
||||
embed = embed_auction("Yahoo! Flea market", url, name, name_en, thumbnail, price)
|
||||
await send_message("Japari Modding", "yahoo-auctions", embed)
|
||||
await ping_users(name)
|
||||
await ping_users(name, name_en)
|
||||
|
||||
print('New item added:', url)
|
||||
processed_urls[url] = date
|
||||
|
@ -152,7 +167,7 @@ async def check_yahoo_auction(search_term: str, page: int, notify: bool):
|
|||
name_en = translate(name)
|
||||
embed = embed_auction("Yahoo! JAPAN Auction", url, name, name_en, thumbnail, price)
|
||||
await send_message("Japari Modding", "yahoo-auctions", embed)
|
||||
await ping_users(name)
|
||||
await ping_users(name, name_en)
|
||||
|
||||
print('New item added:', url)
|
||||
processed_urls[url] = date
|
||||
|
@ -188,4 +203,26 @@ async def myLoop():
|
|||
if onlydate - processed_urls[key] > timedelta(weeks=3):
|
||||
del processed_urls[key]
|
||||
|
||||
@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)
|
||||
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)}", ephemeral=True)
|
||||
else:
|
||||
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)
|
||||
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)}", ephemeral=True)
|
||||
else:
|
||||
await interaction.response.send_message(f"Failed to remove {term}. You are not pinged for anything", ephemeral=True)
|
||||
|
||||
bot.run(config["discord_bot_token"], reconnect=True)
|
Loading…
Reference in New Issue