Class: Async::Matrix::Bridge::Discord::DB::Portal

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/async/matrix/bridge/discord/db/portal.rb

Overview

Maps a Discord channel to a Matrix room.

Uses a composite primary key of (discord_id, receiver). For guild channels, receiver is an empty string. For DMs, receiver is the Discord user ID of the bridge user who owns the portal.

portal = Portal.create(discord_id: "chan123", receiver: "", mxid: "!room:x")
portal.guild      # => Guild or nil
portal.messages   # => [Message, ...]

Instance Method Summary collapse

Instance Method Details

#dm?Boolean

Is this a DM portal? (has a receiver)

Returns:

  • (Boolean)


43
44
45
# File 'lib/async/matrix/bridge/discord/db/portal.rb', line 43

def dm?
  receiver && !receiver.empty?
end

#guild_channel?Boolean

Is this a guild channel portal?

Returns:

  • (Boolean)


48
49
50
# File 'lib/async/matrix/bridge/discord/db/portal.rb', line 48

def guild_channel?
  !dm?
end

#validateObject



37
38
39
40
# File 'lib/async/matrix/bridge/discord/db/portal.rb', line 37

def validate
  super
  errors.add(:discord_id, "cannot be empty") if discord_id.nil? || discord_id.empty?
end