| View previous topic :: View next topic |
| Author |
Message |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Sun May 07, 2006 7:04 am Post subject: |
|
|
| Now I have a last question. Is this possible: If someone in the channel writes "!medals" my bot looks for his name in the textfile and says for example:"$nick has 2 MVP Medal(s) and 1 MostKills Medal(s)". If the bot could not find the name in the textfile it should say: "$nick has no medals yet." |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Sun May 07, 2006 7:37 am Post subject: |
|
|
you can creat a modified copy of the above script. [lindex $line 1] and [lindex $line 2] will contain the counter of the medals and if lsearch returns -1, there is no record of medals of him. _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Sun May 07, 2006 7:55 am Post subject: |
|
|
| Code: | set medalsfile "scripts/medals.txt"
bind pub - !medals medals:get
proc medals:get {nick uhost hand chan arg} {
set fd [open $::medalsfile r+]
while {![eof $fd]} {
lappend list [gets $fd]
}
if {[set le [lsearch -glob $list "$nick *"]] != -1} {
set line [lindex $list $le]
set mvp [lindex $line 1]
set kills [lindex $line 2]
putquick "PRIVMSG $chan :$nick has $mvp MVP Medal(s) and $kills MostKills Medal(s)."
} else {
putquick "PRIVMSG $chan :$nick has no medals yet."
}
} |
I made that script. It works. I hope its a "proper syntax".
Thanks again for your work De Kus. |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Sun May 07, 2006 10:19 am Post subject: |
|
|
well, I would have used a 'return 1' at the end, used puthelp instead of putquick and changed the r+ to r, since we nolonger need to open the file in read and write modus , but its exactly that what I thought you should make .
only 1 note: you forgot to close the file . _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Sun May 07, 2006 10:56 am Post subject: |
|
|
Does it make any difference where I put in the close command? So this should be right?
| Code: | set medalsfile "scripts/medals.txt"
bind pub - !medals medals:get
proc medals:get {nick uhost hand chan arg} {
set fd [open $::medalsfile r+]
while {![eof $fd]} {
lappend list [gets $fd]
}
if {[set le [lsearch -glob $list "$nick *"]] != -1} {
set line [lindex $list $le]
set mvp [lindex $line 1]
set kills [lindex $line 2]
putquick "PRIVMSG $chan :$nick has $mvp MVP Medal(s) and $kills MostKills Medal(s)."
} else {
putquick "PRIVMSG $chan :$nick has no medals yet."
}
close $fd
} |
|
|
| Back to top |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Tue May 16, 2006 9:37 am Post subject: |
|
|
The bot seems to have problems with this nick: {{As}masterblast{GEN}}
It does not make an own line for each time, but it makes a new line everytime for this nick, when it has MVP or MostKills.
Does anyone know why? |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Tue May 16, 2006 4:25 pm Post subject: |
|
|
does the nick stand in the text file exactly like that, or are the {} excaped with \?
Maybe lsearch doenst find it, because of the sublist. You could try to use | Code: | | lappend list "$name $mvp $kills" | instead for a pure string.
You must remove escape characters from the current textfile, of course. _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Mon May 22, 2006 3:16 pm Post subject: |
|
|
Yes in the textfile, there is exactly that nick. When I type "!medals {{As}masterblast{GEN}}" lsearch find this nick. But when I want to store this nick a new line is made everytime. What do you mean with | Code: | | lappend list "$name $mvp $kills" | Instead of what do I have to use this? |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Tue May 23, 2006 4:37 am Post subject: |
|
|
Start using your brain man, there is only line that uses similar vars with lappend. But strange that he finds the nick and creates a new entry anyway... thats irrationel . _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
|