Skip to content

Commit

Permalink
Games have min and max player counts
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Nov 12, 2023
1 parent 43e16f8 commit 94f49a9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/heckbot/cogs/picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from bot import db_conn
from bot import HeckBot

PLAYERS_MAX = 100
PLAYERS_MIN = 1
RESOURCE_DIR = 'resources/'


Expand Down Expand Up @@ -61,7 +63,16 @@ def load_games(self):
with open(f'{RESOURCE_DIR}/games.csv') as f:
csv_reader = csv.reader(f)
for line in csv_reader:
self._game_constraints[line[0]] = int(line[1])
if len(line) == 1:
self._game_constraints[line[0]] = (PLAYERS_MIN, PLAYERS_MAX)
elif len(line) == 2:
self._game_constraints[line[0]] = (
int(line[1]), PLAYERS_MAX
)
else:
self._game_constraints[line[0]] = (
int(line[1]), int(line[2])
)

for player_file in os.listdir(f'{RESOURCE_DIR}/players'):
player = player_file.rpartition('.')[0]
Expand All @@ -84,7 +95,7 @@ def random_game(self, players: list[str]):
options = options.intersection(self._owned_games[player])
options = {
item for item in options
if self._game_constraints[item] <= len(players)
if self._game_constraints[item][0] <= len(players) <= self._game_constraints[item][1]
}
if len(options) == 0:
r += "No games available. Y'all are too picky."
Expand Down

0 comments on commit 94f49a9

Please sign in to comment.