Class: GitAll::Bot::Bots

Inherits:
Object
  • Object
show all
Defined in:
lib/gitall.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#botsObject (readonly)

Returns the value of attribute bots.



61
62
63
# File 'lib/gitall.rb', line 61

def bots
  @bots
end

Class Method Details

.add_botsObject



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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/gitall.rb', line 70

def self.add_bots
  GitAll::Bot::Users.init_users
  @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 = /^\$/
        c.plugins.plugins << Cinch::Plugins::Identify
        identify_with = ncfg.fetch('identify-with')
        case identify_with
        when 'nickserv'
          begin
            c.plugins.options[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.messages_per_second = 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.
          GitAll::Bot::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.options[Cinch::Plugins::BasicCTCP][:replies] = {
            version: "GitAll Version: v#{GitAll::VERSION}",
            source: 'https://gitlab.com/gitall/gitall'
        }
        c.plugins.plugins << ChanControl
        c.plugins.options[ChanControl][:authentication_level] = :admins
        c.plugins.plugins << Admin
        c.plugins.options[Admin][:authentication_level] = :admins
        c.plugins.plugins << Eval
        c.plugins.options[Eval][:authentication_level] = :admins
        c.plugins.plugins << Cinch::Plugins::UserList
        c.plugins.options[Cinch::Plugins::UserList][:authentication_level] = :admins
      end
    end
    bot.loggers.clear
    unless Pathname(Dir.home).join('.girc', 'log', "gitall-#{name}.log").exist?
      FileUtils.mkdir_p(Pathname(Dir.home).join('.girc', 'log').to_path)
    end
    bot.loggers << GitLogger.new(name, File.open(Pathname(Dir.home).join(".girc", "log", "gitall-#{name}.log"), 'a'))
    bot.loggers << GitLogger.new(name, STDOUT)
    bot.loggers.level = :debug
    @bots[name] = bot
  end
end

.botsObject



66
67
68
# File 'lib/gitall.rb', line 66

def self.bots
  @bots
end