elephrame 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -12
- data/README.md +4 -1
- data/elephrame.gemspec +1 -1
- data/examples/notbot_check.rb +14 -0
- data/examples/watcher.rb +14 -0
- data/lib/elephrame/bot.rb +20 -5
- data/lib/elephrame/streaming/bots.rb +25 -0
- data/lib/elephrame/streaming/streaming.rb +1 -0
- data/lib/elephrame/streaming/watcher.rb +47 -0
- data/lib/elephrame/util/status.rb +4 -1
- data/lib/elephrame/version.rb +1 -1
- metadata +8 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 99301911c71cb6fe44225ba4ae6071886359ae6c667471f8a9198daf4a202ef8
         | 
| 4 | 
            +
              data.tar.gz: 98944310ca826e8d5432df0d699cb7eb7ed47c8997b19ef75331954e40b20e47
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: da91f48e6e1502a97fec68ada9d66e0b89c33e231fc884318549af623217468e0b0e393b466496ba19520435f6bcb8ba5bdbd20e111c3a2009c07b0c8606898b
         | 
| 7 | 
            +
              data.tar.gz: fffdcd359ea544c6b7ff4bbe91b00c93f5629ffa51144df1ae10256499b7885d6a486e93e3e5bfbdcb26480a18fc6c5993ba99073f2f4e4e6ffe930e61d3a721
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,22 +1,23 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                elephrame (0.4. | 
| 5 | 
            -
                  moostodon (~> 0. | 
| 4 | 
            +
                elephrame (0.4.5)
         | 
| 5 | 
            +
                  moostodon (~> 0.4.0)
         | 
| 6 6 | 
             
                  rufus-scheduler
         | 
| 7 7 |  | 
| 8 8 | 
             
            GEM
         | 
| 9 9 | 
             
              remote: https://rubygems.org/
         | 
| 10 10 | 
             
              specs:
         | 
| 11 | 
            -
                addressable (2. | 
| 11 | 
            +
                addressable (2.6.0)
         | 
| 12 12 | 
             
                  public_suffix (>= 2.0.2, < 4.0)
         | 
| 13 13 | 
             
                buftok (0.2.0)
         | 
| 14 | 
            +
                concurrent-ruby (1.1.5)
         | 
| 14 15 | 
             
                domain_name (0.5.20180417)
         | 
| 15 16 | 
             
                  unf (>= 0.0.5, < 1.0.0)
         | 
| 16 | 
            -
                et-orbi (1.1. | 
| 17 | 
            +
                et-orbi (1.1.7)
         | 
| 17 18 | 
             
                  tzinfo
         | 
| 18 | 
            -
                fugit (1.1. | 
| 19 | 
            -
                  et-orbi (~> 1.1, >= 1.1. | 
| 19 | 
            +
                fugit (1.1.8)
         | 
| 20 | 
            +
                  et-orbi (~> 1.1, >= 1.1.7)
         | 
| 20 21 | 
             
                  raabro (~> 1.1)
         | 
| 21 22 | 
             
                http (3.3.0)
         | 
| 22 23 | 
             
                  addressable (~> 2.3)
         | 
| @@ -28,20 +29,19 @@ GEM | |
| 28 29 | 
             
                http-form_data (2.1.1)
         | 
| 29 30 | 
             
                http_parser.rb (0.6.0)
         | 
| 30 31 | 
             
                minitest (5.11.3)
         | 
| 31 | 
            -
                moostodon (0. | 
| 32 | 
            +
                moostodon (0.4.0)
         | 
| 32 33 | 
             
                  addressable (~> 2.5)
         | 
| 33 34 | 
             
                  buftok (~> 0)
         | 
| 34 35 | 
             
                  http (~> 3.0)
         | 
| 35 36 | 
             
                  oj (~> 3.3)
         | 
| 36 | 
            -
                oj (3.7. | 
| 37 | 
            +
                oj (3.7.9)
         | 
| 37 38 | 
             
                public_suffix (3.0.3)
         | 
| 38 39 | 
             
                raabro (1.1.6)
         | 
| 39 40 | 
             
                rake (10.5.0)
         | 
| 40 41 | 
             
                rufus-scheduler (3.5.2)
         | 
| 41 42 | 
             
                  fugit (~> 1.1, >= 1.1.5)
         | 
| 42 | 
            -
                 | 
| 43 | 
            -
             | 
| 44 | 
            -
                  thread_safe (~> 0.1)
         | 
| 43 | 
            +
                tzinfo (2.0.0)
         | 
| 44 | 
            +
                  concurrent-ruby (~> 1.0)
         | 
| 45 45 | 
             
                unf (0.1.4)
         | 
| 46 46 | 
             
                  unf_ext
         | 
| 47 47 | 
             
                unf_ext (0.0.7.5)
         | 
| @@ -56,4 +56,4 @@ DEPENDENCIES | |
| 56 56 | 
             
              rake (~> 10.0)
         | 
| 57 57 |  | 
| 58 58 | 
             
            BUNDLED WITH
         | 
| 59 | 
            -
               1.17. | 
| 59 | 
            +
               1.17.2
         | 
    
        data/README.md
    CHANGED
    
    | @@ -72,7 +72,8 @@ Exposed methods from bot object: | |
| 72 72 | 
             
            - `reply(content, *options)` a shorthand method to reply to the last mention (Note: only include the @ for the user who @ed the bot)
         | 
| 73 73 | 
             
            - `reply_with_mentions(content, *options)` similar to `reply` but includes all @s (respects #NoBot)
         | 
| 74 74 | 
             
            - `find_ancestor(id, depth = 10, stop_at = 1)` looks backwards through reply chains for the most recent post the bot made starting at post `id` until it hits `depth` number of posts, or finds `stop_at` number of it's own posts
         | 
| 75 | 
            -
            - `no_bot?(account_id)` returns true if user with `account_id` has some form of "#NoBot" in their bio 
         | 
| 75 | 
            +
            - `no_bot?(account_id)` returns true if user with `account_id` has some form of "#NoBot" in their bio or their profile fields
         | 
| 76 | 
            +
            - `fetch_list_id(name)` return the id of a list with given name `name`
         | 
| 76 77 |  | 
| 77 78 | 
             
            (See RubyDocs for source code documentation)
         | 
| 78 79 |  | 
| @@ -82,6 +83,8 @@ Here's a list of bots that are currently using this framework. If you are using | |
| 82 83 |  | 
| 83 84 | 
             
            - [GameBot](https://github.com/theZacAttacks/GameBot)
         | 
| 84 85 | 
             
            - [EnhanceBot](https://github.com/theZacAttacks/EnhanceBot)
         | 
| 86 | 
            +
            - [RemindMe Bot](https://github.com/theZacAttacks/RemindMeBot)
         | 
| 87 | 
            +
            - [InstanceEmoji Bot](https://github.com/theZacAttacks/InstanceEmojiBot)
         | 
| 85 88 |  | 
| 86 89 | 
             
            ## Development
         | 
| 87 90 |  | 
    
        data/elephrame.gemspec
    CHANGED
    
    
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            require 'elephrame'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # create a bot that watches the public timeline
         | 
| 4 | 
            +
            #  (this gives us the largest sample size)
         | 
| 5 | 
            +
            watcher = Elephrame::Bots::Watcher.new 'public'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            watcher.run do |bot, post|
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              # if the account's profile doesn't contain no bot
         | 
| 10 | 
            +
              #  we print the account's handle and the post's content
         | 
| 11 | 
            +
              if not bot.no_bot? post.account.id
         | 
| 12 | 
            +
                puts "#{post.account.acct}: #{post.content}"
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
    
        data/examples/watcher.rb
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            require 'elephrame'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # here are various examples of how to create a new watcher bot
         | 
| 4 | 
            +
            #tag_watcher   = Elephrame::Bots::Watcher.new 'tag', 'CoolHash'
         | 
| 5 | 
            +
            #local_watcher = Elephrame::Bots::Watcher.new 'local'
         | 
| 6 | 
            +
            #ltag_watcher  = Elephrame::Bots::Watcher.new 'local hashtag', 'LocalTag'
         | 
| 7 | 
            +
            #list_watcher  = Elephrame::Bots::Watcher.new 'list', 'test list'
         | 
| 8 | 
            +
            #home_watcher  = Elephrame::Bots::Watcher.new 'home'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            fedi_watcher = Elephrame::Bots::Watcher.new 'public'
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            fedi_watcher.run do |bot, post|
         | 
| 13 | 
            +
              puts "#{post.account.acct}: #{post.content}"
         | 
| 14 | 
            +
            end
         | 
    
        data/lib/elephrame/bot.rb
    CHANGED
    
    | @@ -87,17 +87,32 @@ module Elephrame | |
| 87 87 | 
             
                  end
         | 
| 88 88 |  | 
| 89 89 | 
             
                  ##
         | 
| 90 | 
            -
                  # Checks to see if a user has some form of "#NoBot" in their bio
         | 
| 91 | 
            -
                  # (so we can make making friendly bots easier!)
         | 
| 90 | 
            +
                  # Checks to see if a user has some form of "#NoBot" in their bio or in
         | 
| 91 | 
            +
                  # their profile fields (so we can make making friendly bots easier!)
         | 
| 92 92 | 
             
                  #
         | 
| 93 93 | 
             
                  # @param account_id [String] id of account to check bio
         | 
| 94 94 | 
             
                  #
         | 
| 95 95 | 
             
                  # @return [Bool]
         | 
| 96 96 |  | 
| 97 97 | 
             
                  def no_bot? account_id
         | 
| 98 | 
            -
                     | 
| 99 | 
            -
                     | 
| 100 | 
            -
             | 
| 98 | 
            +
                    acct = @client.account(account_id)
         | 
| 99 | 
            +
                    acct.note =~ NoBotRegex ||
         | 
| 100 | 
            +
                      acct.fields.any? {|f| f.name =~ NoBotRegex || f.value =~ NoBotRegex}
         | 
| 101 | 
            +
                  end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                  ##
         | 
| 104 | 
            +
                  # Gets the ID of a list given the name
         | 
| 105 | 
            +
                  #
         | 
| 106 | 
            +
                  # @param name [String] name of the list
         | 
| 107 | 
            +
                  #
         | 
| 108 | 
            +
                  # @return [Integer]
         | 
| 109 | 
            +
                  
         | 
| 110 | 
            +
                  def fetch_list_id(name)
         | 
| 111 | 
            +
                    lists = {}
         | 
| 112 | 
            +
                    @client.lists.collect do |l|
         | 
| 113 | 
            +
                      lists[l.title] = l.id
         | 
| 114 | 
            +
                    end
         | 
| 115 | 
            +
                    lists[name]
         | 
| 101 116 | 
             
                  end
         | 
| 102 117 |  | 
| 103 118 | 
             
                  private
         | 
| @@ -67,5 +67,30 @@ module Elephrame | |
| 67 67 | 
             
                  end
         | 
| 68 68 | 
             
                end
         | 
| 69 69 |  | 
| 70 | 
            +
                ##
         | 
| 71 | 
            +
                # A bot that watches timelines or lists
         | 
| 72 | 
            +
                
         | 
| 73 | 
            +
                class Watcher < BaseBot
         | 
| 74 | 
            +
                  include Elephrame::Streaming
         | 
| 75 | 
            +
                  include Elephrame::Reply
         | 
| 76 | 
            +
                  include Elephrame::TimelineWatcher
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                  ##
         | 
| 79 | 
            +
                  # Creates a new Watcher bot
         | 
| 80 | 
            +
                  #
         | 
| 81 | 
            +
                  # @param tl [String] the timeline you want to watch. accepted values are:
         | 
| 82 | 
            +
                  #    'public', 'home', 'list', 'local', 'hashtag'/'tag', 'local hashtag'
         | 
| 83 | 
            +
                  # @param name [String] the name of the list or hashtag to watch
         | 
| 84 | 
            +
                  #
         | 
| 85 | 
            +
                  # @return [Elephrame::Bots::Watcher]
         | 
| 86 | 
            +
             
         | 
| 87 | 
            +
                  def initialize tl, name = nil
         | 
| 88 | 
            +
                    super()
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                    setup_streaming
         | 
| 91 | 
            +
                    setup_watcher tl, name
         | 
| 92 | 
            +
                  end
         | 
| 93 | 
            +
                end
         | 
| 94 | 
            +
                
         | 
| 70 95 | 
             
              end
         | 
| 71 96 | 
             
            end
         | 
| @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            module Elephrame
         | 
| 2 | 
            +
              module TimelineWatcher
         | 
| 3 | 
            +
                attr :endpoint, :endpoint_arg
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def setup_watcher(timeline, arg = nil)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                  @endpoint = format_tl(timeline)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  raise 'list or tag not supplied' if endpoint_needs_arg? and arg.nil?
         | 
| 10 | 
            +
                  @endpoint_arg = arg
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  # does some heavy lifting so the developer
         | 
| 13 | 
            +
                  #  doesn't need to know the ID of the list
         | 
| 14 | 
            +
                  @endpoint_arg = fetch_list_id(arg) if @endpoint == 'list'
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  # in case the the argument contains an actual hash symbol
         | 
| 17 | 
            +
                  @endpoint_arg.gsub!('#', '') if @endpoint =~ /tag/
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
                
         | 
| 20 | 
            +
                def run_watcher &block
         | 
| 21 | 
            +
                  @streamer.send(@endpoint,
         | 
| 22 | 
            +
                                 @endpoint_arg) do |post|
         | 
| 23 | 
            +
                    next if post.kind_of? Mastodon::Notification or
         | 
| 24 | 
            +
                            post.kind_of? Mastodon::Streaming::DeletedStatus
         | 
| 25 | 
            +
                    
         | 
| 26 | 
            +
                    # this makes it so .content calls strip instead 
         | 
| 27 | 
            +
                    post.class.module_eval { alias_method :content, :strip } if @strip_html
         | 
| 28 | 
            +
                    
         | 
| 29 | 
            +
                    block.call(self, post)
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                alias_method :run, :run_watcher
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                private
         | 
| 36 | 
            +
                
         | 
| 37 | 
            +
                def format_tl(tl)
         | 
| 38 | 
            +
                  tl.gsub('home', 'user').gsub('public', 'firehose')
         | 
| 39 | 
            +
                    .gsub(/(hash)?tag/, 'hashtag')
         | 
| 40 | 
            +
                    .gsub('local ', 'local_')
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                def endpoint_needs_arg?
         | 
| 44 | 
            +
                  @endpoint =~ /(list|hashtag)/
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
    
        data/lib/elephrame/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: elephrame
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.4. | 
| 4 | 
            +
              version: 0.4.5
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Zac
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2019-03-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -72,14 +72,14 @@ dependencies: | |
| 72 72 | 
             
                requirements:
         | 
| 73 73 | 
             
                - - "~>"
         | 
| 74 74 | 
             
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            -
                    version: 0. | 
| 75 | 
            +
                    version: 0.4.0
         | 
| 76 76 | 
             
              type: :runtime
         | 
| 77 77 | 
             
              prerelease: false
         | 
| 78 78 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 79 | 
             
                requirements:
         | 
| 80 80 | 
             
                - - "~>"
         | 
| 81 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            -
                    version: 0. | 
| 82 | 
            +
                    version: 0.4.0
         | 
| 83 83 | 
             
            description: 
         | 
| 84 84 | 
             
            email:
         | 
| 85 85 | 
             
            - thezacattacks@gmail.com
         | 
| @@ -102,8 +102,10 @@ files: | |
| 102 102 | 
             
            - examples/combined.rb
         | 
| 103 103 | 
             
            - examples/command.rb
         | 
| 104 104 | 
             
            - examples/interact.rb
         | 
| 105 | 
            +
            - examples/notbot_check.rb
         | 
| 105 106 | 
             
            - examples/periodic.rb
         | 
| 106 107 | 
             
            - examples/reply.rb
         | 
| 108 | 
            +
            - examples/watcher.rb
         | 
| 107 109 | 
             
            - lib/elephrame.rb
         | 
| 108 110 | 
             
            - lib/elephrame/bot.rb
         | 
| 109 111 | 
             
            - lib/elephrame/mix/bots.rb
         | 
| @@ -114,6 +116,7 @@ files: | |
| 114 116 | 
             
            - lib/elephrame/streaming/interaction.rb
         | 
| 115 117 | 
             
            - lib/elephrame/streaming/reply.rb
         | 
| 116 118 | 
             
            - lib/elephrame/streaming/streaming.rb
         | 
| 119 | 
            +
            - lib/elephrame/streaming/watcher.rb
         | 
| 117 120 | 
             
            - lib/elephrame/util/status.rb
         | 
| 118 121 | 
             
            - lib/elephrame/version.rb
         | 
| 119 122 | 
             
            homepage: https://github.com/theZacAttacks/elephrame
         | 
| @@ -139,8 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 139 142 | 
             
                - !ruby/object:Gem::Version
         | 
| 140 143 | 
             
                  version: '0'
         | 
| 141 144 | 
             
            requirements: []
         | 
| 142 | 
            -
             | 
| 143 | 
            -
            rubygems_version: 2.7.7
         | 
| 145 | 
            +
            rubygems_version: 3.0.1
         | 
| 144 146 | 
             
            signing_key: 
         | 
| 145 147 | 
             
            specification_version: 4
         | 
| 146 148 | 
             
            summary: A framework for assisting in making mastodon/pleroma bots
         |