示例#1
0
def get_kudos_given_since(giver_id: int, since: datetime):
    points = (Points.select(Points.awarded, Points.points).where(
        Points.giver_id == giver_id,
        Points.point_type == "KUDOS",
        Points.awarded >= since,
    ).order_by(Points.awarded.desc()).tuples())
    return [(point[0], point[1]) for point in points]
示例#2
0
 async def bump_leaderboard(self, ctx):
     scores = list(
         Points.select(Points.user_id,
                       peewee.fn.sum(Points.points)).order_by(
                           peewee.fn.sum(Points.points).desc()).group_by(
                               Points.user_id).filter(
                                   Points.point_type == "BUMP",
                                   Points.awarded > datetime.utcnow() -
                                   timedelta(days=self._bump_score_days),
                               ).limit(5))
     if scores:
         king = scores.pop(0)
         embed = nextcord.Embed(
             title="Bump Leaders",
             description=
             f"Here are the people who have bumped the most in the last {self._bump_score_days} days!",
             color=YELLOW,
         ).add_field(
             name="👑 Bump King 👑",
             value=
             f"{ctx.guild.get_member(king.user_id).mention} is our Bump King with {king.sum} bumps!",
             inline=False,
         )
         if scores:
             embed.add_field(
                 name="Runners Up",
                 value="\n".join(
                     f"- {ctx.guild.get_member(bumper.user_id).mention} has bumped {bumper.sum} times"
                     for bumper in scores),
                 inline=False,
             )
         await ctx.send(embed=embed)
     else:
         await ctx.send("No bumpers found")
示例#3
0
 def get_bump_king_id(self):
     scores = (Points.select(Points.user_id, peewee.fn.sum(
         Points.points)).order_by(peewee.fn.sum(
             Points.points).desc()).group_by(Points.user_id).filter(
                 Points.point_type == "BUMP",
                 Points.awarded >
                 datetime.utcnow() - timedelta(days=self._bump_score_days),
             ).limit(1))
     return scores.scalar() if scores.count() else None
示例#4
0
def get_highest_kudos(num_users: int = -1) -> List[Tuple[int, int]]:
    query = (Points.select(Points.user_id, peewee.fn.SUM(
        Points.points)).group_by(Points.user_id).order_by(
            peewee.fn.SUM(
                Points.points).desc()).where(Points.point_type == "KUDOS"))
    if num_users > 0:
        query.limit(num_users)

    return query.tuples()
示例#5
0
def give_user_kudos(kudos: int, user_id: int, giver_id: int, message_id: int):
    kudos = Points(
        awarded=datetime.utcnow(),
        user_id=user_id,
        giver_id=giver_id,
        message_id=message_id,
        points=kudos,
        point_type="KUDOS",
    )
    kudos.save()
示例#6
0
    async def bumpers(self, ctx):
        scores = (Points.select(Points.user_id, peewee.fn.sum(
            Points.points)).order_by(peewee.fn.sum(
                Points.points).desc()).group_by(Points.user_id).filter(
                    Points.point_type == "BUMP",
                    Points.awarded >
                    datetime.utcnow() - timedelta(days=self._bump_score_days),
                ).limit(30).tuples())
        message = []
        for emoji, (user_id, points) in zip(
            ["🥇", "🥈", "🥉"] + ["✨"] * max(len(scores) - 3, 0), scores):
            member: nextcord.Member = self.server.get_member(user_id)
            message.append(
                f"{emoji} {member.mention if member else '*Unknown*'} **{str(points)}**"
            )

        await ctx.send(embed=nextcord.Embed(
            title="🏆 Bumping Leaderboard 🏆",
            description="\n".join(message),
            color=YELLOW,
        ))
示例#7
0
 async def bumps(self, ctx):
     bumps = (Points.select(Points.user_id, Points.awarded).order_by(
         Points.awarded.desc()).filter(
             Points.point_type == "BUMP",
             Points.awarded >
             datetime.utcnow() - timedelta(days=self._bump_score_days),
         ).tuples())
     message = ["**Most Recent**"]
     now = datetime.utcnow()
     days = 0
     for index, (user_id, awarded) in enumerate(bumps, start=1):
         if (now - awarded) // timedelta(days=1) > days:
             days = (now - awarded) // timedelta(days=1)
             message.append(f"\n**{days * 24} Hours Ago**")
         message.append(
             f"{index}. <t:{awarded.timestamp():.0f}:t> {ctx.guild.get_member(user_id) or '*Unknown User*'}"
         )
     await ctx.send(embed=nextcord.Embed(
         title="👊 Bump List 🕰",
         description="\n".join(message),
         color=YELLOW,
     ))
示例#8
0
 def award_bump_points(self, author_id):
     bump = Points(awarded=datetime.utcnow(),
                   user_id=author_id,
                   points=1,
                   point_type="BUMP")
     bump.save()
示例#9
0
def remove_kudos(message_id: int, giver_id: int):
    Points.delete().where(
        Points.message_id == message_id,
        Points.giver_id == giver_id,
        Points.point_type == "KUDOS",
    ).execute()
示例#10
0
def get_user_kudos(user_id) -> int:
    kudos = (Points.select(peewee.fn.SUM(Points.points)).where(
        Points.user_id == user_id, Points.point_type == "KUDOS").scalar())
    return 0 if kudos is None else kudos