Code: Select all
[23:15:13] <@Me> !sum
[23:15:15] <+bot> ======= TEAMS =======
[23:15:17] <+bot> [1] England (2 Supporters)
[23:15:19] <+bot> [2] Brazil (1 Supporters)
[23:15:21] <+bot> [3] Leafs (1 Supporters)
[23:15:23] <+bot> [4] Manchester United (1 Supporters)
[23:15:25] <+bot>
[23:15:27] <+bot> Total Players: 5
[23:15:29] <+bot> =====================
Code: Select all
proc matchxtra {xtra} {
set matches ""
foreach i [userlist] {
append matches " [getuser $i XTRA $xtra]"
}
return $matches
}
proc footyplayers {} {
return [llength [matchxtra "TEAM"]]
}
proc footyteams {channel {output ""} {queue ""}} {
if {$output == ""} {
set output "PRIVMSG"
}
if {$queue == ""} {
set queue "puthelp"
}
set contents [matchxtra "TEAM"]
#-- Credit http://wiki.tcl.tk/20508
#
# Count the words
#
foreach word $contents {
if { [info exists count($word)] } {
incr count($word)
} else {
set count($word) 1
}
}
#
# Convert the data into a form easily sorted
#
set frequencies {}
foreach word [array names count] {
lappend frequencies [list $word $count($word)]
}
set sorted [lsort -index 1 -integer -decreasing \
[lsort -index 0 $frequencies]]
$queue "$output $channel :======= TEAMS ======="
set nO 0
foreach frequency $sorted {
set nO [expr {$nO+1}]
$queue "$output $channel :\[$nO\] [regsub -all "_" [lrange $frequency 0 end-1] " "] ([lrange $frequency end end] Supporters)"
}
$queue "$output $channel : "
$queue "$output $channel : Total Players: [footyplayers]"
$queue "$output $channel :====================="
return
}
#since the script adds users to eggdrop's userfile, its very important to
#make sure this setting isn't used to give them any flags!
set default-flags "-"
#please dont remove the above line
proc addplayer {nick {channel ""} hostmask team} {
if {[validuser $nick] || [validuser [nick2hand $nick]]} {
return 3
}
if {($channel == "") && (![onchan $nick])} {
return 4
}
if {[adduser "$nick" "[maskhost $hostmask]"]} {
putlog "football_teams.tcl: Added new user $nick \[$hostmask\] with TEAM: $team to userfile"
setuser $nick XTRA TEAM "$team"
setuser $nick COMMENT "added by football_teams.tcl"
return 1
} else {
return 2
}
}
proc getteam {handle} {
if {[validuser $handle]} {
return [getuser $handle XTRA TEAM]
}
return
}
proc clearteam {handle} {
if {[validuser $handle]} {
setuser $handle XTRA TEAM ""
return 1
}
return 0
}
proc setteam {handle team} {
if {[validuser $handle]} {
setuser $handle XTRA TEAM "$team"
return 1
} elseif {[validuser [nick2hand $handle]]} {
setuser [nick2hand $handle] XTRA TEAM "$team"
return 2
} else {
return 3
}
}
bind pub -|- !team pub:team
bind pub -|- !sum pub:sum
proc pub:team {nick host hand chan text} {
if {[llength $text] == 0} {
set team [getteam $hand]
if {$team != ""} {
puthelp "PRIVMSG $chan :$nick's favourite team is \002$team\002!!!"
}
return
}
set string [lindex [split $text] 0]
if {[validuser "$string"]} {
# first string is a <handle>
set team [join [lrange [split $text] 1 end]]
#check we've been given a team
if {$team == ""} {return}
regsub -all " " $team "_" teamname
switch [setteam "$string" "$teamname"] {
"3" {
#again, shouldn't happen
return
}
"2" {
#just means they were added, but nick2hand was used
puthelp "NOTICE $nick :$string's faviourite team is '$team'"
return 1
}
"1" {
#all good baby!
puthelp "NOTICE $nick :$string's faviourite team is '$team'"
return 1
}
}
} elseif {[validuser [nick2hand "$string"]]} {
# first string is a <handle>
set team [join [lrange [split $text] 1 end]]
#check we've been given a team
if {$team == ""} {return}
regsub -all " " $team "_" teamname
# we dont need an other 'nick2hand' here since the 'setteam' already dose it
switch [setteam "$string" "$teamname"] {
"3" {
#again, shouldn't happen
return
}
"2" {
#just means they were added, but nick2hand was used
puthelp "NOTICE $nick :$string's faviourite team is '$team'"
return 1
}
"1" {
#all good baby!
puthelp "NOTICE $nick :$string's faviourite team is '$team'"
return 1
}
}
} elseif {[onchan "$string" "$chan"]} {
# first string is a <nickname>
#set the team
set team [join [lrange [split $text] 1 end]]
#check a team was given
if {$team == ""} {return}
#we remove spaces here, and replace them with '_'
#since spaces in team names will cause trouble with the output
regsub -all " " $team "_" teamname
set addy "$string![getchanhost $string $chan]"
switch [addplayer "$string" "$chan" "$addy" "$teamname"] {
"3" {
setteam "$string" "$teamname"
puthelp "NOTICE $nick :$string's favourite team is '$team'"
return 1
}
"4" {
#i very much doubt this will even be returned by this proc but just incase
#its here
return
}
"1" {
puthelp "NOTICE $nick :$string's favourite team is '$team'"
return 1
}
"2" {
puthelp "NOTICE $nick :Sorry, i was unable to add '$string' with team '$team' Please try again late."
return 0
}
}
} else {
# first string is a <team>
# validate user
if {[validuser "$hand"]} {
set team [join [lrange [split $text] 0 end]]
regsub -all " " $team "_" teamname
switch [setteam "$nick" "$teamname"] {
"3" {
#again, shouldn't happen
return
}
"2" {
#just means they were added, but nick2hand was used
puthelp "NOTICE $nick :Youre faviourite team is '$team'"
return 1
}
"1" {
#all good baby!
puthelp "NOTICE $nick :You're faviourite team is '$team'"
return 1
}
}
} else {
#set the team
set team [join [lrange [split $text] 0 end]]
#we remove spaces here, and replace them with '_'
#since spaces in team names will cause trouble with the output
regsub -all " " $team "_" teamname
set addy "$nick!$host"
switch [addplayer "$nick" "$chan" "$addy" "$teamname"] {
"3" {
#dont panic, this just means they are already a user *sigh*
#so its safe to assume that we can just use 'setteam' rite?
# -- should of been caught by [validuser $hand] thou? >_<
setteam "$nick" "$teamname"
puthelp "NOTICE $nick :You're favourite team is '$team'"
return 1
}
"4" {
#i very much doubt this will even be returned by this proc but just incase
#its here
return
}
"1" {
puthelp "NOTICE $nick :You're favourite team is '$team'"
return 1
}
"2" {
puthelp "NOTICE $nick :Sorry, i was unable to add u with team '$team' Please try again late."
return 0
}
}
#think thats it for dis bit :>
}
}
}
proc pub:sum {nick host hand chan text} {
if {[footyplayers] == 0} {
puthelp "NOTICE $nick :noone has set there faviourite team yet!"
return 0
}
footyteams "$chan" "" ""
return 1
}
putlog "loaded football_teams.tcl by TCL_no_TK"
return
Code: Select all
if {[onchan "$nick"]} {
if {[adduser "$nick" "[mashost [getchanhost $nick]]"]} {
Code: Select all
if {[onchan "$nick"]} {
if {[adduser "$nick" "[maskhost [getchanhost $nick]]"]} {
Code: Select all
set footyteams(teams) [lsort -unique [lsort -command compare "$tmp"]]
foreach teams $footyteams {
set footyteam($teams)
}
Code: Select all
set footyteams(teams) [lsort -unique [lsort -command compare "$tmp"]]
foreach teams $footyteams(teams) {
set footyteam($teams)
}
Code: Select all
#change these if required
set footyteams(needop) "1"
Code: Select all
foreach team $tmp {
set footyteam($team) [expr {$footyteam($team) +1}]
}
Code: Select all
foreach team $tmp {
if {[info exists footyteam($team)]} {
set footyteam($team) [expr {$footyteam($team) +1}]
}
}
Code: Select all
foreach teams $footyteams {
set footyteam($teams)
}