async def force_notifs(ctx): """Notifies users for today's stock""" if ctx.message.author.id == config.proc: items = [item.name.lower() for item in request.parse_merch_items()] for item in items: await auto_user_notifs(item) else: print("{0} tried to call notif_test!".format(ctx.message.author)) await bot.send_message( bot.procUser, "{0} tried to call notif_test!".format(ctx.message.author)) await bot.say("This command isn't for you!")
async def ah_test(ctx): """Tags the relevant roles in AH discord for the daily stock""" if ctx.message.author.top_role >= discord.utils.get(ctx.message.server.roles, id=config.ah_mod_role) \ or ctx.message.author.id == config.proc: items = [item.name for item in request.parse_merch_items()] data = userdb.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.send_message(discord.Object(id=config.ah_chat_id), tag_string) else: return
async def fix_daily_message(ctx): if ctx.message.author == bot.procUser or userdb.is_authorized( ctx.message.server, ctx.message.author): output.generate_merch_image() new_stock_string = "The new stock for {0} is out!\n".format( datetime.datetime.now().strftime("%m/%d/%Y")) channels = [ bot.get_channel(channel_tuple[0].strip()) for channel_tuple in userdb.get_all_channels() ] if daily_messages is not None: for message in daily_messages: await bot.delete_message(message) for channel in channels: await bot.send_file(channel, output.output_img, content=new_stock_string) items = [item.name.lower() for item in request.parse_merch_items() ] # get a lowercase list of today's stock data = userdb.ah_roles(items) roles = set([role_tuple[0].strip() for role_tuple in data ]) # get the roles for these items in AH discord # format the string to be sent tag_string = "" if roles != set([]): b = [role + '\n' for role in roles] tag_string = "Tags: \n" + ''.join(b) ah_channel = bot.get_channel(config.ah_chat_id) await bot.send_file(ah_channel, output.output_img, content=new_stock_string + tag_string) reaperscapes_role = '<@&488630912729350145>' reaperscapes_channel = bot.get_channel('488636897070153738') await bot.send_file(reaperscapes_channel, output.output_img, content=new_stock_string + reaperscapes_role) else: print("{0} tried to call fix daily messages!".format( ctx.message.author)) await bot.send_message( bot.procUser, "{0} tried to call fix daily messages!".format(ctx.message.author)) await bot.say( "You aren't authorized to do that. If there's been a mistake send me a PM!" )
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) now2 = datetime.datetime.today() # Check the wiki's date to see if it's current. If not, try again in 60 seconds while not now2.day == int(request.parse_stock_date()): print(now2.day) print(request.parse_stock_date()) await asyncio.sleep(60) output.generate_merch_image() # generate the new image items = [item.name.lower() for item in request.parse_merch_items() ] # get a lowercase list of today's stock new_stock_string = "The new stock for {0} is out!\n".format( datetime.datetime.now().strftime("%m/%d/%Y")) data = userdb.ah_roles(items) roles = set([role_tuple[0].strip() for role_tuple in data ]) # get the roles for these items in AH discord # format the string to be sent tag_string = "" if roles != set([]): b = [role + '\n' for role in roles] tag_string = "Tags: \n" + ''.join(b) ah_channel = bot.get_channel(config.ah_chat_id) await bot.send_file(ah_channel, output.output_img, content=new_stock_string + tag_string) reaperscapes_role = '<@&488630912729350145>' reaperscapes_channel = bot.get_channel('488636897070153738') await bot.send_file(reaperscapes_channel, output.output_img, content=new_stock_string + reaperscapes_role) # notify users for each item in today's stock for item in items: await auto_user_notifs(item) # get all the channels for daily messages, then loop through them to send messages # also, store them in daily_messages in case of a bad wiki update daily_messages.clear() channels = [ bot.get_channel(channel_tuple[0].strip()) for channel_tuple in userdb.get_all_channels() ] for channel in channels: try: daily_messages.append(await bot.send_file(channel, output.output_img, content=new_stock_string)) except discord.Forbidden: pass await asyncio.sleep(60)
def generate_merch_image(): image(request.parse_merch_items())