Created
April 27, 2013 20:48
-
-
Save mikesea/5474663 to your computer and use it in GitHub Desktop.
A simple irc bot for telling people where they are.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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