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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
|
//=============================================================================
//
// File : libkvichan.cpp
// Creation date : Sun Feb 02 2002 05:27:11 GMT by Szymon Stefanek
//
// This chan is part of the KVirc irc client distribution
// Copyright (C) 2002-2005 Szymon Stefanek (pragma@kvirc.net)
// Copyright (C) 2002-2004 Juanjo Alvarez (juanjux@yahoo.es)
//
// This program is FREE software. You can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your opinion) any later version.
//
// This program is distributed in the HOPE that it will be USEFUL,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, write to the Free Software Foundation,
// Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================
#include "kvi_module.h"
#include "kvi_string.h"
#include "kvi_app.h"
#include "kvi_channel.h"
#include "kvi_locale.h"
#include "kvi_topicw.h"
#include "kvi_ircmask.h"
#include "kvi_maskeditor.h"
#include "kvi_ircurl.h"
#include "kvi_ircconnectiontarget.h"
#include "kvi_ircconnection.h"
static KviChannel * chan_kvs_find_channel(KviKvsModuleFunctionCall * c,QString &szChan,bool noWarnings=false)
{
if(szChan.isEmpty())
{
if(c->window()->type() == KVI_WINDOW_TYPE_CHANNEL)return (KviChannel *)(c->window());
if(c->window()->type() == KVI_WINDOW_TYPE_DEADCHANNEL)return (KviChannel *)(c->window());
if(!noWarnings) c->warning(__tr2qs("The current window is not a channel"));
} else {
KviWindow * w = g_pApp->findWindow(szChan);
if(!w)
{
if(!noWarnings) c->warning(__tr2qs("Can't find the window with id '%Q'"),&szChan);
return 0;
}
if(w->type() == KVI_WINDOW_TYPE_CHANNEL)return (KviChannel *)w;
if(!noWarnings) c->warning(__tr2qs("The specified window (%Q) is not a channel"),&szChan);
}
return 0;
}
/*
@doc: chan.name
@type:
function
@title:
$chan.name
@short:
Returns the name of a channel
@syntax:
<string> $chan.name
<string> $chan.name(<window_id:string>)
@description:
The first form returns the name of the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and an empty string is returned.[br]
The second form returns the name of the channel specified by <window_id>.[br]
This function works also on dead channels.[br]
*/
static bool chan_kvs_fnc_name(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) {
c->returnValue()->setString(ch->windowName());
}
return true;
}
/*
@doc: chan.getUrl
@type:
function
@title:
$chan.getUrl
@short:
Returns the URL of a channel
@syntax:
<string> $chan.getUrl
<string> $chan.getUrl(<window_id:string>)
<string> $chan.getUrl(<channel_name:string>)
@description:
Returns IRC URL for this channel
*/
static bool chan_kvs_fnc_getUrl(KviKvsModuleFunctionCall * c)
{
QString szId,url;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("channel id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId,true);
if (ch) {
KviIrcUrl::join(url,ch->connection()->target()->server());
url.append(ch->windowName());
if(ch->hasChannelKey())
{
url.append('?');
url.append(ch->channelKey());
}
} else {
if(c->window()->connection()) {
KviIrcUrl::join(url,c->window()->connection()->target()->server());
url.append(szId);
} else {
c->error("There is no active IRC connection for current context");
}
}
c->returnValue()->setString(url);
return true;
}
/*
@doc: chan.isDead
@type:
function
@title:
$chan.isDead
@short:
Checks if a channel is dead
@syntax:
<boolean> $chan.isDead
<boolean> $chan.isDead(<window_id:string>)
@description:
Returns 1 if the channel specified by <window_id> is a dead channel and 0 otherwise.[br]
The form without parameters works on the current window.[br]
*/
static bool chan_kvs_fnc_isdead(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setBoolean((ch->type() == KVI_WINDOW_TYPE_DEADCHANNEL));
return true;
}
/*
@doc: chan.topic
@type:
function
@title:
$chan.topic
@short:
Returns the topic of a channel
@syntax:
<string> $chan.topic
<string> $chan.topic(<window_id:string>)
@description:
The first form returns the topic of the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and an empty string is returned.[br]
The second form returns the topic of the channel specified by <window_id>.[br]
The topic is returned as it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get an empty string (the topic is not yet known).[br]
This function works also on dead channels altough the topic returned is the last
topic seen while the channel wasn't dead.[br]
*/
static bool chan_kvs_fnc_topic(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setString(ch->topicWidget()->topic());
return true;
}
/*
@doc: chan.topicsetby
@type:
function
@title:
$chan.topicsetby
@short:
Returns the author of the topic of a channel
@syntax:
<string> $chan.topicsetby
<string> $chan.topicsetby(<window_id:string>)
@description:
The first form returns the author of the topic of the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and an empty string is returned.[br]
The second form returns the author of the topic of the channel specified by <window_id>.[br]
The topic author nickname is returned if it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get an empty string (the topic is not yet known).[br]
This function works also on dead channels altough the information returned is the last
information seen while the channel wasn't dead.[br]
*/
static bool chan_kvs_fnc_topicsetby(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setString(ch->topicWidget()->topicSetBy());
return true;
}
/*
@doc: chan.topicsetat
@type:
function
@title:
$chan.topicsetat
@short:
Returns the set time of the topic of a channel
@syntax:
<string> $chan.topicsetat
<string> $chan.topicsetat(<window_id:string>)
@description:
The first form returns the set time of the topic of the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and an empty string is returned.[br]
The second form returns the set time of the topic of the channel specified by <window_id>.[br]
The topic set time is returned if it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get an empty string (the topic is not yet known).[br]
This function works also on dead channels altough the information returned is the last
information seen while the channel wasn't dead.[br]
*/
static bool chan_kvs_fnc_topicsetat(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setString(ch->topicWidget()->topicSetAt());
return true;
}
/*
@doc: chan.usercount
@type:
function
@title:
$chan.usercount
@short:
Returns the number of users on a channel
@syntax:
<intger> $chan.usercount
<integer> $chan.usercount(<window_id:string>)
@description:
The first form returns the number of users on the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and an empty string is returned.[br]
The second form returns the number of users on the channel specified by <window_id>.[br]
The number of users is returned if it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get a number that is actually smaller.[br]
*/
static bool chan_kvs_fnc_usercount(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setInteger(ch->count());
return true;
}
/*
@doc: chan.ownercount
@type:
function
@title:
$chan.ownercount
@short:
Returns the number of channel owner users on a channel
@syntax:
<integer> $chan.ownercount
<integer> $chan.ownercount(<window_id:integer>)
@description:
The first form returns the number of owners users on the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and an empty string is returned.[br]
The second form returns the number of owners users on the channel specified by <window_id>.[br]
The number of owners is returned if it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get a number that is actually smaller.[br]
*/
static bool chan_kvs_fnc_ownercount(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setInteger(ch->chanOwnerCount());
return true;
}
/*
@doc: chan.admincount
@type:
function
@title:
$chan.admincount
@short:
Returns the number of channel admin users on a channel
@syntax:
<integer> $chan.admincount
<integer> $chan.admincount(<window_id:string>)
@description:
The first form returns the number of administrator users on the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and an empty string is returned.[br]
The second form returns the number of administrator users on the channel specified by <window_id>.[br]
The number of administrators is returned if it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get a number that is actually smaller.[br]
*/
static bool chan_kvs_fnc_admincount(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setInteger(ch->chanAdminCount());
return true;
}
/*
@doc: chan.opcount
@type:
function
@title:
$chan.opcount
@short:
Returns the number of op users on a channel
@syntax:
<integer> $chan.opcount
<integer> $chan.opcount(<window_id:string>)
@description:
The first form returns the number of op users on the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and an empty string is returned.[br]
The second form returns the number of op users on the channel specified by <window_id>.[br]
The number of ops is returned if it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get a number that is actually smaller.[br]
*/
static bool chan_kvs_fnc_opcount(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setInteger(ch->opCount());
return true;
}
/*
@doc: chan.voicecount
@type:
function
@title:
$chan.voicecount
@short:
Returns the number of voiced users on a channel
@syntax:
<integer> $chan.voicecount
<integer> $chan.voicecount(<window_id:string>)
@description:
The first form returns the number of voiced users on the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and an empty string is returned.[br]
The second form returns the number of voiced users on the channel specified by <window_id>.[br]
The number of voiced users is returned if it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get a number that is actually smaller.[br]
*/
static bool chan_kvs_fnc_voicecount(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setInteger(ch->voiceCount());
return true;
}
/*
@doc: chan.halfopcount
@type:
function
@title:
$chan.halfopcount
@short:
Returns the number of halfop users on a channel
@syntax:
<integer> $chan.halfOpCount
<integer> $chan.halfOpCount(<window_id:string>)
@description:
The first form returns the number of half-operator users on the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and an empty string is returned.[br]
The second form returns the number of half-operator users on the channel specified by <window_id>.[br]
The number of half-operator users is returned if it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get a number that is actually smaller.[br]
*/
static bool chan_kvs_fnc_halfopcount(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setInteger(ch->halfOpCount());
return true;
}
/*
@doc: chan.useropcount
@type:
function
@title:
$chan.useropcount
@short:
Returns the number of userop users on a channel
@syntax:
<integer> $chan.userOpCount
<integer> $chan.userOpCount(<window_id:string>)
@description:
The first form returns the number of user-operator users on the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and an empty string is returned.[br]
The second form returns the number of user-operator users on the channel specified by <window_id>.[br]
The number of user-operator users is returned if it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get a number that is actually smaller.[br]
*/
static bool chan_kvs_fnc_useropcount(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setInteger(ch->userOpCount());
return true;
}
/*
@doc: chan.bancount
@type:
function
@title:
$chan.bancount
@short:
Returns the number of entries in the channel ban list
@syntax:
<integer> $chan.bancount
<integer> $chan.bancount(<window_id:string>)
@description:
The first form returns the number of entries in the ban list of the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and 0 is returned.[br]
The second form returns the number entries in the ban list of the channel specified by <window_id>.[br]
The number of ban list entries is returned if it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get a number that is actually smaller.[br]
*/
static bool chan_kvs_fnc_bancount(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setInteger(ch->banCount());
return true;
}
/*
@doc: chan.banexceptioncount
@type:
function
@title:
$chan.banexceptioncount
@short:
Returns the number of entries in the channel ban exception list
@syntax:
<integer> $chan.banexceptioncount
<integer> $chan.banexceptioncount(<window_id:string>)
@description:
The first form returns the number of entries in the ban exception list of the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and 0 is returned.[br]
The second form returns the number entries in the ban exception list of the channel specified by <window_id>.[br]
The number of ban exception list entries is returned if it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get a number that is actually smaller.[br]
*/
static bool chan_kvs_fnc_banexceptioncount(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setInteger(ch->banExceptionCount());
return true;
}
/*
@doc: chan.invitecount
@type:
function
@title:
$chan.invitecount
@short:
Returns the number of entries in the channel invite list
@syntax:
<integer> $chan.invitecount
<integer> $chan.invitecount(<window_id:string>)
@description:
The first form returns the number of entries in the invite list of the current channel (assuming that the current window
is a channel at all). If the current window is not a channel, a warning is printed
and 0 is returned.[br]
The second form returns the number entries in the invite list of the channel specified by <window_id>.[br]
The number of invite list entries is returned if it is known form at the call time: this means that
if the channel is not synchronized with the server (as just after the join, for example)
you might get a number that is actually smaller.[br]
*/
static bool chan_kvs_fnc_invitecount(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setInteger(ch->inviteCount());
return true;
}
/*
@doc: chan.ison
@type:
function
@title:
$chan.ison
@short:
Checks if an user is on a channel
@syntax:
<boolean> $chan.ison(<nickname:string>[,<window_id:string>])
@description:
Returns 1 if <nickname> is on the channel identified by <window_id>, 0 otherwise.[br]
If <window_id> is not specified the current window is used (assuming that it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
*/
static bool chan_kvs_fnc_ison(KviKvsModuleFunctionCall * c)
{
QString szId,szNick;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("nickname",KVS_PT_NONEMPTYSTRING,0,szNick)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setBoolean(ch->isOn(szNick));
return true;
}
/*
@doc: chan.getflag
@type:
function
@title:
$chan.getflag
@short:
Returns the channel-user mode flag of an user
@syntax:
<char> $chan.getflag(<nickname:string>[,<window_id:string>])
@description:
Returns the channel user mode flag of an user on the channel specified by <window_id>.[br]
If <window_id> is not passed, the current window is used.[br]
If the specified window is not a channel, a warning is printed and an empty string is returned.[br]
If the specified user is not on the channel identified by <window_id>, and empty string is returned.[br]
The possible user flags are:[br]
'!' for channel administrators[br]
'@' for ops[br]
'%' for halfops[br]
'+' for voiced users[br]
'-' for userops[br]
If the user has more than one flag then the highest one is returned.[br]
If the user has no flag at all then an empty string is returned.
*/
static bool chan_kvs_fnc_getflag(KviKvsModuleFunctionCall * c)
{
QString szId,szNick;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("nickname",KVS_PT_NONEMPTYSTRING,0,szNick)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if(ch)
{
QChar cFlag = ch->userListView()->getUserFlag(szNick);
if(cFlag != QChar(0))
{
QString szFlag = cFlag;
c->returnValue()->setString(szFlag);
} else {
c->returnValue()->setNothing();
}
}
return true;
}
#define IS_KVS_FUNC(__clbkname,__chanfunc) \
static bool __clbkname(KviKvsModuleFunctionCall * c) \
{ \
QString szId,szNick;\
KVSM_PARAMETERS_BEGIN(c)\
KVSM_PARAMETER("nickname",KVS_PT_NONEMPTYSTRING,0,szNick)\
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)\
KVSM_PARAMETERS_END(c)\
KviChannel * ch = chan_kvs_find_channel(c,szId); \
if(ch) c->returnValue()->setBoolean(ch->__chanfunc(szNick,true)); \
return true; \
}
/*
@doc: chan.isowner
@type:
function
@title:
$chan.isowner
@short:
Checks if an user is at least a channel owner
@syntax:
<boolean> $chan.isowner(<nickname:string>[,<window_id:string>])
@description:
Returns 1 if <nickname> is at least an owner on the channel identified by <window_id>, 0 otherwise.[br]
If <window_id> is not specified the current window is used (assuming that it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
Note that if the user is not on the channel at all, you will get 0 as return value.[br]
*/
IS_KVS_FUNC(chan_kvs_fnc_isowner,isChanOwner)
/*
@doc: chan.isadmin
@type:
function
@title:
$chan.isadmin
@short:
Checks if an user is at least channel administrator
@syntax:
<boolean> $chan.isadmin(<nickname:string>[,<window_id:string>])
@description:
Returns 1 if <nickname> is at least an administrator on the channel identified by <window_id>, 0 otherwise.[br]
If <window_id> is not specified the current window is used (assuming that it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
Note that if the user is not on the channel at all, you will get 0 as return value.[br]
*/
IS_KVS_FUNC(chan_kvs_fnc_isadmin,isChanAdmin)
/*
@doc: chan.isop
@type:
function
@title:
$chan.isop
@short:
Checks if an user is at least an op on a channel
@syntax:
<boolean> $chan.isop(<nickname:string>[,<window_id:stringn>])
@description:
Returns 1 if <nickname> is at least an operator on the channel identified by <window_id>, 0 otherwise.[br]
If <window_id> is not specified the current window is used (assuming that it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
Note that if the user is not on the channel at all, you will get 0 as return value.[br]
*/
IS_KVS_FUNC(chan_kvs_fnc_isop,isOp)
/*
@doc: chan.isvoice
@type:
function
@title:
$chan.isvoice
@short:
Checks if an user is at least voiced on a channel
@syntax:
<boolean> $chan.isvoice(<nickname:string>[,<window_id:string>])
@description:
Returns 1 if <nickname> is at least voiced on the channel identified by <window_id>, 0 otherwise.[br]
If <window_id> is not specified the current window is used (assuming that it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
Note that if the user is not on the channel at all, you will get 0 as return value.[br]
*/
IS_KVS_FUNC(chan_kvs_fnc_isvoice,isVoice)
/*
@doc: chan.ishalfop
@type:
function
@title:
$chan.ishalfop
@short:
Checks if an user is at least halfop on a channel
@syntax:
<boolean> $chan.ishalfop(<nickname:string>[,<window_id:string>])
@description:
Returns 1 if <nickname> is at least a half-operator on the channel identified by <window_id>, 0 otherwise.[br]
If <window_id> is not specified the current window is used (assuming that it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
Note that if the user is not on the channel at all, you will get 0 as return value.[br]
*/
IS_KVS_FUNC(chan_kvs_fnc_ishalfop,isHalfOp)
/*
@doc: chan.isuserop
@type:
function
@title:
$chan.isuserop
@short:
Checks if an user is at least an userop on a channel
@syntax:
<boolean> $chan.isuserop(<nickname:string>[,<window_id:string>])
@description:
Returns 1 if <nickname> is at least an user-operator on the channel identified by <window_id>, 0 otherwise.[br]
If <window_id> is not specified the current window is used (assuming that it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
Note that if the user is not on the channel at all, you will get 0 as return value.[br]
*/
IS_KVS_FUNC(chan_kvs_fnc_isuserop,isUserOp)
/*
@doc: chan.ismeowner
@type:
function
@title:
$chan.isMeOwner
@short:
Checks if the current user is at least an owner on a channel
@syntax:
<boolean> $chan.isMeOwner
<boolean> $chan.isMeOwner(<window_id:string>)
@description:
Returns 1 if the current user is at least an owner on the channel specified by <window_id>, 0 otherwise.[br]
If <window_id> is not passed, the current window is used (assuming it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
This function is a "shortcut" for [fnc]$chan.isowner[/fnc]([fnc]$me[/fnc]).[br]
*/
#define IS_ME_KVS_FUNC(__clbkname,__chanfunc) \
static bool __clbkname(KviKvsModuleFunctionCall * c) \
{ \
QString szId;\
KVSM_PARAMETERS_BEGIN(c)\
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)\
KVSM_PARAMETERS_END(c)\
KviChannel * ch = chan_kvs_find_channel(c,szId); \
if(ch) c->returnValue()->setBoolean(ch->__chanfunc(true)); \
return true; \
}
IS_ME_KVS_FUNC(chan_kvs_fnc_ismeowner,isMeChanOwner)
/*
@doc: chan.ismeadmin
@type:
function
@title:
$chan.isMeAdmin
@short:
Checks if the current user is at least an administrator on a channel
@syntax:
<boolean> $chan.isMeAdmin
<boolean> $chan.isMeAdmin(<window_id:string>)
@description:
Returns 1 if the current user is at least an administrator on the channel specified by <window_id>, 0 otherwise.[br]
If <window_id> is not passed, the current window is used (assuming it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
This function is a "shortcut" for [fnc]$chan.isadmin[/fnc]([fnc]$me[/fnc]).[br]
*/
IS_ME_KVS_FUNC(chan_kvs_fnc_ismeadmin,isMeChanAdmin)
/*
@doc: chan.ismeop
@type:
function
@title:
$chan.isMeOp
@short:
Checks if the current user is at least op on a channel
@syntax:
<boolean> $chan.isMeOp
<boolean> $chan.isMeOp(<window_id:string>)
@description:
Returns 1 if the current user is at least op on the channel specified by <window_id>, 0 otherwise.[br]
If <window_id> is not passed, the current window is used (assuming it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
This function is a "shortcut" for [fnc]$chan.isop[/fnc]([fnc]$me[/fnc]).[br]
*/
IS_ME_KVS_FUNC(chan_kvs_fnc_ismeop,isMeOp)
/*
@doc: chan.ismehalfop
@type:
function
@title:
$chan.isMeHalfOp
@short:
Checks if the current user is at least an half operator on a channel
@syntax:
<boolean> $chan.isMeHalfOp
<boolean> $chan.isMeHalfOp(<window_id:string>)
@description:
Returns 1 if the current user is at least an half operator on the channel specified by <window_id>, 0 otherwise.[br]
If <window_id> is not passed, the current window is used (assuming it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
This function is a "shortcut" for [fnc]$chan.ishalfop[/fnc]([fnc]$me[/fnc]).[br]
*/
IS_ME_KVS_FUNC(chan_kvs_fnc_ismehalfop,isMeHalfOp)
/*
@doc: chan.ismevoice
@type:
function
@title:
$chan.isMeVoice
@short:
Checks if the current user is at least voice on a channel
@syntax:
<boolean> $chan.isMeVoice
<boolean> $chan.isMeVoice(<window_id:string>)
@description:
Returns 1 if the current user is at least voice on the channel specified by <window_id>, 0 otherwise.[br]
If <window_id> is not passed, the current window is used (assuming it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
This function is a "shortcut" for [fnc]$chan.isvoice[/fnc]([fnc]$me[/fnc]).[br]
*/
IS_ME_KVS_FUNC(chan_kvs_fnc_ismevoice,isMeVoice)
/*
@doc: chan.ismeuserop
@type:
function
@title:
$chan.isMeUserOp
@short:
Checks if the current user is at least an user operator on a channel
@syntax:
<boolean> $chan.isMeUserOp
<boolean> $chan.isMeUserOp(<window_id:String>)
@description:
Returns 1 if the current user is at least an user operator on the channel specified by <window_id>, 0 otherwise.[br]
If <window_id> is not passed, the current window is used (assuming it is a channel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
This function is a "shortcut" for [fnc]$chan.isuserop[/fnc]([fnc]$me[/fnc]).[br]
*/
IS_ME_KVS_FUNC(chan_kvs_fnc_ismeuserop,isMeUserOp)
/*
@doc: chan.mode
@type:
function
@title:
$chan.mode
@short:
Returns the mode string of a channel
@syntax:
<string> $chan.mode
<string> $chan.mode(<window_id:string>)
@description:
Returns the mode string of the channel identified by <window_id>.[br]
If no <window_id> is passed, the current channel mode string is returned (assuming that
the current window is a chnannel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
*/
static bool chan_kvs_fnc_mode(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if(ch)
{
QString chMode;
ch->getChannelModeString(chMode);
c->returnValue()->setString(chMode);
}
return true;
}
/*
@doc: chan.key
@type:
function
@title:
$chan.key
@short:
Returns the key of a channel
@syntax:
<string> $chan.key
<string> $chan.key(<window_id:string>)
@description:
Returns the key of the channel identified by <window_id>.[br]
If no <window_id> is passed, the current channel key is returned (assuming that
the current window is a chnannel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
If the channel has no key set, an empty string is returned.[br]
*/
static bool chan_kvs_fnc_key(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
if (ch) c->returnValue()->setString(ch->channelKey());
return true;
}
/*
@doc: chan.limit
@type:
function
@title:
$chan.limit
@short:
Returns the limit of a channel
@syntax:
<integer> $chan.limit
<integer> $chan.limit(<window_id:string>)
@description:
Returns the limit of the channel identified by <window_id>.[br]
If no <window_id> is passed, the current channel limit is returned (assuming that
the current window is a chnannel at all).[br]
If the window is not a channel, a warning is printed and an empty string is returned.[br]
If the channel has no limit set, "0" is returned.[br]
*/
static bool chan_kvs_fnc_limit(KviKvsModuleFunctionCall * c)
{
QString szId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szId);
kvs_int_t limit=0;
QString lim;
if (ch)
{
if(ch->hasChannelLimit())
{
lim=ch->channelLimit().ptr();
limit=lim.toInt();
}
c->returnValue()->setInteger(limit);
}
return true;
}
/*
@doc: chan.users
@type:
function
@title:
$chan.users
@short:
Returns an array of channel user nicknames
@syntax:
<array> $chan.users([window_id:string],[mask:string],[flags:string])
@description:
Returns an array of nicknames on the channel specified by [window_id].[br]
If [window_id] is empty, the current window is used.[br]
If the window designated by [window_id] is not a channel a warning is printed and an empty array is returned.[br]
If [mask] is given, each user is added to the array only
if it matches the [mask].[br]
[flags] may contain a subset of the letters "aovhnmi":[br]
"ovhn" are mode flags: the users are added to the array only if they are channel administrators ('a'), operators ('o'),
voiced users ('v'), half-operators ('h'), user-operators ('u') or unflagged ('n') users. (Unflagged means not operators, not
voiced and not half-operators). If none of the "ovhun" flags are used, KVIrc behaves like all five were passed.[br]
The flag 'm' causes the entire user masks to be added to the
array entries, as known by KVIrc at the moment of this function call.[br]
The flag 'i' causes KVIrc to invert the match and add only the users that do NOT match [mask].[br]
Please note that on really large channels this function may be time consuming (especially if [mask] is used):
use with care.[br]
@example:
[example]
[comment]# Get the nickname list[/comment]
%test[] = $chan.users
[comment]# And loop thru the items[/comment]
%i = 0
[comment]# %test[]# returns the number of elements in the array[/comment]
%count = %test[]#
while(%i < %count)
{
echo "User %i : %test[%i]"
%i++
}
[comment]# Another way of looping[/comment]
foreach(%tmp,%test[])echo "User %tmp"
[comment]# Find all the users that come from the *.org domain[/comment]
%test[]=$chan.users(,*!*@*.org)
echo %test[]
[comment]# This will work too![/comment]
echo $chan.users(,*!*@*.org)
[comment]# Find all the channel operators[/comment]
%test[] = $chan.users(,,o)
echo %test[]
[comment]# Find all the voiced users that do NOT come from *.edu[/comment]
[comment]# See also their whole mask[/comment]
%test[] = $chan.users(,*!*@*.edu,vim)
echo %test[]
[/example]
*/
static bool chan_kvs_fnc_users(KviKvsModuleFunctionCall * c)
{
QString szWinId,szMask,szFlags;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szWinId)
KVSM_PARAMETER("mask",KVS_PT_STRING,KVS_PF_OPTIONAL,szMask)
KVSM_PARAMETER("flags",KVS_PT_STRING,KVS_PF_OPTIONAL,szFlags)
KVSM_PARAMETERS_END(c)
KviKvsArray * pArray = new KviKvsArray();
c->returnValue()->setArray(pArray);
KviChannel * ch = chan_kvs_find_channel(c,szWinId);
if(!ch)return true;
KviUserListEntry * e = ch->userListView()->firstItem(); // Thnx Julien :)
bool bCheckMask = !szMask.isEmpty();
bool bOp = szFlags.find('o',false) != -1;
bool bVoice = szFlags.find('v',false) != -1;
bool bHalfOp = szFlags.find('h',false) != -1;
bool bChanAdmins = szFlags.find('a',false) != -1;
bool bUserOp = szFlags.find('u',false) != -1;
bool bNone = szFlags.find('n',false) != -1;
bool bCheckFlags = bOp || bVoice || bHalfOp || bNone || bChanAdmins || bUserOp;
bool bAddMask = szFlags.find('m',false) != -1;
int idx = 0;
if(bAddMask || bCheckFlags || bCheckMask)
{
bool bMaskMustMatch = szFlags.find('i',false) == -1;
KviIrcMask mask(szMask);
while(e)
{
if(bCheckFlags)
{
if(bChanAdmins)
{
if(e->flags() & KVI_USERFLAG_CHANADMIN)goto check_mask;
}
if(bOp)
{
if(e->flags() & KVI_USERFLAG_OP)goto check_mask;
}
if(bVoice)
{
if(e->flags() & KVI_USERFLAG_VOICE)goto check_mask;
}
if(bHalfOp)
{
if(e->flags() & KVI_USERFLAG_HALFOP)goto check_mask;
}
if(bUserOp)
{
if(e->flags() & KVI_USERFLAG_USEROP)goto check_mask;
}
if(bNone)
{
if(!(e->flags() & KVI_USERFLAG_MASK))goto check_mask;
}
goto next_item;
}
check_mask:
if(bCheckMask)
{
if(mask.matchesFixed(e->nick(),e->globalData()->user(),e->globalData()->host()) == bMaskMustMatch)goto add_item;
goto next_item;
}
add_item:
if(bAddMask)
{
QString x(e->nick());
x.append('!');
x.append(e->globalData()->user());
x.append('@');
x.append(e->globalData()->host());
pArray->set(idx,new KviKvsVariant(x));
} else {
pArray->set(idx,new KviKvsVariant(e->nick()));
}
idx++;
next_item:
e = e->next();
}
} else {
while(e)
{
pArray->set(idx,new KviKvsVariant(e->nick()));
idx++;
e = e->next();
}
}
return true;
}
/*
@doc: chan.banlist
@type:
function
@title:
$chan.banlist
@short:
Returns an array of channel ban masks
@syntax:
$chan.banlist([window_id])
@description:
Returns an array of ban masks set ont the channel identified by [window_id].[br]
If [window_id] is empty, the current window is used.[br]
If the window designated by [window_id] is not a channel a warning is printed and an empty array is returned.[br]
*/
static bool chan_kvs_fnc_banlist(KviKvsModuleFunctionCall * c)
{
QString szWinId,szMask,szFlags;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szWinId)
KVSM_PARAMETERS_END(c)
KviKvsArray * pArray = new KviKvsArray();
c->returnValue()->setArray(pArray);
KviChannel * ch = chan_kvs_find_channel(c,szWinId);
if(!ch)return true;
int idx = 0;
KviPointerList<KviMaskEntry> * l = ((KviChannel *)(c->window()))->banList();
for(KviMaskEntry * e = l->first();e;e = l->next())
{
pArray->set(idx,new KviKvsVariant(e->szMask));
idx++;
}
return true;
}
/*
@doc: chan.banexceptionlist
@type:
function
@title:
$chan.banexceptionlist
@short:
Returns an array of channel ban exception masks
@syntax:
<array> $chan.banexceptionlist([window_id])
@description:
Returns an array of ban exception masks set ont the channel identified by [window_id].[br]
If [window_id] is empty, the current window is used.[br]
If the window designated by [window_id] is not a channel a warning is printed and an empty array is returned.[br]
*/
static bool chan_kvs_fnc_banexceptionlist(KviKvsModuleFunctionCall * c)
{
QString szWinId,szMask,szFlags;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szWinId)
KVSM_PARAMETERS_END(c)
KviKvsArray * pArray = new KviKvsArray();
c->returnValue()->setArray(pArray);
KviChannel * ch = chan_kvs_find_channel(c,szWinId);
if(!ch)return true;
int idx = 0;
KviPointerList<KviMaskEntry> * l = ((KviChannel *)(c->window()))->banExceptionList();
for(KviMaskEntry * e = l->first();e;e = l->next())
{
pArray->set(idx,new KviKvsVariant(e->szMask));
idx++;
}
return true;
}
/*
@doc: chan.invitelist
@type:
function
@title:
$chan.invitelist
@short:
Returns an array of channel invite masks
@syntax:
<array> $chan.banexceptionlist([window_id])
@description:
Returns an array of invite masks set ont the channel identified by [window_id].[br]
If [window_id] is empty, the current window is used.[br]
If the window designated by [window_id] is not a channel a warning is printed and an empty array is returned.[br]
*/
static bool chan_kvs_fnc_invitelist(KviKvsModuleFunctionCall * c)
{
QString szWinId,szMask,szFlags;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szWinId)
KVSM_PARAMETERS_END(c)
KviKvsArray * pArray = new KviKvsArray();
c->returnValue()->setArray(pArray);
KviChannel * ch = chan_kvs_find_channel(c,szWinId);
if(!ch)return true;
int idx = 0;
KviPointerList<KviMaskEntry> * l = ((KviChannel *)(c->window()))->inviteList();
for(KviMaskEntry * e = l->first();e;e = l->next())
{
pArray->set(idx,new KviKvsVariant(e->szMask));
idx++;
}
return true;
}
/*
@doc: chan.matchban
@type:
function
@title:
$chan.matchban
@short:
Matches a mask agains the channel ban list
@syntax:
<string> $chan.matchban([window_id],<complete_mask>)
@description:
Returns the ban mask that matches <complete_mask> on channel identified by [window_id].[br]
If no ban mask matches <complete_mask> an empty string is returned.[br]
If [window_id] is empty, the current window is used.[br]
If the window designated by [window_id] is not a channel a warning is printed and an empty string is returned.[br]
This function is useful to determine if a ban set on the channel matches an user.[br]
*/
static bool chan_kvs_fnc_matchban(KviKvsModuleFunctionCall * c)
{
QString szWinId,szMask;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,0,szWinId)
KVSM_PARAMETER("mask",KVS_PT_STRING,0,szMask)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szWinId);
if(!ch)
{
c->returnValue()->setNothing();
return true;
}
KviPointerList<KviMaskEntry> * l = ((KviChannel *)(c->window()))->banList();
for(KviMaskEntry * e = l->first();e;e = l->next())
{
if(KviQString::matchStringCI(e->szMask,szMask))
{
c->returnValue()->setString(e->szMask);
return true;
}
}
c->returnValue()->setNothing();
return true;
}
/*
@doc: chan.matchbanexception
@type:
function
@title:
$chan.matchbanexception
@short:
Matches a mask agains the channel ban exception list
@syntax:
<string> $chan.matchbanexception([window_id],<complete_mask>)
@description:
Returns the ban exception mask that matches <complete_mask> on channel identified by [window_id].[br]
If no ban exception mask matches <complete_mask> an empty string is returned.[br]
If [window_id] is empty, the current window is used.[br]
If the window designated by [window_id] is not a channel a warning is printed and an empty string is returned.[br]
This function is useful to determine if a ban exception set on the channel matches an user.[br]
*/
static bool chan_kvs_fnc_matchbanexception(KviKvsModuleFunctionCall * c)
{
QString szWinId,szMask;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,0,szWinId)
KVSM_PARAMETER("mask",KVS_PT_STRING,0,szMask)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szWinId);
if(!ch)
{
c->returnValue()->setNothing();
return true;
}
KviPointerList<KviMaskEntry> * l = ((KviChannel *)(c->window()))->banExceptionList();
for(KviMaskEntry * e = l->first();e;e = l->next())
{
if(KviQString::matchStringCI(e->szMask,szMask))
{
c->returnValue()->setString(e->szMask);
return true;
}
}
c->returnValue()->setNothing();
return true;
}
/*
@doc: chan.matchinvite
@type:
function
@title:
$chan.matchinvite
@short:
Matches a mask agains the channel invite list
@syntax:
<string> $chan.matchinvite([window_id:string],<complete_mask>)
@description:
Returns the invite mask that matches <complete_mask> on channel identified by [window_id].[br]
If no invite mask matches <complete_mask> an empty string is returned.[br]
If [window_id] is empty, the current window is used.[br]
If the window designated by [window_id] is not a channel a warning is printed and an empty string is returned.[br]
This function is useful to determine if a invite set on the channel matches an user.[br]
*/
static bool chan_kvs_fnc_matchinvite(KviKvsModuleFunctionCall * c)
{
QString szWinId,szMask;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("window id",KVS_PT_STRING,0,szWinId)
KVSM_PARAMETER("mask",KVS_PT_STRING,0,szMask)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szWinId);
if(!ch)
{
c->returnValue()->setNothing();
return true;
}
KviPointerList<KviMaskEntry> * l = ((KviChannel *)(c->window()))->inviteList();
for(KviMaskEntry * e = l->first();e;e = l->next())
{
if(KviQString::matchStringCI(e->szMask,szMask))
{
c->returnValue()->setString(e->szMask);
return true;
}
}
c->returnValue()->setNothing();
return true;
}
/*
@doc: chan.usermodelevel
@type:
function
@title:
$chan.usermodelevel
@short:
Returns the channel user-mode level
@syntax:
<integer> $chan.userModeLevel(<nickname:string>[,<window_id:string>])
@description:
Returns an integer identifying the specified user's channel mode on the channel specified by <window_id>.[br]
If <window_id> is not passed, the current window is used.[br]
If the specified window is not a channel, a warning is printed and '0' is returned.[br]
This number can be useful to implement comparison functions between
users in order to determine the actions they can issue between each other.[br]
For example it is granted that an op will have userModeLevel greater than
a voiced user or that a simple "modeless" user will have
an userModeLevel lower than a halfop.[br]
IRC allows multiple modes to be applied to a single user on a channel,
in that case this function will return the level of the highest mode
applied to the user.[br]
Note: Don't rely on this number being any particular exact value except
for the completely modeless users (in which case this function will return always '0').
*/
static bool chan_kvs_fnc_usermodelevel(KviKvsModuleFunctionCall * c)
{
QString szNick,szWinId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("nickname",KVS_PT_STRING,0,szNick)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szWinId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szWinId);
kvs_int_t mode=0;
if(ch) mode=ch->userListView()->getUserModeLevel(szNick);
c->returnValue()->setInteger(mode);
return true;
}
/*
@doc: chan.userjointime
@type:
function
@title:
$chan.userJoinTime
@short:
Returns the time that an user has joined the channel
@syntax:
<integer> $chan.userJoinTime(<nickname:string>[,<window_id:string>])
@description:
Returns the unix time at which the user specified by <nickname> has joined the channel specified by <window_id>.[br]
If <window_id> is not passed, the current window is used.[br]
If the specified window is not a channel, a warning is printed and '0' is returned.[br]
'0' is also returned when the user's join time is unknown: this is true
for all the users that were on the channel before the local user has joined it (e.g.
you know the join time only for users that YOU see joining).[br]
@seealso:
[fnc]$unixTime[/fnc], [fnc]$chan.userLastActionTime[/fnc]
*/
static bool chan_kvs_fnc_userjointime(KviKvsModuleFunctionCall * c)
{
QString szNick,szWinId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("nickname",KVS_PT_STRING,0,szNick)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szWinId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szWinId);
kvs_int_t time=0;
if(ch) time=ch->userListView()->getUserJoinTime(szNick);
c->returnValue()->setInteger(time);
return true;
}
/*
@doc: chan.userlastactiontime
@type:
function
@title:
$chan.userLastActionTime
@short:
Returns the time that an user has last performed some kind of action on the channel
@syntax:
<integer> $chan.userLastActionTime(<nickname:string>[,<window_id:string>])
@description:
Returns the unix time at which the user specified by <nickname> has performed
some kind of action on the channel specified by <window_id>.[br]
If <window_id> is not passed, the current window is used.[br]
If the specified window is not a channel, a warning is printed and '0' is returned.[br]
'0' is also returned when the user's last action time is unknown: this is true
for all the users that were on the channel before the local user has joined it
and have performed no actions since that moment.
@seealso:
[fnc]$unixTime[/fnc], [fnc]$chan.userJoinTime[/fnc]
*/
static bool chan_kvs_fnc_userlastactiontime(KviKvsModuleFunctionCall * c)
{
QString szNick,szWinId;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("nickname",KVS_PT_STRING,0,szNick)
KVSM_PARAMETER("window id",KVS_PT_STRING,KVS_PF_OPTIONAL,szWinId)
KVSM_PARAMETERS_END(c)
KviChannel * ch = chan_kvs_find_channel(c,szWinId);
kvs_int_t time=0;
if(ch) time=ch->userListView()->getUserLastActionTime(szNick);
c->returnValue()->setInteger(time);
return true;
}
static bool chan_module_init(KviModule * m)
{
KVSM_REGISTER_FUNCTION(m,"name",chan_kvs_fnc_name);
KVSM_REGISTER_FUNCTION(m,"topic",chan_kvs_fnc_topic);
KVSM_REGISTER_FUNCTION(m,"topicsetby",chan_kvs_fnc_topicsetby);
KVSM_REGISTER_FUNCTION(m,"topicsetat",chan_kvs_fnc_topicsetat);
KVSM_REGISTER_FUNCTION(m,"usercount",chan_kvs_fnc_usercount);
KVSM_REGISTER_FUNCTION(m,"ownercount",chan_kvs_fnc_ownercount);
KVSM_REGISTER_FUNCTION(m,"admincount",chan_kvs_fnc_admincount);
KVSM_REGISTER_FUNCTION(m,"opcount",chan_kvs_fnc_opcount);
KVSM_REGISTER_FUNCTION(m,"voicecount",chan_kvs_fnc_voicecount);
KVSM_REGISTER_FUNCTION(m,"halfopcount",chan_kvs_fnc_halfopcount);
KVSM_REGISTER_FUNCTION(m,"useropcount",chan_kvs_fnc_useropcount);
KVSM_REGISTER_FUNCTION(m,"isowner",chan_kvs_fnc_isowner);
KVSM_REGISTER_FUNCTION(m,"ison",chan_kvs_fnc_ison);
KVSM_REGISTER_FUNCTION(m,"isadmin",chan_kvs_fnc_isadmin);
KVSM_REGISTER_FUNCTION(m,"isop",chan_kvs_fnc_isop);
KVSM_REGISTER_FUNCTION(m,"isvoice",chan_kvs_fnc_isvoice);
KVSM_REGISTER_FUNCTION(m,"ishalfop",chan_kvs_fnc_ishalfop);
KVSM_REGISTER_FUNCTION(m,"isuserop",chan_kvs_fnc_isuserop);
KVSM_REGISTER_FUNCTION(m,"ismeuserop",chan_kvs_fnc_ismeuserop);
KVSM_REGISTER_FUNCTION(m,"ismevoice",chan_kvs_fnc_ismevoice);
KVSM_REGISTER_FUNCTION(m,"ismehalfop",chan_kvs_fnc_ismehalfop);
KVSM_REGISTER_FUNCTION(m,"ismeop",chan_kvs_fnc_ismeop);
KVSM_REGISTER_FUNCTION(m,"ismeadmin",chan_kvs_fnc_ismeadmin);
KVSM_REGISTER_FUNCTION(m,"ismeowner",chan_kvs_fnc_ismeowner);
KVSM_REGISTER_FUNCTION(m,"isdead",chan_kvs_fnc_isdead);
KVSM_REGISTER_FUNCTION(m,"getflag",chan_kvs_fnc_getflag);
KVSM_REGISTER_FUNCTION(m,"usermodelevel",chan_kvs_fnc_usermodelevel);
KVSM_REGISTER_FUNCTION(m,"userjointime",chan_kvs_fnc_userjointime);//
KVSM_REGISTER_FUNCTION(m,"userlastactiontime",chan_kvs_fnc_userlastactiontime);
KVSM_REGISTER_FUNCTION(m,"mode",chan_kvs_fnc_mode);
KVSM_REGISTER_FUNCTION(m,"key",chan_kvs_fnc_key);
KVSM_REGISTER_FUNCTION(m,"limit",chan_kvs_fnc_limit);
KVSM_REGISTER_FUNCTION(m,"users",chan_kvs_fnc_users);
KVSM_REGISTER_FUNCTION(m,"bancount",chan_kvs_fnc_bancount);
KVSM_REGISTER_FUNCTION(m,"banexceptioncount",chan_kvs_fnc_banexceptioncount);
KVSM_REGISTER_FUNCTION(m,"invitecount",chan_kvs_fnc_invitecount);
KVSM_REGISTER_FUNCTION(m,"banlist",chan_kvs_fnc_banlist);
KVSM_REGISTER_FUNCTION(m,"banexceptionlist",chan_kvs_fnc_banexceptionlist);
KVSM_REGISTER_FUNCTION(m,"invitelist",chan_kvs_fnc_invitelist);
KVSM_REGISTER_FUNCTION(m,"matchban",chan_kvs_fnc_matchban);
KVSM_REGISTER_FUNCTION(m,"matchbanexception",chan_kvs_fnc_matchbanexception);
KVSM_REGISTER_FUNCTION(m,"matchinvite",chan_kvs_fnc_matchinvite);
KVSM_REGISTER_FUNCTION(m,"getUrl",chan_kvs_fnc_getUrl);
return true;
}
static bool chan_module_cleanup(KviModule *m)
{
return true;
}
KVIRC_MODULE(
"Chan", // module name
"1.0.0", // module version
"Copyright (C) 2002 Szymon Stefanek (pragma at kvirc dot net)"\
" (C) 2002 Juanjo Alvarez (juanjux at yahoo dot es)",
"Scripting interface for the channel management",
chan_module_init,
0,
0,
chan_module_cleanup
)
|