forked from mike347/ATSPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATS_Chatgrabber.xml
1525 lines (1345 loc) · 56 KB
/
ATS_Chatgrabber.xml
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
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Bits of this plugin and ideas were borrowed and remixed from the MUSHclient community. http://www.gammon.com.au/forum/?id=9385 and others. -->
<!-- Modifications for Aardwolf and extra awesome sauce added by Fiendish with help from Orogan -->
<!-- Adapated by Nick Gammon for Smaug and similar MUDs -->
<!-- Adapted for ATS, multiwindow support and major enhancements by Mike Taylor (Qon@ATS) -->
<muclient>
<plugin
name="QonChatGrabber_Master"
author="Qon@ATS|Nick Gammon|Fiendish"
id="de6b99ef3f79191fd27d59b0"
language="Lua"
purpose="Move channels to a miniwindow"
date_written="2010-04-04"
date_modified="2015-01-04"
requires="4.84"
version="2.25"
save_state="y"
>
<description trim="y">
USAGE:
LH-click a line to copy it to the clipboard
RH-click main window to see menu of options
Click title bar to drag window.
You should do 'update channels' before anything else
</description>
</plugin>
<triggers>
<trigger
enabled="y" regexp="y"
match="^(.+) (\(\d+\)) (\(.+->\)).+ \[([\d.]+)\].+$"
script="message_handler"
omit_from_output="y"
sequence="100"
send_to="14"
name="navcomp"
group="ATSChatGrabber"
></trigger>
<trigger
enabled="y" regexp="y"
match="^BC .+ --> .+ to dest.$"
script="message_handler"
omit_from_output="y"
sequence="100"
send_to="14"
name="navcomp_bc"
group="ATSChatGrabber"
></trigger>
<trigger
enabled="y"
regexp ="y"
match="^(?:\[.+\] )?<(.*?)> .*$"
script="message_handler"
omit_from_output="y"
sequence="100"
send_to="12"
name="channel"
group="ATSChatGrabber"
></trigger>
<trigger
enabled="y"
regexp ="y"
match="^\[.*\]--\[S2S to (.*):.*\]$"
script="message_handler"
omit_from_output="y"
sequence="100"
send_to="14"
name="s2s_out"
group="ATSChatGrabber"
></trigger>
<trigger
enabled="y"
regexp ="y"
match="^(?:\[.+\] )?<.*?>\-\-<.*?>$"
script="message_handler"
omit_from_output="y"
sequence="40"
send_to="14"
name="s2s_in"
group="ATSChatGrabber"
></trigger>
<trigger
enabled="y" regexp="y"
match="^(?:\[.+\] )?<OOC> (.*)$"
script="message_handler"
omit_from_output="y"
sequence="50"
send_to="14"
name="ooc"
group="ATSChatGrabber"
></trigger>
<trigger
enabled="y" keep_evaluating="y" regexp="y" omit_from_output="y"
match="^(.* pages .*: |Long distance to |You paged |From afar(,)? |.* pages: |\(To: .*\) ).*"
script="message_handler"
sequence="100"
send_to="14"
name="pages"
group="ATSChatGrabber"
></trigger>
<trigger
enabled="y" keep_evaluating="y" regexp="y" omit_from_output="y"
match="^\[([\d\:]+)\]\sIdle\smessage\ssent\sto.*$"
script="message_handler"
sequence="100"
send_to="14"
name="idlemsg"
group="ATSChatGrabber"
></trigger>
</triggers>
<aliases>
<alias
script="chat_echo"
match="^chats echo( on| off)?$"
enabled="y"
regexp="y"
sequence="100"
ignore_case="y"
group="ATSChatGrabber"
></alias>
<alias
script="chat_show"
match="chats show"
enabled="y"
sequence="100"
ignore_case="y"
group="ATSChatGrabber"
></alias>
<alias
script="chat_hide"
match="chats hide"
enabled="y"
sequence="100"
ignore_case="y"
group="ATSChatGrabber"
></alias>
</aliases>
<script>
<![CDATA[
require "movewindow" -- load the movewindow.lua module
require "copytable"
require "pairsbykeys"
require "serialize"
-- Storage for anti-spam filter
status_table = { }
tractor_table = { }
channel_table = { }
search_table = { }
last_search = nil
URL_table = { }
SEARCH_INFO = [[
Search chat window. You can use LUA-type regexp, or globular searches.
E.g. '* says' or
'(Cantitia|Spro) pages: .+'.
See http://lua-users.org/wiki/PatternsTutorial for more examples of searching using Lua Regex-style expressions
]]
assert(loadstring(GetVariable("channel_table") or ""))()
config_table = { }
assert(loadstring(GetVariable("config_table") or "config_table = { pages = false, ooc = false, navcomp = false, s2s = false, spam = true, autoshorten = false, wrapwords = false }"))()
window_title = GetVariable("title") or nil
assert(loadstring(GetVariable("DATA") or ""))()
last_line = 0
if (not window_title ) then
if (GetPluginID() == "de6b99ef3f79191fd27d59b0") then
window_title = "Master"
else
window_title = "Slave"
end
end
BODY_FONT_NAME = GetVariable("bodyfont") or "Dina"
BODY_FONT_SIZE = tonumber(GetVariable("font_size") or 8)
SCROLL_BAR_WIDTH = 15
MAX_LINES = 7500 -- how many lines to store in scrollback
-- date_format = "[%d %b %H:%M:%S] " -- [30 Aug 13:29:49] date and time 24 hour
-- date_format = "[%d %b %I:%M:%S%p] " -- [30 Aug 01:20:12PM] date and time 12 hour
-- date_format = "[%H:%M:%S] " -- [13:29:08] time 24 hour
-- date_format = "[%X] " -- [1:22:06 PM] time 12 hour
TIMESTAMP_TEXT_COLOUR = "white"
TIMESTAMP_BACK_COLOUR = "black"
-- doing it this way makes them default to true the first time around
timestamp = not (GetVariable("timestamp") == "false")
echo = GetVariable("echo") or false
date_format = GetVariable("date_format")
WINDOW_WIDTH = tonumber(GetVariable("WINDOW_WIDTH"))
WINDOW_HEIGHT = tonumber(GetVariable("WINDOW_HEIGHT"))
-- offset of text from edge
TEXT_INSET = 5
-- where to store the chat line
lines = {} -- table of recent chat lines
rawlines = {}
lineStart = ""
lineEnd = ""
WINDOW_COLUMNS = ""
WINDOW_LINES = ""
assert(loadstring(GetVariable("DATA") or ""))()
theme = {
WINDOW_BACKGROUND = ColourNameToRGB ("#000000"), -- for miniwindow body
WINDOW_BORDER = ColourNameToRGB("#E8E8E8"), -- for miniwindow body
HIGHLIGHT=ColourNameToRGB("#FFFFFF"), -- for 3D surfaces
FACE=ColourNameToRGB("#D4D0C8"), -- for 3D surfaces
INNERSHADOW=ColourNameToRGB("#808080"), -- for 3D surfaces
OUTERSHADOW = ColourNameToRGB("#404040"), -- for 3D surfaces
BACK_FACE = ColourNameToRGB ("#E8E8E8"), -- for contrasting details
DETAIL = ColourNameToRGB ("#000000"), -- for contrasting details
TITLE_HEIGHT = 17, -- for miniwindow title area
SUBTITLE_HEIGHT = 17, -- for miniwindow title area
TITLE_FONT_NAME = "Dina", -- for miniwindow title area
TITLE_FONT_SIZE = 8 -- for miniwindow title area
} -- end theme table
-- replacement for WindowRectOp action 5, which allows for a 3D look while maintaining color theme
-- Requires global theme.HIGHLIGHT, theme.FACE, theme.INNERSHADOW, and theme.OUTERSHADOW rgb colors to be set.
function DrawThemed3DRect(Window, left, top, right, bottom)
WindowRectOp(Window, miniwin.rect_fill, left, top, right, bottom, theme.FACE)
WindowLine(Window, left, top, right, top, theme.HIGHLIGHT,
miniwin.pen_solid + miniwin.pen_endcap_flat, 1)
WindowLine(Window, left, top, left, bottom, theme.HIGHLIGHT,
miniwin.pen_solid + miniwin.pen_endcap_flat, 1)
WindowLine(Window, left, bottom-2, right, bottom-2, theme.INNERSHADOW,
miniwin.pen_solid + miniwin.pen_endcap_flat, 1)
WindowLine(Window, right-2, top, right-2, bottom-2, theme.INNERSHADOW,
miniwin.pen_solid + miniwin.pen_endcap_flat, 1)
WindowLine(Window, left, bottom-1, right, bottom-1, theme.OUTERSHADOW,
miniwin.pen_solid + miniwin.pen_endcap_flat, 1)
WindowLine(Window, right-1, top, right-1, bottom-1, theme.OUTERSHADOW,
miniwin.pen_solid + miniwin.pen_endcap_flat, 1)
end
function DrawThemedResizeTag(Window, x1, y1, size)
local x2, y2 = x1+size, y1+size
DrawThemed3DRect(Window, x1, y1, x2, y2)
local m = 2
local n = 2
while (x1+m+2 <= x2-3 and y1+n+1 <= y2-4) do
WindowLine(Window, x1+m+1, y2-4, x2-3, y1+n, theme.HIGHLIGHT,
miniwin.pen_solid, 1)
WindowLine(Window, x1+m+2, y2-4, x2-3, y1+n+1, theme.INNERSHADOW,
miniwin.pen_solid, 1)
m = m+3
n = n+3
end
end -- function DrawThemedResizeTag
Win = GetPluginID()
font_height = ""
line_height = ""
windowinfo = ""
startx = ""
starty = ""
function ResizeMoveCallback()
posx, posy = WindowInfo (Win, 17), WindowInfo (Win, 18)
if (WindowTextWidth(Win, "titlefont"..Win, window_title)+2*SCROLL_BAR_WIDTH <= WINDOW_WIDTH+posx-startx) then
WINDOW_WIDTH = WINDOW_WIDTH+posx-startx
startx = posx
end -- if
if (3*SCROLL_BAR_WIDTH+10+line_height+theme.TITLE_HEIGHT <= WINDOW_HEIGHT+posy-starty) then
WINDOW_HEIGHT = WINDOW_HEIGHT+posy-starty
starty = posy
end -- if
init(false)
end -- function ResizeMoveCallback
function ResizeReleaseCallback()
WINDOW_HEIGHT = theme.TITLE_HEIGHT+(line_height*(WINDOW_LINES-1))+3
init(true)
end -- ResizeReleaseCallback
function OnPluginInstall()
local myID = GetPluginID()
-- If we are a slave, disable the triggers and aliases
if (GetPluginID() ~= "de6b99ef3f79191fd27d59b0") then
EnableTriggerGroup("ATSChatGrabber", false)
EnableAliasGroup("ATSChatGrabber", false)
end
-- Dummy window to get font characteristics
check (WindowCreate (Win, 0, 0, 1, 1, 0, 0, theme.WINDOW_BACKGROUND) )
check (WindowFont(Win, "bodyfont"..Win, BODY_FONT_NAME, BODY_FONT_SIZE))
check (WindowFont(Win, "titlefont"..Win, theme.TITLE_FONT_NAME, theme.TITLE_FONT_SIZE))
check (WindowFont(Win, "bodyfontul"..Win, BODY_FONT_NAME, BODY_FONT_SIZE,false, false, true))
font_height = WindowFontInfo (Win, "bodyfont"..Win, 1) - WindowFontInfo (Win, "bodyfont"..Win, 4) + 1
line_height = font_height+1
font_width = WindowTextWidth (Win, "bodyfont"..Win, "W")
-- install the window movement handler, get back the window position
windowinfo = movewindow.install (Win, miniwin.pos_top_right, miniwin.create_absolute_location, true)
-- check for Echo/Timestamp/date_format/window size (in pixels) variables, if not there, set them
if date_format == nil then
date_format = "[%d %b %H:%M:%S] "
end -- if
if WINDOW_WIDTH == nil then
WINDOW_WIDTH = (font_width*80)+SCROLL_BAR_WIDTH -- 80 columns
end
if WINDOW_HEIGHT == nil then
WINDOW_HEIGHT = theme.TITLE_HEIGHT+(line_height*6)+2 -- 6 lines
end -- if
init(true)
OnPluginEnable () -- do initialization stuff
end -- function OnPluginInstall
function init(firstTime)
-- how many lines and columns will fit?
WINDOW_LINES = math.ceil((WINDOW_HEIGHT-theme.TITLE_HEIGHT)/line_height)
WINDOW_COLUMNS = math.ceil((WINDOW_WIDTH-SCROLL_BAR_WIDTH)/font_width)
local reallyFirstTime = false
if firstTime then
WindowCreate(Win, windowinfo.window_left, windowinfo.window_top, WINDOW_WIDTH, WINDOW_HEIGHT, windowinfo.window_mode, windowinfo.window_flags, theme.WINDOW_BACKGROUND)
-- catch for right-click menu and line selection
WindowAddHotspot(Win, "textarea", 0, theme.TITLE_HEIGHT, WINDOW_WIDTH-SCROLL_BAR_WIDTH,0,
"", "", "MouseDown", "CancelMouseDown", "MouseUp", "",
miniwin.cursor_ibeam, 0)
-- Scrollwheel hook
WindowScrollwheelHandler(Win, "textarea", "wheel_move")
-- add the drag handler so they can move the window around
movewindow.add_drag_handler (Win, 0, 0, 0, theme.TITLE_HEIGHT)
-- scroll bar up/down buttons
WindowAddHotspot(Win, "up", WINDOW_WIDTH-SCROLL_BAR_WIDTH, theme.TITLE_HEIGHT, 0, theme.TITLE_HEIGHT+SCROLL_BAR_WIDTH,
"MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", "",
miniwin.cursor_hand, 0)
WindowAddHotspot(Win, "down", WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-(2*SCROLL_BAR_WIDTH), 0, WINDOW_HEIGHT-SCROLL_BAR_WIDTH,
"MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", "",
miniwin.cursor_hand, 0)
-- add the resize widget hotspot
WindowAddHotspot(Win, "resizer", WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-SCROLL_BAR_WIDTH, WINDOW_WIDTH, WINDOW_HEIGHT,
"MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", "",
miniwin.cursor_nw_se_arrow, 0)
WindowDragHandler(Win, "resizer", "ResizeMoveCallback", "ResizeReleaseCallback", 0)
else
WindowResize(Win, WINDOW_WIDTH, WINDOW_HEIGHT, theme.WINDOW_BACKGROUND)
WindowMoveHotspot(Win, "textarea", 0, theme.TITLE_HEIGHT, WINDOW_WIDTH-SCROLL_BAR_WIDTH, 0)
WindowMoveHotspot(Win, "up", WINDOW_WIDTH-SCROLL_BAR_WIDTH, theme.TITLE_HEIGHT, 0, theme.TITLE_HEIGHT+SCROLL_BAR_WIDTH)
WindowMoveHotspot(Win, "down", WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-(2*SCROLL_BAR_WIDTH), 0, WINDOW_HEIGHT-SCROLL_BAR_WIDTH)
WindowMoveHotspot(Win, "resizer", WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-SCROLL_BAR_WIDTH, WINDOW_WIDTH, 0)
end -- if
WindowShow(Win, true)
lineStart = 1
lineEnd = #rawlines or 1
if (firstTime == true) then
local startTime = GetInfo (232)
lines = {}
for _,styles in ipairs(rawlines) do
fillBuffer(styles)
end -- for each line
local endTime = GetInfo (232)
ColourNote("orange", "", string.format("%s v%s (%s) loaded. (%fs)",GetPluginInfo(GetPluginID(),1), GetPluginInfo(GetPluginID(),19),
window_title, endTime - startTime))
end -- if
lineStart = math.max(1, #lines-WINDOW_LINES+2)
lineEnd = math.max(1, #lines)
refresh()
end -- function init
function OnPluginClose ()
-- if enabled
if GetPluginInfo (GetPluginID(), 17) then
OnPluginDisable()
end -- if enabled
end -- function OnPluginClose
function OnPluginEnable ()
WindowShow (Win, true)
end -- function OnPluginEnable
function OnPluginSaveState ()
-- save window current location for next time
SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID(), 17)))
movewindow.save_state (Win)
-- save echo/timestamp status
if (echo) then
SetVariable ("echo", 1)
else
DeleteVariable("echo")
end
SetVariable ("timestamp", tostring (timestamp))
SetVariable("date_format", date_format)
SetVariable("WINDOW_WIDTH", WINDOW_WIDTH)
SetVariable("WINDOW_HEIGHT", WINDOW_HEIGHT)
SetVariable("channel_table", serialize.save("channel_table"))
SetVariable("title", window_title)
local rawStart, rawEnd = 1, #rawlines
local r = { }
if(rawEnd > 500) then
rawStart = #rawlines - 500
end
local ii = 1
for i = rawStart, rawEnd do
r[ii] = rawlines[i]
ii = ii + 1
end
SetVariable("DATA", serialize.save("rawlines", r))
end -- function OnPluginSaveState
function OnPluginDisable ()
WindowShow( Win, false )
end -- function OnPluginDisable
-- display one line
function Display_Line (line, styles)
local left = TEXT_INSET
local top = theme.TITLE_HEIGHT + (line * line_height) + 1
local bottom = top + line_height
local font = "bodyfont" .. Win
local fontul = "bodyfontul" .. Win
-- Delete any current hotspots.
WindowDeleteHotspot(Win, "line_1_" .. tostring(line))
WindowDeleteHotspot(Win, "line_2_" .. tostring(line))
--WindowDeleteHotspot(Win, "line_" .. tostring(line)) -- Probably don't need this, since we ALWAYS reuse this?
WindowDeleteHotspot(Win, "hyperlink_" .. tostring(line))
if backfill then
WindowRectOp (Win, miniwin.rect_fill, 1, top, WINDOW_WIDTH - SCROLL_BAR_WIDTH, bottom, ColourNameToRGB("#333333"))
end -- backfill
if (styles) then
for _, style in ipairs (styles) do
if (config_table.tooltip and timestamp and style.timestamp) then
else
local width = WindowTextWidth (Win, font, style.text) -- get width of text
local right = left + width
local urls = findURLs(style.text)
if (style.hilite or styles.hilite) then
WindowRectOp (Win, miniwin.rect_fill, left, top, right, bottom, ColourNameToRGB("yellow")) -- draw background
WindowText (Win, font, style.text, left, top, 0, 0, ColourNameToRGB("black")) -- draw text
else
WindowRectOp (Win, miniwin.rect_fill, left, top, right, bottom, style.backcolour) -- draw background
if(urls) then
local sStart = style.text:sub(1, urls.start-1)
local sEnd = style.text:sub(urls.stop+1, #style.text)
local ws = WindowTextWidth(Win, font, sStart) -- Width of text BEFORE the hyperlink
local we = WindowTextWidth(Win, font, sEnd) -- Width of text AFTER hyperlink
local wh = WindowTextWidth(Win, fontul, urls.text) -- Width of the hyperlink itself
WindowText (Win, font, sStart, left, top, 0, 0, style.textcolour) -- draw text
WindowText (Win, fontul, urls.text, (left + ws + 1), top, 0, 0, ColourNameToRGB("blue")) -- draw text
WindowText (Win, font, sEnd, (left + ws + wh + 1), top, 0, 0, style.textcolour) -- draw text
else
WindowText (Win, font, style.text, left, top, 0, 0, style.textcolour) -- draw text
end -- if url
end -- if hilite
left = left + width -- advance horizontally
end -- first
end -- for each style run
end -- if styles
local text = GetLineText(styles,true)
local urls = findURLs(text)
if (urls and urls.start) then -- Special case for making clickable hyperlinks
local sStart = text:sub(1, urls.start-1)
local sEnd = text:sub(urls.start, urls.stop)
local ws = WindowTextWidth(Win, font, sStart) -- Width of text BEFORE the hyperlink
local we = WindowTextWidth(Win, font, sEnd) -- Width of text AFTER hyperlink
local wh = WindowTextWidth(Win, font, urls.text) -- Width of the hyperlink itself
--Note(string.format("%s: WS:%d, WE:%d, WH: %d,%s/%s", urls.text, ws, we, wh, sStart, sEnd))
if (timestamp and styles[1].text and config_table.tooltip) then -- Ugh, tooltip AND hyperlink
WindowAddHotspot(Win, "line_1_" .. tostring(line), TEXT_INSET, top, TEXT_INSET + ws, bottom,
"", "", "MouseDown", "CancelMouseDown", "MouseUp", styles[1].text .. "Start",
miniwin.cursor_ibeam, 0)
WindowScrollwheelHandler(Win, "line_1_" .. tostring(line), "wheel_move")
end
WindowAddHotspot(Win, "hyperlink_" .. tostring(line), TEXT_INSET + ws + 1, top, (TEXT_INSET + ws + 1 + wh), bottom, "", "", "MouseDown", "", "", styles[1].text .. " Click to open",
0, 0)
WindowScrollwheelHandler(Win, "hyperlink_" .. tostring(line), "wheel_move")
URL_table["hyperlink_" .. tostring(line)] = urls.text -- Insert into our table for later use
if ((ws +1 + we) < left and timestamp and styles[1].text and config_table.tooltip) then -- If there is text left, add another hotspot to cover it.
WindowAddHotspot(Win, "line_2_" .. tostring(line), we + 1, top, left, bottom,
"", "", "MouseDown", "CancelMouseDown", "MouseUp", styles[1].text .. "End",
miniwin.cursor_ibeam, 0)
WindowScrollwheelHandler(Win, "line_2_" .. tostring(line), "wheel_move")
end
else
if (timestamp and styles[1].text and config_table.tooltip) then
WindowAddHotspot(Win, "line_" .. tostring(line), TEXT_INSET, top, left, bottom,
"", "", "MouseDown", "CancelMouseDown", "MouseUp", styles[1].text,
miniwin.cursor_ibeam, 0)
WindowScrollwheelHandler(Win, "line_" .. tostring(line), "wheel_move")
end
end
end -- Display_Line
-- display all visible lines
function writeLines()
for count = lineStart, lineEnd do
if (lines[count] and lines[count][1] ) then
Display_Line( count-lineStart, lines[count][1], false )
end
end -- for each line
Redraw()
end -- function writeLines
-- clear and redraw
function refresh()
WindowRectOp(Win, miniwin.rect_fill, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, theme.WINDOW_BACKGROUND)
drawStuff()
end -- function refresh
barPos = ""
barSize = ""
totalSteps = ""
function drawStuff()
-- draw border
WindowRectOp (Win, miniwin.rect_frame, 0, 0, 0, 0, theme.WINDOW_BORDER)
-- Title bar
DrawThemed3DRect(Win, 0, 0, WINDOW_WIDTH, theme.TITLE_HEIGHT)
-- Title text
WindowText(Win, "titlefont"..Win, window_title, ((WINDOW_WIDTH)-(7.5*line_height))/2, (theme.TITLE_HEIGHT-line_height)/2, WINDOW_WIDTH, theme.TITLE_HEIGHT, theme.DETAIL, false)
if #lines >= 1 then
writeLines()
end -- if
-- Scrollbar base
WindowRectOp(Win, miniwin.rect_fill, WINDOW_WIDTH-SCROLL_BAR_WIDTH, theme.TITLE_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, theme.BACK_FACE) -- scroll bar background
WindowRectOp(Win, miniwin.rect_frame, WINDOW_WIDTH-SCROLL_BAR_WIDTH+1, SCROLL_BAR_WIDTH+theme.TITLE_HEIGHT+1, WINDOW_WIDTH-1, WINDOW_HEIGHT-(2*SCROLL_BAR_WIDTH)-1, theme.DETAIL) -- scroll bar background inset rectangle
DrawThemed3DRect(Win, WINDOW_WIDTH-SCROLL_BAR_WIDTH, theme.TITLE_HEIGHT, WINDOW_WIDTH, theme.TITLE_HEIGHT+SCROLL_BAR_WIDTH) -- top scroll button
DrawThemed3DRect(Win, WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-(SCROLL_BAR_WIDTH*2), WINDOW_WIDTH, WINDOW_HEIGHT-SCROLL_BAR_WIDTH) -- bottom scroll button
-- draw triangle in up button
points = string.format ("%i,%i,%i,%i,%i,%i", (WINDOW_WIDTH-SCROLL_BAR_WIDTH)+2, theme.TITLE_HEIGHT+8,(WINDOW_WIDTH-SCROLL_BAR_WIDTH)+6, theme.TITLE_HEIGHT+4,(WINDOW_WIDTH-SCROLL_BAR_WIDTH)+10, theme.TITLE_HEIGHT+8)
WindowPolygon (Win, points,
theme.DETAIL, miniwin.pen_solid, 1, -- pen (solid, width 1)
theme.DETAIL, miniwin.brush_solid, --brush (solid)
true, --close
false) --alt fill
-- draw triangle in down button
points = string.format ("%i,%i,%i,%i,%i,%i", (WINDOW_WIDTH-SCROLL_BAR_WIDTH)+2, (WINDOW_HEIGHT-SCROLL_BAR_WIDTH)-10,(WINDOW_WIDTH-SCROLL_BAR_WIDTH)+6, (WINDOW_HEIGHT-SCROLL_BAR_WIDTH)-6, (WINDOW_WIDTH-SCROLL_BAR_WIDTH)+10,(WINDOW_HEIGHT-SCROLL_BAR_WIDTH)-10)
WindowPolygon (Win, points,
theme.DETAIL, miniwin.pen_solid, 1, -- pen (solid, width 1)
theme.DETAIL, miniwin.brush_solid, --brush (solid)
true, --close
false) --alt fill
-- The scrollbar position indicator
totalSteps = #lines
if (totalSteps <= WINDOW_LINES-1) then totalSteps = 1 end
SCROLL_BAR_HEIGHT = (WINDOW_HEIGHT-(3*SCROLL_BAR_WIDTH)-theme.TITLE_HEIGHT)
if (not dragscrolling) then
stepNum = lineStart-1
barPos = SCROLL_BAR_WIDTH +theme.TITLE_HEIGHT+ ((SCROLL_BAR_HEIGHT/totalSteps) * stepNum)
barSize = (SCROLL_BAR_HEIGHT/math.max(WINDOW_LINES-1,totalSteps)) * (WINDOW_LINES-1)
if barSize < 10 then
barSize = 10
end
if barPos+barSize > SCROLL_BAR_WIDTH+theme.TITLE_HEIGHT+SCROLL_BAR_HEIGHT then
barPos = SCROLL_BAR_WIDTH+theme.TITLE_HEIGHT+SCROLL_BAR_HEIGHT - barSize
end
WindowAddHotspot(Win, "scroller", (WINDOW_WIDTH-SCROLL_BAR_WIDTH), barPos, WINDOW_WIDTH, barPos+barSize,
"MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", "",
miniwin.cursor_hand, 0)
WindowDragHandler(Win, "scroller", "ScrollerMoveCallback", "ScrollerReleaseCallback", 0)
end -- if
DrawThemed3DRect(Win, WINDOW_WIDTH-SCROLL_BAR_WIDTH, barPos, WINDOW_WIDTH, barPos+barSize)
-- resizer tag
DrawThemedResizeTag(Win, WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-SCROLL_BAR_WIDTH, SCROLL_BAR_WIDTH)
Redraw()
end -- function drawStuff
function ScrollerMoveCallback(flags, hotspot_id)
mouseposy = WindowInfo(Win, 18)
windowtop = WindowInfo(Win, 2)
barPos = math.max(mouseposy-windowtop+clickdelta, SCROLL_BAR_WIDTH+theme.TITLE_HEIGHT)
if barPos > WINDOW_HEIGHT-(SCROLL_BAR_WIDTH*2)-barSize then
barPos = WINDOW_HEIGHT-(SCROLL_BAR_WIDTH*2)-barSize
lineStart = math.max(1,#lines-WINDOW_LINES+2)
lineEnd = #lines
else
lineStart = math.floor((barPos-SCROLL_BAR_WIDTH-theme.TITLE_HEIGHT)/(SCROLL_BAR_HEIGHT/totalSteps)+1)
lineEnd = math.min(lineStart + WINDOW_LINES-2, #lines)
end -- if
refresh()
end -- function ScrollerMoveCallback
function ScrollerReleaseCallback(flags, hotspot_id)
dragscrolling = false
refresh()
end -- function ScrollerReleaseCallback
function fillBuffer(rawstyles, location)
local loc = location or nil
local avail = 0
local line_styles
local beginning = true
local ts = nil
-- keep pulling out styles and trying to fit them on the current line
local styles = copytable.deep (rawstyles)
local remove = table.remove
local insert = table.insert
local text = GetLineText(rawstyles)
local urls = findURLs(text)
while #styles > 0 do
if avail <= 0 then -- no room available? start new line
-- remove first line if filled up
if (#lines >= MAX_LINES and not loc) then
remove (lines, 1)
end -- if
avail = WINDOW_WIDTH - (TEXT_INSET * 2) - 9
line_styles = {}
if (loc) then
add_line( line_styles, beginning, loc )
loc = loc + 1
else
add_line( line_styles, beginning )
end
beginning = false
end -- line full
-- get next style, work out how long it is
local style = remove (styles, 1)
local width = WindowTextWidth (Win, "bodyfont"..Win, style.text)
if (style.timestamp and config_table.tooltip) then
width = 0
ts = style -- Save the timestamp for adding back into split lines. fuck.
end
-- if it fits, copy whole style in
if width <= avail then
line_styles[#line_styles+1] = style
avail = avail - width
else -- otherwise, have to split style
-- look for trailing space (work backwards). remember where space is
local col = style.length - 1
local split_col
-- keep going until out of columns
while col > 1 do
width = WindowTextWidth (Win, "bodyfont"..Win, style.text:sub (1, col))
if width <= avail then
if ((not split_col and not config_table.wrapwords)) then
split_col = col -- in case no space found, this is where we can split
end -- if
-- see if space here
if style.text:sub (col, col) == " " then
split_col = col
break
end -- if space
end -- if will now fit
col = col - 1
end -- while
-- if we found a place to split, use old style, and make it shorter. Also make a copy and put the rest in that
if split_col then
line_styles[#line_styles+1] = style
local style_copy = copytable.shallow (style)
style.text = style.text:sub (1, split_col)
style.length = split_col
style_copy.text = style_copy.text:sub (split_col + 1)
style_copy.length = #style_copy.text
insert (styles, 1, style_copy)
if (ts and config_table.tooltip) then
insert(styles, 1, ts)
end
elseif next (line_styles) == nil then
line_styles[#line_styles + 1] = style
else
insert (styles, 1, style)
end -- if
avail = 0 -- now we need to wrap
end -- if could not fit whole thing in
end -- while we still have styles over
end -- function fillBuffer
-- Main capture routine
function chats (name, styles)
-- echo in this world as well if the user wants
if echo then
for _, v in ipairs (styles) do
ColourTell (RGBColourToName (v.textcolour),RGBColourToName (v.backcolour),v.text)
end -- for each style run
Note ("") -- wrap up line
end -- echo wanted
-- inject timestamp if wanted
if timestamp then
local tstamp = os.date (date_format)
table.insert (styles, 1, {
text = tstamp,
textcolour = ColourNameToRGB (TIMESTAMP_TEXT_COLOUR),
backcolour = ColourNameToRGB (TIMESTAMP_BACK_COLOUR),
length = string.len (tstamp),
style = 0,
timestamp = true,
} )
end -- if
-- store the raw lines for use during resizing
if #rawlines >= MAX_LINES then
table.remove(rawlines, 1)
end
rawlines[#rawlines+1] = styles
fillBuffer(styles)
refresh( )
end -- function chats
function add_line ( line, is_beginning_of_message, location )
if (location) then
table.insert(lines, location, {line, false})
lines[location][2] = is_beginning_of_message
else
lines[#lines+1] = {line, false}
lines[#lines][2] = is_beginning_of_message
end
-- advance the count
if #lines >= WINDOW_LINES then
lineStart = lineStart + 1
end -- if
if #lines > 1 then
lineEnd = lineEnd + 1
end -- if
end -- function add_line
keepscrolling = false
require "wait"
function scrollbar(calledBy)
wait.make (function()
while keepscrolling == true do
if calledBy == "up" then
if (lineStart > 1) then
lineStart = lineStart - 1
lineEnd = lineEnd - 1
WindowRectOp(Win, miniwin.rect_draw_edge, (WINDOW_WIDTH-SCROLL_BAR_WIDTH), theme.TITLE_HEIGHT, 0, theme.TITLE_HEIGHT+SCROLL_BAR_WIDTH,
miniwin.rect_edge_sunken, miniwin.rect_edge_at_all + miniwin.rect_option_fill_middle) -- up arrow pushed
points = string.format ("%i,%i,%i,%i,%i,%i", (WINDOW_WIDTH-SCROLL_BAR_WIDTH)+3, theme.TITLE_HEIGHT+9,(WINDOW_WIDTH-SCROLL_BAR_WIDTH)+7, theme.TITLE_HEIGHT+5,(WINDOW_WIDTH-SCROLL_BAR_WIDTH)+11, theme.TITLE_HEIGHT+9)
WindowPolygon (Win, points,
theme.DETAIL, miniwin.pen_solid, 1, -- pen (solid, width 1)
theme.DETAIL, miniwin.brush_solid, -- brush (solid)
true, -- close
false) -- alt fill
else
keepscrolling = false
end
elseif calledBy == "down" then
if (lineEnd < #lines) then
lineStart = lineStart + 1
lineEnd = lineEnd + 1
WindowRectOp(Win, miniwin.rect_draw_edge, (WINDOW_WIDTH-SCROLL_BAR_WIDTH), WINDOW_HEIGHT-(SCROLL_BAR_WIDTH*2), 0, WINDOW_HEIGHT-SCROLL_BAR_WIDTH-1,
miniwin.rect_edge_sunken, miniwin.rect_edge_at_all + miniwin.rect_option_fill_middle) -- down arrow pushed
points = string.format ("%i,%i,%i,%i,%i,%i", (WINDOW_WIDTH-SCROLL_BAR_WIDTH)+3, (WINDOW_HEIGHT-SCROLL_BAR_WIDTH)-11,(WINDOW_WIDTH-SCROLL_BAR_WIDTH)+7, (WINDOW_HEIGHT-SCROLL_BAR_WIDTH)-7, (WINDOW_WIDTH-SCROLL_BAR_WIDTH)+11,(WINDOW_HEIGHT-SCROLL_BAR_WIDTH)-11) -- draw triangle in up button
WindowPolygon (Win, points,
theme.DETAIL, miniwin.pen_solid, 1, -- pen (solid, width 1)
theme.DETAIL, miniwin.brush_solid, -- brush (solid)
true, -- close
false) -- alt fill
else
keepscrolling = false
end
end -- if
wait.time(0.1)
refresh()
end -- while keepscrolling
end) -- wait.make
end -- function scrollbar
function GetLineText (styles, tsonly)
local t = {}
for _, style in ipairs (styles) do
if ((tsonly and not style.timestamp) or not tsonly) then
table.insert (t, style.text)
end
end -- for
return table.concat (t)
end -- function GetLineText
function GetAllBufferedMessages()
local t = {}
for _,styles in ipairs(rawlines) do
table.insert (t, GetLineText (styles))
end -- for
SetClipboard(table.concat(t,"\r\n"))
end -- function GetAllBufferedMessages
function GetBufferedMessage(xpos, ypos)
windowline = math.floor(((ypos-theme.TITLE_HEIGHT)/line_height)+1)-1
text = ""
if (#lines > windowline) then
local line = windowline+lineStart
-- go to beginning of message
if (not lines[line]) then return end
while lines[line][2] ~= true and line > 1 do
line = line - 1
end -- while
-- first line
local styles = copytable.deep(lines[line][1])
if (line-lineStart+1 > 0) then
Display_Line (line-lineStart, styles, true)
end -- if
text = GetLineText (styles)
-- remaining lines
line = line + 1
while line <= #lines and lines[line][2] ~= true do
local styles = copytable.deep(lines[line][1])
if (line-lineStart+1 > 0 and line-lineStart < WINDOW_LINES) then
Display_Line (line-lineStart, styles, true)
end
text = text.. GetLineText (styles,true)
line = line + 1
end -- while
SetClipboard(text)
end -- if
Redraw()
end -- function GetBufferedMessage
function MouseOver(flags, hotspot_id)
keepscrolling = false
end -- function MouseOver
function CancelMouseOver(flags, hotspot_id)
keepscrolling = false
end -- function CancelMouseOver
function MouseDown(flags, hotspot_id)
if (hotspot_id == "resizer") then
startx, starty = WindowInfo (Win, 17), WindowInfo (Win, 18)
elseif (hotspot_id == "scroller") then
clickdelta = WindowHotspotInfo(Win, "scroller", 2)-WindowInfo (Win, 15)
dragscrolling = true
elseif (hotspot_id == "textarea" and flags == miniwin.hotspot_got_lh_mouse) then
GetBufferedMessage(WindowInfo(Win, 14), WindowInfo(Win,15))
elseif (hotspot_id:match("line_*") and flags == miniwin.hotspot_got_lh_mouse) then
local ln = hotspot_id:match("line_(%d+)")
GetBufferedMessage(WindowInfo(Win, 14), WindowInfo(Win,15))
elseif (hotspot_id:match("hyperlink_*") and flags == miniwin.hotspot_got_lh_mouse) then
if (URL_table[hotspot_id]) then
OpenBrowser(URL_table[hotspot_id])
end
else
keepscrolling = true
scrollbar(hotspot_id)
end -- if
end -- function MouseDown
function CancelMouseDown(flags, hotspot_id)
keepscrolling = false
refresh()
end -- function CancelMouseDown
function MouseUp(flags, hotspot_id)
if (hotspot_id == "textarea" and flags == miniwin.hotspot_got_rh_mouse) then
-- build menu for current state
right_click_menu()
elseif (hotspot_id:match("line_*") and flags == miniwin.hotspot_got_rh_mouse) then
right_click_menu()
else
refresh()
end -- if
keepscrolling = false
end -- function MouseUp
function chat_echo (name, line, wildcards)
if wildcards [1] == false then
echo = not echo -- toggle
else
echo = wildcards [1]:lower () == " on"
end -- if
if echo then
ColourNote ("yellow", "", "Echoing chats in main window ENABLED.")
else
ColourNote ("yellow", "", "Echoing chats in main window DISABLED.")
end -- if
end -- function chat_echo
function chat_show (name, line, wildcards)
WindowShow( Win, true )
ColourNote ("yellow", "", "Chats window now shown. Type 'chats hide' to hide it.")
end -- function chat_show
function chat_hide (name, line, wildcards)
WindowShow( Win, false )
ColourNote ("yellow", "", "Chats window now hidden. Type 'chats show' to see it again.")
end -- function chat_hide
-- right click menu
function right_click_menu ()
menustring = string.format("^ChatGrabber v%s|-|", tostring(GetPluginInfo(GetPluginID(), 19)))
menustring = menustring .. "Search|Copy All To Clipboard|Change Font|Rename Window"
menustring = menustring .. string.format("|%sEcho", echo and "+" or "")
menustring = menustring.. string.format("|>Timestamp|No Timestamps|30 Aug 13:29:49|30 Aug 01:20:12PM|13:29:08|1:22:06 PM|23:04|%sTooltip Timestamp",config_table.tooltip and "+" or "")
menustring = menustring .. string.format("|<|Channels|>Other Communications|%sPages|%sSubspace|%sS2S|%sNavcomp|%sLocal OOC|<|Update Channel list",
config_table.pages and "+" or "", config_table.subspace and "+" or "", config_table.s2s and "+" or "", config_table.navcomp and "+" or "", config_table.ooc and "+" or "" )
menustring = menustring .. string.format("|>Other options|%sWrap Words only|%sSubspace Spam Filtering|%sAuto-shorten URLS|Clear Buffer|<", config_table.wrapwords and "+" or "",
config_table.spam and "+" or "", config_table.autoshorten and "+" or "")
result = WindowMenu (Win,
WindowInfo (Win, 14), -- x position
WindowInfo (Win, 15), -- y position
menustring) -- content
if result == "Copy All To Clipboard" then
GetAllBufferedMessages()
ColourNote ("yellow", "", "All buffered messages copied to clipboard.")
elseif result == "Change Font" then
wanted_font = utils.fontpicker (BODY_FONT_NAME, BODY_FONT_SIZE) --font dialog
if wanted_font then
BODY_FONT_NAME = wanted_font.name
BODY_FONT_SIZE = wanted_font.size
SetVariable ("bodyfont", BODY_FONT_NAME)
SetVariable ("font_size", BODY_FONT_SIZE)
OnPluginInstall()
end
elseif result == "Rename Window" then
local tmp = utils.inputbox ("New channel name? (Must be 16 characters or less)", "ATS ChatGrabber 2.0", window_title, "Courier", 9, {max_length = 16 })
if (tmp and tmp ~= window_title) then
ColourNote("yellow", "", window_title .. " has been renamed to " .. tmp)
window_title = tmp
SetVariable("title", window_title)
OnPluginInstall()
end
elseif result == "Search" then
local tmp = utils.inputbox(SEARCH_INFO, "QonChatGrabber", last_search or "Search terms?", "Courier", 9, {max_length = 16, min_length = 3})
if (tmp) then
last_search = tmp