-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
189 lines (163 loc) · 8.35 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
from discord import Client, Intents, Embed
from discord_slash import SlashCommand, SlashContext
from discord_slash.utils.manage_commands import create_option, create_choice
from datetime import datetime, timedelta
from quests import quests
import secrets
import weapon_tinkering
import pymysql
# Connect to ACE Databases
accounts_db = pymysql.connect(host=secrets.db_uri,
port=secrets.db_port,
user=secrets.db_user,
password=secrets.db_pwd,
database='ace_auth',
cursorclass=pymysql.cursors.DictCursor)
characters_db = pymysql.connect(host=secrets.db_uri,
port=secrets.db_port,
user=secrets.db_user,
password=secrets.db_pwd,
database='ace_shard',
cursorclass=pymysql.cursors.DictCursor)
# Connect to Discord
client = Client(intents=Intents.all())
slash = SlashCommand(client, sync_commands=True)
servers = secrets.servers
# Register Slash Commands
quest_choices = []
for key in quests:
quest_choices.append(create_choice(name=quests[key][0], value=key))
@slash.slash(name="timer",
description="Check a quest timer for toons on the specified account.",
options=[
create_option(
name='account',
description='The username for your ACE account.',
option_type=3,
required=True
),
create_option(
name='quest',
description='The shorthand text for the quest (e.g. "bellas").',
option_type=3,
required=True,
choices=quest_choices
)
],
guild_ids=servers)
async def timer(ctx: SlashContext, account: str, quest: str):
await ctx.author.send(f'Looking up quest timer for {quests[quest][0]} for toons on account {account}:')
with accounts_db:
with accounts_db.cursor() as cursor:
sql = 'SELECT `accountId` FROM `account` WHERE `accountName`=%s'
cursor.execute(sql, (account.lower().strip(),))
result_account_id = cursor.fetchone()
if result_account_id is not None:
account_id = result_account_id['accountId']
with characters_db:
with characters_db.cursor() as cursor2:
sql = f'SELECT `id`, `name` FROM `character` WHERE `account_Id`={account_id}'
cursor2.execute(sql)
result_characters = cursor2.fetchall()
if len(result_characters) < 1:
await ctx.author.send(f'Account {account} has no characters.')
else:
for character in result_characters:
character_id = character['id']
character_name = character['name']
sql = f'SELECT `last_Time_Completed` FROM `character_properties_quest_registry` WHERE `character_Id`={character_id} AND `quest_Name`="{quest}"'
cursor2.execute(sql)
result_timer = cursor2.fetchone()
if result_timer is not None:
quest_timer = datetime.fromtimestamp(result_timer['last_Time_Completed'])
is_timer_up = quest_timer.today() - quest_timer > timedelta(quests[quest][1])
# TODO are we at the 27 day maximum of 4 for Stipends?
await ctx.author.send(
f'- {character_name} {quest_timer} {":green_circle:" if is_timer_up else ":red_square:"}')
else:
await ctx.author.send(f'- {character_name} N/A')
else:
await ctx.author.send(f'Account {account} not found on this ACE server.')
@slash.slash(name="rent",
description="Check rent for the housing on the specified account.",
options=[
create_option(
name='account',
description='The username for your ACE account.',
option_type=3,
required=True
)
],
guild_ids=servers)
async def rent(ctx: SlashContext, account: str):
with accounts_db:
with accounts_db.cursor() as cursor:
sql = 'SELECT `accountId` FROM `account` WHERE `accountName`=%s'
cursor.execute(sql, (account.lower().strip(),))
result_account_id = cursor.fetchone()
if result_account_id is not None:
account_id = result_account_id['accountId']
with characters_db:
with characters_db.cursor() as cursor2:
sql = f'SELECT `id` FROM `character` WHERE `account_Id`={account_id}'
cursor2.execute(sql)
result_character = cursor2.fetchone()
if result_character is None:
await ctx.author.send(f'Account {account} has no characters.')
else:
character_id = result_character['id']
sql = f'SELECT `value` FROM `biota_properties_int` WHERE `object_Id`={character_id} AND `type`=9011'
cursor2.execute(sql)
result_timer = cursor2.fetchone()
if result_timer is not None:
rent_timer = datetime.fromtimestamp(result_timer['value']).strftime('%B %d %Y %H:%M')
await ctx.author.send(f'Your rent is due: {rent_timer}')
else:
await ctx.author.send(f'Account {account} does not appear to have a rental property.')
else:
await ctx.author.send(f'Account {account} not found on this ACE server.')
@slash.slash(name="ig",
description="Calculate best 9 iron/granite tinks on a rend weapon, assuming BD 8 and basic augs.",
options=[
create_option(
name='min',
description='The unbuffed minimum damage on the weapon.',
option_type=10,
required=True
),
create_option(
name='max',
description='The unbuffed maximum damage on the weapon.',
option_type=10,
required=True
),
create_option(
name='cantrip',
description='The Blood Thirst cantrip on the weapon.',
option_type=4,
required=True,
choices=[
create_choice(name='None', value=0),
create_choice(name='Minor', value=2),
create_choice(name='Major', value=4),
create_choice(name='Epic', value=7),
create_choice(name='Legendary', value=10),
]
)
],
guild_ids=servers)
async def ig(ctx: SlashContext, min: float, max: float, cantrip: int):
# await ctx.send(f'For this weapon, the starting average damage is {weapon_tinkering.starting_average_damage(min, max, 24.0, float(cantrip))} and starting variance is {weapon_tinkering.starting_weapon_variance(min, max)}%')
best_average_damage = 0
best_iron = 0
best_granite = 0
for i in range(0, 10):
average_damage = weapon_tinkering.average_damage(min, max, float(cantrip), i)
iron = i
granite = 9 - i
if average_damage >= best_average_damage:
best_average_damage = average_damage
best_iron = iron
best_granite = granite
await ctx.send(f'For this weapon, the best average damage is {best_average_damage} using {best_iron} iron and {best_granite} granite.')
client.run(secrets.token)