diff --git a/litecord/blueprints/admin_api/guilds.py b/litecord/blueprints/admin_api/guilds.py
index 4e64fb5..0efe9ca 100644
--- a/litecord/blueprints/admin_api/guilds.py
+++ b/litecord/blueprints/admin_api/guilds.py
@@ -17,11 +17,11 @@ along with this program. If not, see .
"""
-from quart import Blueprint, jsonify, current_app as app
+from quart import Blueprint, jsonify, current_app as app, request
from litecord.auth import admin_check
-# from litecord.schemas import validate
-# from litecord.admin_schemas import GUILD_UPDATE
+from litecord.schemas import validate
+from litecord.admin_schemas import GUILD_UPDATE
bp = Blueprint('guilds_admin', __name__)
@@ -34,16 +34,19 @@ async def get_guild(guild_id: int):
await app.storage.get_guild(guild_id)
)
+
@bp.route('/', methods=['PATCH'])
async def update_guild(guild_id: int):
await admin_check()
- # j = validate(await request.get_json(), GUILD_UPDATE)
+ j = validate(await request.get_json(), GUILD_UPDATE)
- # TODO: add guild availability update, we don't store it, should we?
# TODO: what happens to the other guild attributes when its
# unavailable? do they vanish?
+ if 'unavailable' in j:
+ app.guild_store.set(guild_id, 'unavailable', True)
+
guild = await app.storage.get_guild(guild_id)
await app.dispatcher.dispatch_guild(guild_id, 'GUILD_UPDATE', guild)
return jsonify(guild)
diff --git a/litecord/guild_memory_store.py b/litecord/guild_memory_store.py
new file mode 100644
index 0000000..f092f19
--- /dev/null
+++ b/litecord/guild_memory_store.py
@@ -0,0 +1,17 @@
+
+class GuildMemoryStore:
+ """Store in-memory properties about guilds.
+
+ I could have just used Redis... probably too overkill to add
+ aioredis to the already long depedency list, plus, I don't need
+ """
+ def __init__(self):
+ self._store = {}
+
+ def get(self, guild_id: int, attribute: str, default=None):
+ """get a key"""
+ return self._store.get(f'{guild_id}:{attribute}', default)
+
+ def set(self, guild_id: int, attribute: str, value):
+ """set a key"""
+ self._store[f'{guild_id}:{attribute}'] = value
diff --git a/litecord/storage.py b/litecord/storage.py
index 3446fe2..136f84f 100644
--- a/litecord/storage.py
+++ b/litecord/storage.py
@@ -192,6 +192,12 @@ class Storage:
drow['max_presences'] = 1000
drow['max_members'] = 1000
+ # this is kept in memory
+ drow['unavailable'] = self.app.guild_store.get(
+ guild_id, 'unavailable', False)
+
+ # TODO: strip everything when unavailable
+
return drow
async def _member_basic(self, guild_id: int, member_id: int):
diff --git a/run.py b/run.py
index ef5e118..d851fdc 100644
--- a/run.py
+++ b/run.py
@@ -75,6 +75,7 @@ from litecord.presence import PresenceManager
from litecord.images import IconManager
from litecord.jobs import JobManager
from litecord.voice.manager import VoiceManager
+from litecord.guild_memory_store import GuildMemoryStore
from litecord.gateway.gateway import websocket_handler
@@ -246,6 +247,7 @@ def init_app_managers(app_):
app_.storage.presence = app_.presence
app_.voice = VoiceManager(app_)
+ app_.guild_store = GuildMemoryStore()
async def api_index(app_):