tcpbot/plugins/HHH.rb

72 lines
2.1 KiB
Ruby
Raw Normal View History

2016-07-27 20:52:33 +00:00
# encoding: utf-8
require 'cinch'
require_relative '../classes/Util.rb'
class HHH
2021-05-30 18:11:54 +00:00
include Util::PluginHelper
include Cinch::Plugin
listen_to :message
$responses = {
:h =>
{ :match => /^h$/i, :response => "h" },
:same =>
{ :match => /^same\s*$/i, :response => "[✔] Same" },
:hi =>
{ :match => /^hi$/i, :response => "yes helo" },
:the =>
{ :match => /^the$/i, :response => "the" },
:five =>
{ :match => /^(5 *|(5 )+)$/, :response => (("5 "*5)+"\n")*5 },
:good_bot =>
{ :match => /good bot/i, :method => Util::Util.instance.method(:getSuccess)},
:bad_bot =>
{ :match => /bad bot/i, :method => Util::Util.instance.method(:getExcuse )},
2021-05-10 09:32:29 +00:00
2021-05-30 18:11:54 +00:00
}
$can_speak = $responses.map { |k,v|
k.to_sym
}
#puts $can_speak.inspect
$offset = 10
def listen(m)
msg = m.message
target = ""
response = ""
#puts "canspeak: #{$can_speak.inspect}"
$responses.each { |k, v|
#puts "\ttrying #{msg} against #{v.inspect}"
if msg.match v[:match]
#puts "\t#{msg} matched #{v[:match]}"
target = k
#puts "\ttarget: #{target}, response: #{v[:response]}"
if(v[:method].nil?)
response = v[:response]
else
response = v[:method].call
end
end
}
puts response.inspect
if(idx = $can_speak.find_index { |x|
#puts "\tcomparing #{x} to #{target}"
x == target
})
m.reply response
#puts "deleting #{target}"
$can_speak.delete(target)
$can_speak.delete("")
#puts $can_speak.inspect
end
Timer($offset, {:shots => 1}) do
unless target == "" or target == nil
#puts "\tpushing #{target} back into canspeak"
$can_speak.push target
end
end if idx
end
2016-07-27 20:52:33 +00:00
end
2021-05-30 18:11:54 +00:00