169 lines
9.4 KiB
Python
169 lines
9.4 KiB
Python
from disnake.ext import commands
|
|
import disnake
|
|
import sqlite3
|
|
import time
|
|
|
|
class Rare_Hunter(commands.Cog):
|
|
def __init__(self,bot:commands.InteractionBot):
|
|
self.bot = bot
|
|
|
|
@commands.slash_command(description="Announce a rare spawn")
|
|
async def rare_spawn(self,
|
|
inter:disnake.ApplicationCommandInteraction,
|
|
mob:str,
|
|
party_leader:str):
|
|
await inter.response.defer()
|
|
|
|
guild = self.bot.get_guild(inter.guild_id)
|
|
role = guild.get_role(1017730289239330857)
|
|
log_channel = guild.get_channel(1039075467715678308)
|
|
connection = sqlite3.connect("store.db")
|
|
cursor = connection.cursor()
|
|
result = cursor.execute('SELECT * FROM rares WHERE name = ?',(mob,)).fetchone()
|
|
cursor.execute(f"INSERT INTO reports(mob_id,party_leader) VALUES(?,?)",(result[0],party_leader))
|
|
eventid = cursor.lastrowid
|
|
connection.commit()
|
|
count = connection.execute(f"SELECT COUNT(id) FROM reports WHERE mob_id = '{result[0]}'").fetchone()
|
|
members_with_kill = [x[0] for x in connection.execute(f"SELECT discord_user_id from mobs_gotten WHERE mob_id = '{result[0]}'").fetchall()]
|
|
temp_mentions = [f"{result[2]} Spotted!"]
|
|
index = 0
|
|
for member in role.members:
|
|
if member.id in members_with_kill:
|
|
continue #Skip members who has the kills
|
|
if len(temp_mentions[index]) > 1950: #Discord has a 2k char limit, bit of a conservative limit at 1950 but its safe.
|
|
index+=1
|
|
temp_mentions.append(f"{result[2]} Spotted!")
|
|
temp_mentions[index] += f"<@{member.id}>"
|
|
|
|
print(f"{party_leader} found {result[2]} at {time.ctime(time.time())}")
|
|
|
|
embed = disnake.Embed()
|
|
embed.title = f"Target: **{result[2]}**"
|
|
embed.description = f"Whisper **{party_leader}** for invite\n This message will self-destruct <t:{int(time.time())+800}:R>"
|
|
embed.set_image(result[4])
|
|
embed.add_field(name="Zone:",value=result[3])
|
|
embed.add_field(name="Seen:",value=f"{count[0]} times")
|
|
got_it_button = disnake.ui.Button(emoji='🎯', label="Got it",custom_id=f"rspe-mark_done-{eventid}")
|
|
killed_button = disnake.ui.Button(emoji='☠️',label="Dead",custom_id=f"rspe-mob_dead-{eventid}")
|
|
|
|
log_embed = disnake.Embed()
|
|
log_embed.title = f"{result[2]} Spotted by {party_leader}"
|
|
log_embed.set_thumbnail(result[4])
|
|
|
|
cursor.close()
|
|
connection.close()
|
|
for string in temp_mentions:
|
|
await inter.channel.send(content=string,delete_after=1)
|
|
await inter.followup.send(embed=embed,components=[got_it_button,killed_button],delete_after=800)
|
|
await log_channel.send(embed=log_embed,components=[got_it_button])
|
|
|
|
|
|
@rare_spawn.autocomplete("mob")
|
|
async def autocomp_mobs(self,inter:disnake.ApplicationCommandInteraction, user_input:str):
|
|
connection = sqlite3.connect("store.db")
|
|
result = [x[0] for x in connection.execute(f"SELECT name FROM rares WHERE INSTR(LOWER(name),?) > 0 LIMIT 25",(user_input.lower(),)).fetchall()]
|
|
connection.close()
|
|
return result
|
|
|
|
@commands.slash_command(description="Spawn a mob selector for members to pick",default_member_permissions=disnake.Permissions(manage_guild=True))
|
|
async def view_mob_toggles(self,inter:disnake.ApplicationCommandInteraction):
|
|
connection = sqlite3.connect("store.db")
|
|
outland_mobs = connection.execute("SELECT name,id FROM rares WHERE continent = 'Outland'").fetchall()
|
|
northrend_mobs = connection.execute("SELECT name,id FROM rares WHERE continent = 'Northrend'").fetchall()
|
|
connection.close()
|
|
options_outland = dict((x, y) for x, y in outland_mobs)#[x[0] for x in outland_mobs ]
|
|
options_northrend = dict((x, y) for x, y in northrend_mobs)
|
|
select_outland = disnake.ui.Select(custom_id='rspe-Outland-select',placeholder="Select Outland mob to toggle state",options=options_outland,max_values=1)
|
|
select_northrend = disnake.ui.Select(custom_id='rspe-Northrend-select',placeholder="Select Northrend mob to toggle state",options=options_northrend,max_values=1)
|
|
|
|
outland_button = disnake.ui.Button(custom_id="rspe-Outland-show",label="Show Outland Mobs",emoji="<:Outland:1034280526065958952>")
|
|
northrend_button = disnake.ui.Button(custom_id="rspe-Northrend-show",label="Show Northrend Mobs",emoji="<:Northrend:1034280524602150952>")
|
|
|
|
embed = disnake.Embed()
|
|
embed.title = "Edit which mobs you're looking for"
|
|
embed.description = "Whenever /rare_spawn is invoked all users with the rare mobs tag, who needs this kill will get pinged.\nYou can use this to set which mobs you have and which you need.\nClick the buttons below to see what the bot knows about you now, and use the drop downs to mark rares accordingly"
|
|
|
|
await inter.response.send_message(embed=embed,components=[[select_outland],[select_northrend],[outland_button,northrend_button]])
|
|
|
|
def generate_moblist_embed(self,zone,author_id):
|
|
connection = sqlite3.connect("store.db")
|
|
outland_mobs = connection.execute("SELECT name,id FROM rares WHERE continent = ?",(zone,)).fetchall()
|
|
mobs_killed = [x[0] for x in connection.execute("SELECT mob_id FROM mobs_gotten WHERE discord_user_id = ?",(author_id,)).fetchall()]
|
|
temp_str1 = ""
|
|
temp_str2 = ""
|
|
line_break = 10
|
|
if zone == "Northrend": line_break = 12
|
|
for index,mob in enumerate(outland_mobs):
|
|
if index >= line_break:
|
|
if mob[1] in mobs_killed:
|
|
temp_str2 += f"✅{mob[0]}\n"
|
|
else:
|
|
temp_str2 += f"🛑{mob[0]}\n"
|
|
else:
|
|
if mob[1] in mobs_killed:
|
|
temp_str1 += f"✅{mob[0]}\n"
|
|
else:
|
|
temp_str1 += f"🛑{mob[0]}\n"
|
|
embed = disnake.Embed()
|
|
embed.title = f"{zone} Rares"
|
|
embed.add_field(name="\u200b",value=temp_str1)
|
|
embed.add_field(name="\u200b",value=temp_str2)
|
|
connection.close()
|
|
return embed
|
|
|
|
@commands.slash_command(description="Spawn a list for your eyes only of the mobs you've killed")
|
|
async def view_outland_rares(self,inter:disnake.ApplicationCommandInteraction):
|
|
embed = self.generate_moblist_embed("Outland",inter.author.id)
|
|
await inter.response.send_message(embed=embed,ephemeral=True)
|
|
|
|
@commands.slash_command(description="Spawn a list for your eyes only of the mobs you've killed")
|
|
async def view_northrend_rares(self,inter:disnake.ApplicationCommandInteraction):
|
|
embed = self.generate_moblist_embed("Northrend",inter.author.id)
|
|
await inter.response.send_message(embed=embed,ephemeral=True)
|
|
|
|
@commands.Cog.listener()
|
|
async def on_message_interaction(self,inter:disnake.MessageInteraction):
|
|
if "rspe" in inter.component.custom_id:
|
|
|
|
if "select" in inter.component.custom_id:
|
|
connection = sqlite3.connect("store.db")
|
|
mobs_killed = [x[0] for x in connection.execute("SELECT mob_id FROM mobs_gotten WHERE discord_user_id = ?",(inter.author.id,)).fetchall()]
|
|
|
|
for selected in inter.values:
|
|
to_int = int(selected)
|
|
if to_int in mobs_killed:
|
|
print("Deleting Entry",to_int)#Delete the entry
|
|
connection.execute("DELETE FROM mobs_gotten WHERE discord_user_id = ? AND mob_id = ?",(inter.author.id,to_int))
|
|
else:
|
|
print("Adding Entry", to_int)#Add the entry
|
|
connection.execute("INSERT INTO mobs_gotten(discord_user_id,mob_id) VALUES(?,?)",(inter.author.id,to_int))
|
|
connection.commit()
|
|
connection.close()
|
|
embed = self.generate_moblist_embed(inter.component.custom_id.partition("rspe-")[2].partition("-select")[0],inter.author.id)
|
|
await inter.response.defer()
|
|
|
|
|
|
return
|
|
if "show" in inter.component.custom_id:
|
|
embed = self.generate_moblist_embed(inter.component.custom_id.partition("rspe-")[2].partition("-show")[0],inter.author.id)
|
|
await inter.response.send_message(embed=embed,ephemeral=True)
|
|
return
|
|
if "mark_done" in inter.component.custom_id:
|
|
connection = sqlite3.connect("store.db")
|
|
cursor = connection.cursor()
|
|
mob_id = cursor.execute(f"SELECT mob_id FROM reports WHERE id = ?",(inter.component.custom_id.partition("mark_done-")[2],)).fetchone()[0]
|
|
cursor.execute(f"INSERT INTO mobs_gotten(discord_user_id,mob_id) VALUES(?,?)",(inter.author.id,mob_id))
|
|
connection.commit()
|
|
cursor.close()
|
|
connection.close()
|
|
await inter.response.send_message(ephemeral=True,content="Marked this rare as completed, you should not get anymore pings from this mob")
|
|
return
|
|
if "mob_dead" in inter.component.custom_id:
|
|
embed = inter.message.embeds[0]
|
|
if embed.color == disnake.Color.brand_red():
|
|
await inter.response.defer()
|
|
return
|
|
embed.color = disnake.Color.brand_red()
|
|
embed.title += " - Killed!"
|
|
inter.component.disabled = True
|
|
await inter.response.edit_message(embed=embed) |