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 

GEOIP Location

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Sun Jun 16, 2013 6:52 am    Post subject: GEOIP Location Reply with quote

This a script that keep count of the users who joined your channel (from whtat their country are they and what city). It also has !top commands to display a specified top daily/weekly/monthly/total

Code:

#### ++++ Author: MadaliN <madalinmen28@yahoo.com>
### +++ Website: www.Ascenture.ro
## +++ TCL Name: GEOIP Location
# +++ Version: 1.0
## ++++
# Commands:
#   !top <country|city> [today/weekly/monthly/total]
#
# IMPORTANT
#   - You need TDOM installed on your system
#
# NOTES
#   - It will record every IP (only once) so if the same user will cycle the channel it wont be recorded again
#   - The .chanset #channel +geoip (dcc chat command) will only deactivate the auto message. The ip recording will still be enabled
########
#   You need to be atleast VOICE or OP in the channel
########

bind JOIN - * geoip
bind PUBM - * geoip:main

bind TIME - "00 14 * * *" geoip:routine
bind TIME - "00 20 * * *" geoip:routine
bind TIME - "00 23 * * *" geoip:routine

set temp(trigger) {! . `}

package require http
package require tdom

setudef flag geoip

proc geoip:main {nick uhost hand chan arg} {
   global temp

   if {[string index $arg 0] in $temp(trigger)} {
      set temp(cmd) [string range $arg 1 end]
      set temp(cmd) [lindex [split $temp(cmd)] 0]
      set arg [join [lrange [split $arg] 1 end]]
   } elseif {[isbotnick [lindex [split $arg] 0]]} {
      set temp(cmd) [lindex [split $arg] 1]
      set arg [join [lrange [split $arg] 2 end]]
   } else { return 0 }

   if {[info commands geoip:$temp(cmd)] != ""} { geoip:$temp(cmd) $nick $uhost $hand $chan $arg }
}

proc geoip:top {nick uhost hand chan arg} {
   global top temp

   if {[isvoice $nick $chan] || [isop $nick $chan]} {
      switch -exact -- [lindex [split $arg] 0] {
         tara -
         country {
            switch -exact -- [lindex [split $arg] 1] {
               today { geoip:parse country today $chan $nick }
               weekly { geoip:parse country weekly $chan $nick }
               monthly { geoip:parse country monthly $chan $nick }
               anually { geoip:parse country anually $chan $nick }
               total { geoip:parse country total $chan $nick }
               default { geoip:parse country total $chan $nick }
            }
         }
         oras -
         city {
            switch -exact -- [lindex [split $arg] 1] {
               today { geoip:parse city today $chan $nick }
               weekly { geoip:parse city weekly $chan $nick }
               monthly { geoip:parse city monthly $chan $nick }
               anually { geoip:parse city anually $chan $nick }
               total { geoip:parse city total $chan $nick }
               default { geoip:parse city total $chan $nick }
            }
         }
      }

   }
}

proc geoip:parse {{one ""} {two ""} {three ""} {four ""}} {
   global top temp

   switch -exact -- $two {
      today { set temp(type) 0 }
      weekly { set temp(type 1 }
      monthly { set temp(type) 2 }
      anually { set temp(type) 3}
      total { set temp(type) 4 }
      default { set temp(type) 4 }
   }

   switch -exact -- $one {
      country {

         set temp(list) ""; set temp(tdisplay) ""

         foreach n [array names top $three,$one,*] { lappend temp(list) "[list [lindex [split $n ,] 2] [lindex [split $top($n)] $temp(type)]]" }

         set temp(list) [lsort -integer -decreasing -index 1 $temp(list)]

         set place 0

         foreach x $temp(list) {
            incr place

            set country [join [lrange $x 0 0]]
            set times [join [lrange $x 1 1]]

            if {$country != "" && $times != ""} {
               lappend temp(tdisplay) "\00312\002#$place\002 \00304$country \00310$times\003"
            }
         }

         set temp(td) [join [lrange $temp(tdisplay) 0 9]]

         if {$temp(td) == ""} { putserv "PRIVMSG $three :\002$four\002 - There are no informations yet, please try again later."; return }

         putserv "PRIVMSG $three :\002$four\002 - TOP $one: $two = $temp(td)"
      }
      city {
         set temp(list) ""
         set temp(tdisplay) ""

         foreach n [array names top $three,$one,*] {
            lappend temp(list) "[list [lindex [split $n ,] 2] [lindex [split $top($n)] 4] [lindex [split $top($n)] 5]]"
         }

         set temp(list) [lsort -integer -decreasing -index 1 $temp(list)]

         set place 0

         foreach x $temp(list) {
            incr place

            set country [join [lrange $x 0 0]]
            set times [join [lrange $x 1 1]]
            set code [join [lrange $x 2 2]]

            if {$country != "" && $times != "" && $code != ""} {
               lappend temp(tdisplay) "\00312\002#$place\002 \00304$country\003 (\00312$code\003) \00310$times\003"
            }
         }

         set temp(td) [join [lrange $temp(tdisplay) 0 9]]

         if {$temp(td) == ""} { putserv "PRIVMSG $three :\002$four\002 - There are no informations yet, please try again later."; return }

         putserv "PRIVMSG $three :\002$four\002 - TOP $one: $two = $temp(td)"
      }
   }
}

proc geoip {nick uhost hand chan} {
   global top temp ignoreit

   if {[isbotnick $nick]} { return }
   if {[string match -nocase *users* [lindex [split $uhost @] 1]]} { return }
   if {[info exists ignoreit($chan,[lindex [split $uhost @] 1])]} { return }
   if {![info exists ignoreit($chan,[lindex [split $uhost @] 1])]} { set ignoreit($chan,[lindex [split $uhost @] 1]) "[unixtime]"; geoip:save }

   set token [http::config -useragent Mozilla]
   set token [http::geturl "http://freegeoip.net/xml/[lindex [split $uhost @] 1]"]
   set data [::http::data $token]
   ::http::cleanup $token

   set XML $data

   set doc [dom parse $XML]

   set root [$doc documentElement]

   set country [$root selectNodes CountryName]
   set country [$country asText]

   set code [$root selectNodes CountryCode]
   set code [$code asText]

   set city [$root selectNodes City]
   set city [$city asText]

   if {$country == "" || $code == "" || $city == ""} { return }

   if {![info exists top($chan,country,$country)]} { set top($chan,country,$country) "1 1 1 1 1 $nick [lindex [split $uhost @] 1] [unixtime]"; geoip:save } else { set top($chan,country,$country) "[expr [lindex [split $top($chan,country,$country)] 0] +1] [expr [lindex [split $top($chan,country,$country)] 1] +1] [expr [lindex [split $top($chan,country,$country)] 2] +1] [expr [lindex [split $top($chan,country,$country)] 3] +1] [expr [lindex [split $top($chan,country,$country)] 4] +1] $nick [lindex [split $uhost @] 1] [unixtime]"; geoip:save }
   if {![info exists top($chan,city,$city)]} { set top($chan,city,$city) "1 1 1 1 1 $code $nick [lindex [split $uhost @] 1] [unixtime]"; geoip:save } else { set top($chan,city,$city) "[expr [lindex [split $top($chan,city,$city)] 0] +1] [expr [lindex [split $top($chan,city,$city))] 1] +1] [expr [lindex [split $top($chan,city,$city))] 2] +1] [expr [lindex [split $top($chan,city,$city)] 3] +1] [expr [lindex [split $top($chan,city,$city)] 4] +1] $code $nick [lindex [split $uhost @] 1] [unixtime]"; geoip:save }
}

proc geoip:check {what chan} {
   global top

   switch -exact -- $what {
      tara -
      country {
         set temp(list) ""
         set temp(tdisplay) ""

         foreach n [array names top $chan,country,*] { lappend temp(list) "[list [lindex [split $n ,] 2] [lindex [split $top($n)] 4]]" }

         set temp(list) [lsort -integer -decreasing -index 1 $temp(list)]

         foreach x $temp(list) { return "[lindex [split $x] 0]" }
      }
      oras -
      city {
         set temp(list) ""
         set temp(tdisplay) ""

         foreach n [array names top $chan,city,*] { lappend temp(list) "[list [lindex [split $n ,] 2] [lindex [split $top($n)] 4]]" }

         set temp(list) [lsort -integer -decreasing -index 1 $temp(list)]

         foreach x $temp(list) { return "[lindex [split $x] 0]" }
      }
      ccountry { set nr 0; foreach n [array names top $chan,country,*] { incr nr }; return $nr }
      ccity { set nr 0; foreach n [array names top $chan,city,*] { incr nr }; return $nr }
   }
}

proc geoip:routine {min hour day month year} {

   foreach n [channels] {
      if {[channel get $n geoip]} {
         if {[geoip:check ccountry $n] == 0} { return }
         putserv "PRIVMSG $n :The most active users who visited \002$n\002 are from country \00312[geoip:check country $n]\003 and city \00304[geoip:check city $n]\003 accumulating a total of \00305[geoip:check ccountry $n]\003 countries and \00305[geoip:check ccity $n]\003 cities that have visited this channel so far."
      }
   }
}

proc geoip:save {} {
   global top ignoreit

   set nfw [open geoip w]
   puts $nfw "array set top [list [array get top]]"
   puts $nfw "array set ignoreit [list [array get ignoreit]]"
   close $nfw
}

catch {source geoip}

putlog "++ Succesfully loaded: \00312GEOIP Location"

_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL


Last edited by Madalin on Sat Jun 22, 2013 1:00 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Hero
Halfop


Joined: 26 Jun 2012
Posts: 49
Location: root@localhost

PostPosted: Sat Jun 22, 2013 5:11 am    Post subject: Reply with quote

How To Install tdom???
_________________
The Road To Hell Is Full Of Good Intentions
Back to top
View user's profile Send private message Visit poster's website
Hero
Halfop


Joined: 26 Jun 2012
Posts: 49
Location: root@localhost

PostPosted: Sat Jun 22, 2013 5:20 am    Post subject: Reply with quote

And Im Getting This Error Too!

Code:
[14:19:24] Tcl error [geoip:main]: syntax error in expression "[string index $arg 0] in $temp(trigger)": extra tokens at end of expression

_________________
The Road To Hell Is Full Of Good Intentions
Back to top
View user's profile Send private message Visit poster's website
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Sat Jun 22, 2013 6:05 am    Post subject: Reply with quote

What version of tcl are you using. This can be caused if you are using something lower than tcl8.5. I am not sure but this would be a reason (the problem is i dont have a system with tcl8.4 to test on). Type .status in dcc chat and see what version of tcl you are using then tell me.
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Hero
Halfop


Joined: 26 Jun 2012
Posts: 49
Location: root@localhost

PostPosted: Sat Jun 22, 2013 10:51 am    Post subject: Reply with quote

Check This!

Code:
<X> I am X, running eggdrop v1.6.21: 1 user (mem: 715k).
<X> Online for 05:59 (background) - CPU: 00:01 - Cache hit: 66.3%
<X> Configured with:
<X> Admin: Hero
<X> Config file: eggdrop.conf
<X> OS: Linux 2.6.32-5-xen-amd64
<X> Tcl library: /usr/share/tcltk/tcl8.5
<X> Tcl version: 8.5.8 (header version 8.5.8)
<X> Tcl is threaded.
<X> Socket table: 20/100

_________________
The Road To Hell Is Full Of Good Intentions
Back to top
View user's profile Send private message Visit poster's website
Hero
Halfop


Joined: 26 Jun 2012
Posts: 49
Location: root@localhost

PostPosted: Sat Jun 22, 2013 10:58 am    Post subject: Reply with quote

And Server Info Here! But Im Getting Same Error In Both Servers!

Code:
<X> I am X, running eggdrop v1.6.21: 1 user (mem: 352k).
<X> Online for 05:39 (background) - CPU: 00:02 - Cache hit:  0.5%
<X> Configured with:
<X> Admin: Hero
<X> Config file: eggdrop.conf
<X> OS: Linux 3.2.0-23-generic
<X> Tcl library: /usr/local/lib/tcl8.4
<X> Tcl version: 8.4.19 (header version 8.4.19)
<X> Socket table: 20/100

_________________
The Road To Hell Is Full Of Good Intentions
Back to top
View user's profile Send private message Visit poster's website
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Sat Jun 22, 2013 1:01 pm    Post subject: Reply with quote

I edited my first post .. i copyed the exact code i am using now on my eggdrop and works. Try copy everything again and see if it works
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Hero
Halfop


Joined: 26 Jun 2012
Posts: 49
Location: root@localhost

PostPosted: Sat Jun 22, 2013 3:56 pm    Post subject: Reply with quote

Same Error!!

Code:
[00:56:08] Tcl error [geoip:main]: syntax error in expression "[string index $arg 0] in $temp(trigger)": extra tokens at end of expression

_________________
The Road To Hell Is Full Of Good Intentions
Back to top
View user's profile Send private message Visit poster's website
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Sat Jun 22, 2013 4:06 pm    Post subject: Reply with quote

I really dont know. There are alot other that are using the same script and noone get that error before. Maybe someone else that will see this post will figure out what is wrong.
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Hero
Halfop


Joined: 26 Jun 2012
Posts: 49
Location: root@localhost

PostPosted: Sat Jun 22, 2013 4:08 pm    Post subject: Reply with quote

Hehe Ok No Problem Buddy Smile
_________________
The Road To Hell Is Full Of Good Intentions
Back to top
View user's profile Send private message Visit poster's website
Hero
Halfop


Joined: 26 Jun 2012
Posts: 49
Location: root@localhost

PostPosted: Sat Jun 22, 2013 5:12 pm    Post subject: Reply with quote

Thanks MadaliN My Issue Resolved Now Smile
_________________
The Road To Hell Is Full Of Good Intentions
Back to top
View user's profile Send private message Visit poster's website
SmasHinG
Voice


Joined: 29 Aug 2011
Posts: 29

PostPosted: Fri Apr 18, 2014 4:45 pm    Post subject: Reply with quote

if someone can do to set ban to certain city/country i will be very happy
thank you
_________________
SmasHinG®
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases 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