Class: CeilingCat::Plugin::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ceiling_cat/plugins/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ Base

Returns a new instance of Base.


6
7
8
# File 'lib/ceiling_cat/plugins/base.rb', line 6

def initialize(event)
  @event = event
end

Instance Attribute Details

#eventObject

Returns the value of attribute event


4
5
6
# File 'lib/ceiling_cat/plugins/base.rb', line 4

def event
  @event
end

Class Method Details

.commandsObject


36
37
38
# File 'lib/ceiling_cat/plugins/base.rb', line 36

def self.commands
  []
end

.descriptionObject


28
29
30
# File 'lib/ceiling_cat/plugins/base.rb', line 28

def self.description
  "No description"
end

.nameObject


24
25
26
# File 'lib/ceiling_cat/plugins/base.rb', line 24

def self.name
  self.to_s.gsub("CeilingCat::Plugin::","")
end

.public?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'lib/ceiling_cat/plugins/base.rb', line 32

def self.public?
  false #assume we don't want people to know a plugin is available.
end

.storeObject


56
57
58
# File 'lib/ceiling_cat/plugins/base.rb', line 56

def self.store
  CeilingCat::Setup.config ? CeilingCat::Setup.config.storage : CeilingCat::Storage::Hash
end

Instance Method Details

#bodyObject


60
61
62
# File 'lib/ceiling_cat/plugins/base.rb', line 60

def body
  event.body
end

#body_without_command(command, text = body) ⇒ Object


76
77
78
# File 'lib/ceiling_cat/plugins/base.rb', line 76

def body_without_command(command,text=body)
  text.sub(/^!#{command}:?\s*/i,"").strip
end

#body_without_nick(text = body) ⇒ Object


80
81
82
# File 'lib/ceiling_cat/plugins/base.rb', line 80

def body_without_nick(text=body)
  text.sub(/^#{room.me.name}:?\s*/i,'').strip
end

#body_without_nick_or_command(command, text = body) ⇒ Object


84
85
86
# File 'lib/ceiling_cat/plugins/base.rb', line 84

def body_without_nick_or_command(command,text=body)
  body_without_command(command, body_without_nick(text).sub(/^#{command}/i,"!#{command}"))
end

#commandsObject


40
41
42
# File 'lib/ceiling_cat/plugins/base.rb', line 40

def commands
  self.class.commands || []
end

#handleObject


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ceiling_cat/plugins/base.rb', line 10

def handle
  if command = commands.find{|command| body =~ /^(!|#{room.me.name}:?\s*)#{command[:command]}/i}
    begin
      if command[:public] || user.is_registered?
        self.send command[:method]
        return true
      end
    rescue => e
      reply "There was an error: #{$!}"
      raise e
    end
  end
end

#pluralize(n, singular, plural = nil) ⇒ Object


88
89
90
91
92
93
94
95
96
# File 'lib/ceiling_cat/plugins/base.rb', line 88

def pluralize(n, singular, plural=nil)
  if n == 1
      "#{singular}"
  elsif plural
      "#{plural}"
  else
      "#{singular}s"
  end
end

#reply(message) ⇒ Object


68
69
70
# File 'lib/ceiling_cat/plugins/base.rb', line 68

def reply(message)
  room.say(message)
end

#roomObject


48
49
50
# File 'lib/ceiling_cat/plugins/base.rb', line 48

def room
  event.room
end

#storeObject


52
53
54
# File 'lib/ceiling_cat/plugins/base.rb', line 52

def store
  self.class.store
end

#userObject


64
65
66
# File 'lib/ceiling_cat/plugins/base.rb', line 64

def user
  event.user
end

#wordsObject


72
73
74
# File 'lib/ceiling_cat/plugins/base.rb', line 72

def words
  body.split
end