Skip to content

Commit 732cb51

Browse files
committed
[CHANGE] Switch to slash commands for price checks
1 parent dfba27e commit 732cb51

File tree

2 files changed

+87
-32
lines changed

2 files changed

+87
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Changed
1111

1212
- Embed creation for a market moved to its own function
13+
- Switch to slash commands for price checks
1314

1415
## \[0.5.0\] - 2023-08-01
1516

tnnt_discordbot_cogs/cogs/price_check.py

Lines changed: 86 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# Third Party
1111
import requests
12+
from aadiscordbot import app_settings
1213
from discord.colour import Color
1314
from discord.embeds import Embed
1415
from discord.ext import commands
@@ -52,7 +53,7 @@ def _build_market_price_embed(
5253
market_system_id = market["system_id"]
5354
url = "https://market.fuzzwork.co.uk/aggregates/"
5455
url_params = {"system": market_system_id, "types": eve_type_id}
55-
market_data = requests.get(url=url, params=url_params, timeout=2.50)
56+
market_data = requests.get(url=url, params=url_params, timeout=5.00)
5657

5758
embed.add_field(
5859
name=market_system_name,
@@ -120,8 +121,9 @@ def _build_market_price_embed(
120121
inline=False,
121122
)
122123

123-
@commands.command(pass_context=True)
124-
async def price(self, ctx):
124+
# @commands.command(pass_context=True)
125+
@commands.slash_command(name="price", guild_ids=app_settings.get_all_servers())
126+
async def price(self, ctx, item_name: str):
125127
"""
126128
Check an item price on all major market hubs
127129
@@ -131,59 +133,113 @@ async def price(self, ctx):
131133
:rtype:
132134
"""
133135

134-
markets = [
135-
{"name": "Jita", "system_id": 30000142},
136-
{"name": "Amarr", "system_id": 30002187},
137-
{"name": "Rens", "system_id": 60004588},
138-
{"name": "Hek", "system_id": 60005686},
139-
{"name": "Dodixie", "system_id": 30002659},
140-
]
136+
return await ctx.respond(
137+
embed=self.price_check(
138+
markets=[
139+
{"name": "Jita", "system_id": 30000142},
140+
{"name": "Amarr", "system_id": 30002187},
141+
{"name": "Rens", "system_id": 60004588},
142+
{"name": "Hek", "system_id": 60005686},
143+
{"name": "Dodixie", "system_id": 30002659},
144+
],
145+
item_name=item_name,
146+
),
147+
ephemeral=True,
148+
)
141149

142-
await ctx.trigger_typing()
150+
@commands.slash_command(name="jita", guild_ids=app_settings.get_all_servers())
151+
async def jita(self, ctx, item_name: str):
152+
"""
153+
Check an item price on Jita market
143154
144-
item_name = ctx.message.content[7:]
155+
:param ctx:
156+
:type ctx:
157+
:return:
158+
:rtype:
159+
"""
145160

146-
await self.price_check(ctx=ctx, markets=markets, item_name=item_name)
161+
return await ctx.respond(
162+
embed=self.price_check(
163+
markets=[{"name": "Jita", "system_id": 30000142}], item_name=item_name
164+
),
165+
ephemeral=True,
166+
)
147167

148-
@commands.command(pass_context=True)
149-
async def jita(self, ctx):
168+
@commands.slash_command(name="amarr", guild_ids=app_settings.get_all_servers())
169+
async def amarr(self, ctx, item_name: str):
150170
"""
151-
Check an item price on Jita market
171+
Check an item price on Amarr market
152172
153173
:param ctx:
154174
:type ctx:
155175
:return:
156176
:rtype:
157177
"""
158178

159-
markets = [{"name": "Jita", "system_id": 30000142}]
179+
return await ctx.respond(
180+
embed=self.price_check(
181+
markets=[{"name": "Amarr", "system_id": 60008494}], item_name=item_name
182+
),
183+
ephemeral=True,
184+
)
160185

161-
await ctx.trigger_typing()
186+
@commands.slash_command(name="rens", guild_ids=app_settings.get_all_servers())
187+
async def rens(self, ctx, item_name: str):
188+
"""
189+
Check an item price on Rens market
162190
163-
item_name = ctx.message.content[6:]
191+
:param ctx:
192+
:type ctx:
193+
:return:
194+
:rtype:
195+
"""
164196

165-
await self.price_check(ctx=ctx, markets=markets, item_name=item_name)
197+
return await ctx.respond(
198+
embed=self.price_check(
199+
markets=[{"name": "Rens", "system_id": 60004588}], item_name=item_name
200+
),
201+
ephemeral=True,
202+
)
166203

167-
@commands.command(pass_context=True)
168-
async def amarr(self, ctx):
204+
@commands.slash_command(name="hek", guild_ids=app_settings.get_all_servers())
205+
async def hek(self, ctx, item_name: str):
169206
"""
170-
Check an item price on Amarr market
207+
Check an item price on Hek market
171208
172209
:param ctx:
173210
:type ctx:
174211
:return:
175212
:rtype:
176213
"""
177214

178-
markets = [{"name": "Amarr", "system_id": 60008494}]
215+
return await ctx.respond(
216+
embed=self.price_check(
217+
markets=[{"name": "Hek", "system_id": 60005686}], item_name=item_name
218+
),
219+
ephemeral=True,
220+
)
179221

180-
await ctx.trigger_typing()
222+
@commands.slash_command(name="dodixie", guild_ids=app_settings.get_all_servers())
223+
async def dodixie(self, ctx, item_name: str):
224+
"""
225+
Check an item price on Dodixie market
181226
182-
item_name = ctx.message.content[7:]
227+
:param ctx:
228+
:type ctx:
229+
:return:
230+
:rtype:
231+
"""
183232

184-
await self.price_check(ctx=ctx, markets=markets, item_name=item_name)
233+
return await ctx.respond(
234+
embed=self.price_check(
235+
markets=[{"name": "Dodixie", "system_id": 30002659}],
236+
item_name=item_name,
237+
),
238+
ephemeral=True,
239+
)
185240

186-
async def price_check(self, ctx, markets, item_name: str = None) -> Coroutine:
241+
@classmethod
242+
def price_check(cls, markets, item_name: str = None) -> Coroutine:
187243
"""
188244
Do the price checks and post to Discord
189245
@@ -197,8 +253,6 @@ async def price_check(self, ctx, markets, item_name: str = None) -> Coroutine:
197253
:rtype:
198254
"""
199255

200-
await ctx.trigger_typing()
201-
202256
if item_name != "":
203257
try:
204258
eve_type = (
@@ -229,7 +283,7 @@ async def price_check(self, ctx, markets, item_name: str = None) -> Coroutine:
229283
)
230284

231285
for market in markets:
232-
self._build_market_price_embed(
286+
cls._build_market_price_embed(
233287
embed=embed,
234288
market=market,
235289
item_name=item_name,
@@ -249,7 +303,7 @@ async def price_check(self, ctx, markets, item_name: str = None) -> Coroutine:
249303
inline=False,
250304
)
251305

252-
return await ctx.send(embed=embed)
306+
return embed
253307

254308

255309
def setup(bot) -> None:

0 commit comments

Comments
 (0)