@honeybbq/teamspeak 0.0.1 → 1.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +726 -2
- package/dist/client/abort.d.ts +5 -0
- package/dist/client/abort.d.ts.map +1 -0
- package/dist/client/abort.js +23 -0
- package/dist/client/abort.js.map +1 -0
- package/dist/client/address.d.ts +17 -0
- package/dist/client/address.d.ts.map +1 -0
- package/dist/client/address.js +66 -0
- package/dist/client/address.js.map +1 -0
- package/dist/client/api/voice.d.ts +24 -0
- package/dist/client/api/voice.d.ts.map +1 -0
- package/dist/client/api/voice.js +33 -0
- package/dist/client/api/voice.js.map +1 -0
- package/dist/client/capabilities.d.ts +68 -0
- package/dist/client/capabilities.d.ts.map +1 -0
- package/dist/client/capabilities.js +59 -0
- package/dist/client/capabilities.js.map +1 -0
- package/dist/client/client.d.ts +196 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +1523 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/commands.d.ts +66 -0
- package/dist/client/commands.d.ts.map +1 -0
- package/dist/client/commands.js +162 -0
- package/dist/client/commands.js.map +1 -0
- package/dist/client/crypto/crypt-ops.d.ts +7 -0
- package/dist/client/crypto/crypt-ops.d.ts.map +1 -0
- package/dist/client/crypto/crypt-ops.js +2 -0
- package/dist/client/crypto/crypt-ops.js.map +1 -0
- package/dist/client/crypto/crypt.d.ts +37 -0
- package/dist/client/crypto/crypt.d.ts.map +1 -0
- package/dist/client/crypto/crypt.js +203 -0
- package/dist/client/crypto/crypt.js.map +1 -0
- package/dist/client/crypto/eax.d.ts +12 -0
- package/dist/client/crypto/eax.d.ts.map +1 -0
- package/dist/client/crypto/eax.js +118 -0
- package/dist/client/crypto/eax.js.map +1 -0
- package/dist/client/crypto/identity.d.ts +97 -0
- package/dist/client/crypto/identity.d.ts.map +1 -0
- package/dist/client/crypto/identity.js +412 -0
- package/dist/client/crypto/identity.js.map +1 -0
- package/dist/client/crypto/index.d.ts +7 -0
- package/dist/client/crypto/index.d.ts.map +1 -0
- package/dist/client/crypto/index.js +5 -0
- package/dist/client/crypto/index.js.map +1 -0
- package/dist/client/crypto/primitives.d.ts +43 -0
- package/dist/client/crypto/primitives.d.ts.map +1 -0
- package/dist/client/crypto/primitives.js +116 -0
- package/dist/client/crypto/primitives.js.map +1 -0
- package/dist/client/diagnostics.d.ts +45 -0
- package/dist/client/diagnostics.d.ts.map +1 -0
- package/dist/client/diagnostics.js +30 -0
- package/dist/client/diagnostics.js.map +1 -0
- package/dist/client/discovery/index.d.ts +2 -0
- package/dist/client/discovery/index.d.ts.map +1 -0
- package/dist/client/discovery/index.js +2 -0
- package/dist/client/discovery/index.js.map +1 -0
- package/dist/client/discovery/resolver.d.ts +26 -0
- package/dist/client/discovery/resolver.d.ts.map +1 -0
- package/dist/client/discovery/resolver.js +275 -0
- package/dist/client/discovery/resolver.js.map +1 -0
- package/dist/client/errors.d.ts +82 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/errors.js +201 -0
- package/dist/client/errors.js.map +1 -0
- package/dist/client/events.d.ts +3 -0
- package/dist/client/events.d.ts.map +1 -0
- package/dist/client/events.js +8 -0
- package/dist/client/events.js.map +1 -0
- package/dist/client/handshake/crypt-handshake.d.ts +17 -0
- package/dist/client/handshake/crypt-handshake.d.ts.map +1 -0
- package/dist/client/handshake/crypt-handshake.js +128 -0
- package/dist/client/handshake/crypt-handshake.js.map +1 -0
- package/dist/client/handshake/crypt-init2.d.ts +7 -0
- package/dist/client/handshake/crypt-init2.d.ts.map +1 -0
- package/dist/client/handshake/crypt-init2.js +37 -0
- package/dist/client/handshake/crypt-init2.js.map +1 -0
- package/dist/client/handshake/index.d.ts +4 -0
- package/dist/client/handshake/index.d.ts.map +1 -0
- package/dist/client/handshake/index.js +4 -0
- package/dist/client/handshake/index.js.map +1 -0
- package/dist/client/handshake/license.d.ts +35 -0
- package/dist/client/handshake/license.d.ts.map +1 -0
- package/dist/client/handshake/license.js +169 -0
- package/dist/client/handshake/license.js.map +1 -0
- package/dist/client/handshake.d.ts +27 -0
- package/dist/client/handshake.d.ts.map +1 -0
- package/dist/client/handshake.js +126 -0
- package/dist/client/handshake.js.map +1 -0
- package/dist/client/helpers.d.ts +6 -0
- package/dist/client/helpers.d.ts.map +1 -0
- package/dist/client/helpers.js +13 -0
- package/dist/client/helpers.js.map +1 -0
- package/dist/client/hooks.d.ts +7 -0
- package/dist/client/hooks.d.ts.map +1 -0
- package/dist/client/hooks.js +28 -0
- package/dist/client/hooks.js.map +1 -0
- package/dist/client/index.d.ts +26 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +28 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/reconnect.d.ts +12 -0
- package/dist/client/reconnect.d.ts.map +1 -0
- package/dist/client/reconnect.js +44 -0
- package/dist/client/reconnect.js.map +1 -0
- package/dist/client/throttle.d.ts +20 -0
- package/dist/client/throttle.d.ts.map +1 -0
- package/dist/client/throttle.js +83 -0
- package/dist/client/throttle.js.map +1 -0
- package/dist/client/trace.d.ts +223 -0
- package/dist/client/trace.d.ts.map +1 -0
- package/dist/client/trace.js +13 -0
- package/dist/client/trace.js.map +1 -0
- package/dist/client/transfer.d.ts +111 -0
- package/dist/client/transfer.d.ts.map +1 -0
- package/dist/client/transfer.js +243 -0
- package/dist/client/transfer.js.map +1 -0
- package/dist/client/transport/generation-window.d.ts +30 -0
- package/dist/client/transport/generation-window.d.ts.map +1 -0
- package/dist/client/transport/generation-window.js +97 -0
- package/dist/client/transport/generation-window.js.map +1 -0
- package/dist/client/transport/handler.d.ts +61 -0
- package/dist/client/transport/handler.d.ts.map +1 -0
- package/dist/client/transport/handler.js +793 -0
- package/dist/client/transport/handler.js.map +1 -0
- package/dist/client/transport/index.d.ts +6 -0
- package/dist/client/transport/index.d.ts.map +1 -0
- package/dist/client/transport/index.js +5 -0
- package/dist/client/transport/index.js.map +1 -0
- package/dist/client/transport/packet.d.ts +36 -0
- package/dist/client/transport/packet.d.ts.map +1 -0
- package/dist/client/transport/packet.js +55 -0
- package/dist/client/transport/packet.js.map +1 -0
- package/dist/client/transport/quicklz.d.ts +24 -0
- package/dist/client/transport/quicklz.d.ts.map +1 -0
- package/dist/client/transport/quicklz.js +179 -0
- package/dist/client/transport/quicklz.js.map +1 -0
- package/dist/client/types.d.ts +226 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +39 -0
- package/dist/client/types.js.map +1 -0
- package/dist/core/api/channels.d.ts +182 -0
- package/dist/core/api/channels.d.ts.map +1 -0
- package/dist/core/api/channels.js +155 -0
- package/dist/core/api/channels.js.map +1 -0
- package/dist/core/api/clients.d.ts +304 -0
- package/dist/core/api/clients.d.ts.map +1 -0
- package/dist/core/api/clients.js +260 -0
- package/dist/core/api/clients.js.map +1 -0
- package/dist/core/api/command.d.ts +305 -0
- package/dist/core/api/command.d.ts.map +1 -0
- package/dist/core/api/command.js +363 -0
- package/dist/core/api/command.js.map +1 -0
- package/dist/core/api/files.d.ts +153 -0
- package/dist/core/api/files.d.ts.map +1 -0
- package/dist/core/api/files.js +181 -0
- package/dist/core/api/files.js.map +1 -0
- package/dist/core/api/groups.d.ts +248 -0
- package/dist/core/api/groups.d.ts.map +1 -0
- package/dist/core/api/groups.js +271 -0
- package/dist/core/api/groups.js.map +1 -0
- package/dist/core/api/moderation.d.ts +205 -0
- package/dist/core/api/moderation.d.ts.map +1 -0
- package/dist/core/api/moderation.js +209 -0
- package/dist/core/api/moderation.js.map +1 -0
- package/dist/core/api/parse.d.ts +16 -0
- package/dist/core/api/parse.d.ts.map +1 -0
- package/dist/core/api/parse.js +40 -0
- package/dist/core/api/parse.js.map +1 -0
- package/dist/core/api/server.d.ts +310 -0
- package/dist/core/api/server.d.ts.map +1 -0
- package/dist/core/api/server.js +290 -0
- package/dist/core/api/server.js.map +1 -0
- package/dist/core/command/command.d.ts +20 -0
- package/dist/core/command/command.d.ts.map +1 -0
- package/dist/core/command/command.js +112 -0
- package/dist/core/command/command.js.map +1 -0
- package/dist/core/command/ids.d.ts +125 -0
- package/dist/core/command/ids.d.ts.map +1 -0
- package/dist/core/command/ids.js +85 -0
- package/dist/core/command/ids.js.map +1 -0
- package/dist/core/command/parser.d.ts +17 -0
- package/dist/core/command/parser.d.ts.map +1 -0
- package/dist/core/command/parser.js +65 -0
- package/dist/core/command/parser.js.map +1 -0
- package/dist/core/command/request.d.ts +61 -0
- package/dist/core/command/request.d.ts.map +1 -0
- package/dist/core/command/request.js +64 -0
- package/dist/core/command/request.js.map +1 -0
- package/dist/core/command/responses.d.ts +59 -0
- package/dist/core/command/responses.d.ts.map +1 -0
- package/dist/core/command/responses.js +74 -0
- package/dist/core/command/responses.js.map +1 -0
- package/dist/core/command-name.d.ts +333 -0
- package/dist/core/command-name.d.ts.map +1 -0
- package/dist/core/command-name.js +331 -0
- package/dist/core/command-name.js.map +1 -0
- package/dist/core/enums.d.ts +146 -0
- package/dist/core/enums.d.ts.map +1 -0
- package/dist/core/enums.js +132 -0
- package/dist/core/enums.js.map +1 -0
- package/dist/core/errorcode.d.ts +413 -0
- package/dist/core/errorcode.d.ts.map +1 -0
- package/dist/core/errorcode.js +410 -0
- package/dist/core/errorcode.js.map +1 -0
- package/dist/core/errors.d.ts +111 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +233 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/events.d.ts +207 -0
- package/dist/core/events.d.ts.map +1 -0
- package/dist/core/events.js +6 -0
- package/dist/core/events.js.map +1 -0
- package/dist/core/helpers.d.ts +42 -0
- package/dist/core/helpers.d.ts.map +1 -0
- package/dist/core/helpers.js +156 -0
- package/dist/core/helpers.js.map +1 -0
- package/dist/core/index.d.ts +35 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +34 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/internal.d.ts +23 -0
- package/dist/core/internal.d.ts.map +1 -0
- package/dist/core/internal.js +20 -0
- package/dist/core/internal.js.map +1 -0
- package/dist/core/middleware.d.ts +14 -0
- package/dist/core/middleware.d.ts.map +1 -0
- package/dist/core/middleware.js +18 -0
- package/dist/core/middleware.js.map +1 -0
- package/dist/core/notification-name.d.ts +154 -0
- package/dist/core/notification-name.d.ts.map +1 -0
- package/dist/core/notification-name.js +152 -0
- package/dist/core/notification-name.js.map +1 -0
- package/dist/core/notifications.d.ts +43 -0
- package/dist/core/notifications.d.ts.map +1 -0
- package/dist/core/notifications.js +116 -0
- package/dist/core/notifications.js.map +1 -0
- package/dist/core/permission-name.d.ts +533 -0
- package/dist/core/permission-name.d.ts.map +1 -0
- package/dist/core/permission-name.js +531 -0
- package/dist/core/permission-name.js.map +1 -0
- package/dist/core/permission.d.ts +31 -0
- package/dist/core/permission.d.ts.map +1 -0
- package/dist/core/permission.js +20 -0
- package/dist/core/permission.js.map +1 -0
- package/dist/core/property-name.d.ts +403 -0
- package/dist/core/property-name.d.ts.map +1 -0
- package/dist/core/property-name.js +405 -0
- package/dist/core/property-name.js.map +1 -0
- package/dist/core/reason.d.ts +39 -0
- package/dist/core/reason.d.ts.map +1 -0
- package/dist/core/reason.js +36 -0
- package/dist/core/reason.js.map +1 -0
- package/dist/core/reconnect.d.ts +59 -0
- package/dist/core/reconnect.d.ts.map +1 -0
- package/dist/core/reconnect.js +55 -0
- package/dist/core/reconnect.js.map +1 -0
- package/dist/core/types.d.ts +110 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +27 -0
- package/dist/core/types.js.map +1 -0
- package/dist/query/client.d.ts +194 -0
- package/dist/query/client.d.ts.map +1 -0
- package/dist/query/client.js +967 -0
- package/dist/query/client.js.map +1 -0
- package/dist/query/errors.d.ts +61 -0
- package/dist/query/errors.d.ts.map +1 -0
- package/dist/query/errors.js +100 -0
- package/dist/query/errors.js.map +1 -0
- package/dist/query/index.d.ts +36 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +34 -0
- package/dist/query/index.js.map +1 -0
- package/dist/query/knownhosts.d.ts +61 -0
- package/dist/query/knownhosts.d.ts.map +1 -0
- package/dist/query/knownhosts.js +223 -0
- package/dist/query/knownhosts.js.map +1 -0
- package/dist/query/lines.d.ts +14 -0
- package/dist/query/lines.d.ts.map +1 -0
- package/dist/query/lines.js +29 -0
- package/dist/query/lines.js.map +1 -0
- package/dist/query/options.d.ts +187 -0
- package/dist/query/options.d.ts.map +1 -0
- package/dist/query/options.js +213 -0
- package/dist/query/options.js.map +1 -0
- package/dist/query/reconnect.d.ts +29 -0
- package/dist/query/reconnect.d.ts.map +1 -0
- package/dist/query/reconnect.js +87 -0
- package/dist/query/reconnect.js.map +1 -0
- package/dist/query/ssh.d.ts +345 -0
- package/dist/query/ssh.d.ts.map +1 -0
- package/dist/query/ssh.js +241 -0
- package/dist/query/ssh.js.map +1 -0
- package/dist/query/stream.d.ts +38 -0
- package/dist/query/stream.d.ts.map +1 -0
- package/dist/query/stream.js +70 -0
- package/dist/query/stream.js.map +1 -0
- package/dist/query/tcp.d.ts +38 -0
- package/dist/query/tcp.d.ts.map +1 -0
- package/dist/query/tcp.js +53 -0
- package/dist/query/tcp.js.map +1 -0
- package/dist/query/transport.d.ts +36 -0
- package/dist/query/transport.d.ts.map +1 -0
- package/dist/query/transport.js +2 -0
- package/dist/query/transport.js.map +1 -0
- package/dist/query/web.d.ts +54 -0
- package/dist/query/web.d.ts.map +1 -0
- package/dist/query/web.js +146 -0
- package/dist/query/web.js.map +1 -0
- package/dist/versions/index.d.ts +3094 -0
- package/dist/versions/index.d.ts.map +1 -0
- package/dist/versions/index.js +9237 -0
- package/dist/versions/index.js.map +1 -0
- package/package.json +118 -4
- package/src/client/abort.ts +24 -0
- package/src/client/address.ts +74 -0
- package/src/client/api/voice.ts +61 -0
- package/src/client/capabilities.ts +106 -0
- package/src/client/client.ts +1809 -0
- package/src/client/commands.ts +193 -0
- package/src/client/crypto/crypt-ops.ts +6 -0
- package/src/client/crypto/crypt.ts +275 -0
- package/src/client/crypto/eax.ts +152 -0
- package/src/client/crypto/identity.ts +484 -0
- package/src/client/crypto/index.ts +21 -0
- package/src/client/crypto/primitives.ts +141 -0
- package/src/client/diagnostics.ts +58 -0
- package/src/client/discovery/index.ts +1 -0
- package/src/client/discovery/resolver.ts +325 -0
- package/src/client/errors.ts +217 -0
- package/src/client/events.ts +12 -0
- package/src/client/handshake/crypt-handshake.ts +157 -0
- package/src/client/handshake/crypt-init2.ts +48 -0
- package/src/client/handshake/index.ts +3 -0
- package/src/client/handshake/license.ts +208 -0
- package/src/client/handshake.ts +150 -0
- package/src/client/helpers.ts +10 -0
- package/src/client/hooks.ts +30 -0
- package/src/client/index.ts +93 -0
- package/src/client/reconnect.ts +43 -0
- package/src/client/throttle.ts +92 -0
- package/src/client/trace.ts +237 -0
- package/src/client/transfer.ts +436 -0
- package/src/client/transport/generation-window.ts +108 -0
- package/src/client/transport/handler.ts +926 -0
- package/src/client/transport/index.ts +14 -0
- package/src/client/transport/packet.ts +69 -0
- package/src/client/transport/quicklz.ts +209 -0
- package/src/client/types.ts +268 -0
- package/src/core/api/channels.ts +396 -0
- package/src/core/api/clients.ts +654 -0
- package/src/core/api/command.ts +563 -0
- package/src/core/api/files.ts +405 -0
- package/src/core/api/groups.ts +622 -0
- package/src/core/api/moderation.ts +525 -0
- package/src/core/api/parse.ts +52 -0
- package/src/core/api/server.ts +709 -0
- package/src/core/command/command.ts +125 -0
- package/src/core/command/ids.ts +149 -0
- package/src/core/command/parser.ts +68 -0
- package/src/core/command/request.ts +119 -0
- package/src/core/command/responses.ts +114 -0
- package/src/core/command-name.ts +334 -0
- package/src/core/enums.ts +167 -0
- package/src/core/errorcode.ts +412 -0
- package/src/core/errors.ts +258 -0
- package/src/core/events.ts +219 -0
- package/src/core/helpers.ts +161 -0
- package/src/core/index.ts +126 -0
- package/src/core/internal.ts +23 -0
- package/src/core/middleware.ts +24 -0
- package/src/core/notification-name.ts +155 -0
- package/src/core/notifications.ts +157 -0
- package/src/core/permission-name.ts +538 -0
- package/src/core/permission.ts +34 -0
- package/src/core/property-name.ts +411 -0
- package/src/core/reason.ts +38 -0
- package/src/core/reconnect.ts +98 -0
- package/src/core/types.ts +138 -0
- package/src/query/client.ts +1132 -0
- package/src/query/errors.ts +108 -0
- package/src/query/index.ts +65 -0
- package/src/query/knownhosts.ts +257 -0
- package/src/query/lines.ts +28 -0
- package/src/query/options.ts +388 -0
- package/src/query/reconnect.ts +84 -0
- package/src/query/ssh.ts +614 -0
- package/src/query/stream.ts +91 -0
- package/src/query/tcp.ts +85 -0
- package/src/query/transport.ts +35 -0
- package/src/query/web.ts +195 -0
- package/src/versions/index.ts +10774 -0
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Channel groups, the permission catalogue, and the privilege keys that grant groups.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
nonZero,
|
|
7
|
+
uint,
|
|
8
|
+
U32,
|
|
9
|
+
firstRow,
|
|
10
|
+
exec,
|
|
11
|
+
query,
|
|
12
|
+
list,
|
|
13
|
+
encodeFields,
|
|
14
|
+
nonEmpty,
|
|
15
|
+
parsePermission,
|
|
16
|
+
permissionParam,
|
|
17
|
+
createdGroupID,
|
|
18
|
+
str,
|
|
19
|
+
big,
|
|
20
|
+
num,
|
|
21
|
+
bool,
|
|
22
|
+
icon,
|
|
23
|
+
date,
|
|
24
|
+
} from "./command.js";
|
|
25
|
+
import type { Params, PermissionEntry, WireNames } from "./command.js";
|
|
26
|
+
import type { CommandExecutor, CommandOptions } from "../command/request.js";
|
|
27
|
+
import type {
|
|
28
|
+
ChannelGroupID,
|
|
29
|
+
ChannelID,
|
|
30
|
+
ClientDBID,
|
|
31
|
+
IconID,
|
|
32
|
+
PermissionID,
|
|
33
|
+
ServerGroupID,
|
|
34
|
+
} from "../command/ids.js";
|
|
35
|
+
import {
|
|
36
|
+
asChannelGroupID,
|
|
37
|
+
asChannelID,
|
|
38
|
+
asClientDBID,
|
|
39
|
+
asPermissionID,
|
|
40
|
+
asServerGroupID,
|
|
41
|
+
} from "../command/ids.js";
|
|
42
|
+
import { PermissionTarget, PrivilegeKeyType } from "../enums.js";
|
|
43
|
+
import type { GroupType } from "../enums.js";
|
|
44
|
+
import type { Permission } from "../permission.js";
|
|
45
|
+
|
|
46
|
+
/** A channel group as `channelgrouplist` reports it. */
|
|
47
|
+
export interface ChannelGroup {
|
|
48
|
+
/** The group's id. */
|
|
49
|
+
readonly id: ChannelGroupID;
|
|
50
|
+
/** The group's name. */
|
|
51
|
+
readonly name: string;
|
|
52
|
+
/** What kind of group this is, one of {@link GroupType}. */
|
|
53
|
+
readonly type: number;
|
|
54
|
+
/** The group's icon, or undefined for none. */
|
|
55
|
+
readonly iconID: IconID | undefined;
|
|
56
|
+
/** Whether membership is stored, rather than lost when the server restarts. */
|
|
57
|
+
readonly savedInDatabase: boolean;
|
|
58
|
+
/** Where the group sorts among the others; a 32-bit value. */
|
|
59
|
+
readonly sortID: number;
|
|
60
|
+
/** Where the group's name shows beside a member's nickname, one of {@link GroupNameMode}. */
|
|
61
|
+
readonly nameMode: number;
|
|
62
|
+
/** The power needed to modify the group. */
|
|
63
|
+
readonly modifyPower: number;
|
|
64
|
+
/** The power needed to add a member. */
|
|
65
|
+
readonly memberAddPower: number;
|
|
66
|
+
/** The power needed to remove a member. */
|
|
67
|
+
readonly memberRemovePower: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const parseChannelGroup = (row: Record<string, string>): ChannelGroup => ({
|
|
71
|
+
id: asChannelGroupID(big(row, "cgid")),
|
|
72
|
+
name: str(row, "name"),
|
|
73
|
+
type: num(row, "type"),
|
|
74
|
+
iconID: icon(row, "iconid"),
|
|
75
|
+
savedInDatabase: bool(row, "savedb"),
|
|
76
|
+
sortID: num(row, "sortid"),
|
|
77
|
+
nameMode: num(row, "namemode"),
|
|
78
|
+
modifyPower: num(row, "n_modifyp"),
|
|
79
|
+
memberAddPower: num(row, "n_member_addp"),
|
|
80
|
+
memberRemovePower: num(row, "n_member_removep"),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/** Every channel group. */
|
|
84
|
+
export async function listChannelGroups(
|
|
85
|
+
client: CommandExecutor,
|
|
86
|
+
options?: CommandOptions,
|
|
87
|
+
): Promise<ChannelGroup[]> {
|
|
88
|
+
return (await list(client, "channelgrouplist", [], options)).map(parseChannelGroup);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Create a channel group.
|
|
93
|
+
*
|
|
94
|
+
* `type` is required, and always sent: the server's own default is
|
|
95
|
+
* `GroupType.Regular`, while the type's first value is `Template`, so leaving
|
|
96
|
+
* it to a default on either side is a trap.
|
|
97
|
+
*/
|
|
98
|
+
export async function createChannelGroup(
|
|
99
|
+
client: CommandExecutor,
|
|
100
|
+
name: string,
|
|
101
|
+
type: GroupType,
|
|
102
|
+
options?: CommandOptions,
|
|
103
|
+
): Promise<ChannelGroupID> {
|
|
104
|
+
const rows = await query(
|
|
105
|
+
client,
|
|
106
|
+
"channelgroupadd",
|
|
107
|
+
[
|
|
108
|
+
["name", name],
|
|
109
|
+
["type", type],
|
|
110
|
+
],
|
|
111
|
+
options,
|
|
112
|
+
);
|
|
113
|
+
return asChannelGroupID(createdGroupID(rows, "cgid", name, "channelgroupadd"));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** How a group is deleted. */
|
|
117
|
+
export interface GroupDeleteOptions extends CommandOptions {
|
|
118
|
+
/** Delete the group even while it has members; false by default (`force`, always sent). */
|
|
119
|
+
readonly force?: boolean | undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Delete a channel group. */
|
|
123
|
+
export async function deleteChannelGroup(
|
|
124
|
+
client: CommandExecutor,
|
|
125
|
+
cgid: ChannelGroupID,
|
|
126
|
+
options: GroupDeleteOptions = {},
|
|
127
|
+
): Promise<void> {
|
|
128
|
+
await exec(
|
|
129
|
+
client,
|
|
130
|
+
"channelgroupdel",
|
|
131
|
+
[
|
|
132
|
+
["cgid", cgid],
|
|
133
|
+
["force", options.force ?? false],
|
|
134
|
+
],
|
|
135
|
+
options,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Rename a channel group. */
|
|
140
|
+
export async function renameChannelGroup(
|
|
141
|
+
client: CommandExecutor,
|
|
142
|
+
cgid: ChannelGroupID,
|
|
143
|
+
name: string,
|
|
144
|
+
options?: CommandOptions,
|
|
145
|
+
): Promise<void> {
|
|
146
|
+
await exec(
|
|
147
|
+
client,
|
|
148
|
+
"channelgrouprename",
|
|
149
|
+
[
|
|
150
|
+
["cgid", cgid],
|
|
151
|
+
["name", name],
|
|
152
|
+
],
|
|
153
|
+
options,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Copy a channel group's permissions onto another; a `targetGroupID` of 0
|
|
159
|
+
* makes the server create a new group named `name`, of `type`.
|
|
160
|
+
*/
|
|
161
|
+
export async function copyChannelGroup(
|
|
162
|
+
client: CommandExecutor,
|
|
163
|
+
sourceGroupID: ChannelGroupID,
|
|
164
|
+
targetGroupID: ChannelGroupID,
|
|
165
|
+
name: string,
|
|
166
|
+
type: GroupType,
|
|
167
|
+
options?: CommandOptions,
|
|
168
|
+
): Promise<ChannelGroupID> {
|
|
169
|
+
const rows = await query(
|
|
170
|
+
client,
|
|
171
|
+
"channelgroupcopy",
|
|
172
|
+
[
|
|
173
|
+
["scgid", sourceGroupID],
|
|
174
|
+
["tcgid", targetGroupID],
|
|
175
|
+
["name", name],
|
|
176
|
+
["type", type],
|
|
177
|
+
],
|
|
178
|
+
options,
|
|
179
|
+
);
|
|
180
|
+
// Copying onto an existing group keeps that group's id.
|
|
181
|
+
if (targetGroupID !== 0n) return targetGroupID;
|
|
182
|
+
return asChannelGroupID(createdGroupID(rows, "cgid", name, "channelgroupcopy"));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Which channel group memberships {@link listChannelGroupClients} reports.
|
|
187
|
+
* Unset fields do not narrow the list.
|
|
188
|
+
*/
|
|
189
|
+
export interface ChannelGroupClientListOptions extends CommandOptions {
|
|
190
|
+
/** Only memberships in this channel (`cid`). */
|
|
191
|
+
readonly channelID?: ChannelID | undefined;
|
|
192
|
+
/** Only this client's memberships (`cldbid`). */
|
|
193
|
+
readonly databaseID?: ClientDBID | undefined;
|
|
194
|
+
/** Only memberships of this group (`cgid`). */
|
|
195
|
+
readonly groupID?: ChannelGroupID | undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// A filter of 0 matches nothing in particular, so it is omitted, as unset is.
|
|
199
|
+
const membershipFilterNames: WireNames<ChannelGroupClientListOptions> = {
|
|
200
|
+
channelID: ["cid", nonZero],
|
|
201
|
+
databaseID: ["cldbid", nonZero],
|
|
202
|
+
groupID: ["cgid", nonZero],
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/** One client holding one channel group in one channel. */
|
|
206
|
+
export interface ChannelGroupMembership {
|
|
207
|
+
/** The channel. */
|
|
208
|
+
readonly channelID: ChannelID;
|
|
209
|
+
/** The client's database id. */
|
|
210
|
+
readonly databaseID: ClientDBID;
|
|
211
|
+
/** The channel group. */
|
|
212
|
+
readonly groupID: ChannelGroupID;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Which channel group each client holds in which channel.
|
|
217
|
+
*
|
|
218
|
+
* Set at least one filter field to narrow it; called with none the server may
|
|
219
|
+
* return nothing.
|
|
220
|
+
*/
|
|
221
|
+
export async function listChannelGroupClients(
|
|
222
|
+
client: CommandExecutor,
|
|
223
|
+
options: ChannelGroupClientListOptions = {},
|
|
224
|
+
): Promise<ChannelGroupMembership[]> {
|
|
225
|
+
const rows = await list(
|
|
226
|
+
client,
|
|
227
|
+
"channelgroupclientlist",
|
|
228
|
+
encodeFields(options, membershipFilterNames),
|
|
229
|
+
options,
|
|
230
|
+
);
|
|
231
|
+
return rows.map((row) => ({
|
|
232
|
+
channelID: asChannelID(big(row, "cid")),
|
|
233
|
+
databaseID: asClientDBID(big(row, "cldbid")),
|
|
234
|
+
groupID: asChannelGroupID(big(row, "cgid")),
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** Permissions set on a channel group. */
|
|
239
|
+
export async function listChannelGroupPermissions(
|
|
240
|
+
client: CommandExecutor,
|
|
241
|
+
cgid: ChannelGroupID,
|
|
242
|
+
options?: CommandOptions,
|
|
243
|
+
): Promise<PermissionEntry[]> {
|
|
244
|
+
return (await list(client, "channelgrouppermlist", [["cgid", cgid]], options)).map(
|
|
245
|
+
parsePermission,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Set a permission on a channel group. */
|
|
250
|
+
export async function addChannelGroupPermission(
|
|
251
|
+
client: CommandExecutor,
|
|
252
|
+
cgid: ChannelGroupID,
|
|
253
|
+
permission: Permission,
|
|
254
|
+
value: number,
|
|
255
|
+
options?: CommandOptions,
|
|
256
|
+
): Promise<void> {
|
|
257
|
+
await exec(
|
|
258
|
+
client,
|
|
259
|
+
"channelgroupaddperm",
|
|
260
|
+
[["cgid", cgid], permissionParam(permission), ["permvalue", value]],
|
|
261
|
+
options,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Remove a permission from a channel group. */
|
|
266
|
+
export async function deleteChannelGroupPermission(
|
|
267
|
+
client: CommandExecutor,
|
|
268
|
+
cgid: ChannelGroupID,
|
|
269
|
+
permission: Permission,
|
|
270
|
+
options?: CommandOptions,
|
|
271
|
+
): Promise<void> {
|
|
272
|
+
await exec(client, "channelgroupdelperm", [["cgid", cgid], permissionParam(permission)], options);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ---- Permissions ------------------------------------------------------------
|
|
276
|
+
|
|
277
|
+
/** One permission in the server's catalogue. */
|
|
278
|
+
export interface PermissionInfo {
|
|
279
|
+
/** The permission's id on this server build (`permid`). */
|
|
280
|
+
readonly id: PermissionID;
|
|
281
|
+
/** The permission's name, such as "i_client_talk_power" (`permname`). */
|
|
282
|
+
readonly name: string;
|
|
283
|
+
/** What the permission controls (`permdesc`). */
|
|
284
|
+
readonly description: string;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* The server's full permission catalogue.
|
|
289
|
+
*
|
|
290
|
+
* Rows that name no permission — the group markers some servers interleave —
|
|
291
|
+
* are left out.
|
|
292
|
+
*
|
|
293
|
+
* ServerQuery sends each permission's id. The voice protocol sends none: there
|
|
294
|
+
* a permission's id is its place in the list, counting from 1, which `id` is
|
|
295
|
+
* set to.
|
|
296
|
+
*/
|
|
297
|
+
export async function listPermissions(
|
|
298
|
+
client: CommandExecutor,
|
|
299
|
+
options?: CommandOptions,
|
|
300
|
+
): Promise<PermissionInfo[]> {
|
|
301
|
+
const rows = await list(client, "permissionlist", [], options);
|
|
302
|
+
return rows
|
|
303
|
+
.filter((row) => row["permname"] !== undefined)
|
|
304
|
+
.map((row, index) => ({
|
|
305
|
+
id: asPermissionID(row["permid"] === undefined ? index + 1 : uint(row, "permid", U32)),
|
|
306
|
+
name: str(row, "permname"),
|
|
307
|
+
description: str(row, "permdesc"),
|
|
308
|
+
}));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Resolve a permission name to its numeric id, or undefined when the server
|
|
313
|
+
* knows no such permission.
|
|
314
|
+
*
|
|
315
|
+
* Needs an instance-level permission (`b_serverinstance_*`), which not even the
|
|
316
|
+
* Server Admin group holds by default — expect error 2568 until it is granted.
|
|
317
|
+
* Granted, it works over the voice protocol like any other query.
|
|
318
|
+
*/
|
|
319
|
+
export async function getPermissionIDByName(
|
|
320
|
+
client: CommandExecutor,
|
|
321
|
+
name: string,
|
|
322
|
+
options?: CommandOptions,
|
|
323
|
+
): Promise<PermissionID | undefined> {
|
|
324
|
+
const rows = await query(client, "permidgetbyname", [["permsid", name]], options);
|
|
325
|
+
if (rows.length === 0) return undefined;
|
|
326
|
+
return asPermissionID(uint(firstRow(rows, "permidgetbyname", "permid"), "permid", U32));
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* What a permission is set on, as `permfind` and `permoverview` report it:
|
|
331
|
+
* discriminated on `target`, so each kind carries its own typed ids. The wire
|
|
332
|
+
* sends them as `t`, `id1` and `id2`, whose meaning depends on `t`; a row with
|
|
333
|
+
* a target this table does not name is left out of the results.
|
|
334
|
+
*/
|
|
335
|
+
export type PermissionLocation =
|
|
336
|
+
| {
|
|
337
|
+
/** Set on a server group. */
|
|
338
|
+
readonly target: typeof PermissionTarget.ServerGroup;
|
|
339
|
+
/** The group (`id1`). */
|
|
340
|
+
readonly serverGroupID: ServerGroupID;
|
|
341
|
+
/** The permission (`p`). */
|
|
342
|
+
readonly permission: PermissionID;
|
|
343
|
+
}
|
|
344
|
+
| {
|
|
345
|
+
/** Set on a client, server-wide. */
|
|
346
|
+
readonly target: typeof PermissionTarget.Client;
|
|
347
|
+
/** The client (`id1`). */
|
|
348
|
+
readonly databaseID: ClientDBID;
|
|
349
|
+
/** The permission (`p`). */
|
|
350
|
+
readonly permission: PermissionID;
|
|
351
|
+
}
|
|
352
|
+
| {
|
|
353
|
+
/** Set on a channel. */
|
|
354
|
+
readonly target: typeof PermissionTarget.Channel;
|
|
355
|
+
/** The channel (`id1`). */
|
|
356
|
+
readonly channelID: ChannelID;
|
|
357
|
+
/** The permission (`p`). */
|
|
358
|
+
readonly permission: PermissionID;
|
|
359
|
+
}
|
|
360
|
+
| {
|
|
361
|
+
/** Set on a channel group, in one channel. */
|
|
362
|
+
readonly target: typeof PermissionTarget.ChannelGroup;
|
|
363
|
+
/** The channel (`id1`). */
|
|
364
|
+
readonly channelID: ChannelID;
|
|
365
|
+
/** The group (`id2`). */
|
|
366
|
+
readonly channelGroupID: ChannelGroupID;
|
|
367
|
+
/** The permission (`p`). */
|
|
368
|
+
readonly permission: PermissionID;
|
|
369
|
+
}
|
|
370
|
+
| {
|
|
371
|
+
/** Set on a client within one channel. */
|
|
372
|
+
readonly target: typeof PermissionTarget.ChannelClient;
|
|
373
|
+
/** The channel (`id1`). */
|
|
374
|
+
readonly channelID: ChannelID;
|
|
375
|
+
/** The client (`id2`). */
|
|
376
|
+
readonly databaseID: ClientDBID;
|
|
377
|
+
/** The permission (`p`). */
|
|
378
|
+
readonly permission: PermissionID;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
/** Read a location from a `permfind` or `permoverview` row; undefined for an unknown target. */
|
|
382
|
+
function parseLocation(row: Record<string, string>): PermissionLocation | undefined {
|
|
383
|
+
const permission = asPermissionID(uint(row, "p", U32));
|
|
384
|
+
const id1 = big(row, "id1");
|
|
385
|
+
const id2 = big(row, "id2");
|
|
386
|
+
switch (num(row, "t")) {
|
|
387
|
+
case PermissionTarget.ServerGroup:
|
|
388
|
+
return {
|
|
389
|
+
target: PermissionTarget.ServerGroup,
|
|
390
|
+
serverGroupID: asServerGroupID(id1),
|
|
391
|
+
permission,
|
|
392
|
+
};
|
|
393
|
+
case PermissionTarget.Client:
|
|
394
|
+
return { target: PermissionTarget.Client, databaseID: asClientDBID(id1), permission };
|
|
395
|
+
case PermissionTarget.Channel:
|
|
396
|
+
return { target: PermissionTarget.Channel, channelID: asChannelID(id1), permission };
|
|
397
|
+
case PermissionTarget.ChannelGroup:
|
|
398
|
+
return {
|
|
399
|
+
target: PermissionTarget.ChannelGroup,
|
|
400
|
+
channelID: asChannelID(id1),
|
|
401
|
+
channelGroupID: asChannelGroupID(id2),
|
|
402
|
+
permission,
|
|
403
|
+
};
|
|
404
|
+
case PermissionTarget.ChannelClient:
|
|
405
|
+
return {
|
|
406
|
+
target: PermissionTarget.ChannelClient,
|
|
407
|
+
channelID: asChannelID(id1),
|
|
408
|
+
databaseID: asClientDBID(id2),
|
|
409
|
+
permission,
|
|
410
|
+
};
|
|
411
|
+
default:
|
|
412
|
+
return undefined;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** Every place a permission is set. */
|
|
417
|
+
export async function findPermission(
|
|
418
|
+
client: CommandExecutor,
|
|
419
|
+
permission: Permission,
|
|
420
|
+
options?: CommandOptions,
|
|
421
|
+
): Promise<PermissionLocation[]> {
|
|
422
|
+
const rows = await list(client, "permfind", [permissionParam(permission)], options);
|
|
423
|
+
return rows.flatMap((row) => parseLocation(row) ?? []);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** How a permission applies, in a {@link PermissionOverviewEntry}. */
|
|
427
|
+
export interface PermissionOverviewValue {
|
|
428
|
+
/** The permission's value there (`v`). */
|
|
429
|
+
readonly value: number;
|
|
430
|
+
/** Whether the value is negated (`n`). */
|
|
431
|
+
readonly negated: boolean;
|
|
432
|
+
/** Whether it skips channel and client overrides (`s`). */
|
|
433
|
+
readonly skip: boolean;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** One permission applying to a client in a channel, as `permoverview` reports it. */
|
|
437
|
+
export type PermissionOverviewEntry = PermissionLocation & PermissionOverviewValue;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Every permission that applies to a client in a channel, from every source,
|
|
441
|
+
* unfiltered.
|
|
442
|
+
*
|
|
443
|
+
* It always asks for all of them (`permid=0`): the server requires a
|
|
444
|
+
* permission parameter — omitting it fails with 1539 — and treats 0 as "all".
|
|
445
|
+
* Each entry names its permission, so one is easy to pick out.
|
|
446
|
+
*/
|
|
447
|
+
export async function getPermissionOverview(
|
|
448
|
+
client: CommandExecutor,
|
|
449
|
+
cid: ChannelID,
|
|
450
|
+
cldbid: ClientDBID,
|
|
451
|
+
options?: CommandOptions,
|
|
452
|
+
): Promise<PermissionOverviewEntry[]> {
|
|
453
|
+
const rows = await list(
|
|
454
|
+
client,
|
|
455
|
+
"permoverview",
|
|
456
|
+
[
|
|
457
|
+
["cid", cid],
|
|
458
|
+
["cldbid", cldbid],
|
|
459
|
+
["permid", 0],
|
|
460
|
+
],
|
|
461
|
+
options,
|
|
462
|
+
);
|
|
463
|
+
return rows.flatMap((row) => {
|
|
464
|
+
const location = parseLocation(row);
|
|
465
|
+
if (location === undefined) return [];
|
|
466
|
+
return [{ ...location, value: num(row, "v"), negated: bool(row, "n"), skip: bool(row, "s") }];
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Wipe all permission overrides and restore the defaults.
|
|
472
|
+
*
|
|
473
|
+
* Destructive: every custom permission on the server goes. It also drops the
|
|
474
|
+
* caller's own rights, because it resets the group they rely on.
|
|
475
|
+
*/
|
|
476
|
+
export async function resetPermissions(
|
|
477
|
+
client: CommandExecutor,
|
|
478
|
+
options?: CommandOptions,
|
|
479
|
+
): Promise<void> {
|
|
480
|
+
await exec(client, "permreset", [], options);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// ---- Privilege keys ----------------------------------------------
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* A privilege key, which grants a group when redeemed. The server also
|
|
487
|
+
* accepts the older `token…` commands for the same keys; these functions use
|
|
488
|
+
* the `privilegekey…` ones.
|
|
489
|
+
*/
|
|
490
|
+
export interface PrivilegeKey {
|
|
491
|
+
/** The key itself. */
|
|
492
|
+
readonly token: string;
|
|
493
|
+
/** Which kind of group the key grants, one of {@link PrivilegeKeyType}. */
|
|
494
|
+
readonly type: number;
|
|
495
|
+
/** The server group a `PrivilegeKeyType.ServerGroup` key grants; undefined otherwise. */
|
|
496
|
+
readonly serverGroupID: ServerGroupID | undefined;
|
|
497
|
+
/** The channel group a `PrivilegeKeyType.ChannelGroup` key grants; undefined otherwise. */
|
|
498
|
+
readonly channelGroupID: ChannelGroupID | undefined;
|
|
499
|
+
/** The channel a `PrivilegeKeyType.ChannelGroup` key grants its group in; undefined otherwise. */
|
|
500
|
+
readonly channelID: ChannelID | undefined;
|
|
501
|
+
/** The key's description. */
|
|
502
|
+
readonly description: string;
|
|
503
|
+
/** When the key was created. */
|
|
504
|
+
readonly createdAt: Date | undefined;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Read a key. The wire carries the group as `token_id1` and the channel as
|
|
509
|
+
* `token_id2`, whichever kind of group it is; which typed field each belongs in
|
|
510
|
+
* depends on the token type.
|
|
511
|
+
*/
|
|
512
|
+
const parseKey = (row: Record<string, string>): PrivilegeKey => {
|
|
513
|
+
const type = num(row, "token_type");
|
|
514
|
+
const channelGroup = type === PrivilegeKeyType.ChannelGroup;
|
|
515
|
+
return {
|
|
516
|
+
token: str(row, "token"),
|
|
517
|
+
type,
|
|
518
|
+
serverGroupID: channelGroup ? undefined : asServerGroupID(big(row, "token_id1")),
|
|
519
|
+
channelGroupID: channelGroup ? asChannelGroupID(big(row, "token_id1")) : undefined,
|
|
520
|
+
channelID: channelGroup ? asChannelID(big(row, "token_id2")) : undefined,
|
|
521
|
+
description: str(row, "token_description"),
|
|
522
|
+
createdAt: date(row, "token_created"),
|
|
523
|
+
};
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
/** Every privilege key on the server. */
|
|
527
|
+
export async function listPrivilegeKeys(
|
|
528
|
+
client: CommandExecutor,
|
|
529
|
+
options?: CommandOptions,
|
|
530
|
+
): Promise<PrivilegeKey[]> {
|
|
531
|
+
return (await list(client, "privilegekeylist", [], options)).map(parseKey);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* A privilege key to create: one that grants a server group, or one that
|
|
536
|
+
* grants a channel group in one channel.
|
|
537
|
+
*/
|
|
538
|
+
export type PrivilegeKeyOptions =
|
|
539
|
+
| {
|
|
540
|
+
/** The server group the key grants. */
|
|
541
|
+
readonly serverGroupID: ServerGroupID;
|
|
542
|
+
readonly channelGroupID?: never;
|
|
543
|
+
readonly channelID?: never;
|
|
544
|
+
/** Shown in the key list; unset or "" sends none. */
|
|
545
|
+
readonly description?: string | undefined;
|
|
546
|
+
}
|
|
547
|
+
| {
|
|
548
|
+
readonly serverGroupID?: never;
|
|
549
|
+
/** The channel group the key grants. */
|
|
550
|
+
readonly channelGroupID: ChannelGroupID;
|
|
551
|
+
/** The channel it grants the group in. */
|
|
552
|
+
readonly channelID: ChannelID;
|
|
553
|
+
/** Shown in the key list; unset or "" sends none. */
|
|
554
|
+
readonly description?: string | undefined;
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Encode the group a key grants.
|
|
559
|
+
*
|
|
560
|
+
* The wire form is a type and two untyped ids whose meaning depends on it:
|
|
561
|
+
* `tokenid1` is the group and `tokenid2` the channel. The options used to take
|
|
562
|
+
* them as such, documented the other way round, so the typed fields are checked
|
|
563
|
+
* here to describe exactly one kind of key.
|
|
564
|
+
*/
|
|
565
|
+
function keyParams(key: PrivilegeKeyOptions): Params {
|
|
566
|
+
const { serverGroupID, channelGroupID, channelID } = key as {
|
|
567
|
+
serverGroupID?: unknown;
|
|
568
|
+
channelGroupID?: unknown;
|
|
569
|
+
channelID?: unknown;
|
|
570
|
+
};
|
|
571
|
+
const isID = (v: unknown): v is bigint => typeof v === "bigint" && v > 0n;
|
|
572
|
+
const description = nonEmpty(key.description ?? "");
|
|
573
|
+
if (isID(serverGroupID) && channelGroupID === undefined && channelID === undefined) {
|
|
574
|
+
return [
|
|
575
|
+
["tokentype", PrivilegeKeyType.ServerGroup],
|
|
576
|
+
["tokenid1", serverGroupID],
|
|
577
|
+
["tokenid2", 0],
|
|
578
|
+
["tokendescription", description],
|
|
579
|
+
];
|
|
580
|
+
}
|
|
581
|
+
if (serverGroupID === undefined && isID(channelGroupID) && isID(channelID)) {
|
|
582
|
+
return [
|
|
583
|
+
["tokentype", PrivilegeKeyType.ChannelGroup],
|
|
584
|
+
["tokenid1", channelGroupID],
|
|
585
|
+
["tokenid2", channelID],
|
|
586
|
+
["tokendescription", description],
|
|
587
|
+
];
|
|
588
|
+
}
|
|
589
|
+
throw new TypeError("a key grants a server group, or a channel group in a channel");
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/** Create a privilege key. Returns the key as the server generated it. */
|
|
593
|
+
export async function addPrivilegeKey(
|
|
594
|
+
client: CommandExecutor,
|
|
595
|
+
key: PrivilegeKeyOptions,
|
|
596
|
+
options?: CommandOptions,
|
|
597
|
+
): Promise<string> {
|
|
598
|
+
const rows = await query(client, "privilegekeyadd", keyParams(key), options);
|
|
599
|
+
return str(firstRow(rows, "privilegekeyadd", "token"), "token");
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/** Delete a privilege key. */
|
|
603
|
+
export async function deletePrivilegeKey(
|
|
604
|
+
client: CommandExecutor,
|
|
605
|
+
token: string,
|
|
606
|
+
options?: CommandOptions,
|
|
607
|
+
): Promise<void> {
|
|
608
|
+
await exec(client, "privilegekeydelete", [["token", token]], options);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Redeem a privilege key.
|
|
613
|
+
*
|
|
614
|
+
* The key grants only if this connection has not already used one.
|
|
615
|
+
*/
|
|
616
|
+
export async function usePrivilegeKey(
|
|
617
|
+
client: CommandExecutor,
|
|
618
|
+
token: string,
|
|
619
|
+
options?: CommandOptions,
|
|
620
|
+
): Promise<void> {
|
|
621
|
+
await exec(client, "privilegekeyuse", [["token", token]], options);
|
|
622
|
+
}
|