Class: Discordrb::Bot
Instance Method Summary collapse
- #channel(id) ⇒ Object
- #debug=(debug) ⇒ Object
- #disconnected(attributes = {}, &block) ⇒ Object
-
#initialize(email, password) ⇒ Bot
constructor
A new instance of Bot.
- #message(attributes = {}, &block) ⇒ Object
- #presence(attributes = {}, &block) ⇒ Object
- #ready(attributes = {}, &block) ⇒ Object
- #run ⇒ Object
- #send_message(channel_id, content) ⇒ Object
- #server(id) ⇒ Object
- #typing(attributes = {}, &block) ⇒ Object
- #user(id) ⇒ Object
Methods included from Events
Constructor Details
#initialize(email, password) ⇒ Bot
Returns a new instance of Bot.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/discordrb/bot.rb', line 18 def initialize(email, password) @email = email @password = password @token = login @event_handlers = {} @channels = {} @users = {} @debug = false end |
Instance Method Details
#channel(id) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/discordrb/bot.rb', line 46 def channel(id) debug("Obtaining data for channel with id #{id}") return @channels[id] if @channels[id] response = RestClient.get Discordrb::Endpoints::CHANNELS + "/#{id}", {:Authorization => @token} channel = Channel.new(JSON.parse(response), self) @channels[id] = channel end |
#debug=(debug) ⇒ Object
73 74 75 |
# File 'lib/discordrb/bot.rb', line 73 def debug=(debug) @debug = debug end |
#disconnected(attributes = {}, &block) ⇒ Object
85 86 87 |
# File 'lib/discordrb/bot.rb', line 85 def disconnected(attributes = {}, &block) register_event(DisconnectEvent, attributes, block) end |
#message(attributes = {}, &block) ⇒ Object
77 78 79 |
# File 'lib/discordrb/bot.rb', line 77 def (attributes = {}, &block) register_event(MessageEvent, attributes, block) end |
#presence(attributes = {}, &block) ⇒ Object
93 94 95 |
# File 'lib/discordrb/bot.rb', line 93 def presence(attributes = {}, &block) register_event(PresenceEvent, attributes, block) end |
#ready(attributes = {}, &block) ⇒ Object
81 82 83 |
# File 'lib/discordrb/bot.rb', line 81 def ready(attributes = {}, &block) register_event(ReadyEvent, attributes, block) end |
#run ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/discordrb/bot.rb', line 32 def run # Handle heartbeats @heartbeat_interval = 1 @heartbeat_active = false @heartbeat_thread = Thread.new do while true do sleep @heartbeat_interval send_heartbeat if @heartbeat_active end end websocket_connect end |
#send_message(channel_id, content) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/discordrb/bot.rb', line 63 def (channel_id, content) debug("Sending message to #{channel_id} with content '#{content}'") data = { 'content' => content, 'mentions' => [] } RestClient.post Discordrb::Endpoints::CHANNELS + "/#{channel_id}/messages", data.to_json, {:Authorization => @token, :content_type => :json} end |
#server(id) ⇒ Object
59 60 61 |
# File 'lib/discordrb/bot.rb', line 59 def server(id) @servers[id] end |
#typing(attributes = {}, &block) ⇒ Object
89 90 91 |
# File 'lib/discordrb/bot.rb', line 89 def typing(attributes = {}, &block) register_event(TypingEvent, attributes, block) end |
#user(id) ⇒ Object
55 56 57 |
# File 'lib/discordrb/bot.rb', line 55 def user(id) @users[id] end |