Class: GitAll::Bots
- Inherits:
-
Object
- Object
- GitAll::Bots
- Defined in:
- lib/gitall/gitall.rb
Instance Attribute Summary collapse
-
#bots ⇒ Object
readonly
Returns the value of attribute bots.
Instance Method Summary collapse
Instance Attribute Details
#bots ⇒ Object (readonly)
Returns the value of attribute bots.
35 36 37 |
# File 'lib/gitall/gitall.rb', line 35 def bots @bots end |
Instance Method Details
#add_bots ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/gitall/gitall.rb', line 42 def add_bots @config['networks'].each do |name, ncfg| bot = Cinch::Bot.new do configure do |c| c.server = ncfg.fetch('server') c.port = ncfg.fetch('port') c.nick = ncfg.fetch('nickname') c.user = ncfg.fetch('username') c.realname = ncfg.fetch('realname') c.plugins.prefix = Regexp.new(ncfg.fetch('prefix')) c.plugins.plugins << Cinch::Plugins::Identify identify_with = ncfg.fetch('identify-with') case identify_with when 'nickserv' begin c.plugins.[Cinch::Plugins::Identify] = { :username => ncfg.fetch('sasl-username'), :password => ncfg.fetch('sasl-password'), :type => :nickserv, } rescue KeyError # ignored end when 'sasl' begin c.sasl.username = ncfg.fetch('sasl-username') c.sasl.password = ncfg.fetch('sasl-password') rescue KeyError # ignored end when 'cert' begin c.ssl.client_cert = ncfg.fetch('certfp') rescue KeyError # ignored end when 'none' # Don't identify else # noop end c.channels = ncfg.fetch('channels') c.ssl.use = ncfg.fetch('ssl') c.ssl.verify = ncfg.fetch('sslverify') c. = ncfg.fetch('mps') # Global configuration. This means that all plugins / matchers that # implement authentication make use of the :login strategy, with a user # level of :users. c.authentication = Cinch::Configuration::Authentication.new c.authentication.strategy = :login c.authentication.level = :users # The UserLogin plugin will call this lambda when a user runs !register. #c.authentication.registration = lambda { |nickname, password| # If you were using an ORM, you'd do something like # `User.create(:nickname => nickname, :password => password)` here. # return false if Users.users.one? { |user| user.nickname == nickname } # Users.users << User.new(nickname, password, 'user') #} # The UserLogin plugin will call this lambda when a user runs !login. Note: # the class it returns must respond to #authenticate with 1 argument (the # password the user tries to login with). c.authentication.fetch_user = lambda { |nickname| # If you were using an ORM, you'd probably do something like # `User.first(:nickname => nickname)` here. Users.users.find { |user| user.nickname == nickname } } # The Authentication mixin will call these lambdas to check if a user is # allowed to run a command. c.authentication.users = lambda { |user| user.type == 'user' } c.authentication.admins = lambda { |user| user.type == 'admin' } c.plugins.plugins << Cinch::Plugins::UserLogin c.plugins.plugins << Cinch::Plugins::BasicCTCP c.plugins.[Cinch::Plugins::BasicCTCP][:replies] = { version: Version::Bot.version, source: 'https://gitlab.com/gitall/gitall' } c.plugins.plugins << ChanControl c.plugins.[ChanControl][:authentication_level] = :admins c.plugins.plugins << Admin c.plugins.[Admin][:authentication_level] = :admins c.plugins.plugins << Eval c.plugins.[Eval][:authentication_level] = :admins c.plugins.plugins << Cinch::Plugins::UserList c.plugins.[Cinch::Plugins::UserList][:authentication_level] = :admins end end bot.loggers.clear bot.loggers << GitLogger.new(name, File.open("log/gitall-#{name}.log", 'a')) bot.loggers << GitLogger.new(name, STDOUT) bot.loggers.level = :debug self.bots[name] = bot end end |