コード例 #1
0
    async def handle_message_inline_rolls(self, message):
        # find roll expressions
        if not INLINE_ROLLING_RE.search(message.content):
            return

        # inline rolling feature flag
        if not await self.bot.ldclient.variation(
                "cog.dice.inline_rolling.enabled",
                user=discord_user_to_dict(message.author),
                default=False):
            return

        if message.guild is not None:  # (always enabled in pms)
            guild_settings = await utils.settings.ServerSettings.for_guild(
                self.bot.mdb, message.guild.id)

            # if inline rolling is disabled on this server, skip
            if guild_settings.inline_enabled is utils.settings.guild.InlineRollingType.DISABLED:
                return

            # if inline rolling is set to react only, pop a reaction on it and return (we re-enter from on_reaction)
            if guild_settings.inline_enabled is utils.settings.guild.InlineRollingType.REACTION:
                try:
                    await message.add_reaction(INLINE_ROLLING_EMOJI)
                except disnake.HTTPException:
                    return  # if we can't react, just skip
                await self.inline_rolling_reaction_onboarding(message.author)
                return

        # if this is the user's first interaction with inline rolling, send an onboarding message
        await self.inline_rolling_message_onboarding(message.author)

        # otherwise do the rolls
        await self.do_inline_rolls(message)
コード例 #2
0
ファイル: servsettings.py プロジェクト: 1drturtle/avrae
    async def get_inline_rolling_desc(self) -> str:
        flag_enabled = await self.bot.ldclient.variation(
            "cog.dice.inline_rolling.enabled",
            user=discord_user_to_dict(self.owner),
            default=False)
        if not flag_enabled:
            return "Inline rolling is currently **globally disabled** for all users. Check back soon!"

        if self.settings.inline_enabled == InlineRollingType.DISABLED:
            return "Inline rolling is currently **disabled**."
        elif self.settings.inline_enabled == InlineRollingType.REACTION:
            return (
                "Inline rolling is currently set to **react**. I'll look for messages containing `[[dice]]` "
                "and react with :game_die: - click the reaction to roll!")
        return "Inline rolling is currently **enabled**. I'll roll any `[[dice]]` I find in messages!"
コード例 #3
0
ファイル: checks.py プロジェクト: driesceuppens/avrae
    async def predicate(ctx):
        if use_ddb_user:
            ddb_user = await ctx.bot.ddb.get_ddb_user(ctx, ctx.author.id)
            if ddb_user is None:
                user = {"key": str(ctx.author.id), "anonymous": True}
            else:
                user = ddb_user.to_ld_dict()
        else:
            user = discord_user_to_dict(ctx.author)

        flag_on = await ctx.bot.ldclient.variation(flag_name, user, default)
        if flag_on:
            return True

        raise commands.CheckFailure(
            "This command is currently disabled. Check back later!")
コード例 #4
0
    async def handle_reaction_inline_rolls(self, reaction, user):
        if user.id != reaction.message.author.id:
            return
        if reaction.emoji != INLINE_ROLLING_EMOJI:
            return
        message = reaction.message

        # find roll expressions
        if not INLINE_ROLLING_RE.search(message.content):
            return

        # if the reaction is in PMs (inline rolling always enabled), skip
        if message.guild is None:
            return

        # inline rolling feature flag
        if not await self.bot.ldclient.variation(
                "cog.dice.inline_rolling.enabled",
                user=discord_user_to_dict(message.author),
                default=False):
            return

        # if inline rolling is not set to reactions, skip
        guild_settings = await utils.settings.ServerSettings.for_guild(
            self.bot.mdb, message.guild.id)
        if guild_settings.inline_enabled is not utils.settings.guild.InlineRollingType.REACTION:
            return

        # if this message has already been processed, skip
        if await self.bot.rdb.get(
                f"cog.dice.inline_rolling.messages.{message.id}.processed"):
            return

        # otherwise save that this message has been processed, remove reactions, and do the rolls
        await self.bot.rdb.setex(
            f"cog.dice.inline_rolling.messages.{message.id}.processed",
            str(time.time()), 60 * 60 * 24)
        await self.do_inline_rolls(message)
        try:
            await reaction.clear()
        except disnake.HTTPException:
            pass
コード例 #5
0
ファイル: __init__.py プロジェクト: driesceuppens/avrae
    async def send_welcome_message(self, guild):
        owner = await get_guild_member(guild, guild.owner_id)
        if owner is None:
            return
        flag_on = await self.bot.ldclient.variation(
            'cog.tutorials.guild_join.enabled',
            discord_user_to_dict(owner),
            default=False)
        if not flag_on:
            return
        prefix = await self.bot.get_guild_prefix(guild)
        prefix_is_default = prefix == config.DEFAULT_PREFIX

        embed = discord.Embed()
        embed.set_author(name=self.bot.user.name,
                         icon_url=self.bot.user.display_avatar.url)
        embed.colour = discord.Colour.blurple()
        embed.description = textwrap.dedent(f"""
        :wave: Hi there! Thanks for adding me to {guild.name}!
        
        I'm ready to roll, but before we get started, let's take a look at some of the things I can do! 
        """).strip()

        if not prefix_is_default:
            embed.add_field(
                name="Prefix",
                inline=False,
                value=
                f"Looks like you've added me to {guild.name} in the past before. On {guild.name}, my prefix is "
                f"`{prefix}`, but by default, it's `{config.DEFAULT_PREFIX}`. You can reset it with "
                f"`{prefix}prefix {config.DEFAULT_PREFIX}`, or roll with it using the examples below!"
            )

        embed.add_field(
            name="Rolling Dice",
            inline=False,
            value=
            f"Want to get rolling as soon as possible? Just use the `{prefix}roll` command to get started! "
            f"Here's some examples: ```\n"
            f"{prefix}roll 1d20\n"
            f"{prefix}roll 4d6kh3\n"
            f"{prefix}roll 1d20+1 adv\n"
            f"{prefix}r 1d10[cold]+2d6[piercing]\n"
            f"```")

        embed.add_field(
            name="Quickstart",
            inline=False,
            value=
            f"I can do more than just roll dice, too! If you'd like to learn more about importing a "
            f"character and rolling checks, saves, and attacks, try out the Quickstart tutorial!"
            f"```\n{prefix}tutorial quickstart\n```")

        embed.add_field(
            name="Content Lookup",
            inline=False,
            value=
            f"You can look up any spell, item, creature, and more right in Discord! Just use the `{prefix}spell`"
            f", `{prefix}item`, `{prefix}monster`, or other lookup command! You can see a full list with "
            f"`{prefix}help Lookup`.\n\n"
            f"I'll even link with your D&D Beyond account to give you access to everything you've unlocked, "
            f"all for free! To get started, try out the D&D Beyond tutorial."
            f"```\n{prefix}tutorial beyond\n```\n"
            f"\u203b By default, for servers with less than 250 members, a monster's full stat block will be "
            f"hidden unless you have a Discord role named `Dungeon Master`. You can turn this off with "
            f"`{prefix}lookup_settings -req_dm_monster false`.")

        embed.add_field(
            name="Initiative Tracking",
            inline=False,
            value=
            f"Once you're familiar with the basics, to learn how to get started with initiative tracking, "
            f"try out the initiative tutorial! You can choose between a Dungeon Master's or a player's "
            f"perspective."
            f"```\n{prefix}tutorial initiative\n```")

        embed.add_field(
            name="Custom Commands",
            inline=False,
            value=
            f"Want to do even more? Check out the list of user-made commands at "
            f"https://avrae.io/dashboard/workshop, and add them to Discord with one click!"
        )

        embed.add_field(
            name="More Resources",
            inline=False,
            value=
            f"If you ever want a refresher on a command or feature, use the `{prefix}help` command for help on a "
            f"command, or `{prefix}tutorial` for a list of available tutorials.\n\n"
            f"For even more resources, come join us in the development Discord at <https://support.avrae.io>!"
        )

        try:
            await owner.send(embed=embed)
        except discord.HTTPException:
            pass