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.



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

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.



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

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.



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

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

Instance Method Details

#validateObject



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

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