Class: Nanobot::Channels::Discord
- Inherits:
-
BaseChannel
- Object
- BaseChannel
- Nanobot::Channels::Discord
- Defined in:
- lib/nanobot/channels/discord.rb
Overview
Discord channel integration using the discordrb gem. Listens for server messages and responds in the same channel.
Instance Attribute Summary
Attributes inherited from BaseChannel
Instance Method Summary collapse
-
#send(message) ⇒ Object
Send a message to a Discord channel, splitting at the 2000-char limit.
- #start ⇒ Object
- #stop ⇒ Object
Methods inherited from BaseChannel
#allowed?, #initialize, #running?
Constructor Details
This class inherits a constructor from Nanobot::Channels::BaseChannel
Instance Method Details
#send(message) ⇒ Object
Send a message to a Discord channel, splitting at the 2000-char limit.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/nanobot/channels/discord.rb', line 40 def send() return unless @bot channel = @bot.channel(.chat_id.to_i) return unless channel (.content, 2000).each do |chunk| channel.(chunk) end end |
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nanobot/channels/discord.rb', line 14 def start @running = true @bot = Discordrb::Bot.new(token: @config.token, intents: [:server_messages]) @bot. do |event| next if event..bot_account? next unless allowed?(event..id.to_s) ( sender_id: event..id.to_s, chat_id: event.channel.id.to_s, content: event.content ) end @logger.info 'Discord bot connecting...' @bot.run end |
#stop ⇒ Object
33 34 35 36 |
# File 'lib/nanobot/channels/discord.rb', line 33 def stop @running = false @bot&.stop end |