Commit 7eb70310 authored by Violet White's avatar Violet White Committed by Elizabeth Myers
Browse files

Listgroup command

parent ebfd1e53
......@@ -68,5 +68,8 @@ def init():
from dcp.commands.messagedelete import MessageDelete
type_registry[] = MessageDelete()
from dcp.commands.listgroups import ListGroups
type_registry[] = ListGroups()
from dcp.commands.quit import Quit
type_registry[] = Quit()
from sqlalchemy.future import select
from sqlalchemy.exc import NoResultFound
from dcp.config import conf
from dcp.db import (StorageUser,StorageGroup,StorageGroupAcl,
from dcp.frame import Frame
from dcp.client import username_to_client
from dcp.send import sendto_user, sendto_group, filt_exclude_client
from dcp.commands import Command, CommandError
class ListGroups(Command):
name = 'listgroups'
async def pre_reg(self, _client, _frame):
raise CommandError("You have not identified")
async def reg(self, client, frame):
target = "none"
if len(frame.dst)>1:
if target != 'user' and target != 'none':
raise CommandError(f"{target} is Invalid usage. Accepts user or none, for listing groups you are a member of, or all publicly listed groups on the server")
async with async_session() as session:
async with session.begin():
if target == 'user':
stmt = (select(StorageGroup)
stmt = (select(StorageGroup))
result = await session.execute(stmt)
reply = Frame.create(f'@{client.username}', frame.dst,
{'groups':[ for i in result]})
await sendto_user(client.username,reply)
......@@ -125,6 +125,15 @@ Format:
See the Registration flow for more information.
### ```listgroups```
Client Format:
```{... 'type': 'listgroups', 'dst':('user'|'group')}```
Server Format:
```{... 'type': 'listgroups', 'dst':('user'|'group'),'data':{'groups':[<strings>]}}```
List the groups on the server when the destination is specified as `group` or not at all,
or the groups the user is a part of when `user` is specified.
### ```login```
Client: ```{... 'type': 'login', 'data': {'auth': 'password', 'password': <string>}}```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment