This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Karma.tcl

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Karma.tcl

Post by ComputerTech »

So, "Trying" to get this script to work, would appreciate if someone can guide me the right direction

Code: Select all

###################################
#Karma 1.0 ComputerTech
###################################
#Usage
###################################
#!++nick 1   << Increases nicks reputation to +1

array set act {
   ++
   --
}

set actcmd "!"

bind pub - "${actcmd}$act*" do:act:hehe

proc do:act:hehe {nick host hand chan text} {
set var0 "[lindex [split $text] 0 ]"
set blah($var0) 0 

if {[$act eq "++"]} { ;incr blah($var0) +1 
} else {
incr blah($var0) -1

putserv "PRIVMSG $chan :$var0 now has Reputation blah($var0)"
 }
}
it's meant to be a !karma script
like one from bitbot, so you do !nick++ to increase their reputation, and !nick-- to decrease their reputation, thanks in advanced :P :P
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

You'll have to bind pubm and not pub if you want to get the command.
With pub, the text contains everything following the command.

Try something like:

Code: Select all

bind pubm - "#% ${actcmd}%++" do:act:hehe
bind pubm - "#% ${actcmd}%--" do:act:hehe
(not tested, I don't remember if - and + are in the % wildcard)

Nota: in your code, you say "!++nick" and "!--nick" and in your post you say "!nick++" and "!nick--"... Chose :)
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Ah hehe, i'll stick to "!nick++" and "!nick--"

And how would i check if !nick++ or !nick-- was used?

Like to use "if" command to find which one was used? :shock:

Thanks in advanced :P


EDIT, another thing, how can i check if blah($var0) is -1 or +1, so if rhe current amount is +1 it will show on the putserv "output" either + or - with the value, Make sense? :roll:
Last edited by ComputerTech on Sat Nov 21, 2020 9:55 am, edited 1 time in total.
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

I made tests.

The bind pubm - "#% !%++" works well, but if you want to allow extra characters you need to add * at the end:

Code: Select all

.tcl proc karma {nick uhost handle chan text} { putlog "binded with $text"}
.tcl bind pubm - "#% !%++" karma
<me> !rasp++
[14:49] triggering bind karma
[14:49] binded with !rasp++
<me> !rasp++ test
(nothing)
[14:49] triggering bind karma
.tcl bind pubm - "#% !%++*" karma
<me> !rasp++ test
[14:53] triggering bind karma
[14:53] binded with !rasp++ test
Your proc must get the first item of $text and cut it:
1st char is the command symbol (!)
Last 2 chars are the modifier (++ or --)
Everyting else is the nick:

Code: Select all

set text [lindex $text 0]
set cmd [string index $text 0]
set mod [string range $text end-1 end]
set unick [string range $text 1 end-2]

Code: Select all

.tcl set text !rasp++
[14:58] tcl: builtin dcc call: *dcc:tcl CrazyCat 12 set text !rasp++
[14:58] tcl: evaluate (.tcl): set text !rasp++
Tcl: !rasp++
.tcl set cmd [string index $text 0]
[14:58] tcl: builtin dcc call: *dcc:tcl CrazyCat 12 set cmd [string index $text 0]
[14:58] tcl: evaluate (.tcl): set cmd [string index $text 0]
Tcl: !
.tcl set mod [string range $text end-1 end]
[14:58] tcl: builtin dcc call: *dcc:tcl CrazyCat 12 set mod [string range $text end-1 end]
[14:58] tcl: evaluate (.tcl): set mod [string range $text end-1 end]
Tcl: ++
.tcl set unick [string range $text 1 end-2]
[14:59] tcl: builtin dcc call: *dcc:tcl CrazyCat 12 set unick [string range $text 1 end-2]
[14:59] tcl: evaluate (.tcl): set unick [string range $text 1 end-2]
Tcl: rasp
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

And actually seems i made a typo last night (tired last night)

The way it should work is

original start of per nick is 0, neither + or -

so

!nick++

Code: Select all

Putserv "PRIVMSG $chan :$var0 now has Reputation +1"
!nick--

Code: Select all

Putserv "PRIVMSG $chan :$var0 now has Reputation 0"
!nick--

Code: Select all

Putserv "PRIVMSG $chan :$var0 now has Reputation -0"
hope this clears it a bit :P
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

I don't understand your trouble:

Code: Select all

if {[$act eq "++"]} {
   incr blah($var0)
} elseif {[$act eq "--"] && blah($var0)>0} {
   incr blah($var0) -1
}
putserv "PRIVMSG $chan :$var0 now has Reputation blah($var0)"
do you want to display "-0" if someone try to decrease karma when it's already equal to 0?
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Basically if -0. it will show -1 and not just keep 0 as the lowest number, so if - rhat will fall into the hated category and if above -0 it will be on the love side :lol:

All new nicks will start off with 0 neither + or -

Example

Code: Select all

!love nick will make it +1

!hate nick will make it -1
hope that makes sense :P

I am.not sure if incr will make a number below 0 a - ? i never tried that heh, :roll:
ComputerTech
Post Reply