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

26 lines
677 B
Ruby
Raw Normal View History

2017-04-17 20:57:29 +00:00
require 'json'
require 'net/http'
2017-04-18 20:38:56 +00:00
require 'botish/base'
2017-04-17 20:57:29 +00:00
module Botish
2017-04-18 20:38:56 +00:00
class Wikipedia < Base
def run(args)
2017-04-17 20:57:29 +00:00
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(' ', '_')}")
2017-04-18 20:38:56 +00:00
send_msg("PRIVMSG #{args[:channel]} :#{args[:user]}: #{data['title']} => #{url}")
2017-04-17 20:57:29 +00:00
end
end
end