Skip to content

Instantly share code, notes, and snippets.

@mikesea
Created April 27, 2013 20:48
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/5474663 to your computer and use it in GitHub Desktop.
Save mikesea/5474663 to your computer and use it in GitHub Desktop.
A simple irc bot for telling people where they are.
require 'rubygems'
require 'cinch'
require 'geocoder'
bot = Cinch::Bot.new do
configure do |c|
c.server = "irc.freenode.org"
c.channels = ["#super-cool-beans"]
c.nick = "_davebot_"
end
on :message, /hello/ do |m|
m.reply "Hello, #{m.user.nick}"
end
on :message, /whereami/ do |m|
m.reply "@#{m.user}, one moment, fetching your current location..."
# Spin up a new thread to fetch location info and respond to the user
Thread.new do
ip = m.user.host[/(\d+\.\d+\.\d+\.\d+$)/, 1]
location = Geocoder.search(ip).first
m.reply "@#{m.user}, you are somewhere near #{location.city}, #{location.state}."
end
end
end
bot.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment