67 lines
2.8 KiB
Python
67 lines
2.8 KiB
Python
from disnake.ext import commands
|
|
import disnake
|
|
import db
|
|
import httpx
|
|
from datetime import datetime
|
|
from loguru import logger
|
|
import sb_utils
|
|
import sb_emojis
|
|
import csv
|
|
from io import StringIO
|
|
from uuid import uuid4
|
|
from embed_factory import castle_design_confirmation
|
|
from os import makedirs
|
|
|
|
|
|
class Player_Intel(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
|
|
@commands.slash_command()
|
|
async def upload_castle(self, inter:disnake.ApplicationCommandInteraction,player: str, design: disnake.Attachment):
|
|
if not design.content_type.startswith('image'):
|
|
return await inter.send("You can only use this with pictures",ephemeral=True)
|
|
async with httpx.AsyncClient() as client:
|
|
response = await client.get(
|
|
f"http://login.strongholdkingdoms.com/ajaxphp/username_search.php?term={player}"
|
|
)
|
|
response = response.json()
|
|
if len(response) != 1:
|
|
return await inter.send(f"Sorry, {player} could not be found or theres too many results, check spelling")
|
|
|
|
await inter.response.defer(ephemeral=True)
|
|
|
|
with db.get_session()() as session:
|
|
player:db.Player = db.get_or_create(session,db.Player,player_name = player)[0]
|
|
server:db.Server = db.get_or_create(session,db.Server,server_name = inter.guild.name,discord_guild_id = inter.guild.id)[0]
|
|
file_name, ext = design.filename.split('.')
|
|
path = f"castle_designs//{player.id}"
|
|
makedirs(path)
|
|
await design.save(f"{path}//{uuid4()}.{ext}")
|
|
castle_design = db.Player_Castle_Designs(path=f"{path}//{uuid4()}.{ext}", player_id=player.id, server_id=server.id)
|
|
session.add(castle_design)
|
|
session.commit()
|
|
target_advert = session.query(db.Advert).filter(db.Advert.server_id == server.id).filter(db.Advert.advert_type_id == 6).first()
|
|
if not target_advert:
|
|
await inter.send("There's not a castle_design channel for this server, so posting confirmation in this channel")
|
|
await inter.channel.send(embed=castle_design_confirmation.generate_embed(design,player.player_name,inter.author.display_name),components=castle_design_confirmation.generate_buttons(inter.author.id))
|
|
|
|
|
|
|
|
@upload_castle.autocomplete("player")
|
|
async def autocomp_input(
|
|
self, inter: disnake.ApplicationCommandInteraction, user_input: str
|
|
):
|
|
if len(user_input) == 0:
|
|
return []
|
|
async with httpx.AsyncClient() as client:
|
|
response = await client.get(
|
|
f"http://login.strongholdkingdoms.com/ajaxphp/username_search.php?term={user_input}"
|
|
)
|
|
return response.json()
|
|
|
|
|
|
def setup(bot):
|
|
logger.info(f"{__name__} Loaded")
|
|
bot.add_cog(Player_Intel(bot))
|