示例#1
0
文件: user.py 项目: MujyKun/miso-bot
    async def activity(self,
                       ctx,
                       user: typing.Optional[discord.Member] = None,
                       scope=""):
        """See your hourly activity chart (GMT)."""
        if user is None:
            user = ctx.author

        is_global = scope.lower() == "global"

        if is_global:
            global_activity = await self.bot.db.execute(
                """
                SELECT h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13,h14,h15,h16,h17,h18,h19,h20,h21,h22,h23
                    FROM user_activity
                WHERE user_id = %s
                GROUP BY guild_id
                """,
                user.id,
            )
            if global_activity:
                activity_data = []
                for i in range(24):
                    activity_data.append(sum(r[i] for r in global_activity))
                xp = sum(activity_data)
            else:
                activity_data = [0] * 24
                xp = 0
        else:
            activity_data = await self.bot.db.execute(
                """
                SELECT h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13,h14,h15,h16,h17,h18,h19,h20,h21,h22,h23
                    FROM user_activity
                WHERE user_id = %s AND guild_id = %s
                """,
                user.id,
                ctx.guild.id,
                one_row=True,
            )
            xp = sum(activity_data) if activity_data else 0

        if xp == 0:
            return ctx.send("No data!")

        level = util.get_level(xp)

        title = (
            f"LVL {level} | {xp - util.get_xp(level)}/"
            f"{util.xp_to_next_level(level)} XP to levelup | Total xp: {xp}")

        plotter.create_graph(activity_data, str(user.color), title=title)

        with open("downloads/graph.png", "rb") as img:
            await ctx.send(
                f"`Hourly cumulative {'global' if is_global else 'server'} activity for {user}`",
                file=discord.File(img),
            )
示例#2
0
    async def activity(self,
                       ctx,
                       user: typing.Optional[discord.Member] = None,
                       scope=""):
        """See your hourly activity chart (GMT)."""
        if user is None:
            user = ctx.author

        is_global = scope.lower() == "global"

        if is_global:
            activitydata = db.global_activitydata(user.id)
        else:
            activitydata = db.get_user_activity(ctx.guild.id, user.id)

        if activitydata is None:
            return await ctx.send("No activity found!")

        activities = list(activitydata)
        xp = sum(activities)
        level = util.get_level(xp)

        title = (
            f"LVL {level} | {xp - util.get_xp(level)}/"
            f"{util.xp_to_next_level(level)} XP to levelup | Total xp: {xp}")

        await self.bot.loop.run_in_executor(
            None, lambda: plotter.create_graph(
                activities, str(user.color), title=title))

        with open("downloads/graph.png", "rb") as img:
            await ctx.send(
                f"`Hourly cumulative {'global' if is_global else 'server'} activity for {user}`",
                file=discord.File(img),
            )
示例#3
0
    async def activity(self, ctx, user: discord.Member = None):
        """See your hourly server activity chart (GMT)"""
        if user is None:
            user = ctx.author

        activitydata = db.activitydata(ctx.guild.id, user.id)
        if activitydata is None:
            return await ctx.send(
                f"No activity for `{user}` found on this server")

        activities = list(activitydata[3:])
        xp = sum(activities)
        level = util.get_level(xp)

        title = f"LVL {level} | {xp - util.get_xp(level)}/" \
                f"{util.xp_to_next_level(level)} XP to levelup | Total xp: {xp}"

        await self.bot.loop.run_in_executor(
            None, lambda: plotter.create_graph(
                activities, str(user.color), title=title))

        with open("downloads/graph.png", "rb") as img:
            await ctx.send(f"`Hourly cumulative server activity for {user}`",
                           file=discord.File(img))