Class: MijDiscord::Data::Message
- Inherits:
-
Object
- Object
- MijDiscord::Data::Message
- Includes:
- IDObject
- Defined in:
- lib/mij-discord/data/message.rb
Instance Attribute Summary collapse
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#author ⇒ Object
(also: #user)
readonly
Returns the value of attribute author.
-
#bot ⇒ Object
readonly
Returns the value of attribute bot.
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#content ⇒ Object
(also: #text, #to_s)
readonly
Returns the value of attribute content.
-
#edited ⇒ Object
(also: #edited?)
readonly
attr_reader :nonce.
-
#edited_timestamp ⇒ Object
(also: #edit_timestamp)
readonly
Returns the value of attribute edited_timestamp.
-
#embeds ⇒ Object
readonly
Returns the value of attribute embeds.
-
#mention_everyone ⇒ Object
readonly
Returns the value of attribute mention_everyone.
-
#pinned ⇒ Object
(also: #pinned?)
readonly
Returns the value of attribute pinned.
-
#role_mentions ⇒ Object
readonly
Returns the value of attribute role_mentions.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#tts ⇒ Object
(also: #tts?)
readonly
attr_reader :reactions.
-
#user_mentions ⇒ Object
readonly
Returns the value of attribute user_mentions.
-
#webhook_id ⇒ Object
readonly
Returns the value of attribute webhook_id.
Attributes included from IDObject
Instance Method Summary collapse
- #clear_reactions ⇒ Object
-
#create_reaction(reaction) ⇒ Object
(also: #add_reaction)
def my_reactions @reactions.select(&:me) end.
- #delete ⇒ Object
- #delete_reaction(reaction, user: nil) ⇒ Object
- #edit(text: '', embed: nil) ⇒ Object
-
#initialize(data, bot) ⇒ Message
constructor
A new instance of Message.
- #pin ⇒ Object
- #reacted_with(reaction) ⇒ Object
- #reply(text: '', embed: nil, tts: false) ⇒ Object
- #reply_file(file, caption: '', tts: false) ⇒ Object
- #unpin ⇒ Object
- #update_data(data) ⇒ Object
- #webhook? ⇒ Boolean
Methods included from IDObject
#==, #creation_time, #hash, synthesize
Constructor Details
#initialize(data, bot) ⇒ Message
Returns a new instance of Message.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/mij-discord/data/message.rb', line 48 def initialize(data, bot) @bot = bot @id = data['id'].to_i @channel = @bot.channel(data['channel_id']) # @nonce = data['nonce'] @webhook_id = data['webhook_id']&.to_i if ( = data['author']) if ['discriminator'] == '0000' @author = @bot.cache.put_user() elsif @channel.private? @author = @channel.recipient else member = @channel.server.member(['id']) @author = member || @bot.user(['id']) end end update_data(data) end |
Instance Attribute Details
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
29 30 31 |
# File 'lib/mij-discord/data/message.rb', line 29 def @attachments end |
#author ⇒ Object (readonly) Also known as: user
Returns the value of attribute author.
13 14 15 |
# File 'lib/mij-discord/data/message.rb', line 13 def @author end |
#bot ⇒ Object (readonly)
Returns the value of attribute bot.
7 8 9 |
# File 'lib/mij-discord/data/message.rb', line 7 def bot @bot end |
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
16 17 18 |
# File 'lib/mij-discord/data/message.rb', line 16 def channel @channel end |
#content ⇒ Object (readonly) Also known as: text, to_s
Returns the value of attribute content.
9 10 11 |
# File 'lib/mij-discord/data/message.rb', line 9 def content @content end |
#edited ⇒ Object (readonly) Also known as: edited?
attr_reader :nonce
40 41 42 |
# File 'lib/mij-discord/data/message.rb', line 40 def edited @edited end |
#edited_timestamp ⇒ Object (readonly) Also known as: edit_timestamp
Returns the value of attribute edited_timestamp.
20 21 22 |
# File 'lib/mij-discord/data/message.rb', line 20 def @edited_timestamp end |
#embeds ⇒ Object (readonly)
Returns the value of attribute embeds.
31 32 33 |
# File 'lib/mij-discord/data/message.rb', line 31 def @embeds end |
#mention_everyone ⇒ Object (readonly)
Returns the value of attribute mention_everyone.
27 28 29 |
# File 'lib/mij-discord/data/message.rb', line 27 def mention_everyone @mention_everyone end |
#pinned ⇒ Object (readonly) Also known as: pinned?
Returns the value of attribute pinned.
43 44 45 |
# File 'lib/mij-discord/data/message.rb', line 43 def pinned @pinned end |
#role_mentions ⇒ Object (readonly)
Returns the value of attribute role_mentions.
25 26 27 |
# File 'lib/mij-discord/data/message.rb', line 25 def role_mentions @role_mentions end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
18 19 20 |
# File 'lib/mij-discord/data/message.rb', line 18 def @timestamp end |
#tts ⇒ Object (readonly) Also known as: tts?
attr_reader :reactions
35 36 37 |
# File 'lib/mij-discord/data/message.rb', line 35 def tts @tts end |
#user_mentions ⇒ Object (readonly)
Returns the value of attribute user_mentions.
23 24 25 |
# File 'lib/mij-discord/data/message.rb', line 23 def user_mentions @user_mentions end |
#webhook_id ⇒ Object (readonly)
Returns the value of attribute webhook_id.
46 47 48 |
# File 'lib/mij-discord/data/message.rb', line 46 def webhook_id @webhook_id end |
Instance Method Details
#clear_reactions ⇒ Object
164 165 166 167 |
# File 'lib/mij-discord/data/message.rb', line 164 def clear_reactions MijDiscord::Core::API::Channel.delete_all_reactions(@bot.auth, @channel.id, @id) nil end |
#create_reaction(reaction) ⇒ Object Also known as: add_reaction
def my_reactions
@reactions.select(&:me)
end
140 141 142 143 144 |
# File 'lib/mij-discord/data/message.rb', line 140 def create_reaction(reaction) emoji = reaction.respond_to?(:reaction) ? reaction.reaction : reaction MijDiscord::Core::API::Channel.create_reaction(@bot.auth, @channel.id, @id, emoji) nil end |
#delete ⇒ Object
169 170 171 172 |
# File 'lib/mij-discord/data/message.rb', line 169 def delete MijDiscord::Core::API::Channel.(@bot.auth, @channel.id, @id) nil end |
#delete_reaction(reaction, user: nil) ⇒ Object
154 155 156 157 158 159 160 161 162 |
# File 'lib/mij-discord/data/message.rb', line 154 def delete_reaction(reaction, user: nil) emoji = reaction.respond_to?(:reaction) ? reaction.reaction : reaction if user.nil? MijDiscord::Core::API::Channel.delete_own_reaction(@bot.auth, @channel.id, @id, emoji) else MijDiscord::Core::API::Channel.delete_user_reaction(@bot.auth, @channel.id, @id, emoji, user.to_id) end nil end |
#edit(text: '', embed: nil) ⇒ Object
116 117 118 119 120 |
# File 'lib/mij-discord/data/message.rb', line 116 def edit(text: '', embed: nil) response = MijDiscord::Core::API::Channel.(@bot.auth, @channel.id, @id, text, [], &.to_h) @channel.cache.(JSON.parse(response), update: true) end |
#pin ⇒ Object
122 123 124 125 |
# File 'lib/mij-discord/data/message.rb', line 122 def pin MijDiscord::Core::API::Channel.(@bot.auth, @channel.id, @id) nil end |
#reacted_with(reaction) ⇒ Object
148 149 150 151 152 |
# File 'lib/mij-discord/data/message.rb', line 148 def reacted_with(reaction) emoji = reaction.respond_to?(:reaction) ? reaction.reaction : reaction response = MijDiscord::Core::API::Channel.get_reactions(@bot.auth, @channel.id, @id, emoji) JSON.parse(response).map {|x| @bot.cache.put_user(x) } end |
#reply(text: '', embed: nil, tts: false) ⇒ Object
108 109 110 |
# File 'lib/mij-discord/data/message.rb', line 108 def reply(text: '', embed: nil, tts: false) @channel.(text: text, embed: , tts: tts) end |
#reply_file(file, caption: '', tts: false) ⇒ Object
112 113 114 |
# File 'lib/mij-discord/data/message.rb', line 112 def reply_file(file, caption: '', tts: false) @channel.send_file(file, caption: caption, tts: tts) end |
#unpin ⇒ Object
127 128 129 130 |
# File 'lib/mij-discord/data/message.rb', line 127 def unpin MijDiscord::Core::API::Channel.(@bot.auth, @channel.id, @id) nil end |
#update_data(data) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/mij-discord/data/message.rb', line 71 def update_data(data) @content = data.fetch('content', @content) @pinned = data.fetch('pinned', @pinned) @tts = data.fetch('tts', @tts) @timestamp = Time.parse(data['timestamp']).utc if data['timestamp'] @edited_timestamp = Time.parse(data['edited_timestamp']).utc if data['edited_timestamp'] @edited = !!@edited_timestamp @mention_everyone = !!data['mention_everyone'] # @reactions = [] # if (reactions = data['reactions']) # reactions.each {|x| @reactions << Reaction.new(x) } # end @user_mentions = [] if (mentions = data['mentions']) mentions.each {|x| @user_mentions << @bot.cache.put_user(x) } end @role_mentions = [] if @channel.text? && (mentions = data['mention_roles']) mentions.each {|x| @role_mentions << @channel.server.role(x) } end @attachments = [] if ( = data['attachments']) .each {|x| @attachments << Attachment.new(x, self) } end @embeds = [] if ( = data['embeds']) .each {|x| @embeds << Embed.new(x) } end end |
#webhook? ⇒ Boolean
132 133 134 |
# File 'lib/mij-discord/data/message.rb', line 132 def webhook? !@webhook_id.nil? end |