def generate_merch_image(days=0, items=None): if items: image(items) elif days == 0: image(merch.get_stock(days)) elif days == 1: image(merch.get_stock(days), tomorrow_img) else: image(merch.get_stock(days), custom_img)
async def _next(ctx, *, item): await ctx.trigger_typing() stritem = str(item).lower() lst = [item.lower() for item in itemlist.item_list] results = get_matches(stritem, lst) if stritem not in lst: if results[0][1] - results[1][1] < 20: if results[1][1] > 80: suggestions = [x[0] for x in results if x[1] > 80] b = [':small_blue_diamond:' + x + '\n' for x in suggestions] await ctx.send( "Make sure you're spelling your item correctly! Maybe you meant to type one of these:\n" + "".join(b)) return if results[0][1] < 75: await ctx.send( "Make sure you're spelling your item correctly!\nCheck your PMs for a list of correct " "spellings, or refer to the wikia page.") b = sorted([item + '\n' for item in itemlist.item_list]) itemstrv2 = ''.join(b) await ctx.author.send('Possible items:\n' + itemstrv2) return stritem = results[0][0] i = 1 while i < 200: stock = merch.get_stock(i) for x in stock: if x.name.lower() == stritem: time = datetime.datetime.now() + datetime.timedelta(days=i) await ctx.send( f'{x.name} is next in stock {i} days from now, on {time.strftime("%A, %B %d")}.' ) return i += 1 await ctx.send(f"Couldn't find {stritem} in the next 200 days!")
async def custom_stock(ctx, *items): stock = [] print(items) if items[0] == 'normal': output.generate_merch_image() output.generate_merch_image(1) await send_stock(merch.get_stock()) return lst = [item for item in itemlist.item_list] if any([x not in lst for x in items]): await ctx.send("Try typing that out again!") return if len(items) == 3: stock.append( merch.MerchItem( 'Uncharted island map (Deep Sea Fishing).png', 'Uncharted island map', '800,000', 1, "Allows travel to an [[uncharted island]] with the chance of 3-6 special resources at the cost " "of no supplies<br />In addition, players may also rarely receive a [[Uncharted island map (" "red)|red uncharted island map]].", "<:Uncharted_map:755960222949965825>")) for item in items: stock.append(merch.MerchItem(f'{item}.png', item, *it.get_attrs(item))) output.generate_merch_image(items=stock) await send_stock(stock)
async def force_notifs(ctx): """Notifies users for today's stock""" if ctx.author == bot.procUser: items = [item.name.lower() for item in merch.get_stock()] for item in items: await auto_user_notifs(item) else: await bot.procUser.send(f"{ctx.author} tried to call notif_test!") await ctx.send("This command isn't for you!")
async def ah_test(ctx): """Tags the relevant roles in AH discord for the daily stock""" if ctx.author.top_role >= discord.utils.get(ctx.guild.roles, id=config.ah_mod_role) \ or ctx.author == bot.procUser: items = [item.name.lower() for item in merch.get_stock()] data = await bot.db.ah_roles(items) roles = [role_tuple[0].strip() for role_tuple in data] b = [role + '\n' for role in roles] tag_string = "Tags: " + ''.join(b) await bot.get_channel(config.ah_chat_id ).send(content=tag_string, file=discord.File(output.today_img))
async def _next(self, interaction: discord.Interaction, item: str): """Finds the next time a given item will be in stock""" i = 1 while i < 200: stock = merch.get_stock(i) for x in stock: if x.name.lower() == item.lower(): time = datetime.datetime.now() + datetime.timedelta(days=i) await interaction.response.send_message( f'{x.name} is next in stock {i} days from now, on {time.strftime("%A, %B %d")}.' ) return i += 1 await interaction.response.send_message( f"Couldn't find {item} in the next 200 days!")
def generate_merch_embed(days=0, items=None, dsf=False, worlds=[]): items = merch.get_stock(days) if not items else items embed = discord.Embed() embed.title = f"Stock for {(datetime.datetime.now()+ datetime.timedelta(days=days)).strftime('%B %d %Y')}:" embed.description = "" for item in items: embed.description += f"\u200b \u200b \u200b \u200b \u200b \u200b" \ f"{item.emoji} {item.quantity} **{item.name}** - {item.cost[:-4]}k\n\n" if days == 0: if worlds: embed.description += f"Latest worlds from [DSF discord](https://discord.gg/whirlpooldnd): {', '.join([str(_) for _ in worlds])}\n\n" embed.description += f"**Tomorrow:** {', '.join([x.name for x in merch.get_stock(1)][1:])}\n" if not dsf: embed.description += "[Command reference](https://github.com/ragnarak54/DiscordBot)" else: embed.colour = discord.Color.blue() embed.set_footer(text="made by Proclivity (ragnarak54#9413)") return embed
async def daily_message(): await bot.wait_until_ready() while not bot.is_closed(): now = datetime.datetime.now() schedule_time = now.replace(hour=0, minute=1) + timedelta(days=1) time_left = schedule_time - now sleep_time = time_left.total_seconds( ) # seconds from now until tomorrow at 00:01 print(sleep_time) await asyncio.sleep(sleep_time) output.generate_merch_image( ) # generate the new image for today and tomorrow output.generate_merch_image(1) await send_stock(merch.get_stock()) await asyncio.sleep(60)
async def dsf_merch(ctx): if (await bot.db.is_authorized(ctx.author) and ctx.guild.id == 420803245758480405) or await bot.is_owner( ctx.author): items = [item.name.lower() for item in merch.get_stock()] dsf_roles = [ role_tuple[0].strip() for role_tuple in await bot.db.dsf_roles(items) ] tag_string = "" if dsf_roles: tag_string = " ".join(dsf_roles) try: em = output.generate_merch_embed(dsf=True) em.description += f'\n{bot.get_channel(789279009333575700).mention} for worlds, or join **WhirlpoolDnD** FC!' await ctx.send(tag_string, embed=em) except Exception as e: await bot.procUser.send(f"Couldn't send message to DSF: {e}") else: await bot.procUser.send( f"{ctx.author} tried to call dsf_merch in {ctx.guild}!")
async def fix_daily_message(ctx, send_dsf=False): if ctx.author == bot.procUser: await send_stock(merch.get_stock(), send_dsf=send_dsf) else: await bot.procUser.send( f"{ctx.author} tried to call fix daily messages!")