Exemple #1
0
    async def leaderboard(self, ctx) -> None:
        await asyncio.sleep(1)  # let the database catch up

        # index discord.Member object: all_member_data[i][0]
        # index member data: all_member_data[i][1]
        all_member_data = GuildDatabase(ctx.guild).get_all_members()
        author_data = [
            ctx.author,
            GuildDatabase(ctx.guild).get_member_data(ctx.author)
        ]

        all_member_data.sort(key=lambda x: x[1]["EXP"], reverse=True)

        embed = construct_embed(title=f"`{ctx.guild}`  Leaderboard",
                                color=embed_color["DEFAULT"])

        embed.description = f"You are rank `#{(all_member_data.index(author_data)) + 1}` on this server."
        embed.set_thumbnail(url="https://files.catbox.moe/alavwx.gif")

        server_leaderboard = ""

        for i in range(0, 10):
            member_data = all_member_data[i]

            server_leaderboard += f"**{i + 1}.** `{member_data[0].name}` "
            server_leaderboard += f'with {round(member_data[1]["EXP"])} Exp.'
            server_leaderboard += "\n"

        embed.add_field(name="Top 10 Members", value=server_leaderboard)

        await ctx.send(embed=embed)
Exemple #2
0
    async def dj(self, ctx, member: discord.Member):
        """Moderator command, changes the DJ status of a member."""
        member_dj_status = GuildDatabase(
            ctx.guild).get_member_data(member)["DJ_STATUS"]

        if member_dj_status == 0:
            GuildDatabase(ctx.guild).update_member_data(member, "dj_status", 1)
            await ctx.send(f"{member.mention} is now a DJ.")
        else:
            GuildDatabase(ctx.guild).update_member_data(member, "dj_status", 0)
            await ctx.send(f"{member.mention} is no longer a DJ.")
Exemple #3
0
    async def skip(self, ctx):
        """Stars a vote to Skip the current Song."""
        try:
            self.skip_votes[ctx.guild.id] += 1
        except KeyError:
            self.skip_votes[ctx.guild.id] = 1

        member_count = 0
        for member in ctx.voice_client.channel.members:
            if member.bot == False:
                member_count += 1

        member_dj_status = GuildDatabase(ctx.guild).get_member_data(
            ctx.author)["DJ_STATUS"]

        if member_dj_status == 0:
            if member_count / self.skip_votes[ctx.guild.id] <= 2:
                await self.get_player(ctx).stop_current_song()
                await ctx.send("Skipping.")
            else:
                await ctx.send(
                    f"**{self.skip_votes[ctx.guild.id]}/{member_count}** members have voted to skip."
                )
        else:
            await self.get_player(ctx).stop_current_song()
            await ctx.send("**[DJ]** Skipping.")
Exemple #4
0
    async def database_edit(self, ctx, guild, member: discord.Member, key,
                            value) -> None:
        if os.path.exists(f"database/{guild}.db"):
            guild = self.bot.get_guild(int(guild))
            GuildDatabase(guild).update_member_data(member, key, value)

            await ctx.send(
                f"Database edited for **{guild.name}** guild's member <@{member.id}>."
            )
Exemple #5
0
    async def database_reset(self, ctx, guild) -> None:
        if os.path.exists(f"database/{guild}.db"):
            os.remove(f"database/{guild}.db")

            guild = self.bot.get_guild(int(guild))
            GuildDatabase(guild).initialize()

            await ctx.send(
                f"Database for guild **{guild.name}** has been reset.")
Exemple #6
0
    async def on_ready(self) -> None:
        print("Connected")

        await self.change_presence(activity=construct_base_activity())

        GlobalDatabase(self.guilds).initialize()

        for guild in self.guilds:
            GuildDatabase(guild).initialize()
Exemple #7
0
    async def on_message(self, message) -> None:
        if message.author.bot:
            return

        author = message.author

        db = GuildDatabase(message.guild)
        db_global = GlobalDatabase(self.bot.guilds)

        if len(message.content) > random.randint(4, 10):
            should_give_exp = True
        elif len(message.content) == 0:
            if len(message.attachments) > 0:
                should_give_exp = True
        else:
            should_give_exp = False

        if should_give_exp:
            new_server_xp = db.get_member_data(author)["EXP"] + random.uniform(
                2, 4)
            db.update_member_data(author, "exp", new_server_xp)

            author_lvl = db_global.get_member_data(author)["LEVEL"]

            new_global_exp = db_global.get_member_data(author)["EXP"] + (
                random.uniform(2, 4) / (author_lvl / 2))
            db_global.update_member_data(author, "exp", new_global_exp)

            if new_global_exp > 50:
                db_global.update_member_data(author, "exp",
                                             new_global_exp - 50)
                db_global.update_member_data(author, "level", author_lvl + 1)

                await message.channel.send(embed=construct_embed(
                    title="Level Up.",
                    description=
                    f"{author.mention} you've leveled up to level {author_lvl + 1}",
                    color=embed_color["DEFAULT"]))

        del db
        del db_global
Exemple #8
0
    async def on_member_join(self, member):
        if member.bot:
            return

        embed = construct_embed(
            title="A member has joined the server.",
            description = f"Username: {member}\nUser ID: {member.id}\nAccount Date: {member.created_at.strftime('%Y/%m/%d')}\n",
            color=0x2F3136,
            timestamp=datetime.utcnow()
        )

        embed.set_thumbnail(url=member.avatar_url)

        if GuildDatabase(member.guild).check_member(member) == True:
            embed.description += "Member has already joined this server previously."

        channel = self.bot.get_channel_by_name(member.guild, "audit")

        await channel.send(embed=embed)
Exemple #9
0
    async def on_member_join(self, member) -> None:
        if GuildDatabase(member.guild).check_member(member) == False:
            GuildDatabase(member.guild).add_guild_member(member)

        if GlobalDatabase(self.guilds).check_member(member) == False:
            GlobalDatabase(self.guilds).add_guild_member(member)
Exemple #10
0
 async def on_guild_join(self, guild) -> None:
     GuildDatabase(guild).initialize()