Class: ChatgptAssistant::VoiceConnectService

Inherits:
Object
  • Object
show all
Defined in:
lib/chatgpt_assistant/bots/services/voice_connect_service.rb

Overview

This class is responsible to handle the discord bot

Instance Method Summary collapse

Constructor Details

#initialize(channel_id) ⇒ VoiceConnectService

Returns a new instance of VoiceConnectService.



6
7
8
9
10
# File 'lib/chatgpt_assistant/bots/services/voice_connect_service.rb', line 6

def initialize(channel_id)
  @channel_id = channel_id
  @config = Config.new
  # @config.db_connection
end

Instance Method Details

#botObject



12
13
14
# File 'lib/chatgpt_assistant/bots/services/voice_connect_service.rb', line 12

def bot
  @bot ||= Discordrb::Bot.new(token: @config.discord_token)
end

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/chatgpt_assistant/bots/services/voice_connect_service.rb', line 16

def call
  bot.run :async
  channel = bot.channel(@channel_id)

  bot.voice_connect(channel)
  bot.join
  true
rescue StandardError => e
  puts e.message
  e.backtrace.each { |line| puts line }
  false
end