Skip to content

Commit

Permalink
Remove fluff
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghostopheles committed Jun 28, 2024
1 parent 272e396 commit 57b8a62
Showing 1 changed file with 0 additions and 82 deletions.
82 changes: 0 additions & 82 deletions cogs/user_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,85 +321,3 @@ def default(self, obj):
if isinstance(obj, UserConfigFile):
return obj.to_json()
return super().default(self, obj)


class ConfigFileDecoder(json.JSONDecoder):
def __init__(self, config_file: UserConfigFile, *args, **kwargs):
super().__init__(*args, **kwargs)
self.config_file = config_file

def decode(self, json_string):
parsed_data = super().decode(json_string)
if "users" in parsed_data and "lookup" in parsed_data and self.config_file:
return self.config_file.__populate()
return parsed_data


class UserCFG:
CONFIG = CacheConfig()

def is_valid_branch(self, branch: str):
return SUPPORTED_PRODUCTS.has_key(branch)

def lookup(self, branch: str) -> list[int]:
data = self.read()

return data["lookup"][branch]

def make_unique(self, obj: list) -> list:
return list(set(obj))

def subscribe(self, user_id: int, branch: str) -> tuple[bool, str]:
if not self.is_valid_branch(branch):
return False, "Invalid branch"

config = self.read()

lookup = config["lookup"][branch]
if user_id in lookup:
return False, "Already subscribed"

lookup.append(user_id)
lookup = self.make_unique(lookup)

user_id = str(user_id)
user_config = config["users"]
if not user_id in user_config.keys():
user_config[user_id] = self.get_default_user_entry()

watchlist = user_config[user_id]["watchlist"]
watchlist.append(branch)
watchlist = self.make_unique(watchlist)

self.write(config)
return True, "Success"

def get_subscribed(self, user_id: int):
config = self.read()

user_id = str(user_id)
users = config["users"]
if user_id not in users.keys():
users[user_id] = self.get_default_user_entry()

watchlist = config["users"][user_id]["watchlist"]
return watchlist

def unsubscribe(self, user_id: int, branch: str) -> tuple[bool, str]:
if not self.is_valid_branch(branch):
return False, "Invalid branch"

config = self.read()

lookup = config["lookup"][branch]
if user_id not in lookup:
return False, "Not subscribed"

lookup.remove(user_id)

user_id = str(user_id)
user_watchlist = config["users"][user_id]["watchlist"]
user_watchlist.remove(branch)

self.write(config)
return True, "Success"

0 comments on commit 57b8a62

Please sign in to comment.