lib/cinch/plugins/octospy.rb in octospy-0.0.8 vs lib/cinch/plugins/octospy.rb in octospy-0.1.0
- old
+ new
@@ -6,19 +6,19 @@
class Octospy
include Cinch::Plugin
include Octospy::Recording
include Octospy::Job
- set :prefix, ->(m) { %r(^#{Regexp.escape "#{m.bot.nick}: "}) }
+ set :prefix, ->(m) { %r(^ ?#{Regexp.escape "#{m.bot.nick}"}:? ) }
match(/hello|hi|hey/, method: :greet)
match('ping', method: :pong)
match('rename', method: :rename)
match(/join (.+)/, method: :join)
match(/part(?: (.+))?/, method: :part)
match(/show status/, method: :show_status)
- match(/show commands/, method: :show_commands)
+ match(/show commands|help/, method: :show_commands)
listen_to :invite, method: :join_on_invite
def greet(m)
m.reply "hi #{m.user.nick}"
@@ -48,17 +48,23 @@
end
def show_status(m)
@bot.channels.each.with_index(1) do |channel, i|
number = ::Octospy::Recordable.channel(channel).repos.count
- m.reply "#{"%02d" % i} #{channel}: #{number} repo"
+ m.reply "#{"%02d" % i} #{channel}: #{number} repo#{'s' unless number.zero?}"
end
end
def show_commands(m)
- # @matchers.each.with_index(1) do |matcher, i|
- # m.reply "#{"%02d" % i} #{matcher}"
- # end
+ m.reply "#{m.bot.name}:"
+ @handlers.each do |handler|
+ pattern = handler.pattern.pattern
+ command = case pattern.class.name
+ when 'Regexp' then pattern.source unless pattern.source == ''
+ when 'String' then pattern unless pattern.empty?
+ end
+ m.reply " #{command}" if command
+ end
end
def join_on_invite(m)
Channel(m.channel).join
end