File: capctl

package info (click to toggle)
epic5 3.0.3-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 5,328 kB
  • sloc: ansic: 75,810; makefile: 648; ruby: 227; python: 215; sh: 78; perl: 13
file content (65 lines) | stat: -rw-r--r-- 1,890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
if (word(2 $loadinfo()) != [pf]) {
	load -pf $word(1 $loadinfo());
	return;
};

package capctl;

## Capability negotiation script for EPIC5.
## Written by zlonix@efnet, public domain.
##
## Version: 1.0 (September, 2022)
##  - Initial roll-out

## This script allows you to request needed capabilities from CAP-enabled server,
## at present only simple and unconditional requests are supported, so there are
## no checks for NAKs from the server, or any other complicated logic.
##
## Version 302 of the LS protocol is not supported at present time.
##
## Be careful about which capabilities you enable, because it will change the
## way server send you messages. Capabilities which use message-tags are safe to
## turn on, you can get them with built-in function $tags(), which you can check
## in your hooks, it works the same way as $userhost() does.
##
## Usage:
##	capctl req *.libera.chat account-tag draft/example-1 draft/example-2
##
## This will request three capabilities uppon connect to a server matching
## *.libera.chat.

alias capctl (verb, server, caps) {
	if (@verb && @server && @caps) {
		@ :server_enc = encode($server);

		@ push(cap.servers $server);
		@ cap[$server_enc][$verb] = caps;
	};
};

on #-server_established 1000 '\\\\[$$cap.servers\\\\] %' {
	@ :server = servername();
	@ :idx = rmatch($server $cap.servers)-1;
	@ :server_enc = encode($word($idx $cap.servers));

	quote CAP REQ :$cap[$server_enc][req];
};

## If we use SASL authentication we must wait 903 numeric, otherwise CAP END
## will be sent too early. sasl_in_progress variable is set in every sasl
## script.

on ^odd_server_stuff '\\\\[$$cap.servers\\\\] CAP % ACK *' {
	@ :server_enc = encode($servername());

	if (!@::sasl_in_progress[$server_enc]) {
		quote CAP END;
	};
};

on #-903 -1 * {
	@ :server_enc = encode($servername());
	@ ::sasl_in_progress[$server_enc] = [];

	quote CAP END;
};