-
Notifications
You must be signed in to change notification settings - Fork 3
/
botcmd.rb
51 lines (41 loc) · 1.06 KB
/
botcmd.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
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
46
47
#==================================================================
# Botcmd Class
#
# Commands that are set to :type => :private are only usable by
# admins. If set to :type => :public then anyone can use them.
#
# Copyright 2009 by Steve Gibson
# [email protected] (xmpp and email)
#
# This is free software. You can redistribute it and/or
# modify it under the terms of the BSD license. See
# LICENSE for more details.
#==================================================================
class Botcmd
attr_accessor :name, :type, :code, :return, :helptxt
def initialize(elements)
@elements = elements
@name = @elements[:name]
@type = @elements[:type]
@code = @elements[:code]
@return = @elements[:return]
@helptxt = @elements[:helptxt]
end
def to_s
"#{@name} (#{@type})"
end
def self.get_help(name)
found = nil
ObjectSpace.each_object(Botcmd) { |obj|
found = obj if obj.name == name
found.helptxt
}
end
def exec
if @return
eval(@code).to_s
else
eval(@code)
end
end
end