This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ignoreTextEvents.lua
1815 lines (1693 loc) · 62.7 KB
/
ignoreTextEvents.lua
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
__luapack_modules__ = {
(function()
local utilities = {}
-- Converts table to human readable format
--
-- @param o {input table}
--
-- @return string
--
function utilities.dump(o)
if type(o) == 'table' then
local s = '{ '
for k, v in pairs(o) do
if type(k) ~= 'number' then
k = '"' .. k .. '"'
end
s = s .. '[' .. k .. '] = ' .. utilities.dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
-- Returns an array-like table from a string s, splitting the string using
-- delimiter
--
-- @param s string to split
-- @param delimiter The delimiter to split with
--
-- @return [string]
--
function utilities.split(s, delimiter)
local result = {}
for match in (s .. delimiter):gmatch('(.-)' .. delimiter) do
table.insert(result, match)
end
if (#result == 1 and result[1] == '') then
return {}
else
return result
end
end
--!
--! @brief Joins table entries using delimiter into a string
--!
--! @param tab Array like table
--! @param delimiter The delimiter to join with
--!
--! @return string
--!
function utilities.join(tab, delimiter)
return table.concat(tab, delimiter)
end
-- Removes whitespace around string s
--
-- @param s string to remove whitespace around
--
-- @return string
--
function utilities.trim(s)
return (s:gsub('^%s*(.-)%s*$', '%1'))
end
-- Checks if table tab has value val, return false if not
--
-- @param tab The table to check
-- @param val The value to find in the table
--
-- @return True if table has value, False otherwise.
--
function utilities.has_value(tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
-- https://bitbucket.org/snippets/marcotrosi/XnyRj/lua-isequal
-- Checks if two tables are equal -- can perform deep search
--
-- @param tab1 The first table
-- @param tab2 The second table
--
-- @return True if equal for tables, False otherwise.
--
local function is_equal_for_tables(tab1, tab2)
if tab1 == tab2 then
return true
end
for key, value in pairs(tab1) do
if type(tab1[key]) ~= type(tab2[key]) then
return false
end
if type(tab1[key]) == 'table' then
if not is_equal_for_tables(tab1[key], tab2[key]) then
return false
end
else
if tab1[key] ~= tab2[key] then
return false
end
end
end
for key, value in pairs(tab2) do
if type(tab2[key]) ~= type(tab1[key]) then
return false
end
if type(tab2[key]) == 'table' then
if not is_equal_for_tables(tab2[key], tab1[key]) then
return false
end
else
if tab2[key] ~= tab1[key] then
return false
end
end
end
return true
end
-- Returns index of val in table tab or nil if not found
--
-- @param tab Table to look in
-- @param valueToFind The value to find
--
-- @return Number index or nil if not found
--
function utilities.find(tab, valueToFind)
for i, v in pairs(tab) do
if type(v) == 'table' then
if is_equal_for_tables(v, valueToFind) then
return i
end
elseif v == valueToFind then
return i
end
end
return nil
end
--!
--! @brief Takes string and sets it to len length, padding with whitespace
--! if needed
--!
--! @param str The string
--! @param len Number, The length to set it to
--!
--! @return string
--!
function utilities.length_format(str, len)
if (#str == len) then
return str
elseif (#str > len) then
return string.sub(str, 0, len)
else
for i = len - #str, 1, -1 do
str = str .. ' '
end
return str
end
end
return utilities
end),
(function()
local constants = {}
-- Delimiter variables. Changing preferences delimiter will invalidate preferences
constants.spaceDelimiter = '_,_,_,_'
constants.preferencesDelimiter = '{}}{{}'
constants.preferencesSubDelimiter = ';>;<;>'
-- Prefix for channel keys in preferences
constants.preferencesPrefix = 'ignoreTextEvents_type:'
-- Array-like table of text event strings
constants.listOfTextEvents =
{
'Add Notify',
'Ban List',
'Banned',
'Beep',
'Capability Acknowledgement',
'Capability Deleted',
'Capability List',
'Capability Request',
'Change Nick',
'Channel Action',
'Channel Action Hilight',
'Channel Ban',
'Channel Creation',
'Channel DeHalfOp',
'Channel DeOp',
'Channel DeVoice',
'Channel Exempt',
'Channel Half-Operator',
'Channel INVITE',
'Channel List',
'Channel Message',
'Channel Mode Generic',
'Channel Modes',
'Channel Msg Hilight',
'Channel Notice',
'Channel Operator',
'Channel Quiet',
'Channel Remove Exempt',
'Channel Remove Invite',
'Channel Remove Keyword',
'Channel Remove Limit',
'Channel Set Key',
'Channel Set Limit',
'Channel UnBan',
'Channel UnQuiet',
'Channel Url',
'Channel Voice',
'Connected',
'Connecting',
'Connection Failed',
'CTCP Generic',
'CTCP Generic to Channel',
'CTCP Send',
'CTCP Sound',
'CTCP Sound to Channel',
'DCC CHAT Abort',
'DCC CHAT Connect',
'DCC CHAT Failed',
'DCC CHAT Offer',
'DCC CHAT Offering',
'DCC CHAT Reoffer',
'DCC Conection Failed',
'DCC Generic Offer',
'DCC Header',
'DCC Malformed',
'DCC Offer',
'DCC Offer Not Valid',
'DCC RECV Abort',
'DCC RECV Complete',
'DCC RECV Connect',
'DCC RECV Failed',
'DCC RECV File Open Error',
'DCC Rename',
'DCC RESUME Request',
'DCC SEND Abort',
'DCC SEND Complete',
'DCC SEND Connect',
'DCC SEND Failed',
'DCC SEND Offer',
'DCC Stall',
'DCC Timeout',
'Delete Notify',
'Disconnected',
'Found IP',
'Generic Message',
'Ignore Add',
'Ignore Changed',
'Ignore Footer',
'Ignore Header',
'Ignore Remove',
'Ignorelist Empty',
'Invite',
'Invited',
'Join',
'Keyword',
'Kick',
'Killed',
'Message Send',
'Motd',
'MOTD Skipped',
'Nick Clash',
'Nick Erroneous',
'Nick Failed',
'No DCC',
'No Running Process',
'Notice',
'Notice Send',
'Notify Away',
'Notify Back',
'Notify Empty',
'Notify Header',
'Notify Number',
'Notify Offline',
'Notify Online',
'Open Dialog',
'Part',
'Part with Reason',
'Ping Reply',
'Ping Timeout',
'Private Action',
'Private Action to Dialog',
'Private Message',
'Private Message to Dialog',
'Process Already Running',
'Quit',
'Raw Modes',
'Receive Wallops',
'Resolving User',
'SASL Authenticating',
'SASL Response',
'Server Connected',
'Server Error',
'Server Lookup',
'Server Notice',
'Server Text',
'SSL Message',
'Stop Connection',
'Topic',
'Topic Change',
'Topic Creation',
'Unknown Host',
'User Limit',
'Users On Channel',
'WhoIs Authenticated',
'WhoIs Away Line',
'WhoIs Channel/Oper Line',
'WhoIs End',
'WhoIs Identified',
'WhoIs Idle Line',
'WhoIs Idle Line with Signon',
'WhoIs Name Line',
'WhoIs Real Host',
'WhoIs Server Line',
'WhoIs Special',
'You Join',
'You Kicked',
'You Part',
'You Part with Reason',
'Your Action',
'Your Invitation',
'Your Message',
'Your Nick Changing',
}
return constants
end),
(function()
local db_utils = {}
local util = __luapack_require__(1)
local const = __luapack_require__(2)
-- Splits string into array using comma delimiter
--
-- @param eventsString The events string to be split
--
-- @return [string]
--
function db_utils.comma_delim_string_to_array(value)
local returnArray = util.split(value, ',')
return returnArray
end
-- Opposite of above -- takes flat array like table and concatenates it into a
-- string split by commas
--
-- @param eventsArray Flat array like table of strings
--
-- @return string
--
function db_utils.array_to_comma_delim_string(valueArray)
local returnString = ''
returnString = returnString .. util.join(valueArray, ',')
return returnString
end
--!
--! @brief Takes key from database and extracts the keyType
--! (channel/network/global)
--!
--! @param key The key from the database
--!
--! @return String or nil if not found
--!
function db_utils.extract_keyType(key)
local locationOfFirstDelim =
string.find(key, const.preferencesDelimiter, 0, true)
if locationOfFirstDelim then
return key:sub(
string.len(const.preferencesPrefix) + 1,
locationOfFirstDelim - 1
)
else
return nil
end
end
--!
--! @brief Converts a database key into a more workable table
--!
--! @param key The key from the database
--!
--! @return {keyType = string, textevent/network/channel = string}
--!
function db_utils.convert_key_to_table(key)
local keyType = db_utils.extract_keyType(key)
local keyArray = util.split(key, const.preferencesDelimiter)
local returnTable = { keyType = keyType }
if keyType == 'textevent' then
returnTable['textevent'] = keyArray[2]
elseif keyType ~= 'global' then
returnTable['network'] = keyArray[2]
if keyType == 'channel' then
returnTable['channel'] = keyArray[3]
end
end
return returnTable
end
return db_utils
end),
(function()
local db = {}
local db_utils = __luapack_require__(3)
local const = __luapack_require__(2)
local util = __luapack_require__(1)
-- Creates string corresponding to key in preferences
--
-- @param keyType global, channel, network, textevent
-- @param networkOrTextEvent (Optional) The network or text event
-- @param channel (Optional) The channel
--
-- @return string
--
local function compose_preferences_key(keyType, networkOrTextEvent, channel)
if channel then
return const.preferencesPrefix .. keyType .. const.preferencesDelimiter .. networkOrTextEvent .. const.preferencesDelimiter .. channel
elseif networkOrTextEvent then
return const.preferencesPrefix .. keyType .. const.preferencesDelimiter .. networkOrTextEvent
else
return const.preferencesPrefix .. keyType
end
end
----------------------------------------------------
-- Plugin preferences: general
----------------------------------------------------
-- Set version, for future proofing in case a reset is ever needed
--
-- @param version The version in semantic versioning format
--
function db.set_version(version)
hexchat.pluginprefs['version'] = 'v' .. version
end
-- Resets all hexchat plugin preferences related to this script
function db.reset()
for a, b in pairs(hexchat.pluginprefs) do
hexchat.pluginprefs[a] = nil
end
end
function db.debug()
print(util.dump(hexchat.pluginprefs))
end
----------------------------------------------------
-- Plugin preferences: set and get from database
----------------------------------------------------
-- Get plugin preferences value based on inputs or empty string if not found
--
-- @param keyType global, channel, network, textevent
-- @param networkOrTextEvent (Optional) The network or text event
-- @param channel (Optional) The channel
--
-- @return string
--
function db.get_preference_valuestring(keyType, networkOrTextEvent, channel)
local pref = false
pref =
hexchat.pluginprefs[compose_preferences_key(
keyType,
networkOrTextEvent,
channel
)]
if pref then
return pref
end
return ''
end
-- Set plugin preferences value
--
-- @param keyType global, channel, network, textevent
-- @param value The value to set the key to
-- @param networkOrTextEvent (Optional) The network or text event
-- @param channel (Optional) The channel
--
-- @return { description_of_the_return_value }
--
function db.set_preference_valuestring(
keyType,
value,
networkOrTextEvent,
channel
)
hexchat.pluginprefs[compose_preferences_key(
keyType,
networkOrTextEvent,
channel
)]
= value
end
--!
--! @brief Checks if a key string is of type keyType
--!
--! @param keyType string: global, network, channel, textevent
--! @param key key string
--!
--! @return True if keytype, False otherwise.
--!
local function is_keytype(keyType, key)
if db_utils.extract_keyType(key) == keyType then
return true
else
return false
end
end
-- Iterates through preferences of keyType and passes their names and
-- values to given function
--
-- @param keyType string: global, network, channel, textevent
-- @param lambda The lambda function to call with the key and value
--
-- @return { description_of_the_return_value }
--
function db.iterate_prefs_over_lambda(keyType, lambda)
for key, value in pairs(hexchat.pluginprefs) do
if is_keytype(keyType, key) then
lambda(key, value)
end
end
end
return db
end),
(function()
local models_channetg = {}
local db = __luapack_require__(4)
local db_utils = __luapack_require__(3)
local util = __luapack_require__(1)
----------------------------------------------------
-- Models: Channel/network/global aka Channetg
--
-- DB model:
-- ignoreTextEvents_type:channel/network,
-- network name,
-- (if channel) channel name
-- =
-- list of text events
----------------------------------------------------
--!
--! @brief Gets the events ignored in current context in an array-like
--! table
--!
--! @param keyType The context to ignore in: global, network, channel
--! @param network (Optional) The network to ignore in
--! @param channel (Optional) The channel to ignore in
--!
--! @return [string]
--!
function models_channetg.get_events_array(keyType, network, channel)
return db_utils.comma_delim_string_to_array(
db.get_preference_valuestring(keyType, network, channel)
)
end
--!
--! @brief Adds an event to the channel/network/global models.
--!
--! @param keyType The context to ignore in: global, network, channel
--! @param event The textevent to ignore
--! @param network (Optional) The network to ignore in
--! @param channel (Optional) The channel to ignore in
--!
function models_channetg.add_event(keyType, event, network, channel)
local previousValueTable =
models_channetg.get_events_array(keyType, network, channel)
if previousValueTable ~= nil and next(
previousValueTable
) ~= nil and previousValueTable[1] ~= '' then
table.insert(previousValueTable, event)
else
previousValueTable = { event }
end
local newValue = db_utils.array_to_comma_delim_string(previousValueTable)
db.set_preference_valuestring(keyType, newValue, network, channel)
end
--!
--! @brief Removes an event from channel/network/global models
--!
--! @param keyType The context to ignore in: global, network, channel
--! @param event The textevent to ignore
--! @param network (Optional) The network to ignore in
--! @param channel (Optional) The channel to ignore in
--!
--! @return [array-like table of value strings]
--!
function models_channetg.remove_event(keyType, event, network, channel)
local previousValueTable =
models_channetg.get_events_array(keyType, network, channel)
table.remove(previousValueTable, util.find(previousValueTable, event))
local newValue = db_utils.array_to_comma_delim_string(previousValueTable)
if newValue == '' then
newValue = nil
end
db.set_preference_valuestring(keyType, newValue, network, channel)
return previousValueTable
end
--!
--! @brief Iterates all database values matching keyType over lambda. Key
--! is converted to {channel=string,network=string} format.
--!
--! @param keyType The key type -- network, channel, global
--! @param lambda The lambda with two arguments roughly corresponding to
--! key,value
--!
function models_channetg.iterate_over_lambda(keyType, lambda)
local model_lambda = function(name, value)
local chanNetTable = db_utils.convert_key_to_table(name)
lambda(chanNetTable, value)
end
db.iterate_prefs_over_lambda(keyType, model_lambda)
end
return models_channetg
end),
(function()
local models_textEvent = {}
local db = __luapack_require__(4)
local db_util = __luapack_require__(3)
local util = __luapack_require__(1)
local const = __luapack_require__(2)
----------------------------------------------------
-- Models: text event
-- DB model:
-- ignoreTextEvents_type:textevent,
-- text event name
-- =
-- global boolean,
-- networks,
-- channel;;;;;;network pairs
--
-- Value should look something like:
-- gbool||||||n1,n3,n3||||||c1;;;;;;nc1,c2;;;;;;nc2,c3;;;;;;nc3
----------------------------------------------------
--!
--! @brief Convert textevent model database value into table
--!
--! @param value The database value -- see info above
--!
--! @return {global=string,networks=[string],channets=[{channel=string,
--! network=string}]}
--!
local function convert_tevalue_to_table(value)
local splitTable = util.split(value, const.preferencesDelimiter)
if #splitTable == 3 then
local formattedTable = {}
formattedTable['global'] = splitTable[1]
formattedTable['networks'] = util.split(splitTable[2], ',')
local channetUndelim = util.split(splitTable[3], ',')
formattedTable['channets'] = {}
for i, channet in pairs(channetUndelim) do
local channetPair =
util.split(channet, const.preferencesSubDelimiter)
table.insert(formattedTable['channets'], {
channel = channetPair[1],
network = channetPair[2],
})
end
return formattedTable
else
return {
global = 'false',
networks = {},
channets = {},
}
end
end
--!
--! @brief Opposite operation of above function -- output from above
--! function into a value for storing in the database
--!
--! @param valueTable The value table generated from
--! convert_tevalue_to_table
--!
--! @return String, the database value -- see info above
--!
local function convert_table_to_tevalue(valueTable)
local returnString = ''
returnString =
returnString .. valueTable['global'] .. const.preferencesDelimiter
returnString =
returnString .. util.join(
valueTable['networks'],
','
) .. const.preferencesDelimiter
local channetArray = {}
for i, channet in pairs(valueTable['channets']) do
local channetString =
channet['channel'] .. const.preferencesSubDelimiter .. channet['network']
table.insert(channetArray, channetString)
end
returnString = returnString .. util.join(channetArray, ',')
return returnString
end
--!
--! @brief Returns info table about event in database
--!
--! @param event The event string
--!
--! @return {global=string,networks=[string],channets=[{channel=string,
--! network=string}]}
--!
function models_textEvent.get_event(event)
local prefValue = db.get_preference_valuestring('textevent', event)
local formattedTable = convert_tevalue_to_table(prefValue)
return formattedTable
end
--!
--! @brief Adds an event to the models_textEvent model in the database.
--!
--! @param keyType The context to ignore in: global, network, channel
--! @param event The textevent to ignore
--! @param network (Optional) The network to ignore in
--! @param channel (Optional) The channel to ignore in
--!
function models_textEvent.add_event(keyType, event, network, channel)
local formattedTable = models_textEvent.get_event(event)
if keyType == 'global' then
formattedTable['global'] = 'true'
elseif keyType == 'network' then
table.insert(formattedTable['networks'], network)
else
table.insert(formattedTable['channets'], {
channel = channel,
network = network,
})
end
local formattedTextEventValue = convert_table_to_tevalue(formattedTable)
db.set_preference_valuestring('textevent', formattedTextEventValue, event)
end
--!
--! @brief Removes an event from the models_textEvent model in the database.
--!
--! @param keyType The context to ignore in: global, network, channel
--! @param event The textevent to ignore
--! @param network (Optional) The network to ignore in
--! @param channel (Optional) The channel to ignore in
--!
function models_textEvent.remove_event(keyType, event, network, channel)
local formattedTable = models_textEvent.get_event(event)
if keyType == 'global' then
formattedTable['global'] = 'false'
elseif keyType == 'network' then
table.remove(
formattedTable['networks'],
util.find(formattedTable['networks'], network)
)
else
table.remove(
formattedTable['channets'],
util.find(formattedTable['channets'], {
channel = channel,
network = network,
})
)
end
local formattedTextEventValue = convert_table_to_tevalue(formattedTable)
if formattedTextEventValue == ('false' .. const.preferencesDelimiter .. const.preferencesDelimiter) then
formattedTextEventValue = nil
end
db.set_preference_valuestring('textevent', formattedTextEventValue, event)
end
--!
--! @brief Iterates all database values matching textevent model over
--! lambda. Key is converted to a string indicating the event. Value
--! is converted into
--! {global=string,networks=[string],channets=[{channel=string,
--! network=string}]} format.
--!
--! @param lambda The lambda with two arguments roughly corresponding to
--! key,value
--!
function models_textEvent.iterate_over_lambda(lambda)
local model_lambda = function(name, value)
local delimStart, delimEnd =
string.find(name, const.preferencesDelimiter, 0, true)
local event = name:sub(delimEnd + 1)
local ignoredData = convert_tevalue_to_table(value)
lambda(event, ignoredData)
end
db.iterate_prefs_over_lambda('textevent', model_lambda)
end
return models_textEvent
end),
(function()
local models = {}
local channetg = __luapack_require__(5)
local te = __luapack_require__(6)
local db = __luapack_require__(4)
--!
--! @brief Adds an event to both model types.
--!
--! @param keyType The context to ignore in: global, network, channel
--! @param event The textevent to ignore
--! @param network (Optional) The network to ignore in
--! @param channel (Optional) The channel to ignore in
--!
--! @return { description_of_the_return_value }
--!
function models.add_event(keyType, event, network, channel)
channetg.add_event(keyType, event, network, channel)
te.add_event(keyType, event, network, channel)
end
--!
--! @brief Removes an event from both models types.
--!
--! @param keyType The context to ignore in: global, network, channel
--! @param event The textevent to ignore
--! @param network (Optional) The network to ignore in
--! @param channel (Optional) The channel to ignore in
--!
--! @return [string array of events in current context]
--!
function models.remove_event(keyType, event, network, channel)
local updatedValueTable =
channetg.remove_event(keyType, event, network, channel)
te.remove_event(keyType, event, network, channel)
return updatedValueTable
end
--!
--! @brief Resets the database.
--!
function models.reset()
db.reset()
end
--!
--! @brief Prints out information from database.
--!
function models.debug()
db.debug()
end
--!
--! @brief Iterates lambda over text event information.
--!
--! @param lambda The lambda -- see models_te for info
--!
function models.iterate_over_all_event_data(lambda)
te.iterate_over_lambda(lambda)
end
--!
--! @brief Sets the version in the database
--!
--! @param version The version string
--!
function models.set_version(version)
db.set_version(version)
end
return models
end),
(function()
local views = {}
local channet = __luapack_require__(5)
local const = __luapack_require__(2)
local util = __luapack_require__(1)
local db_utils = __luapack_require__(3)
local models = __luapack_require__(7)
----------------------------------------------------
-- Views: Menu manipulation
----------------------------------------------------
--!
--! @brief Adds a text event to an already created menu.
--!
--! @param eventsString The event or comma delim string of events
--! @param menuSettings {type=channel/network,network=string,
--! (channel)=string}
--!
local function add_text_events_to_currently_ignored_in_menu(
eventsString,
menuSettings
)
local eventsArray = db_utils.comma_delim_string_to_array(eventsString)
for key, event in pairs(eventsArray) do
local commandToAdd =
'menu -t1 add "Settings/Ignore Text Events/Events Currently Ignored In/'
if (menuSettings.type == 'channel') then
commandToAdd =
commandToAdd .. 'Channels/' .. menuSettings.network:gsub(
'/',
'|'
) .. '/' .. menuSettings.channel:gsub('/', '|') .. '/'
else
commandToAdd =
commandToAdd .. 'Networks/' .. menuSettings.network:gsub(
'/',
'|'
) .. '/'
end
commandToAdd =
commandToAdd .. event .. '" "" "stopIgnoringEvent ' .. menuSettings.type .. ' ' .. event:gsub(
' ',
const.spaceDelimiter
) .. ' ' .. menuSettings.network:gsub(' ', const.spaceDelimiter)
if (menuSettings.type == 'channel') then
commandToAdd =
commandToAdd .. ' ' .. menuSettings.channel:gsub(
' ',
const.spaceDelimiter
)
end
commandToAdd = commandToAdd .. '"'
hexchat.command(commandToAdd)
end
end
--!
--! @brief Adds a currently ignored in > network > channel > event item
--!
--! @param network The network the channel is in
--! @param channel The channel to ignore
--! @param eventsString The event string (or multiple events comma delim)
--!
--! @return { description_of_the_return_value }
--!
local function add_ignored_channel_menu(network, channel, eventsString)
hexchat.command(
'menu add "Settings/Ignore Text Events/Events Currently Ignored In/Channels/' .. network:gsub(
'/',
'|'
) .. '"'
)
hexchat.command(
'menu add "Settings/Ignore Text Events/Events Currently Ignored In/Channels/' .. network:gsub(
'/',
'|'
) .. '/' .. channel:gsub('/', '|') .. '"'
)
local menuSettings = {
type = 'channel',
channel = channel,
network = network,
}
add_text_events_to_currently_ignored_in_menu(eventsString, menuSettings)
end
--!
--! @brief Adds a currently ignored in > network > event menu item toggle
--!
--! @param network The network to ignore
--! @param eventsString The event string (or multiple events comma delim)
--!
local function add_ignored_network_menu(network, eventsString)
hexchat.command(
'menu add "Settings/Ignore Text Events/Events Currently Ignored In/Networks/' .. network:gsub(
'/',
'|'
) .. '"'
)
local menuSettings = {
type = 'network',