initial commit
This commit is contained in:
commit
c33cf8274e
|
@ -0,0 +1 @@
|
|||
TOKEN = MzA1MDI4MzE5NTA0NjI5NzYw.GRmc_y.343Ir3cXyRhKuYLVKiKMYC6ecjnRjrjJTHxx7E
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,102 @@
|
|||
import asyncio
|
||||
from disnake.ext import commands, tasks
|
||||
import disnake
|
||||
import sqlite3
|
||||
import time
|
||||
|
||||
|
||||
class Bookclub(commands.Cog):
|
||||
booktypes = [
|
||||
"1-Abjuration-Visitor Center",
|
||||
"2-Enchantment-Balcony",
|
||||
"3-Illusion-Violet Hold",
|
||||
"4-Necromancy-Inn 2nd Floor",
|
||||
"5-Divination-Citadel Top",
|
||||
"6-Introduction-Violet Gate",
|
||||
"7-Transmutation-Inn 1st Floor",
|
||||
"8-Conjuration-Citadel Bottom",
|
||||
]
|
||||
def __init__(self,bot:commands.InteractionBot):
|
||||
self.bot = bot
|
||||
self.advert_updater.start()
|
||||
|
||||
async def update_advert(self,guild_id:int):
|
||||
connection = sqlite3.connect("store.db")
|
||||
cursor = connection.cursor()
|
||||
|
||||
advert_info = cursor.execute("SELECT * FROM adverts WHERE server_id = ?",(guild_id,)).fetchone()
|
||||
advert_data = cursor.execute("SELECT * FROM advert_data WHERE reported_at > unixepoch('now','-4 hours') ORDER BY layer, reported_at").fetchall()
|
||||
book_types = cursor.execute("SELECT * FROM books").fetchall()
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
timers = {}
|
||||
|
||||
for entry in advert_data:
|
||||
if entry[1] not in timers.keys():
|
||||
timers[entry[1]] = {}
|
||||
timers[entry[1]][entry[2]] = entry[3]
|
||||
timers[entry[1]] = dict(sorted(timers[entry[1]].items(), key=lambda item:item[1]))
|
||||
|
||||
command_id = self.bot.get_global_command_named(name="book_report")
|
||||
|
||||
embed = disnake.Embed()
|
||||
embed.set_thumbnail("https://i.imgur.com/Jaa3CgV.png")
|
||||
embed.title = "🌟 - Dalaran Bookclub - 🌟"
|
||||
embed.description = f"Use the command </book_report:{command_id.id}> **<-Click it!** to mark what book and what layer you found it at.\n Timers are for when the spawn window opens.\n Window is open for 1 hour.\nOld timers get purged when not updated"
|
||||
for layer,times in timers.items():
|
||||
tempstring = ""
|
||||
for book,time in times.items():
|
||||
tempstring += f"{book_types[book-1][2]} - <t:{time+10800}:R> - <t:{time+10800}:t>\n"
|
||||
embed.add_field(name=f"Layer {layer}:",value=tempstring,inline=False)
|
||||
embed.set_footer(text= "Use reactions below to select which books you need, and the bot will ping you when its seen - Hover to see name")
|
||||
message:disnake.Message = await self.bot.get_channel(advert_info[2]).fetch_message(advert_info[3])
|
||||
await message.edit(content="",embed=embed)
|
||||
|
||||
@commands.slash_command(description="[Admin]Create Bookclub advert",default_member_permissions=disnake.Permissions(manage_guild=True))
|
||||
async def setup_bookclub(self,
|
||||
inter:disnake.ApplicationCommandInteraction):
|
||||
connection = sqlite3.connect("store.db")
|
||||
cursor = connection.cursor()
|
||||
await inter.response.defer(ephemeral="Setting things up")
|
||||
message = await inter.channel.send("Advert coming soon")
|
||||
cursor.execute(f"INSERT INTO adverts(server_id,channel_id,message_id) VALUES(?,?,?) ON CONFLICT DO UPDATE SET channel_id = excluded.channel_id, message_id = excluded.message_id",(inter.guild_id,inter.channel_id,message.id))
|
||||
connection.commit()
|
||||
cursor.close()
|
||||
connection.close()
|
||||
await self.update_advert(inter.guild_id)
|
||||
|
||||
@commands.slash_command(description="Report a book sighting")
|
||||
async def book_report(self,
|
||||
inter:disnake.ApplicationCommandInteraction,
|
||||
layer:int = commands.Param(choices=[x for x in range(1,7)],description="Which layer was this?"),
|
||||
book:str = commands.Param(choices=booktypes,description="What book was it?"),
|
||||
real_book:str = commands.Param(choices=["True","False"],default="False",description="Is this book real? Defaults to False if not added. Pings people if True")):
|
||||
connection = sqlite3.connect("store.db")
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(f"INSERT INTO advert_data(layer,book_id,reported_at) VALUES(?,?,?)",(layer,book[0],int(time.time())))
|
||||
connection.commit()
|
||||
if real_book == "True":
|
||||
role_id = cursor.execute("SELECT role_id FROM books WHERE id = ?",(book[0],)).fetchone()[0]
|
||||
advert_info = cursor.execute("SELECT * FROM adverts WHERE server_id = ?",(inter.guild_id,)).fetchone()
|
||||
await self.bot.get_channel(advert_info[2]).send(content=f"Look alive! <@&{role_id}> spawned on Layer {layer} \n{book}",delete_after=300)
|
||||
cursor.close()
|
||||
connection.close()
|
||||
await self.update_advert(inter.guild_id)
|
||||
await inter.response.send_message(ephemeral=True,content="Added to list")
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self,message:disnake.Message):
|
||||
if message.channel.id != 1034201792352886784: return
|
||||
if message.author == self.bot.user: return
|
||||
await message.delete()
|
||||
|
||||
@tasks.loop(hours=1)
|
||||
async def advert_updater(self):
|
||||
await self.bot.wait_until_ready()
|
||||
for guild in self.bot.guilds:
|
||||
await self.update_advert(guild.id)
|
||||
print("Updated Adverts")
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import disnake
|
||||
import os
|
||||
import requests
|
||||
import sqlite3
|
||||
from bookclub import Bookclub
|
||||
import rare_hunter
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from disnake.ext import commands,tasks
|
||||
|
||||
from rare_hunter import Rare_Hunter
|
||||
|
||||
load_dotenv('.env')
|
||||
|
||||
intents = disnake.Intents().all()
|
||||
bot = commands.InteractionBot(
|
||||
command_sync_flags=commands.CommandSyncFlags.all(),
|
||||
intents=intents
|
||||
)
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print('Logged In')
|
||||
|
||||
|
||||
bot.add_cog(Rare_Hunter(bot))
|
||||
bot.add_cog(Bookclub(bot))
|
||||
bot.run(os.getenv('TOKEN'))
|
|
@ -0,0 +1,169 @@
|
|||
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)
|
Loading…
Reference in New Issue