class AdvancedRubyCommandHandler::Client
Attributes
commands[R]
commands_dir[R]
config[R]
console_logger[R]
events_dir[R]
file_logger[R]
Public Class Methods
new(commands_dir: "commands", events_dir: "events", config_file: "config.yml")
click to toggle source
Calls superclass method
# File lib/advanced_ruby_command_handler/app/client.rb, line 14 def initialize(commands_dir: "commands", events_dir: "events", config_file: "config.yml") FileUtils.mkdir_p [commands_dir, events_dir] @commands_dir = commands_dir @events_dir = events_dir @file_logger = AdvancedRubyCommandHandler::Logger.new(:file) @console_logger = AdvancedRubyCommandHandler::Logger.new(:console) base_data = YAML.dump({ :token => "", :prefix => "", :owners => [] }) File.open(config_file, "w+") { |file| file.write(base_data) } unless File.exist? config_file @config = YAML.load_file(config_file) %i[token prefix owners].each do |prop| next if @config[prop] && !@config[prop].empty? @console_logger.error("You have to add '#{prop.to_s}' value in your config file") raise "'#{prop}' missing or empty" end super(:token => @config[:token]) @commands = AdvancedRubyCommandHandler::CommandHandler.load_commands(self) AdvancedRubyCommandHandler::EventHandler.load_events(self) .each do |event| Events.method(event).call(self) end at_exit { @console_logger.info("Application exited") } end
Public Instance Methods
run()
click to toggle source
Calls superclass method
# File lib/advanced_ruby_command_handler/app/client.rb, line 49 def run @console_logger.info("Client login!") Thread.new do @console_logger.info("Type '.exit' to turn off the bot") # @console_logger.info("Type '.reload' to reload the bot") loop do Process.exit!(true) if $stdin.gets.chomp == ".exit" end end super.run end