Class: Async::Matrix::Bridge::Discord::DB::Reaction

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

Overview

Maps a Discord reaction to a Matrix reaction event.

Uniquely identified by (discord_message_id, discord_sender, discord_emoji_name) — one reaction per emoji per user per message.

reaction = Reaction.create(
discord_message_id: "msg1", discord_sender: "user1",
discord_emoji_name: "\u{1f44d}", mxid: "$react1",
discord_channel_id: "ch1"
)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.by_discord_key(message_id:, sender:, emoji_name:) ⇒ Object

Find a specific reaction by Discord compound key.



48
49
50
51
52
53
54
# File 'lib/async/matrix/bridge/discord/db/reaction.rb', line 48

def self.by_discord_key(message_id:, sender:, emoji_name:)
  first(
    discord_message_id: message_id,
    discord_sender: sender,
    discord_emoji_name: emoji_name
  )
end

.by_discord_message(message_id, channel_id, receiver = "") ⇒ Object

Find all reactions on a Discord message.



34
35
36
37
38
39
40
# File 'lib/async/matrix/bridge/discord/db/reaction.rb', line 34

def self.by_discord_message(message_id, channel_id, receiver = "")
  where(
    discord_message_id: message_id,
    discord_channel_id: channel_id,
    discord_channel_receiver: receiver
  ).all
end

.by_mxid(mxid) ⇒ Object

Find a specific reaction by its Matrix event ID.



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

def self.by_mxid(mxid)
  first(mxid: mxid)
end

Instance Method Details

#validateObject



25
26
27
28
29
30
31
# File 'lib/async/matrix/bridge/discord/db/reaction.rb', line 25

def validate
  super
  errors.add(:discord_message_id, "cannot be empty") if discord_message_id.nil? || discord_message_id.empty?
  errors.add(:discord_sender, "cannot be empty") if discord_sender.nil? || discord_sender.empty?
  errors.add(:discord_emoji_name, "cannot be empty") if discord_emoji_name.nil? || discord_emoji_name.empty?
  errors.add(:mxid, "cannot be empty") if mxid.nil? || mxid.empty?
end