Ejemplo n.º 1
0
async def daily_channel(ctx):
    if userdb.is_authorized(
            ctx.message.server,
            ctx.message.author) or ctx.message.author.id == config.proc:
        channel = userdb.get_current_channel(ctx.message.server)
        if channel is not None:
            await bot.say(
                "Currently set to <#" + str((channel[0])[0].strip()) +
                ">.\nUse the `?set_daily_channel` command to change this.")
        else:
            await bot.say(
                "No channel currently set. Use the `?set_daily_channel` command to change this."
            )
Ejemplo n.º 2
0
async def authorize(ctx, user: discord.Member):
    if ctx.message.author.id == config.proc or userdb.is_authorized(
            ctx.message.server, ctx.message.author):
        userdb.authorize_user(ctx.message.server, user)
        await bot.say("{0} authorized".format(user))
        print("{0} authorized".format(user))
    else:
        print("{0} tried to call authorize!".format(ctx.message.author))
        await bot.send_message(
            bot.procUser,
            "{0} tried to call authorize!".format(ctx.message.author))
        await bot.say(
            "You aren't authorized to do that. If there's been a mistake send me a PM!"
        )
Ejemplo n.º 3
0
async def unauthorize(ctx, user: discord.Member):
    if ctx.message.author == bot.procUser:
        if userdb.is_authorized(ctx.message.server, user):
            userdb.unauthorize_user(ctx.message.server, user)
            await bot.say("{0} unauthorized.".format(user))
        else:
            await bot.say("{0} isn't authorized".format(user))
    else:
        print("{0} tried to call unauthorize!".format(ctx.message.author))
        await bot.send_message(
            bot.procUser,
            "{0} tried to call unauthorize!".format(ctx.message.author))
        await bot.say(
            "You aren't authorized to do that. If there's been a mistake send me a PM!"
        )
Ejemplo n.º 4
0
async def adnotif(ctx, *, item):
    if userdb.is_authorized(
            ctx.message.server,
            ctx.message.author) or ctx.message.author == bot.procUser:
        stritem = str(item)
        if not userdb.pref_exists(ctx.message.author.id, stritem):
            if ctx.message.server is None:
                userdb.new_pref(ctx.message.author.id, ctx.message.author,
                                stritem, "direct message")
            else:
                userdb.new_pref(ctx.message.author.id, ctx.message.author,
                                stritem, ctx.message.server.id)
            await bot.say("Notification for {0} added!".format(stritem))
        else:
            await bot.say("Already exists for this user")
Ejemplo n.º 5
0
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!"
        )
Ejemplo n.º 6
0
async def update(ctx):
    if ctx.message.author == bot.procUser or userdb.is_authorized(
            ctx.message.server, ctx.message.author):
        output.generate_merch_image()
        await bot.send_file(ctx.message.channel,
                            output.output_img,
                            content="Stock updated. If this stock is still "
                            "incorrect, verify that "
                            "the wiki has the correct stock, then try "
                            "again.")
    else:
        print("{0} tried to call update!".format(ctx.message.author))
        await bot.send_message(
            bot.procUser,
            "{0} tried to call update!".format(ctx.message.author))
        await bot.say(
            "You aren't authorized to do that. If there's been a mistake send me a PM!"
        )
Ejemplo n.º 7
0
async def user_notifs(ctx, *, item):
    """Notifies users who have the input preference"""
    if ctx.message.author.id == config.proc or userdb.is_authorized(
            ctx.message.server, ctx.message.author):
        data = userdb.users(item)
        users = [user_tuple[0].strip() for user_tuple in data]
        for user in users:
            print(user)
            member = bot.get_server(
                userdb.user_server(user)).get_member(user_id=user)
            await bot.send_message(member, "{0} is in stock!".format(item))
            print(user)
    else:
        print("{0} tried to call user_notifs!".format(ctx.message.author))
        await bot.send_message(
            bot.procUser,
            "{0} tried to call user_notifs!".format(ctx.message.author))
        await bot.say("This command isn't for you!")
Ejemplo n.º 8
0
async def set_daily_channel(ctx, new_channel: discord.Channel):
    """A command for authorized users to set or update the channel that receives the daily stock message"""
    if userdb.is_authorized(
            ctx.message.server,
            ctx.message.author) or ctx.message.author.id == config.proc:
        new = userdb.update_channel(ctx.message.server, new_channel.id)
        if new:
            await bot.say("Channel set")
        else:
            await bot.say("Channel settings updated")
    else:
        print("{0} tried to call set daily channel!".format(
            ctx.message.author))
        await bot.send_message(
            bot.procUser,
            "{0} tried to call set daily channel!".format(ctx.message.author))
        await bot.say(
            "You aren't authorized to do that. If there's been a mistake send me a PM!"
        )
Ejemplo n.º 9
0
async def toggle_daily(ctx):
    """Toggles the daily stock message on or off for your server"""
    if userdb.is_authorized(
            ctx.message.server,
            ctx.message.author) or ctx.message.author.id == config.proc:
        if userdb.remove_channel(ctx.message.server):
            await bot.say("Daily messages toggled off")
        else:
            await bot.say(
                "Use the `?set_daily_channel` command to set which channel the daily message will be sent to"
            )
    else:
        print("{0} tried to call toggle_daily!".format(ctx.message.author))
        await bot.send_message(
            bot.procUser,
            "{0} tried to call toggle_daily!".format(ctx.message.author))
        await bot.say(
            "You aren't authorized to do that. If there's been a mistake send me a PM!"
        )
Ejemplo n.º 10
0
async def restart_background(ctx):
    if ctx.message.author == bot.procUser or userdb.is_authorized(
            ctx.message.server, ctx.message.author):
        await daily_message().close()
        bot.loop.create_task(daily_message())