Exemplo n.º 1
0
async def m(ctx: MessageContext, name: str) -> None:
    """Retrieve the value for a saved macro in this server"""
    if name in ctx.server_ctx.macros:
        await ctx.channel.send(ctx.server_ctx.macros[name])
    else:
        insult = command.get_witty_insult()
        await ctx.channel.send(
            f"There's no macro defined for {name}, {insult}.")
Exemplo n.º 2
0
async def set_tz(ctx: MessageContext, tz: str) -> None:
    if command.has_diceboss_role(ctx.message.author):
        try:
            ctx.server_ctx.tz = tz
            await ctx.channel.send(f"Set this server's timezone to '{tz}'")
        except Exception as e:
            await ctx.channel.send(f"Unknown timezone '{tz}'")
    else:
        insult = command.get_witty_insult()
        await ctx.channel.send(
            f"You're not a diceboss.\nDon't try that shit again, {insult}.")
async def set_turbo_ban_timing_threshold(ctx: MessageContext,
                                         threshold: int) -> None:
    """Set the turbo ban timing threshold (maximum number of seconds before a turbo banned is issued) for this server"""
    if command.has_diceboss_role(ctx.message.author):
        ctx.server_ctx.turbo_ban_timing_threshold = threshold
        await ctx.channel.send(
            f"<@{ctx.discord_id}> set the turbo ban timing threshold to {threshold}"
        )
    else:
        insult = command.get_witty_insult()
        await ctx.channel.send(
            f"You're not a diceboss.\nDon't try that shit again, {insult}.")
Exemplo n.º 4
0
async def macro_del(ctx: MessageContext, name: str) -> None:
    """Delete a macro from the server"""
    if name in ctx.server_ctx.macros:
        old = ctx.server_ctx.macros[name]
        await ctx.channel.send(
            f"Warning: <@{ctx.discord_id}> deleted the macro for {name}\n"
            f"\t- Old macro: {old}")
        ctx.server_ctx.unset_macro(name)
    else:
        insult = command.get_witty_insult()
        await ctx.channel.send(
            f"There's no macro defined for {name}, {insult}.")
Exemplo n.º 5
0
async def set_ban_reaction_threshold(ctx: MessageContext,
                                     threshold: int) -> None:
    """Set the ban reaction threshold (how many reactions before a ban occurs) for this server"""
    if command.has_diceboss_role(ctx.message.author):
        ctx.server_ctx.ban_reaction_threshold = threshold
        await ctx.channel.send(
            f"<@{ctx.discord_id}> set the ban reaction threshold to {threshold}"
        )
    else:
        insult = command.get_witty_insult()
        await ctx.channel.send(
            f"You're not a diceboss.\nDon't try that shit again, {insult}.")
Exemplo n.º 6
0
async def ban(
    ctx: MessageContext,
    target: DiscordUser,
    timer: Time,
    ban_as_bot: BotParam[bool] = False,
) -> None:
    """Ban a user for a given amount of time (bot will shame them)"""
    new_ban = int(time.time()) + timer.seconds
    new_ban_end_str = timezone.localize(new_ban, ctx.server_ctx.tz)
    banner_id = ctx.message.author.id
    if ban_as_bot:
        await ctx.channel.send(f"I have chosen to ban <@{target}>. "
                               f"The ban will end {new_ban_end_str}.\n"
                               f"May God have mercy on your soul.")
        # Need to override banner's ID to denote "no real banner"
        # ID 0 is used as a sentinel for the bot being the banner
        banner_id = 0
    else:
        await ctx.channel.send(f"<@{ctx.discord_id}> has banned <@{target}>. "
                               f"The ban will end {new_ban_end_str}.\n"
                               "May God have mercy on your soul.")

    # Record this ban in the db
    db_helper.record_banned_person(ctx.db_conn, ctx.message.guild.id,
                                   banner_id, target.id)

    current_ban = ctx.server_ctx.bans.get(target.id, -1)
    if current_ban > new_ban:
        localized = timezone.localize(current_ban, ctx.server_ctx.tz)
        await ctx.channel.send(
            f"Oh... you're already banned until {localized}. Wow...")
    ctx.server_ctx.set_ban(target.id,
                           max(current_ban,
                               time.time() + timer.seconds))

    # Tell them they're unbanned 1 second late to ensure any weird delays
    # will still make the logic sound
    await asyncio.sleep(timer.seconds + 1)
    logging.info(f"Check if {target.id} is still banned")

    # Since we're saving/loading file every time, we need to force a reload
    # to check if the user was already unbanned while we were sleeping
    ctx.server_ctx.reload()

    # got banned for *even longer* and we didn't know about it.
    # Check that the bantime is in the past and not -1 (unbanned early)
    # We check the bantime was in the past since we slept 1 more second
    bantime = ctx.server_ctx.bans[target.id]
    if bantime < time.time() and bantime != -1:
        insult = command.get_witty_insult()
        await ctx.channel.send(f"<@{target.id}>: you have been unbanned.\n"
                               f"I hope you learned your lesson, *{insult}*.")
Exemplo n.º 7
0
async def clear_stats(ctx: MessageContext) -> None:
    """Clear all stats in the server's roll record (PERMANENT)"""
    if command.has_diceboss_role(ctx.message.author):
        db_helper.clear_all(ctx.db_conn, ctx.server_ctx.guild_id)
        ctx.server_ctx.current_roll = ctx.server_ctx.DEFAULT_CURRENT_ROLL
        await ctx.channel.send(
            "All winner/loser stats have been cleared for this server.\n"
            f"The next roll for this server has been reset to {ctx.server_ctx.current_roll}"
        )
    else:
        insult = command.get_witty_insult()
        await ctx.channel.send(
            f"You're not a diceboss.\nDon't try that shit again, {insult}.")
Exemplo n.º 8
0
async def set_msg(
    ctx: MessageContext,
    win_or_lose: SetMessageSubcommand,
    msg: GreedyStr,
) -> None:
    """Set the win/loss message in this server for critical success or failure"""
    if command.has_diceboss_role(ctx.message.author):
        if win_or_lose is SetMessageSubcommand.WIN:
            ctx.server_ctx.critical_success_msg = msg
            await ctx.channel.send(f"Set the win message to '{msg}'")
        else:
            ctx.server_ctx.critical_failure_msg = msg
            await ctx.channel.send(f"Set the lose message to '{msg}'")
    else:
        insult = command.get_witty_insult()
        await ctx.channel.send(
            f"You're not a diceboss.\nDon't try that shit again, {insult}.")