HotString v0.1
Type /hotstring to start it.
This script basically acts, well like the title says, a hotstring.
I'll show a screenie so you can see it better:
On the bottom-left you can add a hotstring (No Spaces!). Click add to add it, and you should see it come up in the list on the left side.
The edit box on the right lets you change the text you want to replace. To do so, first click a hotstring and then type the text to replace.
;Hotstring v0.2
;Made by Firstmate
on 1:INPUT:#:{
if ($left($1,1) !== / && !$ctrlenter) {
if (%hs == 1) { msg $active $hs.replace($1-) | halt }
}
}
alias hotstring { dialog $iif($dialog(hs),-v,-dom) hs hs hs | if (!%hs) { set %hs 0 } }
dialog hs {
title "Hotstring v0.1"
size -1 -1 350 170
text "Hotstrings",1,5 5 50 20
list 2, 5 25 100 140
text "Text",3, 120 5 50 20
edit "",4, 120 25 200 20, authos
button "Add",5, 120 60 50 20
button "Remove",6,120 80 50 20
text "",8,180 60 150 200
text "",9, 200 150 200 20
radio "On",7,120 100 50 20, group
radio "Off",10,120 120 50 20
edit "",11,5 145 100 20
}
on *:dialog:hs:init:0: {
if ($lines($hs.txt) > 0) { hs.load 2 }
did -a hs 8 Hi, this script will automatically replace your text. To start using it, add a hotstring (editbox at bottom-left), turn it on, and then the text it will replace.
did -c hs $iif(%hs == 1,7,10)
}
on *:dialog:hs:sclick:*: {
if ($did == 2) {
did -r hs 4
var %a = $did(hs,2,$did(hs,2).sel).text
if ($read($hs.txt,s,%a)) { did -a hs 4 $read($hs.txt,s,%a) }
}
if ($did == 5) {
var %a = $did(hs,11)
if (!%a) { did -a hs 9 Please enter a hotstring }
elseif ($numtok(%a,32) !== 1) { did -a hs 9 Script doesn't support spaces }
elseif ($read($hs.txt,s,%a)) { did -a hs 9 Hotstring already exists }
else { write $hs.txt %a | hs.load 2 }
}
if ($did == 6) {
var %a = $did(hs,2,$did(hs,2).sel).text
if (!%a) { did -a hs 9 Please select a hotstring }
else { write -ds %a $qt($hs.txt) | did -a hs 9 Deleted! | hs.load 2 }
}
if ($did == 7) { set %hs 1 }
if ($did == 10) { set %hs 0 }
}
on *:dialog:hs:edit:4: {
var %a = $did(hs,2,$did(hs,2).sel).text
if (%a) {
write -ds %a $hs.txt
write $hs.txt %a $did(hs,4).text
}
}
alias hs.load {
var %i = 1, %x = $calc($lines($hs.txt) + 1)
if (%x == 1) { did -r hs $1 | halt }
else {
did -r hs $1
while (%i < %x) {
did -a hs $1 $gettok($read($hs.txt,%i),1,32)
inc %i
}
}
}
alias hs.replace {
var %a $1-
var %i = 1, %x = $calc($lines($hs.txt) + 1)
if (%x == 1) { halt }
else {
while (%i < %x) {
var %search = $+(/\b,$gettok($read($hs.txt,%i),1,32),\b/g)
var %replace = $gettok($read($hs.txt,%i),2-,32)
if (%replace) { noop $regsub(%a,%search,%replace,%a) }
inc %i
}
}
return %a
}
alias hs.txt return $qt($+($scriptdir,hs.txt))
Ahh forgot about that, thanks. I was just too lazy to type /hotstring each time to test (and too stupid to make a menu at that time), so I put /hs. Forgot to change it at end.
And yeah, I usually do dialogs like without DStudio or anything so that's why it looks a little less aesthetically pleasing :)
*Updates alias
alias "/hs" is an alias for "/msg hostserv x" on some servers. i suggest you change it (:
and btw, i disagree. i quite like the dialog, from the screenshot.
If i was to be REALLY picky, move the radios down a few px. and make them a bit closer together. and make the edit box as long as the longest part of text (:
Some things I would like to note:
if ($did == 7) { set %hs 1 }
if ($did == 10) { set %hs 0 }
You can use $did(id).state and some $iif's to see whether something is checked or not, and perform various actions on each check, without the use of variables. Also note that those variables can easily be unset. So normally, you wouldn't need to perform an action when you sclick on those $did's (radios, checkboxes, etc).
alias hs { dialog $iif($dialog(hs),-v,-dom) hs hs hs | if (!%hs) { set %hs 0 } }
As I said earlier, you wouldn't need variables for radios. Also, to open a dialog, you only need two dialog id's after the $iif. So you can basically recode this as:
alias hs dialog $iif($dialog(hs),-v,-dom) hs hs
This might be my habit, but I find it awkward to have multiple aliases pertaining to the script that perform different functions.
I see three different aliases:
alias hs.load, hs.replace, hs.txt
Kinda confused me, but I guess you can ignore me on this part and leave it alone.
You said earlier that you don't want to use DSTUDIO (for unknown reasons to me), but I'll say some things:
[list]
On the bright side, you can improve upon things.
In my opinion, I didn't like the edit box directly underneath the list box.
I also didn't like the initiation text event; I thought it was a little useless, and you can cut that large space out.
This is only one opinion, and you can reject this idea if you wish.
Below I've recoded the dialog to what fits me the best, but again, you can ignore me if you want.
dialog hs {
title "Hotstring v0.2"
size -1 -1 151 84
option dbu
text "Resulting text:", 1, 86 9 37 8
text "Hotstring(s):", 2, 16 9 31 8
list 3, 7 19 51 57, size
edit "", 4, 67 19 74 11, read
button "Add", 5, 64 40 35 10
button "Remove", 6, 109 40 35 10
radio "On", 7, 81 60 18 10
radio "Off", 8, 110 60 19 10
box "Hotstring Configuration", 9, 4 1 144 80
}
I just thought this made it look a little "cleaner".
[/list]
That's really all I have to say.
Keep on going; I like the idea of this script.