Module: Elephrame::Reply
- Included in:
- AllInteractions, Bots::GenerativeBot, Bots::Reply, Bots::TraceryBot, Bots::Watcher, Command
- Defined in:
- lib/elephrame/streaming/reply.rb
Instance Attribute Summary collapse
-
#on_reply(&block) ⇒ Object
readonly
Sets on_reply equal to
block
.
Instance Method Summary collapse
-
#reply(text, *options) ⇒ Object
Replies to the last mention the bot recieved using the mention’s visibility and spoiler with
text
. -
#reply_with_mentions(text, *options) ⇒ Object
Replies to the last post and tags everyone who was mentioned (this function respects #NoBot).
-
#run_reply ⇒ Object
(also: #run)
Starts a loop that checks for mentions from the authenticated user account running a supplied block or, if a block is not provided, on_reply.
Instance Attribute Details
#on_reply(&block) ⇒ Object (readonly)
Sets on_reply equal to block
8 9 10 |
# File 'lib/elephrame/streaming/reply.rb', line 8 def on_reply @on_reply end |
Instance Method Details
#reply(text, *options) ⇒ Object
Replies to the last mention the bot recieved using the mention’s
visibility and spoiler with +text+
Automatically includes an @ for the account that mentioned the bot.
Does not include any other @. See +reply_with_mentions+ if you want
to automatically include all mentions
24 25 26 27 28 29 30 31 |
# File 'lib/elephrame/streaming/reply.rb', line 24 def reply(text, *) = Hash[*] post("@#{@mention_data[:account].acct} #{text}", **@mention_data.merge().reject { |k| k == :mentions or k == :account }) end |
#reply_with_mentions(text, *options) ⇒ Object
Replies to the last post and tags everyone who was mentioned
(this function respects #NoBot)
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/elephrame/streaming/reply.rb', line 41 def reply_with_mentions(text, *) # build up a string of all accounts mentioned in the post # unless that account is our own, or the tagged account # has #NoBot mentions = @mention_data[:mentions].collect do |m| "@#{m.acct}" unless m.acct == @username or @client.account(m.id).no_bot? end.join ' ' reply("#{mentions.strip} #{text}", *) end |
#run_reply ⇒ Object Also known as: run
Starts a loop that checks for mentions from the authenticated user account running a supplied block or, if a block is not provided, on_reply
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/elephrame/streaming/reply.rb', line 56 def run_reply @streamer.user do |update| next unless update.kind_of? Mastodon::Notification and update.type == 'mention' # this makes it so .content calls strip instead update.status.class.module_eval { alias_method :content, :strip } if @strip_html store_mention_data update.status if block_given? yield(self, update.status) else @on_reply.call(self, update.status) end end end |