Class: Botaku::Bot
- Inherits:
-
Object
- Object
- Botaku::Bot
- Defined in:
- lib/botaku/bot.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #_self ⇒ Object
-
#initialize(opts) ⇒ Bot
constructor
A new instance of Bot.
- #name ⇒ Object
- #run ⇒ Object (also: #join)
- #say(*as) ⇒ Object
- #typing(channel = @channel) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Bot
Returns a new instance of Bot.
8 9 10 11 12 13 |
# File 'lib/botaku/bot.rb', line 8 def initialize(opts) fail ArgumentError.new('missing :token') unless opts[:token] @opts = opts end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/botaku/bot.rb', line 6 def client @client end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
6 7 8 |
# File 'lib/botaku/bot.rb', line 6 def opts @opts end |
Instance Method Details
#_self ⇒ Object
15 16 17 18 |
# File 'lib/botaku/bot.rb', line 15 def _self @client._self end |
#name ⇒ Object
20 21 22 23 |
# File 'lib/botaku/bot.rb', line 20 def name @client.objects[_self['id']]['name'] end |
#run ⇒ Object Also known as: join
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/botaku/bot.rb', line 35 def run @client = Botaku::Client.new(@opts.dup) @client.on('hello') { invoke(:hello) } @client.on(:close) { |d| invoke(:close, d) } @client.on('message') do |d| (invoke_command(d) || invoke(:message, d)) if d['user'] != _self['id'] end @client.run end |
#say(*as) ⇒ Object
25 26 27 28 |
# File 'lib/botaku/bot.rb', line 25 def say(*as) @client.say(*(as + [ @channel ])) end |
#typing(channel = @channel) ⇒ Object
30 31 32 33 |
# File 'lib/botaku/bot.rb', line 30 def typing(channel=@channel) @client.typing(channel: channel) end |