Skip to content

Instantly share code, notes, and snippets.

@arashm
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arashm/9586588 to your computer and use it in GitHub Desktop.
Save arashm/9586588 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'cinch' # gem install cinch
require 'wolfram-alpha' # gem install wolfram-alpha
options = { "format" => "plaintext" }
APP_ID = 'XXXXXXXXXXXXXXXX' # get your AppID from http://products.wolframalpha.com/api
client = WolframAlpha::Client.new APP_ID, options
bot_name = 'WolframBot'
bot = Cinch::Bot.new do
configure do |c|
c.server = "irc.freenode.org"
c.nick = bot_name
c.channels = ["##pmg", "#mashhadlug"]
end
on :message do |m|
if m.message.start_with? bot_name
begin
query = m.message.gsub(/#{bot_name}[\W+]/,'').strip
response = client.query(query)
# Just some prefered PODs
result = response.map { |pod| (['Result', 'Results', 'Definitions', 'Basic information', 'Definition', 'Notable facts'].include? pod.title) ? pod : nil }.compact
# If none of prefered PODs found, just return second and third ones
if result.empty?
result = response.to_a[1..2]
end
m.reply(response["Input"].subpods[0].plaintext, true)
result.each do |pod|
m.reply(pod.subpods[0].plaintext, true)
end
rescue NoMethodError
m.reply('Nothing Found', true)
end
end
end
end
bot.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment