nadoka/nadoka

View on GitHub
plugins/autoop.nb

Summary

Maintainability
Test Coverage
# -*-ruby-*-
#
# $Id$
#

=begin

== Name

Auto OP

== Abstract

Auto OP

== Configuration

BotConfig = [
  {
    :name         => :AutoOP,
    :friends => [
      { :nick => 'hoge' },
      { :user => 'fuga' },
    ]
  },
]

== License

This program is free software with ABSOLUTELY NO WARRANTY.
You can re-distribute and/or modify this program under
the same terms of the Ruby's license.

== Author

NARUSE, Yui <naruse@airemix.com>

=end


class AutoOP < Nadoka::NDK_Bot
  def bot_initialize
    @friends = @bot_config.fetch(:friends, [])
  end
  def friend?(prefix)
    @friends.any? do |friend|
      friend[:nick] == prefix.nick or friend[:user] == prefix.user[/~?(.*)\z/, 1]
    end
  end
  def on_join(prefix, ch)
    return unless /o/ =~ @state.channel_user_mode(ch, @state.nick)
    if prefix.nick != @state.nick && friend?(prefix)
      change_mode(ch, "+o", prefix.nick)
    end
  end
end