Skip to content

Commit 7129f13

Browse files
FionaDLABizzinotto
authored andcommitted
IIRR-13 Update relationship with channel
1 parent eb9c00a commit 7129f13

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

app/lib/discord/events/server_create.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def create_server(server)
5252
name: server.name
5353
)
5454
if server.system_channel
55-
discord_server.channels.create!(
55+
discord_server.create_channel!(
5656
channel_id: server.system_channel.id,
5757
name: server.system_channel.name
5858
)

app/lib/discord/events/set_channel.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ def listen_to_channel_select
5353
channel = event.values.first # Get the selected channel
5454
server = Server.find_by!(server_id: event.server.id)
5555

56-
existing_channel = server.channels.find_by(channel_id: channel.id)
56+
existing_channel = server.channel
5757

5858
if existing_channel
5959
# If the channel exists, update it
6060
existing_channel.update!(name: channel.name, channel_id: channel.id)
6161
else
6262
# If the channel doesn't exist, create a new one associated with the server
63-
server.channels.create!(name: channel.name, channel_id: channel.id)
63+
server.channel.create!(name: channel.name, channel_id: channel.id)
6464
end
6565

6666
# Respond with a confirmation message

app/models/server.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
class Server < ApplicationRecord
2-
has_many :channels
2+
has_one :channel
3+
# has_and_belongs_to_many :users
34
end

0 commit comments

Comments
 (0)