Browse Source

Fix a bug + store check command

master
noirscape 2 years ago
parent
commit
309cfeca51
Signed by: noirscape GPG Key ID: 38216818B8894B9F
3 changed files with 33 additions and 5 deletions
  1. +13
    -0
      cogs.py
  2. +11
    -3
      main.py
  3. +9
    -2
      utils.py

+ 13
- 0
cogs.py View File

@ -2,6 +2,7 @@ from discord.ext import commands
import discord
import main
import utils
import datetime
class Store(commands.Cog):
def __init__(self, bot: main.FortniteStoreBot):
@ -41,6 +42,11 @@ class Store(commands.Cog):
embed = utils.generate_item_embed(item)
await ctx.send(embed=embed)
@commands.command()
async def get_today_store(self, ctx):
for item in self.bot.store_today:
await ctx.send(embed=utils.generate_item_embed(item, True))
@commands.command()
async def watch_item(self, ctx, itemid, repeat=False):
"""Watch the store for a specific item.
@ -85,3 +91,10 @@ class MetaCommands(commands.Cog):
"""Display invite link for the bot"""
embed = discord.Embed(description=f"[Invite me to your guild!](https://discordapp.com/oauth2/authorize?&client_id={self.bot.user.id}&scope=bot)")
await ctx.send(embed=embed)
@commands.is_owner()
@commands.command()
async def next_notify(self, ctx):
"""Display the time until the next notification."""
final_time = self.bot.current_time + datetime.timedelta(seconds=self.bot.wait_time)
await ctx.send(f"The next time I do a notification checkup is at {final_time}")

+ 11
- 3
main.py View File

@ -31,7 +31,9 @@ class FortniteStoreBot(commands.Bot):
nearest = datetime(curr.year, curr.month, curr.day, hour, minute)
if nearest < curr:
nearest += timedelta(days=1)
self.current_time = curr
self.wait_time = (nearest - curr).seconds
await asyncio.sleep((nearest - curr).seconds)
async def initialize_cache(self):
@ -47,7 +49,10 @@ class FortniteStoreBot(commands.Bot):
user = self.get_user(int(user_id))
if user:
for item in self.store_today:
await user.send(embed=utils.generate_item_embed(item))
try:
await user.send(embed=utils.generate_item_embed(item, True))
except:
pass # Eh
else:
self.store_watch.remove(user_id) # Quietly remove the user from store_watch if we can't find them.
await self.save_watch()
@ -57,7 +62,10 @@ class FortniteStoreBot(commands.Bot):
for user_id in self.item_watch[item_id]:
user = self.get_user(int(user_id))
if user:
await user.send("Hi! The item `{}` you asked me to keep an eye out for is now in the store!".format(item["item"]["name"]))
try:
await user.send("Hi! The item `{}` you asked me to keep an eye out for is now in the store!".format(item["item"]["name"]))
except:
pass
if not self.item_watch[item_id][user_id]["repeat"]:
del self.item_watch[item_id][user_id]
await self.save_watch()


+ 9
- 2
utils.py View File

@ -1,9 +1,16 @@
import discord
def generate_item_embed(item: dict) -> discord.Embed:
def generate_item_embed(item: dict, store: bool=False) -> discord.Embed:
"""Generate an embed for an item.
Argument:
store (bool): Used to check if an item is a store item. Items in the store have more accessible info and different keys."""
embed = discord.Embed()
embed.set_thumbnail(url=item["item"]["images"]["information"])
embed.set_footer(text=item["item"]["obtained"])
if not store:
embed.set_footer(text=item["item"]["obtained"])
else:
embed.set_footer(text=item["store"]["cost"])
embed.title = item["item"]["name"]
embed.description = item["item"]["description"]
embed.add_field(name="Item ID", value=item["itemId"])

Loading…
Cancel
Save