Skip to content

Instantly share code, notes, and snippets.

@mikesea
Last active December 17, 2015 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikesea/5548051 to your computer and use it in GitHub Desktop.
Save mikesea/5548051 to your computer and use it in GitHub Desktop.
determine user's location
on :message, /where\s?is (.+)/ do |m|
nick = m.params[-1][/where\s?is (.+)/, 1]
if nick == @bot.nick
m.reply "#{@bot.nick} is both everywhere and nowhere."
return
end
user = @bot.user_list.find(nick)
if user
Thread.new do
m.reply "One moment, looking up #{user.nick}'s current location"
ip = user.host[/(\d+\.\d+\.\d+\.\d+)/, 1]
location = Geocoder.search(ip).first
m.reply "#{user.nick} is somewhere near #{location.city}, #{location.state}."
end
else
m.reply "Couldn't find user with the nick: #{nick}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment