240 lines
12 KiB
Python
240 lines
12 KiB
Python
from sqlite3 import adapt
|
|
from attr import asdict
|
|
import disnake
|
|
import requests
|
|
import datetime
|
|
import time
|
|
import helpers
|
|
import botOptions
|
|
import json
|
|
from helpers import sql_get
|
|
def lfll(parent):
|
|
embed = disnake.Embed(title="Looking for Liege Lords")
|
|
embed.description = "List of people looking for LL, use /LL anywhere you you have access to add to this list!\n **Open the thread below and ✅ the requests that you fulfill**"
|
|
requests = sql_get("SELECT * FROM llrequests WHERE parentID = {parentID} AND fulfilled = '0'".format(parentID=parent))
|
|
if len(requests) > 0:
|
|
users = {}
|
|
userCP = {}
|
|
for entries in requests:
|
|
if entries[7] in users.keys():
|
|
if entries[4] > userCP[entries[7]]:
|
|
userCP[entries[7]] = entries[4]
|
|
users[entries[7]].append(entries[2])
|
|
else:
|
|
users[entries[7]] = [entries[2]]
|
|
userCP[entries[7]] = entries[4]
|
|
for name,user in users.items():
|
|
field_body = ""
|
|
for villa in user:
|
|
field_body += ">{villa}\n".format(villa=villa)
|
|
embed.add_field(name="{name} CP:{cp}".format(name=name,cp=userCP[name]),value=field_body)
|
|
|
|
return embed
|
|
|
|
def vm_advert(gID = None):
|
|
embed = disnake.Embed(title="VM tracker",description = "Players currently on VM")
|
|
embed.set_author(name='Storm Brigade',icon_url='https://i.imgur.com/Opk3fCq.png')
|
|
if gID == None:
|
|
return embed
|
|
#Cleanup expired vm's
|
|
exired_vms = helpers.sql_get('SELECT name,added FROM vm_entries WHERE gID = {gID} AND added < unixepoch("now","-15 days") AND finished IS NULL'.format(gID=gID))
|
|
vm_length = 1296000
|
|
if len(exired_vms) > 0:
|
|
for vm in exired_vms:
|
|
helpers.sql_set("UPDATE vm_entries SET finished = ? WHERE gID = ? AND name = ? AND added = ?",(vm[1]+vm_length,gID,vm[0],vm[1]))
|
|
|
|
#print(exired_vms)
|
|
from_date = int(datetime.datetime.fromisoformat("{YYYY}-01-01".format(YYYY=datetime.date.today().year)).timestamp())
|
|
to_date = int(datetime.datetime.fromisoformat("{YYYY}-12-31".format(YYYY=datetime.date.today().year)).timestamp())
|
|
#print("SELECT vm_entries.name,vm_entries.added,house.house FROM vm_entries INNER JOIN house ON vm_entries.name = house.username WHERE vm_entries.added BETWEEN {start} AND {end} AND vm_entries.finished IS NULL".format(start=from_date,end=to_date))
|
|
query_result = helpers.sql_get("SELECT vm_entries.name,vm_entries.added,house.house FROM vm_entries INNER JOIN house ON vm_entries.name = house.username WHERE vm_entries.added BETWEEN {start} AND {end} AND vm_entries.finished IS NULL ORDER BY added ASC".format(start=from_date,end=to_date),True)
|
|
house_json = json.loads(helpers.sql_get("SELECT relationships FROM guild WHERE gID = {gID}".format(gID = gID))[0][0])
|
|
if len(query_result) > 0:
|
|
vm_entries = []
|
|
for entry in query_result:
|
|
vm_num = ''
|
|
emojis = ''
|
|
if str(entry['house']) in house_json.keys():
|
|
emojis += botOptions.relationshipEmojis[house_json[str(entry['house'])]]
|
|
if entry['house'] != None:
|
|
emojis += botOptions.houseEmojis[entry['house']]
|
|
vm_entries.append( "{num}{emojis}{name}:<t:{time_remaining}:R>\n".format(num=vm_num,emojis=emojis,name=entry['name'],time_remaining=entry['added']+vm_length))
|
|
temp_value = ''
|
|
for vm_entry in vm_entries:
|
|
if len(temp_value)+len(vm_entry) > 1024:
|
|
if len(embed)+len(temp_value) > 6000:
|
|
print("embed is going to be too large lol")
|
|
break
|
|
embed.add_field(name='\u200b',value=temp_value,inline=False)
|
|
temp_value = ''
|
|
temp_value += vm_entry
|
|
embed.add_field(name='\u200b',value=temp_value,inline=False)
|
|
#print(len(embed))
|
|
return embed
|
|
|
|
def check_player(user:str,gID:int):
|
|
#print("SELECT status,peace FROM players WHERE LOWER(name) = LOWER('{user}' AND gID = {gID})".format(user=user,gID = gID))
|
|
activity = requests.get('https://shk.azure-api.net/shkinfo/v1/UserActivity?world=World%202&username={user}&Key=5E78CFC8-1FFA-4036-8427-D94ED6E1A45B&subscription-key=ff2e578e119348ea8b48a2acd2f5a48d'.format(user=user))
|
|
banStatus = requests.get('http://login.strongholdkingdoms.com/ajaxphp/username_search.php?term={user}'.format(user=user))
|
|
shield = requests.get('https://login.strongholdkingdoms.com/ajaxphp/get_shield_url.php?username={user}&transparent=1'.format(user=user))
|
|
house = helpers.sql_get('SELECT house FROM house WHERE LOWER(username) = LOWER("{user}") AND date > unixepoch("now","-6 hours")'.format(user=user))
|
|
wins = helpers.sql_get('SELECT world,age,rank FROM hallofheroes WHERE LOWER(name) LIKE LOWER("{user}")'.format(user=user))
|
|
query = helpers.sql_get("SELECT status,peace FROM players WHERE LOWER(name) = LOWER('{user}') AND gID = {gID}".format(user=user,gID = gID),True)
|
|
from_date = int(datetime.datetime.fromisoformat("{YYYY}-01-01".format(YYYY=datetime.date.today().year)).timestamp())
|
|
to_date = int(datetime.datetime.fromisoformat("{YYYY}-12-31".format(YYYY=datetime.date.today().year)).timestamp())
|
|
vm_info = helpers.sql_get(f"SELECT added FROM vm_entries WHERE LOWER(name) = LOWER('{user}') AND added BETWEEN {from_date} AND {to_date}")
|
|
#print(vm_info)
|
|
vm_this_year = 0
|
|
vm_active = ''
|
|
if len(vm_info) > 0:
|
|
vm_this_year = len(vm_info)
|
|
vm_active_check = helpers.sql_get(f"SELECT added FROM vm_entries WHERE LOWER(name) = LOWER('{user}') AND finished IS NULL")
|
|
if len(vm_active_check) > 0:
|
|
vm_active = f"On VM out in:<t:{vm_active_check[0][0] + 1296000}:R>"
|
|
#print(query)
|
|
member_wins = ''
|
|
officer_wins = ''
|
|
leader_wins = ''
|
|
marshal_wins = ''
|
|
status = ''
|
|
peace = ''
|
|
status_c = ''
|
|
peace_c = ''
|
|
house_status = ""
|
|
houseNum = 0
|
|
if len(query) > 0:
|
|
status_c = query[0]['status']
|
|
peace_c = query[0]['peace']
|
|
if status_c != "" and status_c != 'None':
|
|
status = status_c
|
|
if peace_c == "True":
|
|
peace = "<:Faction_ally:947479253157560320>"
|
|
if peace_c == "False":
|
|
peace = "<:Enemy_house_faction:947479557982781460>"
|
|
#print(banStatus.encoding,shield.text)
|
|
if len(wins) > 0:
|
|
for win in wins:
|
|
match win[2]:
|
|
case 'Member':
|
|
member_wins += win[0]+'-A{age}\n'.format(age=win[1])
|
|
case 'Officer':
|
|
officer_wins += win[0]+'-A{age}\n'.format(age=win[1])
|
|
case 'Leader':
|
|
leader_wins += win[0]+'-A{age}\n'.format(age=win[1])
|
|
case 'Marshall':
|
|
marshal_wins += win[0]+'-A{age}\n'.format(age=win[1])
|
|
if len(house) > 0:
|
|
houseNum = int(house[0][0])
|
|
house = "{houseEmoji}{house}".format(house=house[0][0],houseEmoji=botOptions.houseEmojis[int(house[0][0])])
|
|
#print("Found Player")
|
|
else:
|
|
house = "Neutral"
|
|
if houseNum > 0:
|
|
house_json = json.loads(helpers.sql_get("SELECT relationships FROM guild WHERE gID = {gID}".format(gID = gID))[0][0])
|
|
if str(houseNum) in house_json:
|
|
house_status = botOptions.relationshipEmojis[house_json[str(houseNum)]]
|
|
#print(banStatus.text)
|
|
banned = "Account is **BANNED**"
|
|
banBool = True
|
|
act = "Error"
|
|
shieldURL=''
|
|
known = False
|
|
if 'error' not in shield.json().keys():
|
|
shieldURL = shield.json()['url']
|
|
known = True
|
|
if len(banStatus.text) == 2:
|
|
banned = "Account is **BANNED**"
|
|
if not known:
|
|
banned = "Account is unknown, typo?"
|
|
|
|
else:
|
|
result = banStatus.json()
|
|
check = user.lower()
|
|
#print('Checking if {x} is banned, comparing to {y}'.format(x=check,y=result))
|
|
if check in (string.lower() for string in result):
|
|
banned = "**NOT** Banned"
|
|
banBool = False
|
|
if activity.text == '01/Jan/0001 00:00:00':
|
|
#print("Unknown player")
|
|
act = "-No W2 Data-"
|
|
else:
|
|
date = datetime.datetime.strptime(activity.text,'%d/%b/%Y %H:%M:%S')
|
|
#print(date)
|
|
act = '<t:{t1}:R>'.format(t1=int(date.timestamp()))
|
|
embed = disnake.Embed(title="{peace}<<{user}>>{status}".format(user=user.capitalize(),peace = peace,status = status))
|
|
embed.description = "Generated <t:{t1}:R>\nCurrent avaliable info is:".format(user=user,t1=int(time.time()))
|
|
embed.add_field(name="Last Activity",value = act)
|
|
embed.add_field(name="Ban Status",value=banned)
|
|
embed.add_field(name="House",value=house_status+house)
|
|
if vm_this_year > 0:
|
|
embed.add_field(name='Vacation',value=f"{vm_this_year} VM's this year\n"+vm_active)
|
|
if marshal_wins != '':
|
|
embed.add_field(name="Marshall Wins",value=marshal_wins)
|
|
if leader_wins != '':
|
|
embed.add_field(name="Leader Wins",value=leader_wins)
|
|
if officer_wins != '':
|
|
embed.add_field(name="Officer Wins",value=officer_wins)
|
|
if member_wins != '':
|
|
embed.add_field(name="Member Wins",value=member_wins)
|
|
|
|
|
|
if user.lower() == 'amber_rose':
|
|
shieldURL = 'https://i.imgur.com/F6ywbGx.png'
|
|
if shieldURL == '':
|
|
embed.set_thumbnail(file=disnake.File('StormBrigade_White.png'))
|
|
else:
|
|
#print(banBool,type(houseNum),houseNum)
|
|
if banBool and houseNum == 13:
|
|
embed.set_thumbnail(file=disnake.File('lol.gif'))
|
|
else:
|
|
embed.set_thumbnail(url=shieldURL)
|
|
return embed
|
|
|
|
def show_castle_designs(gID,name,page=1):
|
|
#print(name,page)
|
|
filepaths = list(json.loads(helpers.sql_get(f"SELECT castle_designs FROM players WHERE LOWER(name) = LOWER('{name}') and gID = {gID}")[0][0]).keys())
|
|
#print(filepaths)
|
|
embed = disnake.Embed()
|
|
embed.set_image(file=disnake.File('images\\{file}'.format(file=filepaths[page-1])))
|
|
embed.title = f"{name} >|< Page {page}"
|
|
embed.description = f"Castle design {page} of {len(filepaths)}"
|
|
return embed
|
|
|
|
def timed_attack(mID = None):
|
|
if mID is None: return
|
|
target = sql_get("SELECT target,duration FROM attack_targets WHERE mID = {mID}".format(mID=mID),True)
|
|
target_id = target[0]['target']
|
|
embed = disnake.Embed()
|
|
print(mID)
|
|
attacks = sql_get("SELECT (times.seconds/times.multi)-times.modifier AS attack_time,times.modifier,times.name, user.d_name FROM times INNER JOIN user ON times.dID = user.dID WHERE target_mID = {t_mID} ORDER BY d_name,attack_time DESC".format(t_mID=mID),True)
|
|
if len(attacks) == 0:
|
|
embed.title = "Timed attack on: {tar}".format(tar=target_id)
|
|
embed.description= "No attacks added, use buttons below to start"
|
|
helpers.sql_set("UPDATE attack_targets SET update_time = 0 WHERE mID = {mID}".format(mID=mID))
|
|
return embed
|
|
longest_attack_query = sql_get('SELECT MAX((seconds/multi)-modifier) FROM times WHERE target_mID = {mID}'.format(mID=mID))
|
|
longest_attack = longest_attack_query[0][0]
|
|
field_text_content = ""
|
|
last_d_name = attacks[0]['d_name']
|
|
for attack in attacks:
|
|
if attack['d_name'] != last_d_name:
|
|
embed.add_field(name = "__{name}__".format(name = last_d_name),value = field_text_content,inline=True)
|
|
last_d_name = attack['d_name']
|
|
field_text_content = ""
|
|
print("**New Field**")
|
|
|
|
#Prepping Phase
|
|
field_text_content += '**{name}**: {t}\n'.format(t=str(datetime.timedelta(seconds=attack['attack_time'])),name=attack['name'])
|
|
embed.add_field(name = "__{name}__".format(name = last_d_name),value = field_text_content,inline=True)
|
|
countdown_string = ''
|
|
|
|
embed.title = "Timed attack on ID: {targetID} - Longest attack: {t} {cd}".format(cd = countdown_string, targetID = target_id,t=str(datetime.timedelta(seconds=longest_attack)))
|
|
embed.description = "To participate add your times using the buttons below, or create check times with /calc_times and add them from there.\nAfter you click start there is a 10 seconds countdown before first attack is launched"
|
|
embed.set_author(name='Storm Brigade',icon_url='https://i.imgur.com/Opk3fCq.png')
|
|
if target[0]['duration'] != None:
|
|
#Do logic to set next update time
|
|
print('Waaa')
|
|
else:
|
|
#Finished updating, wait for changes
|
|
helpers.sql_set("UPDATE attack_targets SET update_time = 0 WHERE mID = {mID}".format(mID=mID))
|
|
return embed |