├── .gitignore ├── .rspec ├── lib ├── .env_sample ├── imgs │ ├── scr2.png │ ├── image0.png │ └── screenshot.png ├── quotes.rb ├── bot.rb └── message.rb ├── Gemfile ├── spec ├── quotes_spec.rb ├── message_spec.rb └── spec_helper.rb ├── bin └── main.rb ├── .github └── workflows │ ├── tests.yml │ └── linters.yml ├── rubocop.yml ├── LICENSE ├── README.md └── Gemfile.lock /.gitignore: -------------------------------------------------------------------------------- 1 | lib/.env -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /lib/.env_sample: -------------------------------------------------------------------------------- 1 | API_KEY=YOUR_API_KEY_HERE -------------------------------------------------------------------------------- /lib/imgs/scr2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anapdh/ruby-capstoneproject/HEAD/lib/imgs/scr2.png -------------------------------------------------------------------------------- /lib/imgs/image0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anapdh/ruby-capstoneproject/HEAD/lib/imgs/image0.png -------------------------------------------------------------------------------- /lib/imgs/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anapdh/ruby-capstoneproject/HEAD/lib/imgs/screenshot.png -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'dotenv-rails', require: 'dotenv/rails-now' 3 | gem 'rspec-rails' 4 | gem 'rubocop', require: false 5 | gem 'telegram-bot-ruby' 6 | -------------------------------------------------------------------------------- /spec/quotes_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../lib/quotes' 2 | 3 | describe Quotes do 4 | context '#initialize' do 5 | let(:value) { Quotes.new } 6 | it 'displays the quote of the day' do 7 | expect(value.value).to_s 8 | end 9 | end 10 | 11 | context 'select_quote' do 12 | let(:value) { Quotes.new } 13 | it 'select a random quote to display to the user' do 14 | expect(value.select_quote(value)).to_s 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /bin/main.rb: -------------------------------------------------------------------------------- 1 | # rubocop:disable Layout/LineLength 2 | 3 | require_relative '../lib/bot' 4 | require_relative '../lib/message' 5 | require 'dotenv' 6 | Dotenv.load('lib/.env') 7 | 8 | puts "Hello there... The bot is running!\n 9 | Now you can access the webpage https://web.telegram.org/#/im?p=@AnaOfZodiacs_bot to start using the bot, or simply search for 'Ana of Zodiacs' in your Telegram search area.\n 10 | Press Ctrl + Z in your keyboard to stop executing." 11 | 12 | Bot.new 13 | 14 | # rubocop:enable Layout/LineLength 15 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | rspec: 7 | name: RSpec 8 | runs-on: ubuntu-18.04 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: actions/setup-ruby@v1 12 | with: 13 | ruby-version: 2.6.x 14 | - name: Setup RSpec 15 | run: | 16 | [ -f Gemfile ] && bundle 17 | gem install --no-document rspec:'~>3.0' 18 | - name: RSpec Report 19 | run: rspec --force-color --format documentation 20 | © 2020 GitHub, Inc. -------------------------------------------------------------------------------- /.github/workflows/linters.yml: -------------------------------------------------------------------------------- 1 | name: Linters 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | rubocop: 7 | name: Rubocop 8 | runs-on: ubuntu-18.04 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: actions/setup-ruby@v1 12 | with: 13 | ruby-version: 2.6.x 14 | - name: Setup Rubocop 15 | run: | 16 | gem install --no-document rubocop:'~>0.81.0' # https://docs.rubocop.org/en/stable/installation/ 17 | [ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ruby/.rubocop.yml 18 | - name: Rubocop Report 19 | run: rubocop --color -------------------------------------------------------------------------------- /spec/message_spec.rb: -------------------------------------------------------------------------------- 1 | # rubocop:disable Layout/LineLength 2 | 3 | require_relative '../lib/message' 4 | 5 | describe ZodiacInfo do 6 | context '#initialize' do 7 | let(:aries) { ZodiacInfo.new } 8 | it 'displays the zodiac sign information' do 9 | expect(aries.aries).to eq( 10 | "You chose Aries! Let's see...\n 11 | Personality Traits: energetic, candid and willful 12 | Date of Birth: March 21 - April 19 13 | Strength: hopeful, active, energetic, honest, versatile, brave, adventurous, passionate, generous, cheerful, argumentative, curious 14 | Weakness: impulsive, naive, self-willed, belligerent, impatient 15 | Symbol: Ram 16 | Element: Fire 17 | Sign Ruler: Mars 18 | Lucky Color: Red 19 | Lucky Number: 5 20 | Jewelry: Ruby 21 | Best Match: Leo, Sagittarius and Aries 22 | Celebrities: Hans Christian Andersen, Jackie Chan, Mariah Carey, Marlon Brando, Dennis Quaid 23 | Chinese zodiac twins: Dragon" 24 | ) 25 | end 26 | end 27 | end 28 | 29 | # rubocop:enable Layout/LineLength 30 | -------------------------------------------------------------------------------- /rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | Exclude: 3 | - "Guardfile" 4 | - "Rakefile" 5 | 6 | DisplayCopNames: true 7 | 8 | Layout/LineLength: 9 | Max: 120 10 | Metrics/MethodLength: 11 | Max: 20 12 | Metrics/AbcSize: 13 | Max: 50 14 | Metrics/ClassLength: 15 | Max: 150 16 | Metrics/BlockLength: 17 | ExcludedMethods: ['describe'] 18 | Max: 30 19 | 20 | 21 | Style/Documentation: 22 | Enabled: false 23 | Style/ClassAndModuleChildren: 24 | Enabled: false 25 | Style/EachForSimpleLoop: 26 | Enabled: false 27 | Style/AndOr: 28 | Enabled: false 29 | Style/DefWithParentheses: 30 | Enabled: false 31 | Style/FrozenStringLiteralComment: 32 | EnforcedStyle: never 33 | 34 | Layout/HashAlignment: 35 | EnforcedColonStyle: key 36 | Layout/ExtraSpacing: 37 | AllowForAlignment: false 38 | Layout/MultilineMethodCallIndentation: 39 | Enabled: true 40 | EnforcedStyle: indented 41 | Lint/RaiseException: 42 | Enabled: false 43 | Lint/StructNewOverride: 44 | Enabled: false 45 | Style/HashEachMethods: 46 | Enabled: false 47 | Style/HashTransformKeys: 48 | Enabled: false 49 | Style/HashTransformValues: 50 | Enabled: false -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ana Paula Hübner 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/quotes.rb: -------------------------------------------------------------------------------- 1 | require_relative 'bot' 2 | require 'telegram/bot' 3 | 4 | # Class for quotes 5 | class Quotes 6 | attr_reader :value, :menu 7 | 8 | def initialize 9 | @value = [ 10 | 'Genius is one percent inspiration and ninety-nine percent perspiration. Author: Thomas Edison', 11 | 'You can observe a lot just by watching. Author: Yogi Berra', 12 | 'A house divided against itself cannot stand. Author: Abraham Lincoln', 13 | 'Difficulties increase the nearer we get to the goal. Author: Johann Wolfgang von Goethe', 14 | 'Fate is in your hands and no one elses. Author: Byron Pulsifer', 15 | 'Be the chief but never the lord. Author: Lao Tzu', 16 | 'Nothing happens unless first we dream. Author: Carl Sandburg', 17 | 'Well begun is half done. Author: Aristotle', 18 | 'Peace comes from within. Do not seek it without. Author Buddha', 19 | 'Life is change. Growth is optional. Choose wisely. Author: Karen Clark', 20 | 'From error to error one discovers the entire truth. Author: Sigmund Freud', 21 | 'Who sows virtue reaps honour. Author: Leonardo da Vinci' 22 | ] 23 | 24 | @menu = 'Return to /menu' 25 | end 26 | 27 | def select_quote(_quote) 28 | @value.sample 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://img.shields.io/badge/Microverse-blueviolet) ![](https://img.shields.io/badge/Ruby-red) ![](https://img.shields.io/badge/Telegram-blue) 2 | 3 | # Ruby-CapstoneProject 4 | 5 | This is a solo project to finish Microverse's **Ruby** section that consists of implementing a **[Telegram](https://en.wikipedia.org/wiki/Telegram_(software)) bot**. 6 | 7 | ### Screenshot: 8 | 9 | ![screenshot](./lib/imgs/screenshot.png) 10 | 11 | 12 | ## About the project 13 | 14 | The goal of the project is to use all the experience acquired in the Ruby Curriculum to set up the basic elements for the bot. 15 | 16 | ## Prerequisites 17 | 18 | To run the bot, you need a personal **Telegram account** and **Ruby** installed in your machine. 19 | 20 | ## Installation and Execution 21 | 22 | 1. Download/clone this repository [GitHub Repository](https://github.com/anapdh/Ruby-CapstoneProject) on your computer. 23 | 2. In your terminal, use the command `cd` to go to the place where you saved/cloned the repository. For example: _Desktop/User/Ruby-CapstoneProject/_. You may use the command `ls` to see the files and repositories existent in your current location. 24 | 3. Still in the terminal, run the command `bundle install`. 25 | 4. Now use the command `ruby bin/main.rb` to automatically access the folder \bin and to start running the bot. 26 | 5. If the bot starts running successfully, you'll see the message "Hello there... The bot is running!" in your terminal. 27 | [**NOTE: I know about the importance of hiding an API token in source code. Because of that, this project provides a Dotenv and a .env (+ .gitignore) file with the code as it should be to hide information, but I preferred to hardcode the token to make it easier for users and TSEs execute the code with no additional commands and complications**] 28 | 29 | ## How to use the bot 30 | 31 | 1. After making sure that the bot is running, you'll need to access the [Telegram Web](https://web.telegram.org/#/im?p=@AnaOfZodiacs_bot). This link redirects automatically to the bot page. If you want to access from your device (Telegram App), you can search for `Ana of Zodiacs` in the chats menu. 32 | 2. The bot will request for you to start. Let's start! 33 | 3. Simply follow to commands to access the bot features or return to the main menu: 34 | 35 | Here's how to use the bot: 36 | 37 | • Use /start to start or restart the bot 38 | 39 | • Use /menu to return to this message 40 | 41 | • Use /stop to end the bot 42 | 43 | • Want to receive your quote of the day? Type /quote 44 | 45 | • Type ' / ' + the zodiac sign you wish to obtain information, or simply select one of the options below: 46 | 47 | /aries /taurus /gemini /cancer 48 | 49 | /leo /virgo /libra /scorpio 50 | 51 | /sagittarius /capricorn /aquarius /pisces 52 | 53 | 4. After you are done with the bot, simply close the 'bot conversation' and press Ctrl + Z in your terminal to stop running the bot. 54 | 55 | 56 | ## Author 57 | 58 | 👩🏼‍💻 **Ana Paula Hübner** 59 | 60 | - GitHub: [@anapdh](https://github.com/anapdh) 61 | - Twitter: [@dev_anahub](https://twitter.com/dev_anahub) 62 | - LinkedIn: [LinkedIn](https://www.linkedin.com/in/anapdh) 63 | 64 | 65 | ## 🤝 Contributing 66 | 67 | Contributions, issues, and feature requests are welcome! 68 | 69 | Feel free to check the [issues page](https://github.com/anapdh/Ruby-CapstoneProject/issues). 70 | 71 | 72 | ## Show your support 73 | 74 | Give a ⭐️ if you like this project! 75 | 76 | 77 | ## 📝 License 78 | 79 | This project is [MIT](./LICENSE) licensed. 80 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actionpack (6.1.0) 5 | actionview (= 6.1.0) 6 | activesupport (= 6.1.0) 7 | rack (~> 2.0, >= 2.0.9) 8 | rack-test (>= 0.6.3) 9 | rails-dom-testing (~> 2.0) 10 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 11 | actionview (6.1.0) 12 | activesupport (= 6.1.0) 13 | builder (~> 3.1) 14 | erubi (~> 1.4) 15 | rails-dom-testing (~> 2.0) 16 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 17 | activesupport (6.1.0) 18 | concurrent-ruby (~> 1.0, >= 1.0.2) 19 | i18n (>= 1.6, < 2) 20 | minitest (>= 5.1) 21 | tzinfo (~> 2.0) 22 | zeitwerk (~> 2.3) 23 | ast (2.4.1) 24 | axiom-types (0.1.1) 25 | descendants_tracker (~> 0.0.4) 26 | ice_nine (~> 0.11.0) 27 | thread_safe (~> 0.3, >= 0.3.1) 28 | builder (3.2.4) 29 | coercible (1.0.0) 30 | descendants_tracker (~> 0.0.1) 31 | concurrent-ruby (1.1.7) 32 | crass (1.0.6) 33 | descendants_tracker (0.0.4) 34 | thread_safe (~> 0.3, >= 0.3.1) 35 | diff-lcs (1.4.4) 36 | dotenv (2.7.6) 37 | dotenv-rails (2.7.6) 38 | dotenv (= 2.7.6) 39 | railties (>= 3.2) 40 | equalizer (0.0.11) 41 | erubi (1.10.0) 42 | faraday (1.1.0) 43 | multipart-post (>= 1.2, < 3) 44 | ruby2_keywords 45 | i18n (1.8.5) 46 | concurrent-ruby (~> 1.0) 47 | ice_nine (0.11.2) 48 | inflecto (0.0.2) 49 | loofah (2.8.0) 50 | crass (~> 1.0.2) 51 | nokogiri (>= 1.5.9) 52 | method_source (1.0.0) 53 | mini_portile2 (2.4.0) 54 | minitest (5.14.2) 55 | multipart-post (2.1.1) 56 | nokogiri (1.10.10) 57 | mini_portile2 (~> 2.4.0) 58 | parallel (1.20.1) 59 | parser (2.7.2.0) 60 | ast (~> 2.4.1) 61 | rack (2.2.3) 62 | rack-test (1.1.0) 63 | rack (>= 1.0, < 3) 64 | rails-dom-testing (2.0.3) 65 | activesupport (>= 4.2.0) 66 | nokogiri (>= 1.6) 67 | rails-html-sanitizer (1.3.0) 68 | loofah (~> 2.3) 69 | railties (6.1.0) 70 | actionpack (= 6.1.0) 71 | activesupport (= 6.1.0) 72 | method_source 73 | rake (>= 0.8.7) 74 | thor (~> 1.0) 75 | rainbow (3.0.0) 76 | rake (13.0.3) 77 | regexp_parser (2.0.1) 78 | rexml (3.2.4) 79 | rspec-core (3.10.0) 80 | rspec-support (~> 3.10.0) 81 | rspec-expectations (3.10.0) 82 | diff-lcs (>= 1.2.0, < 2.0) 83 | rspec-support (~> 3.10.0) 84 | rspec-mocks (3.10.0) 85 | diff-lcs (>= 1.2.0, < 2.0) 86 | rspec-support (~> 3.10.0) 87 | rspec-rails (4.0.1) 88 | actionpack (>= 4.2) 89 | activesupport (>= 4.2) 90 | railties (>= 4.2) 91 | rspec-core (~> 3.9) 92 | rspec-expectations (~> 3.9) 93 | rspec-mocks (~> 3.9) 94 | rspec-support (~> 3.9) 95 | rspec-support (3.10.0) 96 | rubocop (1.6.1) 97 | parallel (~> 1.10) 98 | parser (>= 2.7.1.5) 99 | rainbow (>= 2.2.2, < 4.0) 100 | regexp_parser (>= 1.8, < 3.0) 101 | rexml 102 | rubocop-ast (>= 1.2.0, < 2.0) 103 | ruby-progressbar (~> 1.7) 104 | unicode-display_width (>= 1.4.0, < 2.0) 105 | rubocop-ast (1.3.0) 106 | parser (>= 2.7.1.5) 107 | ruby-progressbar (1.10.1) 108 | ruby2_keywords (0.0.2) 109 | telegram-bot-ruby (0.14.0) 110 | faraday 111 | inflecto 112 | virtus 113 | thor (1.0.1) 114 | thread_safe (0.3.6) 115 | tzinfo (2.0.4) 116 | concurrent-ruby (~> 1.0) 117 | unicode-display_width (1.7.0) 118 | virtus (1.0.5) 119 | axiom-types (~> 0.1) 120 | coercible (~> 1.0) 121 | descendants_tracker (~> 0.0, >= 0.0.3) 122 | equalizer (~> 0.0, >= 0.0.9) 123 | zeitwerk (2.4.2) 124 | 125 | PLATFORMS 126 | x86_64-linux 127 | 128 | DEPENDENCIES 129 | dotenv-rails 130 | rspec-rails 131 | rubocop 132 | telegram-bot-ruby 133 | 134 | BUNDLED WITH 135 | 2.2.2 136 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # rubocop:disable Style/BlockComments 2 | 3 | # This file was generated by the `rspec --init` command. Conventionally, all 4 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 5 | # The generated `.rspec` file contains `--require spec_helper` which will cause 6 | # this file to always be loaded, without a need to explicitly require it in any 7 | # files. 8 | # 9 | # Given that it is always loaded, you are encouraged to keep this file as 10 | # light-weight as possible. Requiring heavyweight dependencies from this file 11 | # will add to the boot time of your test suite on EVERY test run, even for an 12 | # individual file that may not need all of that loaded. Instead, consider making 13 | # a separate helper file that requires the additional dependencies and performs 14 | # the additional setup, and require it from the spec files that actually need 15 | # it. 16 | # 17 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 18 | RSpec.configure do |config| 19 | # rspec-expectations config goes here. You can use an alternate 20 | # assertion/expectation library such as wrong or the stdlib/minitest 21 | # assertions if you prefer. 22 | config.expect_with :rspec do |expectations| 23 | # This option will default to `true` in RSpec 4. It makes the `description` 24 | # and `failure_message` of custom matchers include text for helper methods 25 | # defined using `chain`, e.g.: 26 | # be_bigger_than(2).and_smaller_than(4).description 27 | # # => "be bigger than 2 and smaller than 4" 28 | # ...rather than: 29 | # # => "be bigger than 2" 30 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 31 | end 32 | 33 | # rspec-mocks config goes here. You can use an alternate test double 34 | # library (such as bogus or mocha) by changing the `mock_with` option here. 35 | config.mock_with :rspec do |mocks| 36 | # Prevents you from mocking or stubbing a method that does not exist on 37 | # a real object. This is generally recommended, and will default to 38 | # `true` in RSpec 4. 39 | mocks.verify_partial_doubles = true 40 | end 41 | 42 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 43 | # have no way to turn it off -- the option exists only for backwards 44 | # compatibility in RSpec 3). It causes shared context metadata to be 45 | # inherited by the metadata hash of host groups and examples, rather than 46 | # triggering implicit auto-inclusion in groups with matching metadata. 47 | config.shared_context_metadata_behavior = :apply_to_host_groups 48 | 49 | # The settings below are suggested to provide a good initial experience 50 | # with RSpec, but feel free to customize to your heart's content. 51 | =begin 52 | # This allows you to limit a spec run to individual examples or groups 53 | # you care about by tagging them with `:focus` metadata. When nothing 54 | # is tagged with `:focus`, all examples get run. RSpec also provides 55 | # aliases for `it`, `describe`, and `context` that include `:focus` 56 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 57 | config.filter_run_when_matching :focus 58 | # Allows RSpec to persist some state between runs in order to support 59 | # the `--only-failures` and `--next-failure` CLI options. We recommend 60 | # you configure your source control system to ignore this file. 61 | config.example_status_persistence_file_path = "spec/examples.txt" 62 | # Limits the available syntax to the non-monkey patched syntax that is 63 | # recommended. For more details, see: 64 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 65 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 66 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 67 | config.disable_monkey_patching! 68 | # This setting enables warnings. It's recommended, but in some cases may 69 | # be too noisy due to issues in dependencies. 70 | config.warnings = true 71 | # Many RSpec users commonly either run the entire suite or an individual 72 | # file, and it's useful to allow more verbose output when running an 73 | # individual spec file. 74 | if config.files_to_run.one? 75 | # Use the documentation formatter for detailed output, 76 | # unless a formatter has already been configured 77 | # (e.g. via a command-line flag). 78 | config.default_formatter = "doc" 79 | end 80 | # Print the 10 slowest examples and example groups at the 81 | # end of the spec run, to help surface which specs are running 82 | # particularly slow. 83 | config.profile_examples = 10 84 | # Run specs in random order to surface order dependencies. If you find an 85 | # order dependency and want to debug it, you can fix the order by providing 86 | # the seed, which is printed after each run. 87 | # --seed 1234 88 | config.order = :random 89 | # Seed global randomization in this process using the `--seed` CLI option. 90 | # Setting this allows you to use `--seed` to deterministically reproduce 91 | # test failures related to randomization by passing the same `--seed` value 92 | # as the one that triggered the failure. 93 | Kernel.srand config.seed 94 | =end 95 | end 96 | 97 | # rubocop:enable Style/BlockComments 98 | -------------------------------------------------------------------------------- /lib/bot.rb: -------------------------------------------------------------------------------- 1 | # rubocop: disable Metrics/AbcSize,Metrics/BlockLength,Metrics/CyclomaticComplexity,Metrics/MethodLength 2 | 3 | require 'telegram/bot' 4 | require_relative 'message' 5 | require_relative 'quotes' 6 | 7 | # Class for bot 8 | class Bot 9 | attr_reader :token, :zodiac_sign 10 | 11 | def initialize 12 | @token = '1427773606:AAG-Jk78nFMY2XQJdzCto3YiWRGHc_s6U1U' 13 | @zodiac_sign = ZodiacInfo.new 14 | @quote = Quotes.new 15 | show_messages 16 | end 17 | end 18 | 19 | private 20 | 21 | def show_messages 22 | Telegram::Bot::Client.run(token) do |bot| 23 | bot.listen do |message| 24 | case message.text 25 | 26 | when '/start', '/menu' 27 | bot.api.send_message(chat_id: message.chat.id, text: 28 | "Hello, #{message.from.first_name}!\n 29 | Welcome to Ana of Zodiacs, a Ruby project created by Ana Paula Hübner.\n 30 | Here's how to use the bot:\n 31 | • Use /start to start or restart the bot\n 32 | • Use /menu to return to this message\n 33 | • Use /stop to end the bot\n 34 | • Want to receive your quote of the day? Type /quote\n 35 | • Type ' / ' + the zodiac sign you wish to obtain information, or simply select one of the options below:\n 36 | /aries /taurus /gemini /cancer\n 37 | /leo /virgo /libra /scorpio\n 38 | /sagittarius /capricorn /aquarius /pisces") 39 | 40 | when '/aries' 41 | @zodiac_sign.aries 42 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.aries, date: message.date) 43 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.repeat, date: message.date) 44 | 45 | when '/taurus' 46 | @zodiac_sign.taurus 47 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.taurus, date: message.date) 48 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.repeat, date: message.date) 49 | 50 | when '/gemini' 51 | @zodiac_sign.gemini 52 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.gemini, date: message.date) 53 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.repeat, date: message.date) 54 | 55 | when '/cancer' 56 | @zodiac_sign.cancer 57 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.cancer, date: message.date) 58 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.repeat, date: message.date) 59 | 60 | when '/leo' 61 | @zodiac_sign.leo 62 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.leo, date: message.date) 63 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.repeat, date: message.date) 64 | 65 | when '/virgo' 66 | @zodiac_sign.virgo 67 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.virgo, date: message.date) 68 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.repeat, date: message.date) 69 | 70 | when '/libra' 71 | @zodiac_sign.libra 72 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.libra, date: message.date) 73 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.repeat, date: message.date) 74 | 75 | when '/scorpio' 76 | @zodiac_sign.scorpio 77 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.scorpio, date: message.date) 78 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.repeat, date: message.date) 79 | 80 | when '/sagittarius' 81 | @zodiac_sign.sagittarius 82 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.sagittarius, date: message.date) 83 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.repeat, date: message.date) 84 | 85 | when '/capricorn' 86 | @zodiac_sign.capricorn 87 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.capricorn, date: message.date) 88 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.repeat, date: message.date) 89 | 90 | when '/aquarius' 91 | @zodiac_sign.aquarius 92 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.aquarius, date: message.date) 93 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.repeat, date: message.date) 94 | 95 | when '/pisces' 96 | @zodiac_sign.pisces 97 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.pisces, date: message.date) 98 | bot.api.send_message(chat_id: message.chat.id, text: @zodiac_sign.repeat, date: message.date) 99 | 100 | when '/yes' 101 | bot.api.send_message(chat_id: message.chat.id, text: 102 | "Alright #{message.from.first_name}, type or select another zodiac sign:\n 103 | /aries /taurus /gemini /cancer\n 104 | /leo /virgo /libra /scorpio\n 105 | /sagittarius /capricorn /aquarius /pisces") 106 | 107 | when '/quote' 108 | @quote.select_quote(@value) 109 | bot.api.send_message(chat_id: message.chat.id, text: @quote.select_quote(@value), date: message.date) 110 | bot.api.send_message(chat_id: message.chat.id, text: @quote.menu, date: message.date) 111 | 112 | when '/stop', '/no' 113 | bot.api.send_message(chat_id: message.chat.id, text: 114 | "Thanks for accessing, #{message.from.first_name}! See you next time :)", date: message.date) 115 | 116 | else bot.api.send_message(chat_id: message.chat.id, text: 117 | "Invalid entry! 118 | Please, use /start, /stop, or ' / ' + the zodiac sign of your choice.") 119 | end 120 | end 121 | end 122 | end 123 | 124 | # rubocop: enable Metrics/AbcSize,Metrics/BlockLength,Metrics/CyclomaticComplexity,Metrics/MethodLength 125 | -------------------------------------------------------------------------------- /lib/message.rb: -------------------------------------------------------------------------------- 1 | # rubocop:disable Metrics/MethodLength,Metrics/ClassLength,Layout/LineLength 2 | 3 | require 'telegram/bot' 4 | require_relative 'bot' 5 | 6 | # Class for the horoscope messages 7 | class ZodiacInfo 8 | attr_reader :aries, :taurus, :gemini, :cancer, :leo, :virgo, :libra, :scorpio, :sagittarius, :capricorn, :aquarius, :pisces, :repeat 9 | 10 | def initialize 11 | @aries = "You chose Aries! Let's see...\n 12 | Personality Traits: energetic, candid and willful 13 | Date of Birth: March 21 - April 19 14 | Strength: hopeful, active, energetic, honest, versatile, brave, adventurous, passionate, generous, cheerful, argumentative, curious 15 | Weakness: impulsive, naive, self-willed, belligerent, impatient 16 | Symbol: Ram 17 | Element: Fire 18 | Sign Ruler: Mars 19 | Lucky Color: Red 20 | Lucky Number: 5 21 | Jewelry: Ruby 22 | Best Match: Leo, Sagittarius and Aries 23 | Celebrities: Hans Christian Andersen, Jackie Chan, Mariah Carey, Marlon Brando, Dennis Quaid 24 | Chinese zodiac twins: Dragon" 25 | 26 | @taurus = "You chose Taurus! Let's see...\n 27 | Personality Traits: reliable, diligent and conservative 28 | Strength: romantic, decisive, logical, diligent, ardent, patient, talented in art, perseverant, benevolent 29 | Weakness: prejudiced, dependent, stubborn 30 | Symbol: Bull 31 | Element: Earth 32 | Sign Ruler: Venus 33 | Lucky Color: Pink 34 | Lucky Number: 6 35 | Jewelry: Emerald, Jade 36 | Best Match: Capricorn, Virgo and Taurus 37 | Celebrities: Karl Marx, William Shakespeare, Leonardo da Vinci, David Beckham, Al Pacino 38 | See Also: Taurus Horoscope in 2020 39 | Chinese zodiac twins: Snake" 40 | 41 | @gemini = "You chose Taurus! Let's see...\n 42 | Personality Traits: quick-witted, capricious and cheerful 43 | Strength: multifarious, perspicacious, smart, cheerful, quick-witted, clement, charming 44 | Weakness: fickle, gossipy, amphibian 45 | Symbol: Twins 46 | Element: Air 47 | Sign Ruler: Mercury 48 | Lucky Color: Yellow 49 | Lucky Number: 7 50 | Jewelry: Opal 51 | Best Match: Aquarius, Libra and Gemini 52 | Celebrities: John F. Kennedy, Queen Victoria 53 | Chinese zodiac twins: Horse" 54 | 55 | @cancer = "You chose Cancer! Let's see...\n 56 | Personality Traits: considerate, imaginative and sensitive 57 | Strength: with strong sixth sense, subjective, gentle, swift, imaginative, careful, dedicated, perseverant, kind, caring 58 | Weakness: greedy, possessive, sensitive, prim 59 | Symbol: Crab 60 | Element: Water 61 | Sign Ruler: Moon 62 | Lucky Color: Green 63 | Lucky Number: 2 64 | Jewelry: Pearl 65 | Best Match: Pisces, Scorpio and Cancer 66 | Celebrities: Alexander the Great, Raul Gonzalez 67 | Chinese zodiac twins: Sheep" 68 | 69 | @leo = "You chose Leo! Let's see...\n 70 | Personality Traits: enthusiastic, proud and arrogant 71 | Strength: proud, charitable, reflective, loyal and enthusiastic 72 | Weakness: arrogant, vainglorious, indulgent, wasteful, willful, and self-complacent 73 | Symbol: Lion 74 | Element: Fire 75 | Sign Ruler: Sun 76 | Lucky Colors: Red, Gold, Yellow 77 | Lucky Number: 19 78 | Jewelry: Gold 79 | Best Match: Aries, Sagittarius and Leo 80 | Celebrities: Napoleon Bonaparte, Deng Xiaoping, Alexander Dumas, Jennifer Lopez, Whitney Houston, Sarah Brightman 81 | Chinese zodiac twins: Monkey" 82 | 83 | @virgo = "You chose Virgo! Let's see...\n 84 | Personality Traits: elegant, perfectionist and picky 85 | Strength: helping, elegant, perfectionist, modest, practical, clearheaded 86 | Weakness: picky, nosey, tortuous, confining 87 | Symbol: Virgin maiden 88 | Element: Earth 89 | Sign Ruler: Mercury 90 | Lucky Color: Gray 91 | Lucky Number: 7 92 | Jewelry: Sapphire, Amber 93 | Best Match: Sagittarius, Taurus and Gemini 94 | Celebrities: Warren Buffett, Kobe Bryant, Michael Jackson, Rebecca De Mornay, Richard Gere 95 | Chinese zodiac twins: Rooster" 96 | 97 | @libra = "You chose Libra! Let's see...\n 98 | Personality Traits: equitable, charming and hesitant 99 | Strength: idealistic, equitable, just, strong social skills, aesthetic, charming, artistic, beautiful, kind-hearted 100 | Weakness: hesitant, narcissistic, lazy, perfunctory, freewheeling 101 | Symbol: Scales 102 | Element: Air 103 | Sign Ruler: Venus 104 | Lucky Color: Brown 105 | Lucky Number: 3 106 | Jewelry: Coral, Amber 107 | Best Match: Aquarius, Gemini and Libra 108 | Celebrities: Oscar Wilde, Hillary Duff, Italo Calvino, Evander Hoilrield 109 | Chinese zodiac twins: Dog" 110 | 111 | @scorpio = "You chose Scorpio! Let's see...\n 112 | Personality Traits: insightful, mysterious and suspicious 113 | Strength: mysterious, rational, intelligent, independent, intuitive, dedicated, insightful, charming, sensible 114 | Weakness: suspicious, fanatical, complicated, possessive, arrogant, self-willed, extreme 115 | Symbol: Scorpion 116 | Element: Water 117 | Sign Ruler: Pluto, Mars 118 | Lucky Colors: Purple, Black 119 | Lucky Number: 4 120 | Jewelry: Jasper, Black Crystal 121 | Best Match: Cancer, Capricorn and Pisces 122 | Celebrities: Charles de Gaulle, Bill Gates, Marie Curie, Hillary Clinton, Julia Roberts, Pablo Picasso 123 | See Also: Scorpio Horoscope in 2020 124 | Chinese zodiac twins: Pig" 125 | 126 | @sagittarius = "You chose Sagittarius! Let's see...\n 127 | Personality Traits: unconstrained, lively and rash 128 | Strength: insightful, superior, rational, brave, beautiful, lively, lovely, optimistic 129 | Weakness: forgetful, careless, rash 130 | Symbol: Archer 131 | Element: Fire 132 | Sign Ruler: Jupiter 133 | Lucky Color: Light Blue 134 | Lucky Number: 6 135 | Jewelry: Amethyst 136 | Best Match: Virgo, Leo and Aries 137 | Celebrities: Mark Twain, Beethoven, Taylor Swift, Britney Spears 138 | Chinese zodiac twins: Rat" 139 | 140 | @capricorn = "You chose Capricorn! Let's see...\n 141 | Personality Traits: perseverant, practical and lonely 142 | Strength: excellent, intelligent, practical, reliable, perseverant, generous, optimistic, cute, persistent 143 | Weakness: stubborn, lonely, and suspicious 144 | Symbol: Goat 145 | Element: Earth 146 | Sign Ruler: Saturn 147 | Lucky Colors: Brown, Black, Dark Green 148 | Lucky Number: 4 149 | Jewelry: Black Jade 150 | Best Match: Virgo, Taurus and Pisces 151 | Celebrities: Mao Zedong, Issac Newton, Martin Luther King, Nicholas Cage 152 | Chinese zodiac twins: Ox" 153 | 154 | @aquarius = "You chose Aquarius! Let's see...\n 155 | Personality Traits: smart, liberalistic and changeful 156 | Strength: original, tolerant, ideal, calm, friendly, charitable, independent, smart, practical 157 | Weakness: changeful, disobedient, liberalistic, hasty, rebel 158 | Symbol: Water carrier 159 | Element: Air 160 | Sign Ruler: Uranus 161 | Lucky Color: Bronze 162 | Lucky Number: 22 163 | Jewelry: Black Pearl 164 | Best Match: Gemini, Libra and Aquarius 165 | Celebrities: Francis Bacon, Thomas Edison, Agyness Deyn, Paris Hilton 166 | Chinese zodiac twins: Tiger" 167 | 168 | @pisces = "You chose Pisces! Let's see...\n 169 | Personality Traits: romantic, kind and sentimental 170 | Strength: conscious, aesthetic, platonic, dedicated, kind, with good temper 171 | Weakness: recessive, sentimental, indecisive, unrealistic 172 | Symbol: Fish 173 | Element: Water 174 | Sign Ruler: Neptune 175 | Lucky Color: White 176 | Lucky Number: 11 177 | Jewelry: Ivory Stone 178 | Best Match: Scorpio, Cancer and Capricorn 179 | Celebrities: George Washington, Zhou Enlai, Albert Einstein, Justin Bieber 180 | Chinese zodiac twins: Rabbit" 181 | 182 | @repeat = "\nWould you like to select another zodiac sign? /yes, /no" 183 | end 184 | end 185 | 186 | # rubocop:enable Metrics/MethodLength,Metrics/ClassLength,Layout/LineLength 187 | --------------------------------------------------------------------------------