Class: CeilingCat::Plugin::Base
- Inherits:
-
Object
- Object
- CeilingCat::Plugin::Base
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
#event ⇒ Object
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
.commands ⇒ Object
36
37
38
|
# File 'lib/ceiling_cat/plugins/base.rb', line 36
def self.commands
[]
end
|
.description ⇒ Object
28
29
30
|
# File 'lib/ceiling_cat/plugins/base.rb', line 28
def self.description
"No description"
end
|
.name ⇒ Object
24
25
26
|
# File 'lib/ceiling_cat/plugins/base.rb', line 24
def self.name
self.to_s.gsub("CeilingCat::Plugin::","")
end
|
.public? ⇒ Boolean
32
33
34
|
# File 'lib/ceiling_cat/plugins/base.rb', line 32
def self.public?
false end
|
Instance Method Details
#body ⇒ Object
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
|
#commands ⇒ Object
40
41
42
|
# File 'lib/ceiling_cat/plugins/base.rb', line 40
def commands
self.class.commands || []
end
|
#handle ⇒ Object
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
|
#room ⇒ Object
48
49
50
|
# File 'lib/ceiling_cat/plugins/base.rb', line 48
def room
event.room
end
|
#store ⇒ Object
52
53
54
|
# File 'lib/ceiling_cat/plugins/base.rb', line 52
def store
self.class.store
end
|
#user ⇒ Object
64
65
66
|
# File 'lib/ceiling_cat/plugins/base.rb', line 64
def user
event.user
end
|
#words ⇒ Object
72
73
74
|
# File 'lib/ceiling_cat/plugins/base.rb', line 72
def words
body.split
end
|