1
0
Fork 0
mirror of https://github.com/nishiki/botish.git synced 2024-10-27 07:33:16 +00:00
botish/modules/wikipedia.rb

27 lines
733 B
Ruby

require 'json'
require 'net/http'
require 'botish/base'
module Botish
module Plugin
class Wikipedia < Base
def run(args)
params = {
format: 'json',
action: 'query',
list: 'search',
utf8: true,
srsearch: args[:args]
}
uri = URI('https://fr.wikipedia.org/w/api.php')
uri.query = URI.encode_www_form(params)
data = JSON.parse(Net::HTTP.get(uri))['query']['search'][0]
title = data['title']
url = URI.encode("https://fr.wikipedia.org/wiki/#{title.tr(' ', '_')}")
send_msg("PRIVMSG #{args[:channel]} :#{args[:user]}: #{data['title']} => #{url}")
end
end
end
end