Class: Rubirai::Event
Abstract
- Inherits:
-
Object
show all
- Defined in:
- lib/rubirai/events/event.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#bot ⇒ Bot
88
89
90
|
# File 'lib/rubirai/events/event.rb', line 88
def bot
@bot
end
|
#raw ⇒ Object
Returns the value of attribute raw.
88
|
# File 'lib/rubirai/events/event.rb', line 88
attr_reader :bot, :raw
|
Class Method Details
.parse(hash, bot = nil) ⇒ Object
78
79
80
81
|
# File 'lib/rubirai/events/event.rb', line 78
def self.parse(hash, bot = nil)
hash = hash.stringify_keys
type_to_klass(hash['type']).new hash, bot
end
|
.set_event(type, *attr_keys) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/rubirai/events/event.rb', line 43
def self.set_event(type, *attr_keys)
attr_reader(*attr_keys)
metaclass.instance_eval do
break if type.nil?
define_method(:type) do
type
end
end
class_eval do
define_method(:initialize) do |hash, bot = nil|
super hash, bot
hash = hash.stringify_keys
attr_keys.each do |k|
k2 = k.to_s.snake_to_camel(lower: true)
val = hash[k2]
val = parse_val_from_key k2, val, bot
instance_variable_set("@#{k}", val)
end
end
end
end
|
.type_to_klass(type) ⇒ Object
33
34
35
36
|
# File 'lib/rubirai/events/event.rb', line 33
def self.type_to_klass(type)
type_map[type.to_sym]
end
|
.valid_type?(type) ⇒ Boolean
38
39
40
41
|
# File 'lib/rubirai/events/event.rb', line 38
def self.valid_type?(type)
all_types.include? type
end
|
Instance Method Details
#parse_val_from_key(key, val, bot) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/rubirai/events/event.rb', line 98
def parse_val_from_key(key, val, bot)
case key
when 'group'
Group.new val, bot
when 'operator', 'member'
GroupUser.new val, bot
when 'sender'
if val.key? 'group'
GroupUser.new val, bot
else
User.new val, bot
end
when 'messageChain'
MessageChain.new bot, val
else
val
end
end
|