Class: Botaku::Bot

Inherits:
Object
  • Object
show all
Defined in:
lib/botaku/bot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/botaku/bot.rb', line 6

def client
  @client
end

#optsObject (readonly)

Returns the value of attribute opts.



6
7
8
# File 'lib/botaku/bot.rb', line 6

def opts
  @opts
end

Instance Method Details

#_selfObject



15
16
17
18
# File 'lib/botaku/bot.rb', line 15

def _self

  @client._self
end

#nameObject



20
21
22
23
# File 'lib/botaku/bot.rb', line 20

def name

  @client.objects[_self['id']]['name']
end

#runObject 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