Skip to content

Commit

Permalink
Add get_item_id() limiter option in order to not exceed Discord API…
Browse files Browse the repository at this point in the history
… slash command limits.

The limiter option make sure that not more than 25 item ids are returned, so that it does not exceed the maximum of 25 entries for slash command `choice`.
  • Loading branch information
notsniped committed Mar 22, 2024
1 parent 7fecd1d commit 5eab9e4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions framework/isobot/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ def __init__(self, db_path: str):
self.db_path = db_path
with open(db_path, 'r') as f: self.db = json.load(f)

def get_item_ids(self) -> list:
def get_item_ids(self, *, limited: bool = False) -> list:
"""Fetches and returns all of the shop item ids."""
json_list = list()
for h in self.db: json_list.append(str(h))
if limited:
cnt = 0
for item in self.db:
if cnt <= 24:
cnt += 1
json_list.append(str(item))
else:
for h in self.db: json_list.append(str(h))
return json_list

def get_item_names(self) -> list:
Expand Down

0 comments on commit 5eab9e4

Please sign in to comment.