1
########################################################
2
# AMSNPLUS PLUGIN NAMESPACE
3
########################################################
4
# Maintainer: markitus (markitus@catmail.homelinux.org)
6
########################################################
8
namespace eval ::amsnplus {
11
#//////////////////////////////////////////////////////////////////////////
13
#//////////////////////////////////////////////////////////////////////////
15
################################################
16
# this starts amsnplus
17
proc amsnplusStart { dir } {
19
variable external_commands
20
array set ::amsnplus::external_commands [list]
22
::plugins::RegisterPlugin "aMSN Plus"
23
#set the amsnplus dir in config
24
::config::setKey amsnpluspluginpath $dir
25
#loading lang - if version is 0.95b (keep compatibility with 0.94)
26
if {[::amsnplus::amsn_version] > 94} {
27
set langdir [file join $dir "lang"]
28
set lang [::config::getGlobalKey language]
30
load_lang $lang $langdir
33
if {[::amsnplus::amsn_version] <= 94} {
34
array set ::amsnplus::config {
39
set ::amsnplus::configlist [ list \
40
[list bool "Do you want to allow commands in the chat window?" allow_commands] \
41
[list bool "Do you want to use the quick text feature?" allow_quicktext] \
45
array set ::amsnplus::config {
51
set ::amsnplus::configlist [ list \
52
[list bool "[trans allowcommands]" allow_commands] \
53
[list bool "[trans allowcolours]" allow_colours] \
54
[list bool "[trans allowquicktext]" allow_quicktext] \
59
catch { after 100 ::amsnplus::add_plus_menu }
60
catch { after 100 ::amsnplus::add_chat_menu }
63
::plugins::RegisterEvent "aMSN Plus" chat_msg_send parseCommand
64
::plugins::RegisterEvent "aMSN Plus" chat_msg_receive parse_colours_and_sounds
65
::plugins::RegisterEvent "aMSN Plus" chatwindowbutton chat_color_button
66
::plugins::RegisterEvent "aMSN Plus" chatmenu edit_menu
68
if {[::amsnplus::amsn_version] > 94} {
73
####################################################
74
# deinit procedure, all to do when unloading the plugin
75
proc amsnplusStop { } {
76
#removing the plus menu and chat window pixmap
77
.main_menu delete last
78
::amsnplus::remove_from_chatwindow
83
#//////////////////////////////////////////////////////////////
84
# PLUS MENUS AND PREFERENCES
85
#//////////////////////////////////////////////////////////////
87
####################################################
88
# this proc removes every menu in every chat window
89
# and also the pixmap of amsnplus to choose a color
90
proc remove_from_chatwindow { } {
91
#the path of the menu is always $w.menu
92
if { [::ChatWindow::UseContainer] } {
93
set cont [array get ::ChatWindow::containers]
94
foreach container $cont {
95
catch { ${container}.menu delete last }
98
foreach win $::ChatWindow::windows {
99
catch { ${win}.menu delete last }
104
####################################################
105
# creates the plus sub menu in the main gui menu
106
proc add_plus_menu { } {
108
menu .main_menu.plusmenu -tearoff 0
109
set plusmenu .main_menu.plusmenu
111
#entries for the plus menu
112
$plusmenu add command -label "[trans quicktext]" -command "::amsnplus::qtconfig"
114
.main_menu add cascade -label "Plus!" -menu .main_menu.plusmenu
117
###############################################
118
# creates the chat window menu
119
proc create_chat_menu { win } {
120
set bold [binary format c 2]
121
set italic [binary format c 5]
122
set underline [binary format c 31]
123
set overstrike [binary format c 6]
124
set reset [binary format c 15]
125
set screenshot "/screenshot"
128
menu ${win}.menu.plusmenu -tearoff 0
129
set plusmenu ${win}.menu.plusmenu
131
if { $::amsnplus::config(allow_colours) } {
132
$plusmenu add command -label "[trans choosecolor]" -command "::amsnplus::choose_color $win"
133
$plusmenu add command -label "[trans bold]" -command "::amsnplus::insert_text $win $bold"
134
$plusmenu add command -label "[trans italic]" -command "::amsnplus::insert_text $win $italic"
135
$plusmenu add command -label "[trans underline]" -command "::amsnplus::insert_text $win $underline"
136
$plusmenu add command -label "[trans overstrike]" -command "::amsnplus::insert_text $win $overstrike"
137
$plusmenu add command -label "[trans reset]" -command "::amsnplus::insert_text $win $reset"
138
$plusmenu add separator
140
$plusmenu add command -label "[trans screenshot]" -command "::amsnplus::insert_text $win $screenshot"
141
if {$::amsnplus::config(allow_quicktext)} {
142
$plusmenu add separator
143
#Menu item to edit the currents quick texts
144
$plusmenu add command -label "[trans quicktext]" -command "::amsnplus::qtconfig"
146
#Show all the currents quick texts in the menu
147
foreach {key txt} $::amsnplus::config(quick_text) {
148
$plusmenu add command -label $txt -command "::amsnplus::insert_text $win /$key"
152
set plusmenu ${win}.menu.plusmenu
156
###############################################
157
# attaches the menu on chat window
158
proc add_chat_menu { } {
159
if { [::ChatWindow::UseContainer] } {
160
set cont [array get ::ChatWindow::containers]
161
foreach container $cont {
162
if { [string equal [string index $container 0] "."] } {
164
set plusmenu [::amsnplus::create_chat_menu $container]
165
${container}.menu add cascade -label "Plus!" -menu $plusmenu
171
foreach win $::ChatWindow::windows {
172
#I think the catch is useless but it's in case someone close a chatwindow very fast, then we won't have a stupid bugreport
174
set plusmenu [::amsnplus::create_chat_menu $win]
175
${win}.menu add cascade -label "Plus!" -menu $plusmenu
182
###############################################
183
# this creates some commands for editing in the
184
# chat window packed in the edit menu
185
proc edit_menu {event epvar} {
187
set bold [binary format c 2]
188
set italic [binary format c 5]
189
set underline [binary format c 31]
190
set overstrike [binary format c 6]
191
set reset [binary format c 15]
192
set screenshot "/screenshot"
194
if {![catch {tk windowingsystem} wsystem] && $wsystem == "aqua"} {
200
set menu_name $newvar(menu_name)
201
menu ${menu_name}.plusmenu -tearoff 0
202
$newvar(menu_name) add cascade -label "Plus!" -menu ${menu_name}.plusmenu
203
set plusmenu ${menu_name}.plusmenu
205
if { $::amsnplus::config(allow_colours) } {
206
$plusmenu add command -label "[trans choosecolor]" -command "::amsnplus::choose_color $newvar(window_name)"
207
$plusmenu add command -label "[trans bold]" -command "::amsnplus::insert_text $newvar(window_name) $bold" -accelerator "${key}+B"
208
$plusmenu add command -label "[trans italic]" -command "::amsnplus::insert_text $newvar(window_name) $italic" -accelerator "${key}+I"
209
$plusmenu add command -label "[trans underline]" -command "::amsnplus::insert_text $newvar(window_name) $underline" -accelerator "${key}+U"
210
$plusmenu add command -label "[trans overstrike]" -command "::amsnplus::insert_text $newvar(window_name) $overstrike" -accelerator "${key}+O"
211
$plusmenu add command -label "[trans reset]" -command "::amsnplus::insert_text $newvar(window_name) $reset" -accelerator "${key}+R"
214
$plusmenu add command -label "[trans screenshot]" -command "::amsnplus::insert_text $newvar(window_name) $screenshot"
215
if {$::amsnplus::config(allow_quicktext)} {
216
$plusmenu add separator
217
#Menu item to edit the currents quick texts
218
$plusmenu add command -label "[trans quicktext]" -command "::amsnplus::qtconfig"
220
#Show all the currents quick texts in the menu
221
foreach {key txt} $::amsnplus::config(quick_text) {
222
$plusmenu add command -label $txt -command "::amsnplus::insert_text $newvar(window_name) /$key"
229
#//////////////////////////////////////////////////////////////////////////
230
# GENERAL PURPOSE PROCEDURES
231
#//////////////////////////////////////////////////////////////////////////
233
###################################################################
234
# this returns the readme content in a variable
236
set dir [::config::getKey amsnpluspluginpath]
237
set channel [open "$dir/readme" "RDONLY"]
238
return "[read $channel]"
241
############################################
242
# ::amsnplus::amsn_version #
243
# -----------------------------------------#
244
# Verify if the version of aMSN is 0.94 #
245
# Useful if we want to keep compatibility #
246
############################################
247
proc amsn_version {} {
249
scan $version "%u.%u" y1 y2
250
return [expr {$y1 * 100 + $y2}]
253
####################################################
254
# returns 1 if the char is a numbar, otherwise 0
255
proc is_a_number { char } {
256
set clen [string length $char]
259
set digit [string index $char $i]
260
if {![string match \[0-9\] $digit]} { return 0 }
266
#####################################################
267
# this returns the first word read in a string
268
proc readWord { i msg strlen } {
272
set char [string index $msg $a]
273
if {[string equal $char " "]} {
282
####################################################################
283
# this is a proc to parse description to state in order to make
284
# more easier to the user to change the state
285
proc descriptionToState { newstate } {
286
if {[string equal $newstate "online"]} { return "NLN" }
287
if {[string equal $newstate "away"]} { return "AWY" }
288
if {[string equal $newstate "busy"]} { return "BSY" }
289
if {[string equal $newstate "rightback"]} { return "BRB" }
290
if {[string equal $newstate "onphone"]} { return "PHN" }
291
if {[string equal $newstate "gonelunch"]} { return "LUN" }
292
if {[string equal $newstate "appearoff"]} { return "HDN" }
296
###################################################################
297
# this detects if the state user want to change is valid
298
proc stateIsValid { state } {
299
if {[string equal $state "online"]} { return 1 }
300
if {[string equal $state "away"]} { return 1 }
301
if {[string equal $state "busy"]} { return 1 }
302
if {[string equal $state "rightback"]} { return 1 }
303
if {[string equal $state "onphone"]} { return 1 }
304
if {[string equal $state "gonelunch"]} { return 1 }
305
if {[string equal $state "appearoff"]} { return 1 }
309
###################################################################
310
# this procs writes msg to the window with chatid and checks the
311
# the config if its a received command (env)
312
proc write_window { chatid msg env {colour "green"} } {
313
::amsn::WinWrite $chatid $msg $colour
318
#//////////////////////////////////////////////////////////////////////////
320
#//////////////////////////////////////////////////////////////////////////
322
################################################
323
# this proc lets configure the quick texts
327
#Verify if the window is already opened
328
if {[winfo exists $w]} {
333
toplevel $w -width 600 -height 400
334
wm title $w "[trans quicktext]"
336
#Text explanation, in frame top.help
338
if {[::amsnplus::amsn_version] <= 94} {
339
label $w.top.help -text "Here you should configure your quick text, the keyword and the text. \n Then in the chat window, if you do /keyword, \
340
you'll see the text" -height 2
342
label $w.top.help -text "[trans qthelp]\n"
344
pack $w.top.help -side top -expand true
345
pack $w.top -side top -fill y
348
listbox $w.middle.box -yscrollcommand "$w.middle.ys set" -font splainf -background white -relief flat -highlightthickness 0 -height 10 -width 20 -selectbackground gray
349
scrollbar $w.middle.ys -command "$w.middle.box yview" -highlightthickness 0 -borderwidth 1 -elementborderwidth 2
350
pack $w.middle.ys -side right -fill y
351
pack $w.middle.box -side left -expand true -fill both
353
pack $w.middle -side top -fill both -expand true
355
if { [info exists ::amsnplus::config(quick_text)] } {
357
foreach {key txt} $::amsnplus::config(quick_text) {
358
$w.middle.box insert end "/$key -> $txt"
364
button $w.bottom.close -text "[trans close]" -command "destroy .qtconfig"
365
button $w.bottom.add -text "[trans add]" -command "::amsnplus::qtconfig_add"
366
button $w.bottom.delete -text "[trans delete]" -command "::amsnplus::qtconfig_delete"
368
pack $w.bottom.close -side right -padx 10 -pady 10
369
pack $w.bottom.add -side left -padx 10 -pady 10
370
pack $w.bottom.delete -side left -padx 10 -pady 10
372
pack $w.bottom -side top -fill y -expand true
379
proc qtconfig_add { } {
382
#Verify if the window is already opened
383
if {[winfo exists $w]} {
388
toplevel $w -width 340 -height 270
389
wm title $w "[trans quicktext]"
396
label $w.top.txt -text "[trans edit]"
397
pack $w.top.txt -side top
400
label $w.top.top.amsnplusbutton -image [::skin::loadPixmap amsnplusbutton] -relief flat -padx 0 \
401
-background [::skin::getKey buttonbarbg] -highlightthickness 0 -borderwidth 0 \
402
-highlightbackground [::skin::getKey buttonbarbg] \
403
-activebackground [::skin::getKey buttonbarbg]
404
button $w.top.top.boldbutton -text "B" -command "::amsnplus::insert_text $w [binary format c 2] $w.top.right.entry"
405
button $w.top.top.italicbutton -text "I" -command "::amsnplus::insert_text $w [binary format c 5] $w.top.right.entry"
406
button $w.top.top.overstrikebutton -text "S" -command "::amsnplus::insert_text $w [binary format c 6] $w.top.right.entry"
407
button $w.top.top.underlinebutton -text "U" -command "::amsnplus::insert_text $w [binary format c 31] $w.top.right.entry"
408
button $w.top.top.resetbutton -text "R" -command "::amsnplus::insert_text $w [binary format c 15] $w.top.right.entry"
409
pack $w.top.top.amsnplusbutton -side left -padx 5
410
pack $w.top.top.boldbutton -side left -padx 5
411
pack $w.top.top.italicbutton -side left -padx 5
412
pack $w.top.top.overstrikebutton -side left -padx 5
413
pack $w.top.top.underlinebutton -side left -padx 5
414
pack $w.top.top.resetbutton -side left -padx 5
415
pack $w.top.top -side top
417
label $w.top.left.txt -text "[trans keyword]"
418
label $w.top.right.txt -text "[trans text]"
419
pack $w.top.left.txt -side top
420
pack $w.top.right.txt -side top
422
entry $w.top.left.entry -background #FFFFFF
423
entry $w.top.right.entry -background #FFFFFF
424
pack $w.top.left.entry -side top
425
pack $w.top.right.entry -side top
427
pack $w.top.left -side left -fill x -expand true
428
pack $w.top.right -side right -fill x -expand true
430
pack $w.top -side top -fill x -expand true
434
button $w.bottom.save -text "[trans save]" -command "::amsnplus::qtconfig_add_save"
435
button $w.bottom.cancel -text "[trans cancel]" -command "destroy $w"
436
pack $w.bottom.save -side right -padx 10 -padx 10
437
pack $w.bottom.cancel -side right -padx 10 -padx 10
439
pack $w.bottom -side top -fill x -expand true
444
proc qtconfig_add_save { } {
448
set key [$w.top.left.entry get]
449
set txt [$w.top.right.entry get]
451
if { [string equal $key ""] || [string equal $txt ""] } {
454
set ::amsnplus::config(quick_text) [lappend ::amsnplus::config(quick_text) "$key" "$txt"]
455
.qtconfig.middle.box insert end "/$key -> $txt"
457
::plugins::save_config
463
proc qtconfig_delete { } {
467
set selection [$w.middle.box curselection]
469
if { $selection != "" } {
470
.qtconfig.middle.box delete $selection $selection
471
set selection [expr $selection * 2 ]
472
set ::amsnplus::config(quick_text) [lreplace $::amsnplus::config(quick_text) $selection [expr $selection + 1]]
473
::plugins::save_config
478
####################################################
479
# returns an rbg color with <num> code
480
proc getColor { num default } {
481
array set colors [list 0 "FFFFFF" \
549
if { [info exists colors($num)] } {
550
return [set colors($num)]
558
#//////////////////////////////////////////////////////////////////////////
559
# MULTIPLE FORMATTING TEXT AND COLOR
560
#//////////////////////////////////////////////////////////////////////////
562
###############################################
563
#This is the proc to be compatible with the new way
564
#in 0.95 to get path of input text (::ChatWindow::GetInputText)
565
proc insert_text {win character {input ""} } {
566
if {[::amsnplus::amsn_version] <= 94} {
567
$win.f.bottom.left.in.text insert end $character
569
#if we use tabs then...
570
if { [::ChatWindow::UseContainer] == 1 } {
571
set win [::ChatWindow::GetCurrentWindow $win]
573
if { [string equal $input ""] } {
574
set input [::ChatWindow::GetInputText $win]
576
$input insert end $character
580
###############################################
581
# this adds a button to choose color for our
582
# multi-color text in the chatwindow
583
# now add buttons for multi-format text too
584
proc chat_color_button {event epvar} {
585
if { !$::amsnplus::config(allow_colours) } { return }
589
set amsnplusbutton $newvar(bottom).amsnplus
590
set w $newvar(window_name)
593
label $amsnplusbutton -image [::skin::loadPixmap amsnplusbutton] -relief flat -padx 3 \
594
-background [::skin::getKey buttonbarbg] -highlightthickness 0 -borderwidth 0 \
595
-highlightbackground [::skin::getKey buttonbarbg] -activebackground [::skin::getKey buttonbarbg]
596
set_balloon $amsnplusbutton "[trans multiplecolorsbutton]"
598
#Configure hover button
599
bind $amsnplusbutton <<Button1>> "after 1 ::amsnplus::choose_color $w"
600
bind $amsnplusbutton <Enter> "$amsnplusbutton configure -image [::skin::loadPixmap amsnplusbutton_hover]"
601
bind $amsnplusbutton <Leave> "$amsnplusbutton configure -image [::skin::loadPixmap amsnplusbutton]"
604
pack $amsnplusbutton -side left
607
############################################
608
# ::amsnplus::setPixmap #
609
# -----------------------------------------#
610
# Define the amsnplus pixmaps from the skin#
611
############################################
613
::skin::setPixmap amsnplusbutton amsnplusbutton.gif
614
::skin::setPixmap amsnplusbutton_hover amsnplusbutton_hover.gif
617
###############################################
618
# this opens a tk_color_palette to choose an
619
# rgb color in (rrr,ggg,bbb) format
620
# and insert the color code inside the input text
621
proc choose_color { win {input ""} } {
622
set color [tk_chooseColor -parent $win];
623
if {[string equal $color ""]} { return }
624
set color [::amsnplus::hexToRGB [string range $color 1 end]];
625
set code "[binary format c 3]$color"
626
if { [string equal $input ""] } {
627
::amsnplus::insert_text $win $code
629
::amsnplus::insert_text $win $code $input
633
###############################################
634
# this colours received messages
635
# there are two ways to colorize text:
636
# - preset colors -> (!FC<num>) or (!FG<num>) for background -> there are from 0 to 15
637
# - any colour -> (r,g,b) or (r,g,b),(r,g,b) to add background -> palette to choose (take a look at tk widgeds)
638
proc parse_colours_and_sounds {event epvar} {
639
if { !$::amsnplus::config(allow_colours) } { return }
641
upvar 2 chatid chatid
642
if {[::amsnplus::amsn_version] <= 94} {
643
set fontformat [::config::getKey mychatfont]
646
set fontformat $newvar(fontformat)
648
set color [lindex $fontformat 2]
649
set style [lindex $fontformat 1]
650
set font [lindex $fontformat 0]
651
set strlen [string length $msg]
654
set char [string index $msg $i]
655
if {[string equal $char [binary format c 2]]} {
656
set msg [string replace $msg $i [expr $i - 1] ""]
657
set strlen [string length $msg]
658
set str [string range $msg 0 [expr $i - 1]]
659
set slen [string length $str]
660
set msg [string replace $msg 0 $slen ""]
662
set strlen [string length $msg]
663
set customfont [list $font $style $color]
664
::amsn::WinWrite $chatid $str "user" $customfont
665
set index [lsearch $style "bold"]
666
if {![string equal "-1" $index]} {
667
set style [lreplace $style $index $index]
669
set style [linsert $style end "bold"]
672
if {[string equal $char [binary format c 4]]} {
674
set soundsdir [::config::getKey amsnpluspluginpath]/sounds
675
set next_char [string index $msg [expr $i + 1]]
676
if {[string equal "#" $next_char]} {
677
play_sound $soundsdir/shello.wav
678
} elseif {[string equal "E" $next_char]} {
679
play_sound $soundsdir/sbye.wav
680
} elseif {[string equal "!" $next_char]} {
681
play_sound $soundsdir/sbrb.wav
682
} elseif {[string equal "\$" $next_char]} {
683
play_sound $soundsdir/sdoh.wav
684
} elseif {[string equal "2" $next_char]} {
685
play_sound $soundsdir/sboring.wav
686
} elseif {[string equal "5" $next_char]} {
687
play_sound $soundsdir/smad.wav
688
} elseif {[string equal "9" $next_char]} {
689
play_sound $soundsdir/somg.wav
690
} elseif {[string equal "%" $next_char]} {
691
play_sound $soundsdir/skiss.wav
692
} elseif {[string equal "\"" $next_char]} {
693
play_sound $soundsdir/sevillaugh.wav
694
} elseif {[string equal "J" $next_char]} {
695
play_sound $soundsdir/sevil.wav
696
} elseif {[string equal "*" $next_char]} {
697
play_sound $soundsdir/scomeon.wav
698
} elseif {[string equal "L" $next_char]} {
699
play_sound $soundsdir/sright.wav
700
} elseif {[string equal "&" $next_char]} {
701
play_sound $soundsdir/strek.wav
702
} elseif {[string equal "@" $next_char]} {
703
play_sound $soundsdir/sdanger.wav
704
} elseif {[string equal "'" $next_char]} {
705
play_sound $soundsdir/sapplause.wav
706
} elseif {[string equal "+" $next_char]} {
707
play_sound $soundsdir/swoow.wav
708
} elseif {[string equal "," $next_char]} {
709
play_sound $soundsdir/syawnt.wav
711
set msg [string replace $msg $i [expr $i + 1] ""]
714
if {[string equal $char [binary format c 5]]} {
715
set msg [string replace $msg $i [expr $i - 1] ""]
716
set strlen [string length $msg]
717
set str [string range $msg 0 [expr $i - 1]]
718
set slen [string length $str]
719
set msg [string replace $msg 0 $slen ""]
721
set strlen [string length $msg]
722
set customfont [list $font $style $color]
723
::amsn::WinWrite $chatid $str "user" $customfont
724
set index [lsearch $style "italic"]
725
if {![string equal "-1" $index]} {
726
set style [lreplace $style $index $index]
728
set style [linsert $style end "italic"]
731
if {[string equal $char [binary format c 31]]} {
732
set msg [string replace $msg $i [expr $i - 1] ""]
733
set strlen [string length $msg]
734
set str [string range $msg 0 [expr $i - 1]]
735
set slen [string length $str]
736
set msg [string replace $msg 0 $slen ""]
738
set strlen [string length $msg]
739
set customfont [list $font $style $color]
740
::amsn::WinWrite $chatid $str "user" $customfont
741
set index [lsearch $style "underline"]
742
if {![string equal "-1" $index]} {
743
set style [lreplace $style $index $index]
745
set style [linsert $style end "underline"]
748
if {[string equal $char [binary format c 6]]} {
749
set msg [string replace $msg $i [expr $i - 1] ""]
750
set strlen [string length $msg]
751
set str [string range $msg 0 [expr $i - 1]]
752
set slen [string length $str]
753
set msg [string replace $msg 0 $slen ""]
755
set strlen [string length $msg]
756
set customfont [list $font $style $color]
757
::amsn::WinWrite $chatid $str "user" $customfont
758
set index [lsearch $style "overstrike"]
759
if {![string equal "-1" $index]} {
760
set style [lreplace $style $index $index]
762
set style [linsert $style end "overstrike"]
765
if {[string equal $char [binary format c 15]]} {
766
set msg [string replace $msg $i [expr $i - 1] ""]
767
set strlen [string length $msg]
768
set str [string range $msg 0 [expr $i - 1]]
769
set slen [string length $str]
770
set msg [string replace $msg 0 $slen ""]
772
set strlen [string length $msg]
773
set customfont [list $font $style $color]
774
::amsn::WinWrite $chatid $str "user" $customfont
777
if {[string equal $char [binary format c 3]]} {
778
#predefined colors format
779
if {[::amsnplus::is_a_number [string index $msg [expr $i + 1]]]} {
780
if {[::amsnplus::is_a_number [string index $msg [expr $i + 2]]]} {
781
set new_color [string range $msg [expr $i + 1] [expr $i + 2]]
782
set msg [string replace $msg $i [expr $i + 1] ""]
783
set strlen [string length $msg]
785
set new_color [string index $msg [expr $i + 1]]
786
set msg [string replace $msg $i $i ""]
787
set strlen [string length $msg]
789
set str [string range $msg 0 [expr $i - 1]]
790
set slen [string length $str]
791
set msg [string replace $msg 0 $slen ""]
793
set strlen [string length $msg]
794
set customfont [list $font $style $color]
795
::amsn::WinWrite $chatid $str "user" $customfont
796
if {$new_color < 68 && $new_color >= 0} {
797
set color [::amsnplus::getColor $new_color $color]
799
#(rrr,ggg,bbb) format
800
} elseif {[::amsnplus::is_a_number [string range $msg [expr $i + 2] [expr $i + 4]]]} {
801
if {[::amsnplus::is_a_number [string range $msg [expr $i + 6] [expr $i + 8]]]} {
802
if {[::amsnplus::is_a_number [string range $msg [expr $i + 10] [expr $i + 12]]]} {
803
set rgb [string range $msg [expr $i + 1] [expr $i + 12]]
804
set msg [string replace $msg $i [expr $i + 12] ""]
805
set strlen [string length $msg]
806
set str [string range $msg 0 [expr $i - 1]]
807
set slen [string length $str]
808
set msg [string replace $msg 0 $slen ""]
810
set strlen [string length $msg]
811
set customfont [list $font $style $color]
812
::amsn::WinWrite $chatid $str "user" $customfont
813
set color [::amsnplus::RGBToHex $rgb]
820
if {[::amsnplus::amsn_version] <= 94} {
821
set customfont [list $font $style $color]
822
::amsn::WinWrite $chatid $msg "user" $customfont
825
set newvar(fontformat) [list $font $style $color]
829
###############################################
830
# this proc converts rgb colours into hex colours
831
proc RGBToHex { colour } {
832
scan $colour "(%3u,%3u,%3u)" red green blue
833
return [format "%02X%02X%02X" \
837
################################################
838
# this roc converts hex colours into rgb colours
839
proc hexToRGB { colour } {
840
scan $colour "%2x%2x%2x" red green blue
841
return "($red,$green,$blue)"
844
#//////////////////////////////////////////////////////////////////////////
846
#//////////////////////////////////////////////////////////////////////////
848
################################################
849
# this proc add external commands to amsnplus
850
# (useful for other plugins)
851
proc add_command { keyword proc parameters {win_name 0} {chatid 0} } {
852
set ::amsnplus::external_commands($keyword) [list $proc $parameters $win_name $chatid]
855
#####################################################
856
# this looks chat text for a command
857
# if found, executes what command is supposed to do
858
proc parseCommand {event epvar} {
859
if { !$::amsnplus::config(allow_commands) } { return 0 }
862
upvar 2 chatid chatid
863
upvar 2 win_name win_name
864
upvar 2 fontfamily fontfamily
865
upvar 2 fontcolor fontcolor
866
upvar 2 fontstyle fontstyle
867
set strlen [string length $msg]
868
set sound [binary format c 4]
871
if { [string equal [string index $msg 0] "/"] } {
872
set char [::amsnplus::readWord $i $msg $strlen]
873
#check for the quick texts
874
if {$::amsnplus::config(allow_quicktext)} {
875
foreach {key txt} $::amsnplus::config(quick_text) {
876
if {[string equal $char "/$key"] && ![string equal $char "/"]} {
877
set clen [string length $char]
878
set msg [string replace $msg $i [expr $i + $clen] $txt]
879
set strlen [string length $msg]
880
set qtlen [string length $txt]
881
set i [expr $i + $qtlen]
886
#check for the external_commands
887
set keyword [string replace $char 0 0 ""]
888
if {[info exists ::amsnplus::external_commands($keyword)]} {
889
set clen [string length $char]
890
set msg [string replace $msg $i [expr $i + $clen]]
891
set strlen [string length $msg]
892
set kwdlist $::amsnplus::external_commands($keyword)
893
set proc [lindex $kwdlist 0]
894
set parameters [lindex $kwdlist 1]
897
while { $j < $parameters } {
898
set values [append values [::amsnplus::readWord $i $msg $strlen]]
901
if {[string equal $values ""]} {
902
if {[lindex $kwdlist 2]} {
903
if {[lindex $kwdlist 3]} {
904
$proc $win_name $chatid
909
if {[lindex $kwdlist 3]} {
916
if {[lindex $kwdlist 2]} {
917
if {[lindex $kwdlist 3]} {
918
$proc $win_name $chatid $values
920
$proc $win_name $values
923
if {[lindex $kwdlist 3]} {
924
$proc $chatid $values
933
if {[string equal $char "/all"]} {
934
set msg [string replace $msg $i [expr $i + 4] ""]
935
set strlen [string length $msg]
936
foreach window $::ChatWindow::windows {
937
set chat_id [::ChatWindow::Name $win_name]
938
::amsn::MessageSend $window 0 $msg
941
} elseif {[string equal $char "/shello"]} {
942
set msg [append "" $sound "#" [binary format c 3] "7Hello!"]
943
} elseif {[string equal $char "/sbye"]} {
944
set msg [append "" $sound "E" [binary format c 3] "12Bye"]
945
} elseif {[string equal $char "/sbrb"]} {
946
set msg [append "" $sound "!" [binary format c 3] "10Be right back"]
947
} elseif {[string equal $char "/sdoh"]} {
948
set msg [append "" $sound "\$" [binary format c 3] "4I'm so " [binary format c 2] "stupid" [binary format c 2]]
949
} elseif {[string equal $char "/sboring"]} {
950
set msg [append "" $sound "2" [binary format c 3] "5You're boring! :)"]
951
} elseif {[string equal $char "/smad"]} {
952
set msg [append "" $sound "5" [binary format c 3] "14Are you mad?!?"]
953
} elseif {[string equal $char "/somg"]} {
954
set msg [append "" $sound "9" [binary format c 3] "4Oh my " [binary format c 2] "God" [binary format c 2]]
955
} elseif {[string equal $char "/skiss"]} {
956
set msg [append "" $sound "%" [binary format c 3] "13XxxxXxxxX"]
957
} elseif {[string equal $char "/sevillaugh"]} {
958
set msg [append "" $sound "\"" [binary format c 3] "4Mua" [binary format c 3] "5ha" [binary format c 3] "4ha" [binary format c 3] "5ha" [binary format c 3] "4ha" [binary format c 3] "5!"]
959
} elseif {[string equal $char "/sevil"]} {
960
set msg [append "" $sound "J" [binary format c 3] "1:\[ :\[ :\["]
961
} elseif {[string equal $char "/scomeon"]} {
962
set msg [append "" $sound "*" [binary format c 3] "7Come on!"]
963
} elseif {[string equal $char "/sright"]} {
964
set msg [append "" $sound "L" [binary format c 3] "6Right..."]
965
} elseif {[string equal $char "/strek"]} {
966
set msg [append "" $sound "&" [binary format c 3] "12Live long and prosper"]
967
} elseif {[string equal $char "/sdanger"]} {
968
set msg [append "" $sound "@" [binary format c 3] "2My" [binary format c 3] "55patience " [binary format c 3] "2has its limits" [binary format c 3] "13..." ]
969
} elseif {[string equal $char "/sapplause"]} {
970
set msg [append "" $sound "'(h5)(h5)(h5)(h5)(h5)"]
971
} elseif {[string equal $char "/swoow"]} {
972
set msg [append "" $sound "+" [binary format c 3] "45" [binary format c 2] "Wooooow!"]
973
} elseif {[string equal $char "/syawn"]} {
974
set msg [append "" $sound "," [binary format c 3] "57I'm tired |-)"]
975
} elseif {[string equal $char "/screenshot"]} {
976
set msg [string replace $msg $i [expr $i + 11] ""]
977
set strlen [string length $msg]
979
set shotpng [file join $HOME "screenshot.png"]
980
set time_wait [::amsnplus::readWord $i $msg $strlen]
983
if {![string equal $time_wait ""]} {
984
after [expr $time_wait*1000]
987
#check platform and use utility form this one
989
if {![catch {tk windowingsystem} wsystem] && $wsystem == "aqua"} {
991
} elseif {$tcl_platform(platform) == "windows"} {
992
set shotbmp [file nativename [file join $HOME "screenshot.bmp"]]
993
plugins_log "aMSN Plus" "BMP is $shotbmp"
994
if { [catch {exec [file join [::config::getKey amsnpluspluginpath] "snapshot.exe"] "$shotbmp"} res] } {
995
plugins_log "aMSN Plus" "execution failed : $res"
998
set file [::picture::Convert $shotbmp $shotpng]
1000
} elseif {$tcl_platform(platform) == "unix"} {
1002
if { [catch {exec [file join [::config::getKey amsnpluspluginpath] "snapshot"] "$shotpng"} res] } {
1003
plugins_log "aMSN Plus" "execution failed : $res"
1008
#send the scheenshot if it had been done!
1009
if {![string equal $file ""]} {
1010
::amsn::FileTransferSend $win_name $file
1012
::amsnplus::write_window $chatid "[trans screenshoterr]"
1015
} elseif {[string equal $char "/add"]} {
1016
set msg [string replace $msg $i [expr $i + 4] ""]
1017
set strlen [string length $msg]
1018
set userlogin [::amsnplus::readWord $i $msg $strlen]
1019
set llen [string length $userlogin]
1020
set msg [string replace $msg $i [expr $i + $llen] ""]
1021
::MSN::addUser $userlogin
1022
} elseif {[string equal $char "/addgroup"]} {
1023
set msg [string replace $msg $i [expr $i + 9] ""]
1024
set strlen [string length $msg]
1027
::groups::Add $groupname
1028
if {[::amsnplus::amsn_version] <= 94} {
1029
::amsnplus::write_window $chatid "\nAdded group $groupname" 0
1031
::amsnplus::write_window $chatid "[trans groupadded $groupname]" 0
1033
} elseif {[string equal $char "/block"]} {
1034
set msg [string replace $msg $i [expr $i + 6] ""]
1035
set strlen [string length $msg]
1036
set user_login [::amsnplus::readWord $i $msg $strlen]
1037
set ulen [string length $user_login]
1038
set msg [string replace $msg $i [expr $i + $ulen] ""]
1039
set strlen [string length $msg]
1040
set nick [::abook::getNick $user_login]
1041
::MSN::blockUser $user_login [urlencode $nick]
1042
} elseif {[string equal $char "/clear"]} {
1043
set container [split ::$ChatWindow::msg_windows($chatid) "."]
1044
set container ".[lindex $container 1]"
1045
set msg [string replace $msg $i [expr $i + 6] ""]
1046
set strlen [string length $msg]
1047
if { [::ChatWindow::UseContainer] } {
1048
set chat_win $container
1050
set chat_win $::ChatWindow::msg_windows($chatid)
1052
::ChatWindow::Clear $chat_win
1053
} elseif {[string equal $char "/delete"]} {
1054
set msg [string replace $msg $i [expr $i + 7] ""]
1055
set strlen [string length $msg]
1056
set user_login [::amsnplus::readWord $i $msg $strlen]
1057
set ulen [string length $user_login]
1058
set msg [string replace $msg $i [expr $i + $ulen] ""]
1059
set strlen [string length $msg]
1060
::MSN::deleteUser $user_login
1061
if {[::amsnplus::amsn_version] <= 94} {
1062
::amsnplus::write_window $chatid "\nDeleted contact $user_login" 0
1064
::amsnplus::write_window $chatid "[trans groupdeleted $user_login]" 0
1066
} elseif {[string equal $char "/deletegroup"]} {
1067
set msg [string replace $msg $i [expr $i + 12] ""]
1068
set strlen [string length $msg]
1071
::groups::Delete [::groups::GetId $groupname]
1072
if {[::amsnplus::amsn_version] <= 94} {
1073
::amsnplus::write_window $chatid "\nDeleted group $groupname" 0
1075
::amsnplus::write_window $chatid "[trans groupdeleted $groupname]" 0
1077
} elseif {[string equal $char "/help"]} {
1078
set msg [string replace $msg $i [expr $i + 5] ""]
1079
set strlen [string length $msg]
1080
set help [::amsnplus::help]
1081
::amsnplus::write_window $chatid "\n$help" 0
1082
} elseif {[string equal $char "/info"]} {
1083
set msg [string replace $msg $i [expr $i + 5] ""]
1084
set strlen [string length $msg]
1085
set field [::amsnplus::readWord $i $msg $strlen]
1086
set lfield [string length $field]
1087
set msg [string replace $msg $i [expr $i + $lfield] ""]
1088
set strlen [string length $msg]
1089
if {[string equal $field "color"]} {
1090
if {[::amsnplus::amsn_version] <= 94} {
1091
::amsnplus::write_window $chatid "\nYour color is: $fontcolor" 0
1093
::amsnplus::write_window $chatid "[trans ccolor $fontcolor]" 0
1095
} elseif {[string equal $field "font"]} {
1096
if {[::amsnplus::amsn_version] <= 94} {
1097
::amsnplus::write_window $chatid "\nYour font is: $fontfamily" 0
1099
::amsnplus::write_window $chatid "[trans cfont $fontfamily]" 0
1101
} elseif {[string equal $field "nick"]} {
1102
set nick [::abook::getPersonal nick]
1103
if {[::amsnplus::amsn_version] <= 94} {
1104
::amsnplus::write_window $chatid "\nYour nick is: $nick" 0
1106
::amsnplus::write_window $chatid "[trans cnick $nick]" 0
1108
} elseif {[string equal $field "state"]} {
1109
set status [::MSN::myStatusIs]
1110
set status [::MSN::stateToDescription $status]
1111
if {[::amsnplus::amsn_version] <= 94} {
1112
::amsnplus::write_window $chatid "\nYour status is: $status" 0
1114
::amsnplus::write_window $chatid "[trans cstatus $status]" 0
1116
} elseif {[string equal $field "style"]} {
1117
if {[::amsnplus::amsn_version] <= 94} {
1118
::amsnplus::write_window $chatid "\nYour style is: $fontstyle" 0
1120
::amsnplus::write_window $chatid "[trans cstyle $fontstyle]" 0
1123
} elseif {[string equal $char "/invite"]} {
1124
set msg [string replace $msg $i [expr $i + 7] ""]
1125
set strlen [string length $msg]
1126
set userlogin [::amsnplus::readWord $i $msg $strlen]
1127
set llen [string length $userlogin]
1128
set msg [string replace $msg $i [expr $i + $llen] ""]
1129
::MSN::inviteUser $chatid $userlogin
1130
} elseif {[string equal $char "/kill"]} {
1133
} elseif {[string equal $char "/leave"]} {
1135
::MSN::leaveChat $chatid
1136
if {[::amsnplus::amsn_version] <= 94} {
1137
::amsnplus::write_window $chatid "\nYou've left this conversation" 0
1139
::amsnplus::write_window $chatid "[trans cleave]" 0
1141
} elseif {[string equal $char "/login"]} {
1142
set msg [string replace $msg $i [expr $i + 6] ""]
1143
set strlen [string length $msg]
1145
} elseif {[string equal $char "/logout"]} {
1148
} elseif {[string equal $char "/nick"]} {
1149
set msg [string replace $msg $i [expr $i + 5] ""]
1150
set strlen [string length $msg]
1152
set nlen [string length $nick]
1154
if {[info args ::MSN::changeName] == [list "newname" "update"] } {
1155
::MSN::changeName $nick
1157
::MSN::changeName [::config::getKey login] $nick
1159
if {[string equal $::version "0.95"]} {
1160
::amsnplus::write_window $chatid "[trans cnewnick $nick]" 0
1162
::amsnplus::write_window $chatid "\nYour new nick is: $nick" 0
1164
} elseif {[string equal $char "/pm"]} {
1165
set msg [string replace $msg $i [expr $i + 3] ""]
1166
if { [::config::getKey protocol] >= 11} {
1167
if { [string length $msg] > 130} {
1168
set answer [::amsn::messageBox [trans longpsm] yesno question [trans confirm]]
1169
if { $answer == "no" } {
1174
::MSN::changePSM $msg
1175
::amsnplus::write_window $chatid "\n[trans newpsm $msg]" 0
1178
} elseif {[string equal $char "/pm0"]} {
1179
if { [::config::getKey protocol] >= 11} {
1181
::amsnplus::write_window $chatid "\n[trans newpsmnone]" 0
1184
} elseif {[string equal $char "/qtconfig"]} {
1185
set msg [string replace $msg $i [expr $i + 9] ""]
1186
set strlen [string length $msg]
1187
::amsnplus::qtconfig
1188
} elseif {[string equal $char "/sendfile"]} {
1189
set msg [string replace $msg $i [expr $i + 9] ""]
1190
set strlen [string length $msg]
1191
set file [::amsnplus::readWord $i $msg $strlen]
1192
if {[string equal $file ""]} {
1193
::amsn::FileTransferSend $win_name
1195
if {![string equal $file ""]} {
1196
::amsn::FileTransferSend $win_name $file
1199
} elseif {[string equal $char "/shell"]} {
1200
set command [string replace $msg $i [expr $i + 6] ""]
1202
if {[::amsnplus::amsn_version] <= 94} {
1203
::amsnplus::write_window $chatid "\nExecuting: $command" 0
1205
::amsnplus::write_window $chatid "[trans cshell $command]" 0
1207
set command [linsert [split $command " "] 0 "exec" "--"]
1208
if {[catch { eval $command } result]} {
1209
if {[::amsnplus::amsn_version] <= 94} {
1210
::amsnplus::write_window $chatid "\nYour command is not valid\n$result" 0
1212
::amsnplus::write_window $chatid "[trans cnotvalid]\n$result" 0
1215
if {[::amsnplus::amsn_version] <= 94} {
1216
::amsnplus::write_window $chatid "\nThis is the result of the command:\n$result" 0
1218
::amsnplus::write_window $chatid "[trans cresult $result]" 0
1221
} elseif {[string equal $char "/shells"]} {
1222
set command [string replace $msg $i [expr $i + 7] ""]
1224
if {[::amsnplus::amsn_version] <= 94} {
1225
::amsnplus::write_window $chatid "\nExecuting: $command" 0
1227
::amsnplus::write_window $chatid "[trans cshell $command]" 0
1229
set command [linsert [split $command " "] 0 "exec" "--"]
1230
if {[catch { eval $command } result]} {
1231
if {[::amsnplus::amsn_version] <= 94} {
1232
::amsnplus::write_window $chatid "\nYour command is not valid\n$result" 0
1234
::amsnplus::write_window $chatid "[trans cnotvalid]\n$result" 0
1239
} elseif {[string equal $char "/speak"]} {
1240
set msg [string replace $msg $i [expr $i + 6] ""]
1241
set strlen [string length $msg]
1242
set userlogin [::amsnplus::readWord $i $msg $strlen]
1243
set llen [string length $userlogin]
1244
set msg [string replace $msg $i [expr $i + $llen] ""]
1245
set strlen [string length $msg]
1246
::amsn::chatUser $userlogin
1247
} elseif {[string equal $char "/state"]} {
1248
set msg [string replace $msg $i [expr $i + 6] ""]
1249
set strlen [string length $msg]
1250
set nstate [::amsnplus::readWord $i $msg $strlen]
1251
set slen [string length $nstate]
1252
set msg [string replace $msg $i [expr $i + $slen]]
1253
set strlen [string length $nick]
1254
if {[::amsnplus::stateIsValid $nstate]} {
1255
set cstate [::amsnplus::descriptionToState $nstate]
1256
::MSN::changeStatus $cstate
1257
if {[::amsnplus::amsn_version] <= 94} {
1258
::amsnplus::write_window $chatid "\nNew state is: $nstate" 0
1260
::amsnplus::write_window $chatid "[trans cnewstate $nstate]" 0
1263
if {[::amsnplus::amsn_version] <= 94} {
1264
::amsnplus::write_window $chatid "\n$nstate is not valid" 0
1266
::amsnplus::write_window $chatid "[trans cnewstatenotvalid $nstate]" 0
1269
} elseif {[string equal $char "/unblock"]} {
1270
set msg [string replace $msg $i [expr $i + 8] ""]
1271
set strlen [string length $msg]
1272
set user_login [::amsnplus::readWord $i $msg $strlen]
1273
set ulen [string length $user_login]
1274
set msg [string replace $msg $i [expr $i + $ulen] ""]
1275
set strlen [string length $msg]
1276
set nick [::abook::getNick ${user_login}]
1277
::MSN::unblockUser ${user_login} [urlencode $nick]
1278
} elseif {[string equal $char "/whois"]} {
1279
set msg [string replace $msg $i [expr $i + 6] ""]
1280
set strlen [string length $msg]
1281
set user_login [::amsnplus::readWord $i $msg $strlen]
1282
if {[string equal $user_login ""] || [string equal [::abook::getContactData $user_login nick] ""]} {
1283
set user_login [::ChatWindow::Name $win_name]
1285
set ulen [string length $user_login]
1286
set msg [string replace $msg $i [expr $i + $ulen] ""]
1287
set strlen [string length $msg]
1288
set group [::groups::GetName [::abook::getContactData $user_login group]]
1289
set nick [::abook::getContactData $user_login nick]
1290
set client [::abook::getContactData $user_login clientname]
1291
set os [::abook::getContactData $user_login operatingsystem]
1292
if {[::amsnplus::amsn_version] <= 94} {
1293
::amsnplus::write_window $chatid "\n$user_login info: $nick $group $client $os" 0
1295
::amsnplus::write_window $chatid "[trans cinfo $user_login $nick $group $client $os]" 0
1298
::amsnplus::write_window $chatid "[trans nosuchcommand $char]"