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

28 lines
733 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-19 17:48:41 +00:00
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)
2017-04-17 20:57:29 +00:00
2017-04-19 17:48:41 +00:00
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-17 20:57:29 +00:00
2017-04-19 17:48:41 +00:00
send_msg("PRIVMSG #{args[:channel]} :#{args[:user]}: #{data['title']} => #{url}")
end
2017-04-17 20:57:29 +00:00
end
end
end