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.

Top 10 by country

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Top 10 by country

Post by BigToe »

Just had an idea for a nice script:

You can add a host by !addhost <hosthere> and the bot will count users who join from that host.
User: !addhost *!*@*.fi
Bot: *!*@*.fi Added and will be counted from now on


User: !count *!*@*.fi
Bot: I've counted 20 (15%) users joining from *!*@*.fi Since January 14th, 2010

User: !top10
Bot: Top 10 hosts: *!*@*.fi 20 (15%), *!*@*.de 16 (12%), *!*@*.com 13 (10%)...
please someone?
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Code: Select all

# domains.tcl

# probably not suitable for multiple fast moving channels because it reads/writes per each join
# automatically scans each join on each bot channel. no need for !addhost command
# ignores the botnick joining a channel
# ignores numeric ips
# so far lacks code to reset ?#channel? to zero

# !domains ?#channel? --- outputs top domains joining command source channel, or ?#channel? if specified

bind JOIN - * pDomainsJoin
bind PUB - !domains pDomainsPub

proc pDomainsPub {nick uhost hand chan text} {
    global vDomainsData
    switch -- [llength [split [string trim $text]]] {
        0 {set channel [string tolower $chan]}
        1 {set channel [string tolower [string trim $text]]}
        default {
            putserv "PRIVMSG $chan :correct syntax is !domains ?#channel?"
            return 0
        }
    }
    if {[regexp -- {^#} $channel]} {
        if {[validchan $channel]} {
            if {[botonchan $channel]} {
                pDomainsRead
                if {[info exists vDomainsData]} {
                    if {[llength $vDomainsData] != 0} {
                        for {set loop 0} {$loop < [llength $vDomainsData]} {incr loop} {
                            set c [lindex [split [lindex $vDomainsData $loop]] 0]
                            set d [lindex [split [lindex $vDomainsData $loop]] 1]
                            set n [lindex [split [lindex $vDomainsData $loop]] 2]
                            if {[string equal $c $channel]} {lappend data [list $d $n]}
                        }
                        if {[info exists data]} {
                            set data [join [lrange [lsort -decreasing -integer -index 1 $data] 0 9] "  "]
                            putserv "PRIVMSG $chan :$data"
                        } else {putserv "PRIVMSG $chan :nothing recorded for $channel"}
                    } else {putserv "PRIVMSG $chan :no data has been recorded"}
                } else {putserv "PRIVMSG $chan :no data has been recorded"}
            } else {putserv "PRIVMSG $chan :bot is not currently monitoring $channel"}
        } else {putserv "PRIVMSG $chan :bot does not have a channel record for $channel"}
    } else {putserv "PRIVMSG $chan :$channel is not a legal channel name"}
    return 0
}

proc pDomainsJoin {nick uhost hand chan} {
    global vDomainsData
    if {![isbotnick $nick]} {
        scan $uhost {%[^@]@%s} user host
        if {![regexp -- {([0-9]{1,3}\.){3}[0-9]{1,3}} $host]} {
            set domain .[string tolower [lindex [split $host .] end]]
            pDomainsRead
            if {[info exists vDomainsData]} {
                if {[llength $vDomainsData] != 0} {
                    set found 0
                    for {set loop 0} {$loop < [llength $vDomainsData]} {incr loop} {
                        set c [lindex [split [lindex $vDomainsData $loop]] 0]
                        set d [lindex [split [lindex $vDomainsData $loop]] 1]
                        set n [lindex [split [lindex $vDomainsData $loop]] 2]
                        if {([string equal $d $domain]) && ([string equal $c [string tolower $chan]])} {
                            set vDomainsData [lreplace $vDomainsData $loop $loop "$c $d [incr n]"]
                            set found 1
                            break
                        }
                    }
                    if {!$found} {lappend vDomainsData "[string tolower $chan] $domain 1"}
                } else {lappend vDomainsData "[string tolower $chan] $domain 1"}
            } else {lappend vDomainsData "[string tolower $chan] $domain 1"}
            pDomainsWrite
        }
    }
    return 0
}

proc pDomainsRead {} {
    global vDomainsData
    if {[file exists domains.txt]} {
        set fp [open domains.txt r]
        set vDomainsData [split [read -nonewline $fp] \n]
        close $fp
    }
    return 0
}

proc pDomainsWrite {} {
    global vDomainsData
    set fp [open domains.txt w]
    if {[info exists vDomainsData]} {
        if {[llength vDomainsData] != 0} {
            puts -nonewline $fp [join $vDomainsData \n]
        }
    }
    close $fp
    return 0
}

putlog "domains.tcl loaded"

# eof
I must have had nothing to do
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Thanks arfer!

Will check it out!
Post Reply