lib/sweetie_bot.rb
# Runs the bot using the current configuration.
# @note Config MUST be loaded beforehand!
Runs the bot using the current configuration.
Runs the bot using the current configuration .
def run
    Dir['./handlers/*.rb'].sort.each do |file|
      require file
    end
    @config.bots.each do |bot_id, bot_data|
      conn = DiscordConnection.new(bot_data)
      conn.connection_id = bot_id
      conn.message do |msg|
        next unless @config.discord.allowed_channel_types.include?(msg.channel.channel_type)
        if (prefix = check_prefix(msg.text))
          CommandDispatcher.handle prefix, msg
        else
          @handlers.each do |handler|
            break if handler.call(msg) == true
          end
        end
      end
      conn.mention do |msg|
        next unless @config.discord.allowed_channel_types.include?(msg.channel.channel_type)
        next if msg.content.match? /^(\.|\!)(a|d|add_|del_|delete_|remove_|count_)?q(uote|s|uotes|uote_count)?\b/
        next unless msg.content.present?
        next if bot_data.client_type == :user
        msg.send_message "#{msg.message.author.mention}, please type `.help` if you would like to learn more about my functions!"
      end
      @connections.push conn
      conn.connect
    end
    SweetieBot.log "Made #{@connections.length} connection#{@connections.length > 1 ? 's' : ''}."
    SweetieBot.log 'Ready!'
    loop do
      if @should_stop
        stop!
        exit
      end
      sleep 1
    end
  end
def run Dir [ './handlers/*.rb' ] . sort . each do | file | require file end @config . bots . each do | bot_id , bot_data | conn = DiscordConnection . new ( bot_data ) conn . connection_id = bot_id conn . message do | msg | next unless @config . discord . allowed_channel_types . include? ( msg . channel . channel_type ) if ( prefix = check_prefix ( msg . text ) ) CommandDispatcher . handle prefix , msg else @handlers . each do | handler | break if handler . call ( msg ) == true end end end conn . mention do | msg | next unless @config . discord . allowed_channel_types . include? ( msg . channel . channel_type ) next if msg . content . match? / ^( \. | \! )(a|d|add_|del_|delete_|remove_|count_)?q(uote|s|uotes|uote_count)? \b / next unless msg . content . present? next if bot_data . client_type == :user msg . send_message "#{msg.message.author.mention}, please type `.help` if you would like to learn more about my functions!" end @connections . push conn conn . connect end SweetieBot . log "Made #{@connections.length} connection#{@connections.length > 1 ? 's' : ''}." SweetieBot . log 'Ready!' loop do if @should_stop stop! exit end sleep 1 end end
Runs the bot using the current configuration.
Runs the bot using the current configuration .
# Include all handlers now. # keep the main thread alive
note
Config MUST be loaded beforehand!
Config MUST be loaded beforehand!