class Kybus::Bot::Adapter::Discord
This adapter is intended to be used on unit tests and development.
Attributes
client[R]
Public Class Methods
new(configs)
click to toggle source
It receives a hash with the configurations:
-
name: the name of the channel
-
channels a key value, where the key is a name and the value the list of the messages in the channel.
-
echo: a flag to enable debug messages.
# File lib/kybus/bot/adapters/discord.rb, line 53 def initialize(configs) @config = configs @client = Discordrb::Bot.new(token: @config['token']) @pool = [] @client.message do |msg| @pool << msg end @client.run(:async) end
Public Instance Methods
mention(id)
click to toggle source
# File lib/kybus/bot/adapters/discord.rb, line 65 def mention(id) "<@!#{id}>" end
read_message()
click to toggle source
Interface for receiving message
# File lib/kybus/bot/adapters/discord.rb, line 70 def read_message # take the first message from the first open message, loop do if @pool.empty? sleep(0.1) else break end end DiscordMessage.new(@pool.shift) end
send_message(channel_name, contents)
click to toggle source
interface for sending messages
# File lib/kybus/bot/adapters/discord.rb, line 83 def send_message(channel_name, contents) puts "#{channel_name} => #{contents}" if @config['debug'] channel = @client.channel(channel_name) if channel channel.send_message(contents) else @client.user(channel_name).pm(contents) end end