import disnake from disnake.ext import commands import json import modals import helpers import time import embed_factory from disnake.ext import tasks import sqlite3 from sqlite3 import Cursor, Error import asyncio import botOptions import bingo import random import math import os from datetime import datetime,timezone import datetime import sbclasses import requests intents = disnake.Intents().all() bot = commands.Bot( command_preifx='%', sync_commands_debug=False, intents=intents ) @bot.event async def on_ready(): print('Logged In') @bot.slash_command(description='List some villages in need of LL') async def ll(inter:disnake.ApplicationCommandInteraction): playerCP = helpers.sql_get("SELECT cp,prefPikes,prefArchers FROM user WHERE dID = {dID}".format(dID=inter.author.id)) print(playerCP) cp = 0 prefArcher = 300 prefPikes = 200 if len(playerCP): cp = int(playerCP[0][0]) if playerCP[0][1] != None: prefArcher = int(playerCP[0][2]) prefPikes = int(playerCP[0][1]) await inter.response.send_modal(modal=modals.LLModal(cp=cp,pike=prefPikes,archer=prefArcher)) @bot.event async def on_guild_available(guild): helpers.sql_set('INSERT INTO guild(gID,name) VALUES(?,?) ON CONFLICT DO NOTHING',(guild.id,guild.name)) typeList = ['ll'] @bot.slash_command(description='set LL advert channel') async def create_advert(inter:disnake.ApplicationCommandInteraction,advert_type:str = commands.Param(description='What type=',choices=typeList), target: disnake.abc.GuildChannel = commands.Param(description='Channel override, optional')): embed = disnake.Embed(title='Looking for Liege Lords') result = json.loads(helpers.sql_get("SELECT lldata FROM guild WHERE gID = {gID}".format(gID = inter.guild.id))[0][0]) if advert_type not in result: message = await target.send(embed=embed) await message.create_thread(name="Requests") result[advert_type] = (message.channel.id,message.id) helpers.sql_set("INSERT INTO guild(gID,lldata) VALUES(?,?) ON CONFLICT DO UPDATE SET lldata = excluded.lldata",(message.guild.id,json.dumps(result))) else: await inter.response.send_message(content="Already set",ephemeral=True) @bot.slash_command(description="List some info about target") async def check_player(inter:disnake.ApplicationCommandInteraction,user:str = commands.Param(description='Player Name')): embed = embed_factory.check_player(user) await inter.response.send_message(embed=embed) @bot.event async def on_message_interaction(inter:disnake.MessageInteraction): if inter.component.custom_id == 'llcheck' and not inter.response.is_done(): await inter.response.defer(ephemeral=True) inter.component.disabled = True ll_data_dict = json.loads(helpers.sql_get("SELECT lldata FROM guild WHERE gID = {gid}".format(gid=inter.guild.id))[0][0]) ll_channel = inter.guild.get_channel_or_thread(ll_data_dict['ll'][0]) ll_thread_message = await ll_channel.fetch_message(ll_data_dict['ll'][1]) helpers.sql_set("UPDATE llrequests SET fulfilled = ? WHERE messageID = ?",(time.time(),inter.message.id)) await ll_thread_message.edit(embed= embed_factory.lfll(ll_data_dict['ll'][1])) message = await inter.message.delete() return timedAttacks = {} timesMessages = {} def sql_connection(): try: con = sqlite3.connect('sbingo2.sqlite') return con except Error: print(Error) def sql_setSeed(con,entry): cursorObj = con.cursor() cursorObj.execute('INSERT INTO overrides(dID,seed) VALUES(?,?) ON CONFLICT(dID) DO UPDATE SET seed = excluded.seed',entry) cursorObj.close() con.commit() def sql_setCard(con,entry): cursorObj = con.cursor() cursorObj.execute('INSERT INTO defaultCard(dID,speed) VALUES(?,?) ON CONFLICT(dID) DO UPDATE SET speed = excluded.speed',entry) cursorObj.close() con.commit() def sql_getCard(con,id): cursorObj = con.cursor() query = 'SELECT speed FROM defaultCard WHERE dID = '+str(id) cursorObj.execute(query) result = cursorObj.fetchall() cursorObj.close() if len(result) == 1: return result[0][0] return result def sql_addVM(con,name,dateTime): ok = True data = (name.lower(),dateTime) cursorObj = con.cursor() try: cursorObj.execute('INSERT INTO vecations(name,date) VALUES(?,?)',data) except Error: ok = False cursorObj.close() con.commit() return ok def sql_getVM(con): cursorObj = con.cursor() cursorObj.execute('SELECT * FROM vecations where date > unixepoch("now","-14 days");') result = cursorObj.fetchall() cursorObj.close() return result def sql_getSeed(con,id): cursorObj = con.cursor() query = 'SELECT dID, seed FROM overrides WHERE dID = '+str(id) cursorObj.execute(query) result = cursorObj.fetchall() cursorObj.close() return result def generateBingoCard(display_name, id): bingoimg = bingo.generate_bingo(display_name,id) bingoimg.save(display_name+'.png') @bot.event async def on_message(message): if message.author == bot.user: return if message.content.startswith(botOptions.prefix): #Potential command command = message.content.lower().split()[0][1:] or None args = message.content.split()[1:] or [None] match command: case 'spin': random.seed(time.time()) response = bingo.generate_gif_test(str(message.id),1) await message.channel.send(content='Spinning the wheel for: '+message.author.display_name,file=disnake.File(str(message.id)+".gif")) if response == 'T2': await asyncio.sleep(4) response = bingo.generate_gif_test(str(message.id),2) await message.channel.send(content='LUCKY! You won another spin!',file=disnake.File(str(message.id)+".gif")) if response == 'T3': await asyncio.sleep(4) response = bingo.generate_gif_test(str(message.id),3) await message.channel.send(content='SPINTASTIC!!! Max level spin achieved',file=disnake.File(str(message.id)+".gif")) await asyncio.sleep(4) await message.channel.send('Congratulations! You won: '+response) os.remove(str(message.id)+".gif") case 'bingo': seed = sql_getSeed(con,message.author.id) if seed: generateBingoCard(message.author.display_name,seed[0][1]) else: generateBingoCard(message.author.display_name,message.author.id) await message.channel.send(content='Here is your bingo card, if you find something impossible ask for an override!',file=disnake.File(message.author.display_name+".png")) os.remove(message.author.display_name+".png") case 'reroll': if message.author.id in botOptions.verifiedUsers: if len(args) != 1: await message.channel.send('Expecting an user ID') elif not args[0].isnumeric(): await message.channel.send('The argument needs to be the user ID') else: target = message.guild.get_member(int(args[0])) print(args) print(message.guild) print(target) if target == None: await message.channel.send("Can't find the user in this disnake") await message.delete() return newRandom = math.floor(random.random()*100000000000) sql_setSeed(con,(target.id,newRandom)) generateBingoCard(target.display_name,newRandom) await message.channel.send('New seed set!',file=disnake.File(target.display_name+".png")) os.remove(target.display_name+".png") case 'vm': if len(args) < 1 or args[0] == 'list': vms = sql_getVM(con) print(datetime.fromtimestamp(vms[0][1],timezone.utc)) vmList = 'Players potentially still on VM:' if len(vms) == 0: vmList += '\n-None' else: for player in vms: vmList += '\n'+player[0]+' - ' await message.channel.send(vmList) if len(args) == 1: if sql_addVM(con,args[0],message.created_at.replace(tzinfo=timezone.utc).timestamp()): await message.channel.send(args[0]+' Added to VM list!') else: await message.channel.send(args[0]+' Is already on the list') case 'test': editAttack = timedAttacks[args[0]] editAttack.setMark(time.time()) case ('timed'|'attack'|'countdown'): #validate args if len(args) <= 1: if args[0] == 'help' or args[0] == None: embed = disnake.Embed(color=0x5eb4ee,title="<:SB:947837030782615613> Sheriff Timed Attacks for dummies!"\ ,description="The SB Sheriff can keep track of your times and participating villas!\nThis can be used to keep track of targets and work out what to set the timer to,\n but it can also show a countdown for each attack \ Granted this can be a bit slow, and inconvenient for some, but on large timed operations or keeping track of multiple attacks it can be quite useful!\n\n \ The only command needed is: **{prefix}timed