Skip to content

Commit

Permalink
Merge pull request #77 from Tibo-Ulens/hotfix
Browse files Browse the repository at this point in the history
Remove freudr statistics due to the anti-emiel clique crying about it
  • Loading branch information
Tibo-Ulens authored Feb 6, 2024
2 parents 68d5f50 + 0a1bf8b commit ce6b4e2
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 89 deletions.
17 changes: 0 additions & 17 deletions bot/extensions/fun/freudr.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import asyncio
import time
from discord import Member, app_commands, Interaction, Embed

from bot.bot import Bot
from bot.decorators import check_user_is_verified
from bot.extensions import ErrorHandledCog
from models.profile import Profile
from models.profile_statistics import ProfileStatistics


class Freudr(ErrorHandledCog):
@staticmethod
async def ensure_has_statistics(id1: int, id2: int, guild_id: int):
await asyncio.gather(
*[
ProfileStatistics.get(id1, guild_id),
ProfileStatistics.get(id2, guild_id),
]
)

@staticmethod
def hash_match(user_id, crush_id) -> int:
if user_id <= crush_id:
Expand Down Expand Up @@ -68,8 +57,6 @@ async def like(self, ia: Interaction, crush: Member):
ephemeral=True,
)

await self.ensure_has_statistics(ia.user.id, crush.id, ia.guild_id)

profile = await Profile.find_by_discord_id(ia.user.id)

if crush.id in profile.crushes:
Expand Down Expand Up @@ -129,8 +116,6 @@ async def unlike(self, ia: Interaction, crush: Member):
"https://www.wikihow.com/Love-Yourself", ephemeral=True
)

await self.ensure_has_statistics(ia.user.id, crush.id, ia.guild_id)

profile = await Profile.find_by_discord_id(ia.user.id)

if crush.id not in profile.crushes:
Expand All @@ -155,8 +140,6 @@ async def unlike(self, ia: Interaction, crush: Member):
async def show_list(self, ia: Interaction):
profile = await Profile.find_by_discord_id(ia.user.id)

await self.ensure_has_statistics(ia.user.id, ia.user.id, ia.guild_id)

if not profile.crushes:
return await ia.response.send_message(
"You don't have any crushes, use '/freudr like <user>' to get started",
Expand Down
23 changes: 0 additions & 23 deletions bot/extensions/fun/stats/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ def __init__(self):
label="Confession Exposures",
value="exposed",
),
SelectOption(
label="Freudr Likes",
value="crush",
),
]

super().__init__(options=options)
Expand All @@ -47,9 +43,6 @@ async def callback(self, ia: Interaction):
elif value == "exposed":
self.set_default_option(1)
leaderboard = await self.make_exposed_leaderboard(ia)
elif value == "crush":
self.set_default_option(2)
leaderboard = await self.make_crush_leaderboard(ia)
else:
raise ValueError()

Expand Down Expand Up @@ -85,16 +78,6 @@ async def make_exposed_leaderboard(ia: Interaction) -> Embed:

return Embed(title="Most exposed members", description="\n".join(top_10))

@staticmethod
async def make_crush_leaderboard(ia: Interaction) -> Embed:
top_10 = await Profile.get_most_liked_top_10(ia.guild_id)

top_10 = [f"#{i + 1} - <@{p[0]}> ({p[1]})" for i, p in enumerate(top_10)]

return Embed(
title="Members with the most likes on Freudr", description="\n".join(top_10)
)


class Leaderboard(View):
def __init__(self, owner: Member):
Expand All @@ -121,7 +104,6 @@ async def show_me(self, ia: Interaction):
stats = await ProfileStatistics.get(ia.user.id, ia.guild_id)

rank = await user.get_freudpoint_rank(ia.guild_id)
likes = await user.get_freudr_likes()

profile_embed = (
Embed(title=f"{ia.user.display_name}s Profile", colour=ia.user.colour)
Expand All @@ -141,11 +123,6 @@ async def show_me(self, ia: Interaction):
value=stats.confession_exposed_count,
inline=False,
)
.add_field(
name="Likes on Freudr",
value=likes,
inline=False,
)
)

return await ia.response.send_message(embed=profile_embed)
Expand Down
49 changes: 0 additions & 49 deletions models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,38 +110,6 @@ async def find_verified_in_guild(cls, guild: Guild) -> list["Profile"]:
)
return list(profiles)

@classmethod
async def get_most_liked_top_10(cls, guild_id: int) -> list[tuple[int, int]]:
"""Get a top 10 of the most liked profiles"""

async with session_factory() as session:
result: Result = await session.execute(
text(
"""
select
discord_id,
(
select count(*)
from profile p2
where p1.discord_id = ANY(p2.crushes)
) as likes
from profile p1
where exists(
select *
from profile_statistics ps
where
ps.profile_discord_id=p1.discord_id
and ps.config_guild_id=:guild_id
)
order by likes desc
limit 10;
"""
),
{"guild_id": guild_id},
)

return result.all()

async def get_freudpoint_rank(self, guild_id: int) -> int:
"""Get a profiles FreudPoint score rank in a given guild"""

Expand All @@ -157,23 +125,6 @@ async def get_freudpoint_rank(self, guild_id: int) -> int:

return profiles.index(self)

async def get_freudr_likes(self) -> int:
"""Get the total number of likes this profile has on Freudr"""

async with session_factory() as session:
result: Result = await session.execute(
text(
"""
select count(*)
from profile p
where :discord_id = ANY(p.crushes);
"""
),
{"discord_id": self.discord_id},
)

return result.first()[0]

def is_verified(self) -> bool:
"""Check if a profile is verified"""

Expand Down

0 comments on commit ce6b4e2

Please sign in to comment.