-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguild_settings.py
38 lines (27 loc) · 1.14 KB
/
guild_settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
import os
SETTINGS_PATH = os.getenv("SETTINGS_PATH", "./guild_settings.json")
def load_guild_settings():
if os.path.exists(SETTINGS_PATH):
with open(SETTINGS_PATH, "r") as file:
return json.load(file)
else:
return {"default_prefix": "!", "guilds": {}}
def save_guild_settings(guild_settings):
with open(SETTINGS_PATH, "w") as file:
json.dump(guild_settings, file, indent=4)
def get_prefix(bot, message, guild_settings):
guild_id = str(message.guild.id)
return (
guild_settings["guilds"]
.get(guild_id, {})
.get("prefix", guild_settings["default_prefix"])
)
def set_guild_prefix(guild_id, prefix, guild_settings):
guild_settings["guilds"][guild_id] = guild_settings["guilds"].get(guild_id, {})
guild_settings["guilds"][guild_id]["prefix"] = prefix
save_guild_settings(guild_settings)
def set_guild_resources_channel(guild_id, channel_id, guild_settings):
guild_settings["guilds"][guild_id] = guild_settings["guilds"].get(guild_id, {})
guild_settings["guilds"][guild_id]["resources_channel"] = channel_id
save_guild_settings(guild_settings)