TwitterOfBabel 0.1.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 775ec1d82032069208766c9f4c67958b3f0ccdfd56c06802e4886e448cfbef95
4
- data.tar.gz: 9041edd35e955e1aee4e2bcba996762a92df3c411954cbf1fbd110a7ccf7e67f
3
+ metadata.gz: 329c79a3fe279a32150351818f59e9041dcdde436ab29c312a0745d681fde1df
4
+ data.tar.gz: 2b56a27cc0d2b3bb5c2471293758cba1d83a835afce6041abcc8da5937f3e332
5
5
  SHA512:
6
- metadata.gz: 21e759e023dc7d78a9c9f89e314a432f8468114aab4a8ad8bb42baa7f8160bdec44ce932b79c2e24b35faf40c6533113d5e3ffc438f50dc53c522f9ad4cf81f7
7
- data.tar.gz: 25e92241b6e913767ac1d5d0ae2389d09ff971a06cab67828b1acb1c9bdc5b53e89ff86fd056e99f13cff4630afbe04b372616fcfb040414e11c4aa8e599403b
6
+ metadata.gz: a239c2dc1cd13222090aa19f0e5ce9c995a7e4e02541fe8ff9cd301c443344e53772303b88539c7545fc87df37c49189129af806a1be6081160752bcbc381aca
7
+ data.tar.gz: b3433199e9680c94d56289fdda0b2d2705ab7a7b6c18ef5b8f2e051f02769c6d4ca0c328c69cc0e8bb063d2f36f224e48dba00a0e03e76050595c17e84826681
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## [0.4.0]
2
+
3
+ * Changed the gem to take simple parameters instead of the Twitter object thing
4
+
5
+ ## [0.3.0]
6
+
7
+ * There is no longer a memoization file; this option is no longer requested.
8
+ * There is no longer a request to the user's timeline; instead the client is expected to supply what tweet needs to be responded to.
9
+
10
+ ## [0.2.0]
11
+
12
+ * All tweets now lead with mention of the person who initially tweeted
13
+ * All tweets now are replies to an earlier tweet
14
+
15
+ ## [0.1.1]
16
+
17
+ * Add options for various necessary bits
18
+
1
19
  ## [0.1.0]
2
20
 
3
21
  * Generate a 160 char tweet and submit it to mentions to the bot.
@@ -1,15 +1,16 @@
1
1
  module TwitterOfBabel
2
2
  class AddressExtractor
3
- ADDRESS_REGEX = /0x[a-f0-9]{1,195}/
3
+ ADDRESS_REGEX = /[^a-z0-9]/i
4
+ ACCEPTED_CHARS = /\A[a-z0-9]+\z/
4
5
 
5
6
  attr_reader :address
6
7
 
7
8
  def initialize(input_tweet)
8
- @address = input_tweet.scan(ADDRESS_REGEX).last || ''
9
+ @address = input_tweet.downcase.gsub(/\s+/, '').gsub(ADDRESS_REGEX, '')
9
10
  end
10
11
 
11
12
  def valid?
12
- !address.empty?
13
+ !address.empty? && address =~ ACCEPTED_CHARS
13
14
  end
14
15
 
15
16
  def to_s
@@ -6,13 +6,13 @@ module TwitterOfBabel
6
6
  attr_reader :prepped_rando
7
7
 
8
8
  def initialize(address)
9
- @address = address.to_i(16)
9
+ @address = address.to_i(36)
10
10
  @prepped_rando = Random.new(@address)
11
11
  @str = ''
12
12
  end
13
13
 
14
14
  def response_to(username)
15
- "#{self.to_s}\n@#{username} #TwitterOfBabel"
15
+ "@#{username}\n#{self.to_s}\n#TwitterOfBabel"
16
16
  end
17
17
 
18
18
  def to_s
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwitterOfBabel
4
- VERSION = "0.1.0"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -8,43 +8,36 @@ require_relative "TwitterOfBabel/address_extractor"
8
8
 
9
9
  module TwitterOfBabel
10
10
  class TwitterOfBabel
11
- def respond_to_tweets
12
- client = twitter_client
13
- tweets = client.mentions_timeline
14
- .map { |t| { addr: AddressExtractor.new(t.full_text), tweet: t} }
15
- .select { |h| h[:addr].valid? && h[:tweet].user.screen_name }
16
- .reject { |h| previous_tweets.include?(h[:tweet].id) }
17
- .map { |h|
18
- h.merge({ tweet_text: BabelTweet.new(h[:addr].to_s).response_to(h[:tweet].user.screen_name) })
19
- }
11
+ def initialize(opts = {})
12
+ @consumer_key = opts[:consumer_key] || ENV['TOB_API_KEY']
13
+ @consumer_secret = opts[:consumer_secret] || ENV['TOB_SECRET']
14
+ @access_token = opts[:access_token] || ENV['TOB_ACCESS']
15
+ @access_token_secret = opts[:access_token_secret] || ENV['TOB_ACCESS_SECRET']
16
+ end
20
17
 
21
- tweets.each do |t|
22
- twitter_client.update(t[:tweet_text])
23
- previous_tweets << t[:tweet].id
24
- end
18
+ def respond_to(text, tweet_id, screen_name)
19
+ address = AddressExtractor.new(text)
20
+ return not_valid_address(screen_name, tweet_id) unless address.valid? && screen_name
25
21
 
26
- save_previous_tweets
22
+ b_tweet = BabelTweet.new(address.to_s).response_to(screen_name)
23
+ twitter_client.update(b_tweet, in_reply_to_status_id: tweet_id)
24
+ true
27
25
  end
28
26
 
29
27
  private
30
28
 
31
29
  def twitter_client
32
30
  @twitter_client ||= Twitter::REST::Client.new do |config|
33
- config.consumer_key = ENV['TOB_API_KEY']
34
- config.consumer_secret = ENV['TOB_SECRET']
35
- config.access_token = ENV['TOB_ACCESS']
36
- config.access_token_secret = ENV['TOB_ACCESS_SECRET']
31
+ config.consumer_key = @consumer_key
32
+ config.consumer_secret = @consumer_secret
33
+ config.access_token = @access_token
34
+ config.access_token_secret = @access_token_secret
37
35
  end
38
36
  end
39
37
 
40
- def previous_tweets
41
- @previous_tweets ||= []
42
- end
43
-
44
- def save_previous_tweets
45
- File.open(ENV['TOB_MEMOIZE_FILE'], 'w') do |f|
46
- f.write(previous_tweets.to_yaml)
47
- end
38
+ def not_valid_address(screen_name, tweet_id)
39
+ tweet.update("@#{screen_name} the address you provided is invalid.",
40
+ in_reply_to_status_id: tweet_id)
48
41
  end
49
42
  end
50
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: TwitterOfBabel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andre LaFleur
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-12 00:00:00.000000000 Z
11
+ date: 2021-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter
@@ -24,14 +24,15 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '7.0'
27
- description: A reinterpretation of the Borgesian Library of Babel for Twitter
27
+ description: |
28
+ Every imaginable tweet is encapsulated in this code. Give an address, and get the tweet corresponding to it.
29
+ Be warned, however: there is much folly and little wisdom in its cooridors.
28
30
  email:
29
31
  - cincospenguinos@gmail.com
30
32
  executables: []
31
33
  extensions: []
32
34
  extra_rdoc_files: []
33
35
  files:
34
- - ".ruby-version"
35
36
  - CHANGELOG.md
36
37
  - CODE_OF_CONDUCT.md
37
38
  - Gemfile
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.7.4