TwitterOfBabel 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 775ec1d82032069208766c9f4c67958b3f0ccdfd56c06802e4886e448cfbef95
4
+ data.tar.gz: 9041edd35e955e1aee4e2bcba996762a92df3c411954cbf1fbd110a7ccf7e67f
5
+ SHA512:
6
+ metadata.gz: 21e759e023dc7d78a9c9f89e314a432f8468114aab4a8ad8bb42baa7f8160bdec44ce932b79c2e24b35faf40c6533113d5e3ffc438f50dc53c522f9ad4cf81f7
7
+ data.tar.gz: 25e92241b6e913767ac1d5d0ae2389d09ff971a06cab67828b1acb1c9bdc5b53e89ff86fd056e99f13cff4630afbe04b372616fcfb040414e11c4aa8e599403b
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [0.1.0]
2
+
3
+ * Generate a 160 char tweet and submit it to mentions to the bot.
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at cincospenguinos@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in TwitterOfBabel.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ TwitterOfBabel (0.1.0)
5
+ twitter (~> 7.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ buftok (0.2.0)
13
+ domain_name (0.5.20190701)
14
+ unf (>= 0.0.5, < 1.0.0)
15
+ equalizer (0.0.11)
16
+ ffi (1.15.4)
17
+ ffi-compiler (1.0.1)
18
+ ffi (>= 1.0.0)
19
+ rake
20
+ http (4.4.1)
21
+ addressable (~> 2.3)
22
+ http-cookie (~> 1.0)
23
+ http-form_data (~> 2.2)
24
+ http-parser (~> 1.2.0)
25
+ http-cookie (1.0.4)
26
+ domain_name (~> 0.5)
27
+ http-form_data (2.3.0)
28
+ http-parser (1.2.3)
29
+ ffi-compiler (>= 1.0, < 2.0)
30
+ http_parser.rb (0.6.0)
31
+ memoizable (0.4.2)
32
+ thread_safe (~> 0.3, >= 0.3.1)
33
+ minitest (5.14.4)
34
+ multipart-post (2.1.1)
35
+ naught (1.1.0)
36
+ public_suffix (4.0.6)
37
+ rake (13.0.3)
38
+ simple_oauth (0.3.1)
39
+ thread_safe (0.3.6)
40
+ twitter (7.0.0)
41
+ addressable (~> 2.3)
42
+ buftok (~> 0.2.0)
43
+ equalizer (~> 0.0.11)
44
+ http (~> 4.0)
45
+ http-form_data (~> 2.0)
46
+ http_parser.rb (~> 0.6.0)
47
+ memoizable (~> 0.4.0)
48
+ multipart-post (~> 2.0)
49
+ naught (~> 1.0)
50
+ simple_oauth (~> 0.3.0)
51
+ unf (0.1.4)
52
+ unf_ext
53
+ unf_ext (0.0.8)
54
+
55
+ PLATFORMS
56
+ x86_64-linux
57
+
58
+ DEPENDENCIES
59
+ TwitterOfBabel!
60
+ minitest (~> 5.0)
61
+ rake (~> 13.0)
62
+
63
+ BUNDLED WITH
64
+ 2.2.26
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Andre LaFleur
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # TwitterOfBabel
2
+
3
+ A reinterpretation of [the Borgesian Library of Babel](https://libraryofbabel.info/), for the medium of Twitter.
4
+
5
+ ## How does it work?
6
+
7
+ A hex address of 195 characters is used to "index" into the "database" of tweets. Basically that hex address gets converted to a big number that Ruby uses as a seed for a random number generator. It then generates a random sequence of characters using that seed.
8
+
9
+ ## What are the env variables that have to be set?
10
+
11
+ ```bash
12
+ TOB_API_KEY # API key
13
+ TOB_SECRET # API secret
14
+ TOB_BEARER # Your bearer token
15
+ TOB_ACCESS # Your access key
16
+ TOB_ACCESS_SECRET # Your access secret
17
+ TOB_MEMOIZE_FILE # Where to save the memoization file
18
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "TwitterOfBabel"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ module TwitterOfBabel
2
+ class AddressExtractor
3
+ ADDRESS_REGEX = /0x[a-f0-9]{1,195}/
4
+
5
+ attr_reader :address
6
+
7
+ def initialize(input_tweet)
8
+ @address = input_tweet.scan(ADDRESS_REGEX).last || ''
9
+ end
10
+
11
+ def valid?
12
+ !address.empty?
13
+ end
14
+
15
+ def to_s
16
+ address
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ module TwitterOfBabel
2
+ class BabelTweet
3
+ MAX_TWEET_LENGTH = 160
4
+ CHARS = 'abcdefghijklmnopqrstuvwxyz., '
5
+
6
+ attr_reader :prepped_rando
7
+
8
+ def initialize(address)
9
+ @address = address.to_i(16)
10
+ @prepped_rando = Random.new(@address)
11
+ @str = ''
12
+ end
13
+
14
+ def response_to(username)
15
+ "#{self.to_s}\n@#{username} #TwitterOfBabel"
16
+ end
17
+
18
+ def to_s
19
+ while @str.length < MAX_TWEET_LENGTH do
20
+ idx = prepped_rando.rand(CHARS.length)
21
+ @str += CHARS[idx]
22
+ end
23
+
24
+ @str
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TwitterOfBabel
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ require 'twitter'
3
+ require 'yaml'
4
+
5
+ require_relative "TwitterOfBabel/version"
6
+ require_relative "TwitterOfBabel/babel_tweet"
7
+ require_relative "TwitterOfBabel/address_extractor"
8
+
9
+ module TwitterOfBabel
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
+ }
20
+
21
+ tweets.each do |t|
22
+ twitter_client.update(t[:tweet_text])
23
+ previous_tweets << t[:tweet].id
24
+ end
25
+
26
+ save_previous_tweets
27
+ end
28
+
29
+ private
30
+
31
+ def twitter_client
32
+ @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']
37
+ end
38
+ end
39
+
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
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: TwitterOfBabel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andre LaFleur
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: twitter
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
27
+ description: A reinterpretation of the Borgesian Library of Babel for Twitter
28
+ email:
29
+ - cincospenguinos@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".ruby-version"
35
+ - CHANGELOG.md
36
+ - CODE_OF_CONDUCT.md
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - lib/TwitterOfBabel.rb
45
+ - lib/TwitterOfBabel/address_extractor.rb
46
+ - lib/TwitterOfBabel/babel_tweet.rb
47
+ - lib/TwitterOfBabel/version.rb
48
+ homepage: https://www.github.com/cincospenguinos/TwitterOfBabel
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ allowed_push_host: https://rubygems.org/
53
+ homepage_uri: https://www.github.com/cincospenguinos/TwitterOfBabel
54
+ source_code_uri: https://www.github.com/cincospenguinos/TwitterOfBabel
55
+ changelog_uri: https://www.github.com/cincospenguinos/TwitterOfBabel/CHANGELOG.md
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.4.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.1.6
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: A reinterpretation of the Borgesian Library of Babel for Twitter
75
+ test_files: []