public
Description: Tumblebot that feeds ni.hili.st. Plays well with Autumn Leaves.
Homepage: http://ni.hili.st/post/20314520
Clone URL: git://github.com/flogic/nihilist_bot.git
nihilist_bot / genesis.rb
100644 74 lines (64 sloc) 1.88 kb
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
71
72
73
74
# Loads configuration files, loads leaves and support files, then starts the
# Foliater.
 
require 'yaml'
 
# Add each_char method to String.
class String # :nodoc:
  # Yields each character of the string as an Integer in succession.
  def each_char
    (0..(length-1)).each { |index| yield self[index] }
  end
end
 
# Load the global settings
root = File.dirname(__FILE__)
begin
  $AL_ENV = YAML.load(File.open("#{root}/config/global.yml"))
rescue SystemCallError
  raise "Couldn't find your global.yml file."
end
$AL_ENV['root'] = File.expand_path(root)
 
# Load the season
season_dir = "#{root}/config/seasons/#{$AL_ENV['season']}"
begin
  raise "No leaves.yml file for the current season." unless Dir.entries(season_dir).include? 'leaves.yml'
rescue SystemCallError
  raise "The current season doesn't have a directory."
end
begin
  $AL_ENV['season_config'] = YAML.load(File.open("#{season_dir}/season.yml"))
rescue
  # season.yml is optional
end
$AL_ENV['debug'] = true if $AL_ENV['season_config']['logging'] == 'debug'
 
require "#{root}/libs/inheritable_attributes"
require "#{root}/libs/leaf"
require "#{root}/libs/loader"
require "#{root}/libs/logger"
 
$AL_SRVLOG = ObservantSquirrel.new :leaf_name => '<SYSTEM>', :min_level => :info, :console => $AL_ENV['debug']
 
# Load support files
Dir.new("#{root}/support").each do |file|
  next if file[0] == ?.
  begin
    require "#{root}/support/#{file}"
  rescue
    $AL_SRVLOG.error $!
  end
end
 
# Load the leaves
Dir.new("#{root}/leaves").each do |leaf|
  next if leaf[0] == ?.
  begin
    require "#{root}/leaves/#{leaf}"
  rescue
    $AL_SRVLOG.error $!
  end
end
 
leaves_config_file = "#{season_dir}/leaves.yml"
begin
  Foliater.instance.load_leaves leaves_config_file
  # suspend execution of the master thread until all leaves are dead
  while Foliater.instance.alive?
    Thread.stop
  end
rescue
  $AL_SRVLOG.error $!
end