Skip to content

Commit

Permalink
one more fix
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Oct 7, 2024
1 parent 746fffd commit 675228a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
11 changes: 10 additions & 1 deletion jg/coop/models/club.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class ClubUser(BaseModel):
expires_at = DateTimeField(null=True)
is_bot = BooleanField(default=False)
is_member = BooleanField(default=True)
is_trespassing = BooleanField(null=True)
has_avatar = BooleanField(default=True)
avatar_path = CharField(null=True)
display_name = CharField()
Expand Down Expand Up @@ -200,11 +201,15 @@ def subscription_types_breakdown(cls) -> dict[str, int]:
row.subscription_type: row.count
for row in cls.select(
cls.subscription_type,
fn.COUNT(cls.id).alias("count"),
fn.count(cls.id).alias("count"),
)
.where(
cls.is_bot == False, # noqa: E712
cls.is_member == True, # noqa: E712
(
(cls.is_trespassing == False) # noqa: E712
| cls.is_trespassing.is_null()
),
)
.group_by(cls.subscription_type)
.order_by(cls.subscription_type)
Expand All @@ -226,6 +231,10 @@ def members_listing(cls, shuffle=False) -> Iterable[Self]:
members = cls.listing().where(
cls.is_bot == False, # noqa: E712
cls.is_member == True, # noqa: E712
(
(cls.is_trespassing == False) # noqa: E712
| cls.is_trespassing.is_null()
),
)
if shuffle:
members = members.order_by(fn.random())
Expand Down
26 changes: 13 additions & 13 deletions jg/coop/sync/members/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def main(history_path: Path, today: date):
for member in ClubUser.members_listing()
if member.id not in seen_discord_ids
)
extra_members_ids = []
trespassing_members_ids = []
for member in remaining_members:
if member.id in ADMIN_MEMBER_IDS:
logger.debug(f"Adding subscription type to admin user #{member.id}")
Expand All @@ -155,11 +155,11 @@ def main(history_path: Path, today: date):
f"Discord member #{member.id} doesn't have a Memberful account!"
)
logger.debug(f"User #{member.id}:\n{pformat(model_to_dict(member))}")
member.is_member = False
member.is_trespassing = True
member.save()
extra_members_ids.append(member.id)
if extra_members_ids:
discord_task.run(report_extra_members, extra_members_ids)
trespassing_members_ids.append(member.id)
if trespassing_members_ids:
discord_task.run(report_trespassing_members, trespassing_members_ids)

logger.info("Checking consistency")
for member in ClubUser.members_listing():
Expand Down Expand Up @@ -204,21 +204,21 @@ def main(history_path: Path, today: date):


@db.connection_context()
async def report_extra_members(client: ClubClient, extra_members_ids: list[int]):
async def report_trespassing_members(client: ClubClient, members_ids: list[int]):
logger.info("Prevent mistakes caused by out-of-sync data")
extra_members = []
for extra_member_id in extra_members_ids:
trespassing_members = []
for member_id in members_ids:
try:
extra_members.append(await client.club_guild.fetch_member(extra_member_id))
trespassing_members.append(await client.club_guild.fetch_member(member_id))
except NotFound:
logger.info(f"User #{extra_member_id} is not on Discord anymore, skipping")
if extra_members:
logger.info(f"Verified {len(extra_members)} members, reporting them")
logger.info(f"User #{member_id} is not on Discord anymore, skipping")
if trespassing_members:
logger.info(f"Verified {len(trespassing_members)} members, reporting them")
channel = await client.fetch_channel(ClubChannelID.BUSINESS)
with mutating_discord(channel) as proxy:
await proxy.send(
"⚠️ Vypadá to, že tito členové nemají účet na Memberful: "
f"{', '.join(member.mention for member in extra_members)}"
f"{', '.join(member.mention for member in trespassing_members)}"
)
else:
logger.info("After all, there are no users to report")
Expand Down

0 comments on commit 675228a

Please sign in to comment.