Loading cog/actions.py +12 −6 Original line number Diff line number Diff line Loading @@ -2131,7 +2131,12 @@ async def monitor_snipe_merits(client, *, repeat=True): # pragma: no cover await asyncio.sleep(delay_seconds) # Notify here client.send_message(snipe_chan, "@here Snipe members it is tick day and there are 12 hours remaining.") with cogdb.session_scope(cogdb.Session) as session: if cogdb.query.get_all_snipe_holds(session): client.send_message( snipe_chan, "@here Snipe members it is tick day and there are 12 hours remaining." ) # 30 mins to tick ping remaining in message next_date = next_cycle - datetime.timedelta(minutes=30) Loading @@ -2143,6 +2148,7 @@ async def monitor_snipe_merits(client, *, repeat=True): # pragma: no cover # Notify members holding with cogdb.session_scope(cogdb.Session) as session: if cogdb.query.get_all_snipe_holds(session): to_contact = cogdb.query.get_snipe_members_holding(session, client) msg = """__Final Snipe Reminder__ There are less than **30 minutes left**. The following members are still holding. Loading cogdb/query.py +15 −7 Original line number Diff line number Diff line Loading @@ -115,7 +115,7 @@ def users_with_all_merits(session): """ return session.query(DiscordUser, (sqla.func.ifnull(FortUser.dropped, 0) + sqla.func.ifnull(UMUser.combo, 0)).label('total')).\ outerjoin(FortUser, DiscordUser.pref_name == FortUser.name).\ outerjoin(UMUser, DiscordUser.pref_name == UMUser.name,).\ outerjoin(UMUser, DiscordUser.pref_name == UMUser.name).\ order_by(sqla.desc("total")).\ all() Loading Loading @@ -1302,6 +1302,19 @@ def get_vote(session, discord_id, vote_type): return the_vote def get_all_snipe_holds(session): """ Args: session: A session onto the db. Returns: A list of UMHolds for the snipe sheet. Empty by default. """ return session.query(UMHold).\ filter(UMHold.sheet_src == EUMSheet.snipe, UMHold.held > 0).\ all() def get_snipe_members_holding(session, guild): """ Find the members who are holding merits on the snipe sheet. Loading @@ -1316,14 +1329,9 @@ def get_snipe_members_holding(session, guild): Returns: A string formatted mentioning or naming all users with snipe merits. """ snipe_holds = session.query(UMHold).\ filter(UMHold.sheet_src == EUMSheet.snipe, UMHold.held > 0).\ all() template_msg = "{} is holding {} merits in {}\n" reply = "" for hold in snipe_holds: for hold in get_all_snipe_holds(session): duser = hold.user.discord_user found = guild.get_member_named(duser.pref_name) mention = found.mention if found else duser.pref_name Loading tests/cogdb/test_query.py +4 −4 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ import pytest import cog.exc import cogdb from cogdb.schema import (DiscordUser, FortSystem, FortUser, FortOrder, UMUser, UMHold, AdminPerm, ChannelPerm, RolePerm, UMUser, UMHold, EUMSheet, AdminPerm, ChannelPerm, RolePerm, KOS, TrackSystem, TrackSystemCached, TrackByID, OCRTracker, OCRTrigger, OCRPrep, Global, Vote, VoteType) import cogdb.query Loading Loading @@ -848,9 +848,9 @@ def test_vote_get(session, f_dusers, f_vote_testbed): assert the_vote.vote == VoteType.prep def test_get_snipe_members_holding(session, f_bot, f_dusers, f_um_testbed): expected = 'User3 is holding 5000 merits in ToSnipe\n' results = cogdb.query.get_snipe_members_holding(session, f_bot.guilds[0]) def test_get_all_snipe_holds(session, f_bot, f_dusers, f_um_testbed): expected = [UMHold(id=7, sheet_src=EUMSheet.snipe, system_id=7, user_id=3, held=5000, redeemed=1200)] results = cogdb.query.get_all_snipe_holds(session) assert results == expected Loading Loading
cog/actions.py +12 −6 Original line number Diff line number Diff line Loading @@ -2131,7 +2131,12 @@ async def monitor_snipe_merits(client, *, repeat=True): # pragma: no cover await asyncio.sleep(delay_seconds) # Notify here client.send_message(snipe_chan, "@here Snipe members it is tick day and there are 12 hours remaining.") with cogdb.session_scope(cogdb.Session) as session: if cogdb.query.get_all_snipe_holds(session): client.send_message( snipe_chan, "@here Snipe members it is tick day and there are 12 hours remaining." ) # 30 mins to tick ping remaining in message next_date = next_cycle - datetime.timedelta(minutes=30) Loading @@ -2143,6 +2148,7 @@ async def monitor_snipe_merits(client, *, repeat=True): # pragma: no cover # Notify members holding with cogdb.session_scope(cogdb.Session) as session: if cogdb.query.get_all_snipe_holds(session): to_contact = cogdb.query.get_snipe_members_holding(session, client) msg = """__Final Snipe Reminder__ There are less than **30 minutes left**. The following members are still holding. Loading
cogdb/query.py +15 −7 Original line number Diff line number Diff line Loading @@ -115,7 +115,7 @@ def users_with_all_merits(session): """ return session.query(DiscordUser, (sqla.func.ifnull(FortUser.dropped, 0) + sqla.func.ifnull(UMUser.combo, 0)).label('total')).\ outerjoin(FortUser, DiscordUser.pref_name == FortUser.name).\ outerjoin(UMUser, DiscordUser.pref_name == UMUser.name,).\ outerjoin(UMUser, DiscordUser.pref_name == UMUser.name).\ order_by(sqla.desc("total")).\ all() Loading Loading @@ -1302,6 +1302,19 @@ def get_vote(session, discord_id, vote_type): return the_vote def get_all_snipe_holds(session): """ Args: session: A session onto the db. Returns: A list of UMHolds for the snipe sheet. Empty by default. """ return session.query(UMHold).\ filter(UMHold.sheet_src == EUMSheet.snipe, UMHold.held > 0).\ all() def get_snipe_members_holding(session, guild): """ Find the members who are holding merits on the snipe sheet. Loading @@ -1316,14 +1329,9 @@ def get_snipe_members_holding(session, guild): Returns: A string formatted mentioning or naming all users with snipe merits. """ snipe_holds = session.query(UMHold).\ filter(UMHold.sheet_src == EUMSheet.snipe, UMHold.held > 0).\ all() template_msg = "{} is holding {} merits in {}\n" reply = "" for hold in snipe_holds: for hold in get_all_snipe_holds(session): duser = hold.user.discord_user found = guild.get_member_named(duser.pref_name) mention = found.mention if found else duser.pref_name Loading
tests/cogdb/test_query.py +4 −4 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ import pytest import cog.exc import cogdb from cogdb.schema import (DiscordUser, FortSystem, FortUser, FortOrder, UMUser, UMHold, AdminPerm, ChannelPerm, RolePerm, UMUser, UMHold, EUMSheet, AdminPerm, ChannelPerm, RolePerm, KOS, TrackSystem, TrackSystemCached, TrackByID, OCRTracker, OCRTrigger, OCRPrep, Global, Vote, VoteType) import cogdb.query Loading Loading @@ -848,9 +848,9 @@ def test_vote_get(session, f_dusers, f_vote_testbed): assert the_vote.vote == VoteType.prep def test_get_snipe_members_holding(session, f_bot, f_dusers, f_um_testbed): expected = 'User3 is holding 5000 merits in ToSnipe\n' results = cogdb.query.get_snipe_members_holding(session, f_bot.guilds[0]) def test_get_all_snipe_holds(session, f_bot, f_dusers, f_um_testbed): expected = [UMHold(id=7, sheet_src=EUMSheet.snipe, system_id=7, user_id=3, held=5000, redeemed=1200)] results = cogdb.query.get_all_snipe_holds(session) assert results == expected Loading