コード例 #1
0
ファイル: error.py プロジェクト: ibx34/crate-bot
    async def predicate(ctx):
        if ctx.author.id in Configuration.get_master_key("hard_coded_devs"):
            return True

        cooldown_pybass = Configuration.get_master_key("cooldown_bypass",
                                                       error=False)
        if cooldown_pybass:
            if ctx.author.id in cooldown_pybass["users"]:
                return True
            elif ctx.guild.id in cooldown_pybass["servers"]:
                return True
            elif ctx.channel.id in cooldown_pybass["channels"]:
                return True

        cd = await ctx.bot.redis.pttl(
            f"{ctx.author.id}-{ctx.guild.id}-{ctx.command.qualified_name}")
        if cd == -2:

            await ctx.bot.redis.execute(
                "SET",
                f"{ctx.author.id}-{ctx.guild.id}-{ctx.command.qualified_name}",
                "cooldown",
                "EX",
                cooldown,
            )
            return True

        raise commands.CommandOnCooldown(retry_after=cd / 1000, cooldown=None)
コード例 #2
0
ファイル: Connector.py プロジェクト: ibx34/crate-bot
async def init():
    log.info("Connecting to the database...")

    config = Configuration.get_master_key("database")
    database = await Tortoise.init(
        db_url=
        f"postgres://{config['user']}:{config['password']}@{config['host']}:{config['port']}/{config['database']}",
        modules={"models": ["database.Connector"]},
    )
    await Tortoise.generate_schemas(safe=True)
コード例 #3
0
    async def on_ready(self):

        self.redis = await aioredis.create_redis_pool("redis://localhost",
                                                      loop=self.loop)
        self.pool = await asyncpg.create_pool(**Configuration.get_master_key(
            "database"),
                                              max_size=150)
        await Connector.init()

        self.guild = self.get_guild(825512897080852520)
        self.cm_channel = self.guild.get_channel(
            Configuration.get_master_key("support")["community_market"])
        self.transaction_logs = self.guild.get_channel(
            Configuration.get_master_key("support")["transaction_logs"])
        self.error_logs = self.guild.get_channel(
            Configuration.get_master_key("support")["error_logs"])
        self.server_logs = self.guild.get_channel(
            Configuration.get_master_key("support")["server_logs"])
        self.developer_logs = self.guild.get_channel(
            Configuration.get_master_key("support")["developer_logs"])

        with open("schema.sql") as f:
            await self.pool.execute(f.read())

        for name in await get_extensions():
            self.load_extension(name)

        for shard in self.shards:
            await self.change_presence(
                status=discord.Status.online,
                activity=discord.Game(f"{shard}/{len(self.shards)}"),
                shard_id=shard,
            )
コード例 #4
0
    async def cma(self, ctx, id: int, price: int):

        user = await users.get_or_none(user_id=ctx.author.id)
        item = await user_items.get_or_none(id=id)

        if user is None:
            return await ctx.send(
                f"BRUHHH create an account and get an account :weary: `{ctx.prefix}start`"
            )

        if item is None:
            return await ctx.send(
                f"<:okayboomer:826195153374281788> Uhhhh, so something bad has happened... **THAT ITEM DOESNT EXIST AHHHhhhHHHHHHHHHHHH**"
            )

        confirm = await prompt(
            ctx,
            "ARE YOU SURE YOU WANT TO ADD THIS ITEM TO THE COMMUNITY MARKET?",
            reacquire=False,
            delete_after=False,
            author_id=ctx.author.id,
        )
        if not confirm:
            return await ctx.send(
                "<:thumbsdown55:826198312927494145> ight bet, not added"
            )

        cm_item2 = await cm_item.create(
            user_id=ctx.author.id,
            added_at=datetime.utcnow(),
            rarity=item.rarity,
            float=item.float,
            name=item.name,
            price=price,
        )
        cm_channel = self.bot.guild.get_channel(
            Configuration.get_master_key("support")["community_market"]
        )

        embed = discord.Embed(
            color=Configuration.get_rarity(item.rarity)["color"],
            description=dedent(
                f"""**Name**: {item.name} - **Id**: {item.id}\n**Float**: `{item.float}` - **Rarity**: `{item.rarity}`\n**Name-tagged**: `{"Yes" if item.nicked else "No"}` - **Nickname**: `{item.nickname or "None"}`\n**Tradable**: `{"Yes" if item.tradable else "No"}` - **Sellable**: `{"Yes" if item.sellable else "No"}`"""
            ),
        )

        await cm_channel.send(
            dedent(
                f"""
        <@&826225022531010640> **New item!** 👀 | **Id**: {cm_item2.id} | Price: **{price}**
        """
            ),
            embed=embed,
            allowed_mentions=discord.AllowedMentions(roles=True),
        )

        await ctx.send(
            f"<:thumbsdown55:826198312927494145> alright added your item to the community market!!!!!!! hopefully someone buys it lol"
        )
        await self.bot.transactions(
            ctx,
            action=f"A {cm_item2.name} was added to the **community market** on {datetime.utcnow()}",
        )
コード例 #5
0
async def get_pre(crate, message):

    return commands.when_mentioned_or(
        *Configuration.get_master_key("prefixes"))(crate, message)
コード例 #6
0
    async def start(self):
        self.session = start_session(self)
        await Configuration.init(self)

        await super().start(Configuration.get_master_key("token"))