mirror of https://gitlab.com/litecord/litecord.git
Add basic guild available updates
- add litecord.guild_memory_store - storage: add fetch of unavailable field
This commit is contained in:
parent
85749f2c8e
commit
4a50ceeb67
|
|
@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
"""
|
||||
|
||||
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('/<int:guild_id>', 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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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):
|
||||
|
|
|
|||
2
run.py
2
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_):
|
||||
|
|
|
|||
Loading…
Reference in New Issue