From: Georgios Atheridis Date: Thu, 12 May 2022 07:48:17 +0000 (+0000) Subject: fixed avail and unavail X-Git-Url: https://git.atheridis.org/?a=commitdiff_plain;h=f1e79c68c0def8609e9d986398cae84857bf7eec;p=ihaspeks%2Faptbot-ihaspeks.git fixed avail and unavail --- diff --git a/skgyorugo/commands/available.py b/skgyorugo/commands/available.py index 2e4a33a..8eaa8c8 100644 --- a/skgyorugo/commands/available.py +++ b/skgyorugo/commands/available.py @@ -44,16 +44,64 @@ def main(bot: Bot, message: Message): UPDATE lol_queue SET - position = position + 1 + position = ( + CASE + WHEN ( + SELECT + position + FROM + lol_queue + WHERE + twitch_id = ? + ) < ( + SELECT + max(position) + FROM + lol_queue + WHERE + available = 1 + ORDER BY + position + LIMIT ( + SELECT + data + FROM + lol_queue_data + WHERE + name = 'queuesize' + ) + ) + THEN position + 1 + ELSE position + END + ) WHERE - position >= ( + position > ( SELECT - data - FROM - lol_queue_data + max(position) + FROM + lol_queue WHERE - name = 'queuesize' - ) + priority_queue = 1 + OR position <= ( + SELECT + max(position) + FROM + lol_queue + WHERE + available = 1 + ORDER BY + position + LIMIT ( + SELECT + data + FROM + lol_queue_data + WHERE + name = 'queuesize' + ) + ) + ); """ ) @@ -63,14 +111,63 @@ def main(bot: Bot, message: Message): lol_queue SET available = 1, - position = ( + priority_queue = ( + CASE + WHEN ( + SELECT + position + FROM + lol_queue + WHERE + twitch_id = ? + ) < ( + SELECT + max(position) + FROM + lol_queue + WHERE + available = 1 + ORDER BY + position + LIMIT ( + SELECT + data + FROM + lol_queue_data + WHERE + name = 'queuesize' + ) + ) + THEN 1 + ELSE 0 + END + ), + position = 1 + ( SELECT - data + max(position) FROM - lol_queue_data + lol_queue WHERE - name = 'queuesize' - ), + priority_queue = 1 + OR position <= ( + SELECT + max(position) + FROM + lol_queue + WHERE + available = 1 + ORDER BY + position + LIMIT ( + SELECT + data + FROM + lol_queue_data + WHERE + name = 'queuesize' + ) + ) + ) time_remaining = time_remaining - (? - last_available) WHERE twitch_id = ? diff --git a/skgyorugo/commands/forceavailable.py b/skgyorugo/commands/forceavailable.py index 6a340c8..092e095 100644 --- a/skgyorugo/commands/forceavailable.py +++ b/skgyorugo/commands/forceavailable.py @@ -47,16 +47,64 @@ def main(bot: Bot, message: Message): UPDATE lol_queue SET - position = position + 1 + position = ( + CASE + WHEN ( + SELECT + position + FROM + lol_queue + WHERE + twitch_id = ? + ) < ( + SELECT + max(position) + FROM + lol_queue + WHERE + available = 1 + ORDER BY + position + LIMIT ( + SELECT + data + FROM + lol_queue_data + WHERE + name = 'queuesize' + ) + ) + THEN position + 1 + ELSE position + END + ) WHERE - position >= ( + position > ( SELECT - data - FROM - lol_queue_data + max(position) + FROM + lol_queue WHERE - name = 'queuesize' - ) + priority_queue = 1 + OR position <= ( + SELECT + max(position) + FROM + lol_queue + WHERE + available = 1 + ORDER BY + position + LIMIT ( + SELECT + data + FROM + lol_queue_data + WHERE + name = 'queuesize' + ) + ) + ); """ ) @@ -66,14 +114,63 @@ def main(bot: Bot, message: Message): lol_queue SET available = 1, - position = ( + priority_queue = ( + CASE + WHEN ( + SELECT + position + FROM + lol_queue + WHERE + twitch_id = ? + ) < ( + SELECT + max(position) + FROM + lol_queue + WHERE + available = 1 + ORDER BY + position + LIMIT ( + SELECT + data + FROM + lol_queue_data + WHERE + name = 'queuesize' + ) + ) + THEN 1 + ELSE 0 + END + ), + position = 1 + ( SELECT - data + max(position) FROM - lol_queue_data + lol_queue WHERE - name = 'queuesize' - ), + priority_queue = 1 + OR position <= ( + SELECT + max(position) + FROM + lol_queue + WHERE + available = 1 + ORDER BY + position + LIMIT ( + SELECT + data + FROM + lol_queue_data + WHERE + name = 'queuesize' + ) + ) + ) time_remaining = time_remaining - (? - last_available) WHERE twitch_id = ? diff --git a/skgyorugo/commands/forceunavailable.py b/skgyorugo/commands/forceunavailable.py index 4df29e0..1b355d1 100644 --- a/skgyorugo/commands/forceunavailable.py +++ b/skgyorugo/commands/forceunavailable.py @@ -44,7 +44,7 @@ def main(bot: Bot, message: Message): c.execute( """ - UPDATE lol_queue SET available = 0, last_available = ? WHERE twitch_id = ?; + UPDATE lol_queue SET available = 0, priority_queue = null, last_available = ? WHERE twitch_id = ?; """, ( int(time.time()), diff --git a/skgyorugo/commands/unavailable.py b/skgyorugo/commands/unavailable.py index c95b59c..9a2fb15 100644 --- a/skgyorugo/commands/unavailable.py +++ b/skgyorugo/commands/unavailable.py @@ -41,7 +41,7 @@ def main(bot: Bot, message: Message): c.execute( """ - UPDATE lol_queue SET available = 0, last_available = ? WHERE twitch_id = ?; + UPDATE lol_queue SET available = 0, priority_queue = null, last_available = ? WHERE twitch_id = ?; """, ( int(time.time()), diff --git a/skgyorugo/database_manager.py b/skgyorugo/database_manager.py index 718c274..7f079bf 100644 --- a/skgyorugo/database_manager.py +++ b/skgyorugo/database_manager.py @@ -99,6 +99,7 @@ def create_lol_database(): last_available INTEGER, time_remaining INTEGER NOT NULL, team INTEGER, + priority_queue INTEGER, PRIMARY KEY (twitch_id) ); """