Class: Cinch::Plugins::BotInfo

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/cinch/plugins/botinfo.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ BotInfo


18
19
20
21
# File 'lib/cinch/plugins/botinfo.rb', line 18

def initialize *args
  super
  @started_at = Time.now
end

Instance Method Details

#execute(m) ⇒ Object


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
# File 'lib/cinch/plugins/botinfo.rb', line 29

def execute(m)
  tags = {
    bot_name: @bot.nick,
    cinch_version: Cinch::VERSION,
    #is_admin: config[:admins].is_admin?(m.user.mask) ? "an admin" : "not an admin",
    owner_name: config[:owner],
    plugins_count_remaining: @bot.plugins.length - 10,
    plugins_head: @bot.plugins[0..9].map {|p| p.class.plugin_name }.join(", "),
    ruby_platform: RUBY_PLATFORM,
    ruby_release_date: RUBY_RELEASE_DATE,
    ruby_version: RUBY_VERSION,
    session_start_date: @started_at.strftime("%A, %B %e, %Y, at %l:%M:%S %P"),
    total_channels: @bot.channels.length,
    total_users: proc { 
      users = []; 
      @bot.channels.each {|c| 
          c.users.each {|u| users << u[0].nick 
        }
      }; 
      users.uniq.size
    }.call,
    uptime: ChronicDuration.output(Time.now.to_i - @started_at.to_i)
  }

  tf = TagFormatter.new open(config[:template_path],&:read), tags: tags

  m.user.notice tf.parse
end

#execute_help(m, name) ⇒ Object


66
67
68
69
70
71
# File 'lib/cinch/plugins/botinfo.rb', line 66

def execute_help(m, name)
  list = {}
  @bot.plugins.each {|p| list[p.class.plugin_name.downcase] = {name: p.class.plugin_name, help: p.class.help} };
  return m.user.notice("Help for \"#{name}\" could not be found.") if !list.has_key?(name.downcase)
  m.user.notice("Help for #{Format(:bold,list[name.downcase][:name])}:\n#{list[name.downcase][:help]}")
end

#execute_list(m) ⇒ Object


59
60
61
62
63
# File 'lib/cinch/plugins/botinfo.rb', line 59

def execute_list(m)
  list = []
  @bot.plugins.each {|p| list << p.class.plugin_name };
  m.user.notice("All #{list.size} currently loaded plugins for #{@bot.nick}:\n#{list.to_sentence}.\nTo view help for a plugin, use `/msg #{@bot.nick} help <plugin name>`.")
end