-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f86420
commit bf356ce
Showing
2 changed files
with
34 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,43 @@ | ||
from modules.supabase import supabaseClient | ||
|
||
|
||
def fetch_config(is_prod: bool): | ||
def fetch_configs(is_prod: bool): | ||
supabase_data = supabaseClient.table("server_config").select("*").eq('prod_config', is_prod).execute().data | ||
transformed_dict = { | ||
item['guild_id']: {key: value for key, value in item.items() if key != 'guild_id'} for item in supabase_data | ||
} | ||
return transformed_dict | ||
|
||
|
||
def set_config(guild_id: int, key: str, value: str, is_prod: bool): | ||
supabaseClient.table("server_config").update({key: value}).eq("guild_id", guild_id).eq( | ||
def fetch_guild_config(guild_id: int, is_prod: bool): | ||
response = supabaseClient.table("server_config").select("*").eq("guild_id", guild_id).eq( | ||
"prod_config", is_prod | ||
).execute() | ||
# if there is no data, return an empty dict | ||
if len(response.data) == 0: | ||
return {} | ||
return response.data[0] | ||
|
||
def create_new_config(guild_id: int, server_name: str, is_prod: bool): | ||
response = supabaseClient.table("server_config").insert( | ||
{ | ||
"guild_id": guild_id, | ||
"server_name": server_name, | ||
"prod_config": is_prod, | ||
} | ||
).execute() | ||
return response.data | ||
|
||
|
||
def set_config(guild_id: int, key: str, value: str, is_prod: bool) -> list: | ||
response = supabaseClient.table("server_config").update({key: value}).eq("guild_id", guild_id).eq( | ||
"prod_config", is_prod | ||
).execute() | ||
return response.data | ||
|
||
def remove_config(guild_id: int, is_prod: bool) -> list: | ||
response = supabaseClient.table("server_config").delete().eq("guild_id", guild_id).eq( | ||
"prod_config", is_prod | ||
).execute() | ||
return response.data | ||
|