Пример #1
0
async def set(ctx, new_prefix):
    """changes the bot's prefix for this guild"""

    # instantiate database
    with Postgres() as db:
        # check if there's already an entry for this guild
        entry_exists = db.query(
            'SELECT prefix FROM prefixes WHERE guild_id = %s',
            (ctx.guild.id, ))

        # if there is, then update the entry
        if entry_exists:
            db.execute('UPDATE prefixes SET prefix=%s WHERE guild_id = %s',
                       (new_prefix, ctx.guild.id))
        # else create a new entry for this guild
        else:
            db.execute('INSERT INTO prefixes VALUES (%s, %s)',
                       (ctx.guild.id, new_prefix))

        # check to see if we successfully wrote to the database by checking if a row was modified
        if db.cursor.rowcount == 1:
            await ctx.send(
                f':white_check_mark:⠀⠀**Success!**⠀my prefix is now `{new_prefix}`'
            )
        # else something went wrong
        else:
            await ctx.send(
                '<:wrong:742105251271802910>⠀⠀**Error!!**⠀my prefix couldn\'t be changed because something went wrong'
            )
Пример #2
0
    def get_starboard(self, guild_id):
        with Postgres() as db:
            starboard_from_db = db.query(
                'SELECT * FROM starboard WHERE guild_id = %s', (guild_id, ))

        if starboard_from_db:
            starboard_settings = {
                "channel": self.bot.get_channel((starboard_from_db[0])[1]),
                "star_emoji": (starboard_from_db[0])[2],
                "count": (starboard_from_db[0])[3],
                "conf_emoji": (starboard_from_db[0])[4]
            }
            return starboard_settings

        else:
            return None
Пример #3
0
    async def delete(self, ctx):
        """deletes the starboard for this guild"""

        if self.get_starboard(ctx.guild.id):
            with Postgres() as db:
                db.execute('DELETE FROM starboard WHERE guild_id = %s',
                           (ctx.guild.id, ))

                if db.cursor.rowcount == 1:
                    await ctx.send(content=None,
                                   embed=self.get_success_embed(
                                       ctx, "StarboardDeleted"))
                else:
                    await ctx.send(
                        "something went wrong, starboard could not be deleted")

        else:
            await ctx.send(content=None,
                           embed=self.get_error_embed(ctx,
                                                      "StarboardNotExist"))
Пример #4
0
    async def create(self, ctx, channel: discord.TextChannel):
        """creates a starboard for this guild"""

        if not self.get_starboard(ctx.guild.id):
            with Postgres() as db:
                db.execute(
                    "INSERT INTO starboard VALUES (%s, %s, DEFAULT, DEFAULT, DEFAULT)",
                    (ctx.guild.id, channel.id))

                if db.cursor.rowcount == 1:
                    await ctx.send(content=None,
                                   embed=self.get_success_embed(
                                       ctx, "StarboardCreated"))
                else:
                    await ctx.send(
                        "something went wrong, starboard could not be created")
        else:
            await ctx.send(content=None,
                           embed=self.get_error_embed(
                               ctx, "StarboardAlreadyExists"))
Пример #5
0
def get_prefix(bot, message):
    """a callable prefix for our bot which can be customized by each guild"""

    # set default prefix
    default_prefix = ';'

    # check if we're outside a guild (like in a DM, etc.)
    if not message.guild:
        # only allow the default prefix or mention to be used in DMs
        return commands.when_mentioned_or(*default_prefix)(bot, message)

    with Postgres() as db:
        # check if this guild has a custom prefix
        prefix = db.query('SELECT prefix FROM prefixes WHERE guild_id = %s',
                          (message.guild.id, ))

        # if so, return that prefix
        if prefix:
            return commands.when_mentioned_or(str(*prefix[0]))(bot, message)

    # otherwise return the default prefix
    return commands.when_mentioned_or(*default_prefix)(bot, message)
Пример #6
0
        'NEBULArobo ([https://nebularobo.carrd.co/](https://nebularobo.carrd.co/))',
        inline=False)
    embed.add_field(
        name='Icon Artist',
        value=
        'crankiereddy ([https://twitter.com/crankiereddy](https://twitter.com/crankiereddy))',
        inline=False)
    await ctx.send(content=None, embed=embed)


# Here we load our extensions(cogs) listed above in [initial_extensions].
if __name__ == '__main__':
    for extension in initial_cogs:
        bot.load_extension(extension)

    with Postgres() as db:
        db.create_tables()


@bot.event
async def on_ready():
    print(
        f'\n\nLogged in as: {bot.user.name} - {bot.user.id}\nVersion: {discord.__version__}\n'
    )

    # Changes our bots Playing Status. type=1(streaming) for a standard game you could remove type and url.
    print(f'Successfully logged in and booted...!')


bot.run(os.environ.get("TOKEN"), bot=True, reconnect=True)