Coverage for slidge/command/__init__.py: 88%
8 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-12-01 19:36 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-12-01 19:36 +0000
1"""
2This module implements an unified API to define :term:`adhoc <Ad-hoc Command>`
3or :term:`chatbot <Chatbot Command>` commands. Subclass a :class:`Command`,
4:class:`ContactCommand` or :class:`RoomCommand`, and list it in your gateway's
5:attr:`.BaseGateway.COMMANDS`.
6"""
8from types import ModuleType
10from . import admin, register, user
11from .base import (
12 Command,
13 CommandAccess,
14 CommandBase,
15 CommandResponseType,
16 Confirmation,
17 ContactCommand,
18 Form,
19 FormField,
20 RoomCommand,
21 SearchResult,
22 TableResult,
23)
25BUILTIN_COMMANDS: tuple[type[CommandBase], ...] = (
26 admin.ListUsers,
27 admin.SlidgeInfo,
28 admin.DeleteUser,
29 admin.ChangeLoglevel,
30 admin.Exec,
31 register.Register,
32 user.Search,
33 user.SyncContacts,
34 user.ListContacts,
35 user.ListRooms,
36 user.ListSpaces,
37 user.ListRoomsInSpace,
38 user.SpaceCreate,
39 user.SpaceDelete,
40 user.SpaceAdmin,
41 user.Login,
42 user.CreateGroup,
43 user.Preferences,
44 user.Unregister,
45 user.LeaveGroup,
46 user.InviteInRooms,
47)
48"""
49The commands slidge provides out of the box. They are registered by default
50via :attr:`.BaseGateway.COMMANDS`.
51"""
54def commands_from_module(module: ModuleType) -> tuple[type[CommandBase], ...]:
55 """Collect all :class:`.CommandBase` subclasses defined in ``module``.
57 Does not include classes which are imported from another module or abstract classes.
58 """
59 return tuple(
60 obj
61 for obj in vars(module).values()
62 if isinstance(obj, type)
63 and issubclass(obj, CommandBase)
64 and obj.__module__ == module.__name__
65 and not any(x is NotImplemented for x in (obj.NAME, obj.NODE, obj.CHAT_COMMAND))
66 )
69__all__ = (
70 "BUILTIN_COMMANDS",
71 "Command",
72 "CommandAccess",
73 "CommandBase",
74 "CommandResponseType",
75 "Confirmation",
76 "ContactCommand",
77 "Form",
78 "FormField",
79 "RoomCommand",
80 "SearchResult",
81 "TableResult",
82 "commands_from_module",
83)