Class: ModSpox::ConfigurationWizard

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

Instance Method Summary collapse

Constructor Details

#initializeConfigurationWizard

Returns a new instance of ConfigurationWizard.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mod_spox/ConfigurationWizard.rb', line 11

def initialize
    @echo = nil
    @config = Array.new
    @config_db = Hash.new
    @stuck_visible = true
    begin
        require 'termios'
        @stuck_visible = false
    rescue Object => boom
    end
end

Instance Method Details

#runObject

Run the configuration wizard



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
75
76
77
78
79
80
81
# File 'lib/mod_spox/ConfigurationWizard.rb', line 24

def run
    config = {}
    puts "*********************************"
    puts "* mod_spox Configuration Wizard *"
    puts "*********************************"
    puts ""
    config[:irc_server] = get_input('IRC Server: ', '.+', nil)
    config[:irc_port] = get_input('IRC Port: ', '\d+', '6667')
    config[:reconnect_wait] = get_input('Reconnect wait time: ', '\d+', 10)
    config[:bot_nick] = get_input('IRC Nick: ', '[a-zA-Z].*', 'mod_spox')
    config[:bot_password] = get_input('IRC Nick Password (for nickserv): ', '.*', nil)
    config[:bot_username] = get_input('IRC Username: ', '.+', 'mod_spox')
    config[:bot_realname] = get_input('IRC Real Name: ', '.+', 'mod_spox IRC bot')
    config[:socket_burst] = get_input('Socket burst rate (lines): ', '\d+', '3')
    config[:socket_burst_in] = get_input('Socket burst time: ', '\d+', '2')
    config[:socket_burst_delay] = get_input('Socket burst delay: ', '\d+', '2')
    config[:admin_nick] = get_input('Administator nick: ', '[a-zA-Z].*', nil)
    config[:admin_password] = get_input('Administrator password: ', '.+', nil)
    config[:plugin_directory] = get_input('Plugin temp data driectory (bot needs write permission): ', '.+', '/tmp')
    config[:trigger] = get_input('Default trigger: ', '.+', '!')
    config[:memcache] = get_input('Use memcache (EXPERIMENTAL): ', '(yes|no)', 'no')
    valid_connection = false
    until valid_connection do
        config[:db_adapter] = get_input('Database type (pgsql|sqlite|mysql): ', '(pgsql|sqlite|mysql)', 'sqlite')
        unless(config[:db_adapter] == 'sqlite')
            config[:db_username] = get_input('Database username: ', '.+', 'mod_spox')
            config[:db_password] = get_input('Database password: ', '.*', nil)
            config[:db_host] = get_input('Database host: ', '.*', '127.0.0.1')
            config[:db_database] = get_input('Database name: ', '.+', 'mod_spox')
        end
        begin
            print 'Testing database connection... '
            config[:db_adapter] == 'sqlite' ? test_connection(config[:db_adapter]) : test_connection(config[:db_adapter], config[:db_username], config[:db_password], config[:db_host], config[:db_database])
            puts 'OK'
            valid_connection = true
        rescue Sequel::DatabaseError, URI::InvalidURIError => boom
            puts 'Failed'
            puts 'Error: Connection to database failed'
            puts "Info: #{boom}"
        rescue Object => boom
            puts 'Failed'
            puts 'Error: Unexpected error encountered.'
            puts "Info: #{boom}"
        ensure
            $stdout.flush
        end
    end
    print "Storing configuration values... "
    begin
        save_configuration(config)
        puts 'OK'
        puts 'mod_spox is now configured and ready for use'
    rescue Object => boom
        puts 'Failed'
        puts "Error: #{boom}"
        puts 'Please try running the configuration again'
    end
end

#updateObject



83
84
85
# File 'lib/mod_spox/ConfigurationWizard.rb', line 83

def update
    run
end