Class: Controller

Inherits:
Autumn::Leaf show all
Defined in:
lib/skel/leaves/insulter/controller.rb,
lib/skel/leaves/scorekeeper/controller.rb,
lib/skel/leaves/administrator/controller.rb

Overview

Controller for the Administrator leaf.

Constant Summary

Constants inherited from Autumn::Leaf

Autumn::Leaf::DEFAULT_COMMAND_PREFIX

Instance Attribute Summary

Attributes inherited from Autumn::Leaf

#logger, #options, #stems

Instance Method Summary collapse

Methods inherited from Autumn::Leaf

#database, #database_name, #initialize, #inspect, #irc_invite_event, #irc_join_event, #irc_kick_event, #irc_mode_event, #irc_nick_event, #irc_notice_event, #irc_part_event, #irc_privmsg_event, #irc_quit_event, #irc_topic_event, #method_missing, #preconfigure, #stem_ready, #will_start_up

Constructor Details

This class inherits a constructor from Autumn::Leaf

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Autumn::Leaf

Instance Method Details

#about_command(stem, sender, reply_to, msg) ⇒ Object

Displays an about message.



15
16
# File 'lib/skel/leaves/insulter/controller.rb', line 15

def about_command(stem, sender, reply_to, msg)
end

#autumn_command(stem, sender, reply_to, msg) ⇒ Object

Typing this command will display information about the version of Autumn that is running this leaf.



58
59
60
# File 'lib/skel/leaves/administrator/controller.rb', line 58

def autumn_command(stem, sender, reply_to, msg)
  var :version => AUTUMN_VERSION
end

#commands_command(stem, sender, reply_to, msg) ⇒ Object

Suppress the !commands command; don’t want to publicize the administrative features.



65
66
# File 'lib/skel/leaves/administrator/controller.rb', line 65

def commands_command(stem, sender, reply_to, msg)
end

#insult_command(stem, sender, reply_to, msg) ⇒ Object

Insults the unfortunate argument of this command.



8
9
10
11
# File 'lib/skel/leaves/insulter/controller.rb', line 8

def insult_command(stem, sender, reply_to, msg)
  if msg.nil? then render :help
  else insult msg.capitalize end
end

#points_command(stem, sender, reply_to, msg) ⇒ Object

Displays the current point totals, or modifies someone’s score, depending on the message provided with the command.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/skel/leaves/scorekeeper/controller.rb', line 24

def points_command(stem, sender, reply_to, msg)
  if msg.nil? or msg.empty? then
    var :totals => totals(stem, reply_to)
  elsif msg =~ /^(\w+)\s+history\s*(.*)$/ then
    parse_history stem, reply_to, $1, $2
    render :history
  elsif msg =~ /^(\w+)\s+([\+\-]\d+)\s*(.*)$/ then
    parse_change stem, reply_to, sender, $1, $2.to_i, $3
    render :change
  else
    render :usage
  end
end

#quit_command(stem, sender, reply_to, msg) ⇒ Object

Typing this command will cause the Stem to exit.



50
51
52
# File 'lib/skel/leaves/administrator/controller.rb', line 50

def quit_command(stem, sender, reply_to, msg)
  stem.quit
end

#reload_command(stem, sender, reply_to, msg) ⇒ Object

Typing this command reloads all source code for all leaves and support files, allowing you to make “on-the-fly” changes without restarting the process. It does this by reloading the source files defining the classes.

If you supply the configuration name of a leaf, only that leaf is reloaded.

This command does not reload the YAML configuration files, only the source code.



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
# File 'lib/skel/leaves/administrator/controller.rb', line 14

def reload_command(stem, sender, reply_to, msg)
  var :leaves => Hash.new
  if msg then
    if Foliater.instance.leaves.include?(msg) then
      begin
        Foliater.instance.hot_reload Foliater.instance.leaves[msg]
      rescue
        logger.error "Error when reloading #{msg}:"
        logger.error $!
        var(:leaves)[msg] = $!.to_s
      else
        var(:leaves)[msg] = false
      end
      logger.info "#{msg}: Reloaded"
    else
      var :not_found => msg
    end
  else
    Foliater.instance.leaves.each do |name, leaf|
      begin
        Foliater.instance.hot_reload leaf
      rescue
        logger.error "Error when reloading #{name}:"
        logger.error $!
        var(:leaves)[name] = $!.to_s
      else
        var(:leaves)[name] = false
      end
      logger.info "#{name}: Reloaded"
    end
  end
end