Class: GIRC::Wookie

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yamlfile) ⇒ Wookie

Returns a new instance of Wookie.



9
10
11
# File 'lib/girc/wookie.rb', line 9

def initialize(yamlfile)
  @config = YAML.load_file(yamlfile)
end

Instance Attribute Details

#configHash (readonly)

Returns The hash representation of the YAML config passed in the constructor.

Returns:

  • (Hash)

    The hash representation of the YAML config passed in the constructor.



7
8
9
# File 'lib/girc/wookie.rb', line 7

def config
  @config
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/girc/wookie.rb', line 13

def run
  if @config['github'].key?('auth_code')
    @client = Octokit::Client.new(access_token: @config['github']['auth_code'])
    @client.user.
  else
    @client = Octokit::Client.new(login: @config['github']['username'],
                                  password: @config['github']['password'])
  end

  rooms = @config['irc']['room'].gsub('\\', '')
  hook_config = {
    server: @config['irc']['server'],
    port: @config['irc']['port'],
    room: rooms,
    nick: @config['irc']['nick'],
    branches: @config['irc']['branches'],
    nickserv_password: @config['irc']['nickserv_password'],
    ssl: to_int_string(@config['irc']['ssl']),
    message_without_join: to_int_string(@config['irc']['no_join']),
    no_colors: to_int_string(@config['irc']['no_colors']),
    long_url: to_int_string(@config['irc']['long_url']),
    notice: to_int_string(@config['irc']['notice'])
  }

  if @config['github']['repo'].include? '/'
    repo = @config['github']['repo']
  else
    repo = "#{@config['github']['username']}/#{@config['github']['repo']}"
  end

  @client.create_hook(repo, 'irc', hook_config)
end