summaryrefslogtreecommitdiffstats
path: root/run.rb
blob: eb5e4d67e34b9c9c70c602bd6bd5ee6990ce6b40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
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
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
#!env ruby
# encoding: utf-8

require 'rubygems'
require 'eventmachine'
require 'em-irc'
require 'logger'
require 'hiera'
require 'deep_merge'
require_relative 'repost'

hiera_configuration = {
  backends: "yaml",
  merge_behavior: "deeper",
  yaml: {
    datadir: File.join(File.dirname(__FILE__), "config"),
  },
  hierarchy: [
    '%{network}/%{channel}/%{person}',
    '%{network}/%{person}',
    '%{network}/%{channel}',
    '%{network}',
    'common',
  ],
}

class ConfigSource < Hiera
    def lookup key, default="", scope=nil, *stuff
        super
    end
end

Config = ConfigSource.new(config: hiera_configuration)

# Will have to change it to a normal EM loop if/when i'll want to make a usable
# local console for the bot.
Client = Repost.new do

    scope = { "network" => "freenode" }

    host Config.lookup("server::host", "", scope)
    port Config.lookup("server::port", "", scope)

    on :connect do
        puts "connected! changing nick to #{Config.lookup("client::nick")}" 
        nick Config.lookup("client::nick")
    end

    on :nick do
        Config.lookup("channels").each do |channel|
            puts "joining #{channel}"
            join channel
        end
    end

    # The provided triggers/callbacks for actions are limited - there are no
    # quit/part callbacks, for example - and we'd have to catch raw messages
    # anyway. And since we're doing that, we can just go ahead and hook up to
    # raw callbacks exclusively.
    on :raw do |message|
        self.dispatch_raw_message message
    end

end

# Loading plugins here, because we need the Client object in scope to be able
# to do anything.
Client.load_plugins

Client.run!