Last active
August 29, 2015 13:57
-
-
Save arashm/9586588 to your computer and use it in GitHub Desktop.
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
#!/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