class OmniBot::Launcher
entry point
Public Instance Methods
create_db()
click to toggle source
# File lib/omnibot/launcher.rb, line 24 def create_db db = SQLite3::Database.new(ensure_omnidir + '/omnibot.sqlite3') if db.execute("select * from sqlite_master where type='table' and name='received_messages'").empty? db.execute <<-SQL create table received_messages ( account TEXT, message TEXT, date TEXT ); SQL end db end
ensure_omnidir()
click to toggle source
# File lib/omnibot/launcher.rb, line 13 def ensure_omnidir path = ENV['HOME'] + '/.local/share/omnibot' FileUtils.mkdir path unless File.directory? path path end
get_config_path(args)
click to toggle source
# File lib/omnibot/launcher.rb, line 6 def get_config_path(args) return args[0] if args[0] && File.file?(args[0]) path = ENV['HOME'] + '/.local/share/omnibot/omnibot.yaml' return path if File.file?(path) raise 'No config file found, checked command line and ~/.local/share/omnibot/omnibot.yaml' end
log_path(config)
click to toggle source
# File lib/omnibot/launcher.rb, line 19 def log_path(config) return config['logpath'] unless (config['logpath'] || '').empty? ensure_omnidir + '/omnibot.log' end
provide_handlers(config, db)
click to toggle source
# File lib/omnibot/launcher.rb, line 38 def provide_handlers(config, db) periodic_commands = [config['periodiccommands']].flatten.compact mails = [config['mails']].flatten.compact mail_triggers = [config['mailtriggers']].flatten.compact mail_triggers.each do |mt| raise 'No mail found for a trigger' unless mails.find { |m| m['user'] == mt['for'] } raise 'Not supported action' unless mt['action'] == 'unpack' end used_mails = mails.select { |m| mail_triggers.find { |mt| m['user'] == mt['for'] } } raise 'Sorry but multiple mail addresses is not supported yet' if used_mails.size > 1 [] + periodic_commands.map { |command| PeriodicCommand.new command } + mail_triggers.map { |trigger| MailChecker.new(mails.find { |m| m['user'] == trigger['for'] }, trigger, db) } end
start(args)
click to toggle source
# File lib/omnibot/launcher.rb, line 55 def start(args) config_path = get_config_path args puts "Using config at #{config_path}" config = YAML.load_file(config_path)['config'] OmniLog::log = Logger.new(log_path(config)) OmniLog::log.level = Logger::DEBUG db = create_db consumer = AMQPConsumer.new config consumer.db = db consumer.handlers = provide_handlers(config, db) consumer.start OmniLog::log.close end