add module plugin
This commit is contained in:
parent
faf28ed55d
commit
b4d303747b
3 changed files with 23 additions and 19 deletions
|
@ -53,7 +53,7 @@ module Botish
|
|||
opts[key] = Regexp.last_match(key)
|
||||
end
|
||||
|
||||
plugin_class = "Botish::#{command.capitalize}"
|
||||
plugin_class = "Botish::Plugin::#{command.capitalize}"
|
||||
if Object.const_defined?(plugin_class)
|
||||
Object.const_get(plugin_class).new(@connection).run(options)
|
||||
else
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
require 'botish/base'
|
||||
|
||||
module Botish
|
||||
class Coucou < Base
|
||||
def run(args)
|
||||
send_msg("PRIVMSG #{args[:channel]} :#{args[:user]}: coucou mon petit")
|
||||
module Plugin
|
||||
class Coucou < Base
|
||||
def run(args)
|
||||
send_msg("PRIVMSG #{args[:channel]} :#{args[:user]}: coucou mon petit")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,23 +3,25 @@ require 'net/http'
|
|||
require 'botish/base'
|
||||
|
||||
module Botish
|
||||
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)
|
||||
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(' ', '_')}")
|
||||
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}")
|
||||
send_msg("PRIVMSG #{args[:channel]} :#{args[:user]}: #{data['title']} => #{url}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue