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.

GEOIP Location

Support & discussion of released scripts, and announcements of new releases.
Post Reply
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

GEOIP Location

Post by Madalin »

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: Select all

#### ++++ 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"
Last edited by Madalin on Sat Jun 22, 2013 1:00 pm, edited 1 time in total.
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Post by Hero »

How To Install tdom???
The Road To Hell Is Full Of Good Intentions
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Post by Hero »

And Im Getting This Error Too!

Code: Select all

[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
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

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.
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Post by Hero »

Check This!

Code: Select all

<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
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Post by Hero »

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

Code: Select all

<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
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

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
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Post by Hero »

Same Error!!

Code: Select all

[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
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

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.
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Post by Hero »

Hehe Ok No Problem Buddy :)
The Road To Hell Is Full Of Good Intentions
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Post by Hero »

Thanks MadaliN My Issue Resolved Now :)
The Road To Hell Is Full Of Good Intentions
S
SmasHinG
Voice
Posts: 29
Joined: Mon Aug 29, 2011 2:58 am

Post by SmasHinG »

if someone can do to set ban to certain city/country i will be very happy
thank you
SmasHinG®
Post Reply