Bulk Upload of Codebase
|
@ -0,0 +1,12 @@
|
|||
#Dockerfile, Image, Container
|
||||
FROM python:3.10
|
||||
|
||||
WORKDIR /sbsheriff-app
|
||||
|
||||
COPY requirements.txt .
|
||||
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
COPY ./app .
|
||||
|
||||
CMD [ "python","./main.py" ]
|
|
@ -0,0 +1 @@
|
|||
botOptions.py
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 1.7 MiB After Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
@ -0,0 +1,240 @@
|
|||
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
|
|
@ -0,0 +1,106 @@
|
|||
import sqlite3
|
||||
import re
|
||||
from sqlite3 import Cursor, Error
|
||||
import time
|
||||
import datetime
|
||||
def sql_set(query = None,data = None):
|
||||
if query == None: return
|
||||
try:
|
||||
con = sqlite3.connect('sbsheriff.sqlite')
|
||||
cur = con.cursor()
|
||||
if data != None:
|
||||
cur.execute(query,data)
|
||||
else:
|
||||
cur.execute(query)
|
||||
cur.close()
|
||||
con.commit()
|
||||
con.close()
|
||||
|
||||
except Error as e:
|
||||
print("Sql set error",e)
|
||||
return Error
|
||||
|
||||
def sql_del(query = None):
|
||||
if query == None: return
|
||||
try:
|
||||
con = sqlite3.connect('sbsheriff.sqlite')
|
||||
cur = con.cursor()
|
||||
cur.execute(query)
|
||||
cur.close()
|
||||
con.commit()
|
||||
con.close()
|
||||
|
||||
except Error as e:
|
||||
print(e)
|
||||
return Error
|
||||
|
||||
def sql_get(query = None,rfac = False):
|
||||
if query == None: return
|
||||
try:
|
||||
con = sqlite3.connect('sbsheriff.sqlite')
|
||||
if rfac:
|
||||
con.row_factory = sqlite3.Row
|
||||
cur = con.cursor()
|
||||
cur.execute(query)
|
||||
re = cur.fetchall()
|
||||
cur.close()
|
||||
con.close()
|
||||
return re
|
||||
|
||||
except Error as e:
|
||||
print(e)
|
||||
return Error
|
||||
|
||||
if query == None: return
|
||||
try:
|
||||
con = sqlite3.connect('sbsheriff.sqlite')
|
||||
cur = con.cursor()
|
||||
cur.execute(query)
|
||||
re = cur.fetchall()
|
||||
cur.close()
|
||||
con.close()
|
||||
return re
|
||||
|
||||
except Error as e:
|
||||
print(e)
|
||||
return Error
|
||||
|
||||
def calc_times(times,multi:int):
|
||||
#Split times
|
||||
timeList = re.split(',| ',times)
|
||||
time_tuples = []
|
||||
for num,time_ in enumerate(timeList):
|
||||
if time_ == '':
|
||||
continue
|
||||
#Try and idiotproof some edge cases
|
||||
if time_.startswith((':',';','.')):
|
||||
temp_time = time_[1:]
|
||||
else:
|
||||
temp_time = time_
|
||||
modifier = 0
|
||||
if '|' in time_:
|
||||
temp = time_.split('|')
|
||||
name = temp[0]
|
||||
if name.startswith('>') or name.lower() == 'breaker':
|
||||
#Breaker
|
||||
if name.startswith('>'): name = name[1:]
|
||||
modifier = 10
|
||||
temp_time = temp[1]
|
||||
else:
|
||||
name = '{x}'.format(x = num+1)
|
||||
time_components = [int(s) for s in re.split('\:|\;|\.',temp_time)]
|
||||
time_components.reverse()
|
||||
seconds = 0
|
||||
for n,t in enumerate(time_components):
|
||||
seconds += t*60**n
|
||||
time_tuples.append((name,seconds,multi,modifier))
|
||||
time_tuples.sort(key=lambda y: y[1])
|
||||
time_tuples.reverse()
|
||||
textContent = "**Modifying times to {times}x:**\n".format(times=multi)
|
||||
for tt in time_tuples:
|
||||
emoji = '<:Captain:947543163608924181>'
|
||||
if tt[3] > 0:
|
||||
emoji = '<:Breaker:947543175025819709>'
|
||||
textContent += "{emoji}**{vil}**:{t} -{card}x-> {t1}\n".format(vil=tt[0],t=datetime.timedelta(seconds=tt[1]),t1=datetime.timedelta(seconds=int(tt[1]/tt[2])),card=tt[2],emoji=emoji)
|
||||
textContent += "This message will selfdestruct in <t:{t}:R>".format(t=int(time.time())+540)
|
||||
return (textContent,time_tuples)
|
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 1.1 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 1.2 MiB |
After Width: | Height: | Size: 2.0 MiB |
After Width: | Height: | Size: 1.2 MiB |
After Width: | Height: | Size: 1.1 MiB |
After Width: | Height: | Size: 1.2 MiB |
After Width: | Height: | Size: 2.0 MiB |
After Width: | Height: | Size: 1.2 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.4 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.4 MiB |
After Width: | Height: | Size: 2.5 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 1.2 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 2.0 MiB |
After Width: | Height: | Size: 2.0 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.4 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 2.5 MiB |
After Width: | Height: | Size: 2.5 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 4.0 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 4.0 MiB |
After Width: | Height: | Size: 4.2 MiB |
After Width: | Height: | Size: 4.1 MiB |
After Width: | Height: | Size: 4.1 MiB |
After Width: | Height: | Size: 4.3 MiB |
After Width: | Height: | Size: 1.5 MiB |
After Width: | Height: | Size: 4.1 MiB |
After Width: | Height: | Size: 4.0 MiB |
After Width: | Height: | Size: 4.0 MiB |
After Width: | Height: | Size: 3.9 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 4.0 MiB |
After Width: | Height: | Size: 317 KiB |
Before Width: | Height: | Size: 216 KiB After Width: | Height: | Size: 216 KiB |
|
@ -0,0 +1,293 @@
|
|||
from datetime import datetime
|
||||
from typing import Text
|
||||
import disnake
|
||||
from disnake import TextInputStyle
|
||||
import helpers
|
||||
import json
|
||||
import embed_factory
|
||||
import time
|
||||
import requests
|
||||
class LLModal(disnake.ui.Modal):
|
||||
def __init__(self,cp,pike=0,archer=0):
|
||||
components = [
|
||||
disnake.ui.TextInput(
|
||||
label="Enter CP Rank if number below is wrong",
|
||||
placeholder="Last CP was: {cp}".format(cp=cp),
|
||||
custom_id="cp",
|
||||
style=TextInputStyle.short,
|
||||
max_length=5,
|
||||
required=False,
|
||||
value = cp,
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
label="Villa ID's seperate with space",
|
||||
placeholder="1234 4352 54234 ...etc",
|
||||
custom_id="villa_ids",
|
||||
style=TextInputStyle.short,
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
label="How many Archers?",
|
||||
placeholder="200",
|
||||
custom_id="archers",
|
||||
value=pike,
|
||||
style=TextInputStyle.short,
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
label="How many Pikes?",
|
||||
placeholder="300",
|
||||
custom_id="pikes",
|
||||
value=archer,
|
||||
style=TextInputStyle.short,
|
||||
),
|
||||
]
|
||||
super().__init__(
|
||||
title="Liege Lord Request Form",
|
||||
custom_id="submit_ll",
|
||||
components=components
|
||||
)
|
||||
|
||||
async def callback(self,inter: disnake.ModalInteraction):
|
||||
await inter.response.defer(ephemeral=True)
|
||||
playerCP = inter.text_values['cp']
|
||||
prefArchers = inter.text_values['archers']
|
||||
prefPikes = inter.text_values['pikes']
|
||||
print("{player} is cp {cp} and input: {villaids}".format(player=inter.author.display_name,cp=playerCP,villaids=inter.text_values['villa_ids']))
|
||||
helpers.sql_set("INSERT INTO user(dID,d_name,cp,gID,prefArchers,prefPikes) VALUES(?,?,?,?,?,?) ON CONFLICT(dID) DO UPDATE SET cp = excluded.cp,prefArchers = excluded.prefArchers,prefPikes = excluded.prefPikes",(inter.author.id,inter.author.display_name,playerCP,inter.guild_id,prefArchers,prefPikes))
|
||||
result = json.loads(helpers.sql_get("SELECT advert_data FROM guild WHERE gID = {gID}".format(gID = inter.guild.id))[0][0])
|
||||
|
||||
if 'll' not in result.keys():
|
||||
await inter.response.send_message(content="Failed, no thread open", ephemeral=True)
|
||||
return
|
||||
thread = inter.guild.get_channel_or_thread(result['ll'][1])
|
||||
|
||||
if ',' in inter.text_values['villa_ids']:
|
||||
villa_ids = [villa for villa in inter.text_values['villa_ids'].split(',')]
|
||||
else:
|
||||
villa_ids = [villa for villa in inter.text_values['villa_ids'].split()]
|
||||
if len(villa_ids):
|
||||
for villa in villa_ids:
|
||||
button_done = disnake.ui.Button(emoji='✅',custom_id='llcheck')
|
||||
#button_done.callback = sbComponents.ll_button_callback
|
||||
embed = disnake.Embed(title="LL Request - {id} from {name} CP: {cp}".format(id=villa,cp=playerCP,name=inter.author.display_name))
|
||||
embed.description = "{name} is looking for a LL for {id}, if you fulfill this request, or have gotten a LL click the ✅ below to remove it from the list".format(name=inter.author.display_name,id=villa)
|
||||
embed.add_field(name="Archers",value=prefArchers,inline=True)
|
||||
embed.add_field(name="Pikes",value=prefPikes,inline=True)
|
||||
view = disnake.ui.View()
|
||||
view.add_item(button_done)
|
||||
msg = await thread.send(embed=embed,view=view)
|
||||
helpers.sql_set("INSERT INTO llrequests(parentID,villaID,ownerID,ownerCP,fulfilled,messageID,displayName) VALUES(?,?,?,?,?,?,?)",(thread.id,villa,inter.author.id,playerCP,0,msg.id,inter.author.display_name))
|
||||
channel = inter.guild.get_channel_or_thread(result['ll'][0])
|
||||
message = await channel.fetch_message(result['ll'][1])
|
||||
button_r_ll = disnake.ui.Button(emoji='<:LiegeLord:1003401484295213066>',custom_id='request_ll',label="Click here to request a Liege Lord")
|
||||
embed_view = disnake.ui.View()
|
||||
embed_view.add_item(button_r_ll)
|
||||
await message.edit(embed=embed_factory.lfll(result['ll'][1]),view=embed_view)
|
||||
await channel.send(content="Request has been added!",delete_after=30)
|
||||
await inter.followup.send(content="Done! Should be listed here: <#{id}>".format(id=channel.id))
|
||||
return
|
||||
|
||||
class timesModal(disnake.ui.Modal):
|
||||
def __init__(self,multi=4):
|
||||
components = [
|
||||
disnake.ui.TextInput(
|
||||
label="name|hh:mm:ss or hh:mm:ss can add multiple",
|
||||
placeholder="Times to convert",
|
||||
custom_id="times",
|
||||
required=True,
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
label="Time multiplier",
|
||||
placeholder="4",
|
||||
custom_id="multi_value",
|
||||
style= TextInputStyle.short,
|
||||
max_length=1,
|
||||
value = multi,
|
||||
),
|
||||
]
|
||||
super().__init__(
|
||||
title="Calculate attack times",
|
||||
custom_id="submit_calc",
|
||||
components=components
|
||||
)
|
||||
async def callback(self, interaction: disnake.ModalInteraction):
|
||||
await interaction.response.defer()
|
||||
times = interaction.text_values['times']
|
||||
multi = int(interaction.text_values['multi_value'])
|
||||
#do tests on times:
|
||||
response = helpers.calc_times(times,multi)
|
||||
view = disnake.ui.View()
|
||||
add_to_attack = disnake.ui.Button(emoji='<:Captain_blue:947543163608924181>',custom_id='add_to_attack',label='Copy to timed attack')
|
||||
view.add_item(add_to_attack)
|
||||
message:disnake.Message = await interaction.followup.send(view = view,content=response[0],delete_after=540)
|
||||
for time in response[1]:
|
||||
helpers.sql_set("INSERT INTO times(dID,mID,gID,seconds,name,multi,modifier) VALUES(?,?,?,?,?,?,?)",(interaction.author.id,message.id,interaction.guild_id,time[1],time[0],time[2],time[3]))
|
||||
return
|
||||
################################################
|
||||
# Remember to mirror changes in the main!! #
|
||||
################################################
|
||||
|
||||
class timed_add(disnake.ui.Modal):
|
||||
def __init__(self):
|
||||
components = [
|
||||
disnake.ui.TextInput(
|
||||
label="name|hh:mm:ss or hh:mm:ss can add multiple",
|
||||
placeholder="Times to add",
|
||||
custom_id="times",
|
||||
required=True,
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
label="Time multiplier",
|
||||
value=1,
|
||||
custom_id="multi_value",
|
||||
style= TextInputStyle.short,
|
||||
max_length=1,
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
label="Help",
|
||||
style=TextInputStyle.paragraph,
|
||||
placeholder="Attacks named Breaker or starts with a > will have 10 seconds removed from them",
|
||||
custom_id="help_line",
|
||||
required=False,
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
label=" ",
|
||||
style=TextInputStyle.paragraph,
|
||||
placeholder="Changing time multi alters time entered",
|
||||
custom_id="help_line2",
|
||||
required=False,
|
||||
),
|
||||
]
|
||||
super().__init__(
|
||||
title="Add times to attack",
|
||||
custom_id="submit_timed_add",
|
||||
components=components
|
||||
)
|
||||
async def callback(self, interaction: disnake.ModalInteraction):
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
current_time = int(time.time())
|
||||
times = interaction.text_values['times']
|
||||
multi = int(interaction.text_values['multi_value'])
|
||||
#do tests on times:
|
||||
response = helpers.calc_times(times,multi)
|
||||
for atk_time in response[1]:
|
||||
helpers.sql_set("INSERT INTO times(dID,gID,seconds,name,multi,modifier,target_mID,mID) VALUES(?,?,?,?,?,?,?,0)",(interaction.author.id,interaction.guild_id,atk_time[1],atk_time[0],atk_time[2],atk_time[3],interaction.message.id))
|
||||
helpers.sql_set("UPDATE attack_targets SET update_time = {cur_time} WHERE mID = {mID}".format(cur_time = current_time,mID = interaction.message.id))
|
||||
await interaction.followup.send(content="done",delete_after=1)
|
||||
return
|
||||
|
||||
#class add_attack_modal(disnake.ui.Modal):
|
||||
# def __init__(self,target):
|
||||
# return
|
||||
|
||||
class add_vm(disnake.ui.Modal):
|
||||
def __init__(self):
|
||||
components = [
|
||||
disnake.ui.TextInput(
|
||||
label="Name",
|
||||
placeholder="Check spelling!",
|
||||
custom_id="user",
|
||||
required=True,
|
||||
),
|
||||
]
|
||||
super().__init__(
|
||||
title="Report VM",
|
||||
custom_id="add_vm",
|
||||
components=components
|
||||
)
|
||||
async def callback(self, interaction: disnake.ModalInteraction):
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
user = interaction.text_values['user']
|
||||
shield = requests.get('https://login.strongholdkingdoms.com/ajaxphp/get_shield_url.php?username={user}&transparent=1'.format(user=user))
|
||||
if 'error' in shield.json().keys():
|
||||
await interaction.response.send_message("Unknown player are you sure you typed correctly? - "+user)
|
||||
return
|
||||
else:
|
||||
query_response = helpers.sql_get("SELECT * FROM vm_entries WHERE name = '{user}' AND finished IS NULL".format(user=user),True)
|
||||
if len(query_response) > 0:
|
||||
await interaction.response.send_message("This player is already marked as on VM")
|
||||
return
|
||||
#TODO addbutton
|
||||
helpers.sql_set("INSERT INTO vm_entries(gID,name,added) VALUES(?,?,?)",(interaction.guild_id,user,int(time.time())))
|
||||
advert_result = json.loads(helpers.sql_get("SELECT advert_data FROM guild WHERE gID = {gID}".format(gID = interaction.guild.id))[0][0])
|
||||
channel = interaction.guild.get_channel_or_thread(advert_result['vm'][0])
|
||||
message = await channel.fetch_message(advert_result['vm'][1])
|
||||
button_add_vm = disnake.ui.Button(emoji='➕',custom_id='add_vm',label="Report VM")
|
||||
button_rem_vm = disnake.ui.Button(emoji="➖",custom_id="rem_vm",label="Remove VM")
|
||||
embed_view = disnake.ui.View()
|
||||
embed_view.add_item(button_add_vm)
|
||||
embed_view.add_item(button_rem_vm)
|
||||
await message.edit(view=embed_view,embed=embed_factory.vm_advert(interaction.guild_id))
|
||||
await interaction.followup.send(ephemeral=True,content="{user} added to list".format(user=user))
|
||||
|
||||
class rem_vm(disnake.ui.Modal):
|
||||
def __init__(self,candidates1:list,candidates2:list):
|
||||
components = [
|
||||
disnake.ui.TextInput(
|
||||
placeholder="Check spelling!",
|
||||
custom_id="user",
|
||||
required=True,
|
||||
label="Name"
|
||||
),
|
||||
]
|
||||
super().__init__(
|
||||
title="Remove VM",
|
||||
custom_id="rem_vm",
|
||||
components=components
|
||||
)
|
||||
async def callback(self, interaction: disnake.ModalInteraction):
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
user = interaction.text_values['user']
|
||||
query_result = helpers.sql_get("SELECT name,added FROM vm_entries WHERE name = '{user}' AND gID = {gID} AND finished IS NULL".format(user=user,gID=interaction.guild_id))
|
||||
if len(query_result) == 0:
|
||||
await interaction.followup.send(ephemeral=True,content="Not found or already ended")
|
||||
return
|
||||
helpers.sql_set("UPDATE vm_entries SET finished = ? WHERE gID = ? AND name = ? AND added = ?",(int(time.time()),interaction.guild_id,query_result[0][0],query_result[0][1]))
|
||||
advert_result = json.loads(helpers.sql_get("SELECT advert_data FROM guild WHERE gID = {gID}".format(gID = interaction.guild.id))[0][0])
|
||||
channel = interaction.guild.get_channel_or_thread(advert_result['vm'][0])
|
||||
message = await channel.fetch_message(advert_result['vm'][1])
|
||||
button_add_vm = disnake.ui.Button(emoji='➕',custom_id='add_vm',label="Report VM")
|
||||
button_rem_vm = disnake.ui.Button(emoji='➖',custom_id="rem_vm",label="Remove VM")
|
||||
embed_view = disnake.ui.View()
|
||||
embed_view.add_item(button_add_vm)
|
||||
embed_view.add_item(button_rem_vm)
|
||||
await message.edit(view=embed_view,embed=embed_factory.vm_advert(interaction.guild_id))
|
||||
await interaction.followup.send(ephemeral=True,content="{user} removed from the list".format(user=user))
|
||||
|
||||
class capture_castle(disnake.ui.Modal):
|
||||
def __init__(self,user,filename):
|
||||
components = [
|
||||
disnake.ui.TextInput(
|
||||
placeholder="Who's castle is this?",
|
||||
custom_id="user",
|
||||
required=True,
|
||||
label="Castle Owner",
|
||||
value=user,
|
||||
style=TextInputStyle.multi_line
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
placeholder="If you see this abort",
|
||||
custom_id="image_id",
|
||||
required=True,
|
||||
label="Don't Touch!",
|
||||
value=filename
|
||||
),
|
||||
]
|
||||
super().__init__(
|
||||
title="Capture Castle",
|
||||
custom_id="capture_castle",
|
||||
components=components
|
||||
)
|
||||
async def callback(self, interaction: disnake.ModalInteraction):
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
shield = requests.get('https://login.strongholdkingdoms.com/ajaxphp/get_shield_url.php?username={user}&transparent=1'.format(user=interaction.text_values['user']))
|
||||
if 'error' in shield.json().keys():
|
||||
await interaction.response.send_message("Unknown player are you sure you typed correctly? - "+interaction.text_values['user'])
|
||||
return
|
||||
query_response=helpers.sql_get("SELECT castle_designs FROM players WHERE gID = {gID} AND LOWER(name) = LOWER('{user}')".format(gID = interaction.guild_id,user=interaction.text_values['user']))
|
||||
if len(query_response) > 0:
|
||||
json_object = json.loads(query_response[0][0])
|
||||
else:
|
||||
json_object = {}
|
||||
json_object[interaction.text_values['image_id']] = interaction.text_values['image_id']
|
||||
helpers.sql_set("INSERT INTO players(gID,name,castle_designs) VALUES(?,?,?) ON CONFLICT(name) DO UPDATE SET castle_designs = excluded.castle_designs",(interaction.guild_id,interaction.text_values['user'].lower(),json.dumps(json_object)))
|
||||
await interaction.followup.send(ephemeral=True,content="Nom nom, thats {num} images for {user}".format(user=interaction.text_values['user'],num=len(json_object)))
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |