egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Define script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Football
Master


Joined: 26 Dec 2008
Posts: 205
Location: Quakenet, #Football

PostPosted: Thu Jul 09, 2009 4:31 am    Post subject: Define script Reply with quote

A script request.

a Script that will have a define trigger (!Team), so that when you type !team <nick> team it will define that nick's team.
example:

<Xabriel> !Team Xabriel Tottenham
[11:29:03] -EPL- Xabriel's favourite team is now 'Tottenham'

and then when you type !Sum on the channel it will announce how many users are defined, and out of the defined users how many supports which teams (in percent)

Example:
<Xabriel> !Sum
<EPL> There are 18 defined users. 9 Support Tottenham (50%), 9 Support Arsenal (50%)
_________________
Idling at #Football, Quakenet.
Back to top
View user's profile Send private message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Wed Jul 29, 2009 2:43 pm    Post subject: SCRIPT Reply with quote

Here's the example of the some of the output
Code:
[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> =====================
It was alot of fun testing it so i hope ur channel will enjoy it alot Very Happy

rewrote almost the whole thing again! and got alot of code and points from the tcl wiki' so look out for the credits in the script Smile hope it works great for you! but if not just let make an other post n i'll see what i can do Wink

Code:
 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

_________________
TCL the misunderstood


Last edited by TCL_no_TK on Sun Aug 02, 2009 6:20 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Football
Master


Joined: 26 Dec 2008
Posts: 205
Location: Quakenet, #Football

PostPosted: Thu Jul 30, 2009 6:33 am    Post subject: Reply with quote

Thanks for helping out.

I have two errors though.

the !team <nick> team-here works
but the eggy writes me the error
[13:30:42] <EPL> [12:30] Tcl error [ft:team:pub]: invalid command name "mashost"

even though when I type !Team, it shows me the team I've set.

Second error, after I added the 'Sum' part:

[13:32:05] <EPL> [12:31] Tcl error [ft:sum:pub]: can't read "footyteams": variable is array
_________________
Idling at #Football, Quakenet.
Back to top
View user's profile Send private message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Thu Jul 30, 2009 8:01 am    Post subject: Reply with quote

Code:
  if {[onchan "$nick"]} {
   if {[adduser "$nick" "[mashost [getchanhost $nick]]"]} {
Error was a spelling mistake, change the above line to
Code:
  if {[onchan "$nick"]} {
   if {[adduser "$nick" "[maskhost [getchanhost $nick]]"]} {
Smile
Second part, lost track of what i was doing! change
Code:
 set footyteams(teams) [lsort -unique [lsort -command compare "$tmp"]]
 foreach teams $footyteams {
  set footyteam($teams)
 }
to this
Code:
 set footyteams(teams) [lsort -unique [lsort -command compare "$tmp"]]
 foreach teams $footyteams(teams) {
  set footyteam($teams)
 }
Very Happy

One thingy i didn't mention, the following settings
Code:
#change these if required
set footyteams(needop) "1"

Setting this to 1 will only allow Channel Operators to change someone else's fave team, setting this to -1 will only allow people who are voiced on the channel to change someone else's fave team. Exclamation
_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
Football
Master


Joined: 26 Dec 2008
Posts: 205
Location: Quakenet, #Football

PostPosted: Thu Jul 30, 2009 11:18 am    Post subject: Reply with quote

Thanks a lot, it works good now

only problem I guess is with the sum

Tcl error [ft:sum:pub]: can't read "footyteam(BarcelonaDinamo)": no such variable
_________________
Idling at #Football, Quakenet.
Back to top
View user's profile Send private message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Thu Jul 30, 2009 12:29 pm    Post subject: Reply with quote

Code:
 foreach team $tmp {
  set footyteam($team) [expr {$footyteam($team) +1}]
 }
changing this to
Code:
 foreach team $tmp {
  if {[info exists footyteam($team)]} {
   set footyteam($team) [expr {$footyteam($team) +1}]
  }
 }
should fix that with a bit of luck Smile
_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
Football
Master


Joined: 26 Dec 2008
Posts: 205
Location: Quakenet, #Football

PostPosted: Thu Jul 30, 2009 12:56 pm    Post subject: Reply with quote

Same error Sad
_________________
Idling at #Football, Quakenet.
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Thu Jul 30, 2009 1:38 pm    Post subject: Reply with quote

The error lies within these three lines:
Code:
 foreach teams $footyteams {
  set footyteam($teams)
 }


Using set with no value argument is equivalent as reading the variable (set will return the current value of the variable, or throw an error if the variable is not set).
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Football
Master


Joined: 26 Dec 2008
Posts: 205
Location: Quakenet, #Football

PostPosted: Fri Jul 31, 2009 8:10 am    Post subject: Reply with quote

any solution for how it should look like, nml375?
_________________
Idling at #Football, Quakenet.
Back to top
View user's profile Send private message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Fri Jul 31, 2009 12:26 pm    Post subject: Reply with quote

Code:
 foreach teams $footyteams {
  set footyteam($teams) 0
 }
Razz
_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
Football
Master


Joined: 26 Dec 2008
Posts: 205
Location: Quakenet, #Football

PostPosted: Sat Aug 01, 2009 1:34 pm    Post subject: Reply with quote

still doesn't work :/
_________________
Idling at #Football, Quakenet.
Back to top
View user's profile Send private message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Sun Aug 02, 2009 12:23 pm    Post subject: Reply with quote

Am currently doing more testing on it, for now i'll reply/edit and post anything i find here soon Smile

EDIT: Exclamation Fixed see this post for the script! Very Happy
_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber