-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Homework 2 #775
Open
YuliyaBond
wants to merge
7
commits into
rubyroidlabs:master
Choose a base branch
from
YuliyaBond:homework-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Homework 2 #775
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
26de7da
homework 1
YuliyaBond 5c5a3b3
homework-2
YuliyaBond 9135bae
delete hm1
YuliyaBond d41a3e3
delete everything that is not safe
YuliyaBond 1701753
delete everything that is not safe
YuliyaBond d5807db
delete everything that is not safe
YuliyaBond 556cd79
delete everything that is not safe
YuliyaBond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'terminfo' | ||
|
||
def tree(number, base_number) | ||
width = TermInfo.screen_size | ||
puts 'Pascal triangle'.center(width[1].to_i) | ||
number.times do |index| | ||
trn = [base_number] | ||
temp = base_number | ||
s = 1 | ||
branch = [' /'] | ||
index.times do | ||
temp = ((temp * (index - s + 1)) / s) | ||
trn.push temp | ||
s += 1 | ||
branch.push ' /' | ||
end | ||
arr_to_str = trn.join(' ') | ||
str_end = branch.join(' \\') | ||
puts "#{index + 1}:" + ' ' + arr_to_str.center(width[1].to_i) | ||
if index != (number - 1) | ||
puts ' ' + "#{str_end} \\".center(width[1].to_i) | ||
end | ||
end | ||
end | ||
|
||
puts 'Depth?' | ||
number = gets.chomp | ||
base_number = ENV['BASE'] | ||
if number.to_i <= 0 | ||
loop do | ||
puts 'depth must be positive. ' | ||
puts 'Depth?' | ||
number = gets.chomp | ||
break if number.to_i > 0 | ||
end | ||
elsif base_number.to_i <= 0 | ||
loop do | ||
puts 'BASE must be positive. ' | ||
puts 'BASE?' | ||
base_number = gets.chomp | ||
break if base_number.to_i > 0 | ||
end | ||
end | ||
tree(number.to_i, base_number.to_i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
settings.yml | ||
.bundle/ | ||
chat_ids/* | ||
1/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
gem 'telegram-bot-ruby' | ||
gem 'github_api' | ||
gem 'redis' | ||
gem 'octokit', :git => 'https://github.com/octokit/octokit.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
GIT | ||
remote: https://github.com/octokit/octokit.rb | ||
revision: f2a5ff176447afc61caa0e0d95b0cd02c031512f | ||
specs: | ||
octokit (4.8.0) | ||
sawyer (~> 0.8.0, >= 0.5.3) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
addressable (2.5.2) | ||
public_suffix (>= 2.0.2, < 4.0) | ||
axiom-types (0.1.1) | ||
descendants_tracker (~> 0.0.4) | ||
ice_nine (~> 0.11.0) | ||
thread_safe (~> 0.3, >= 0.3.1) | ||
coercible (1.0.0) | ||
descendants_tracker (~> 0.0.1) | ||
descendants_tracker (0.0.4) | ||
thread_safe (~> 0.3, >= 0.3.1) | ||
equalizer (0.0.11) | ||
faraday (0.12.2) | ||
multipart-post (>= 1.2, < 3) | ||
github_api (0.18.2) | ||
addressable (~> 2.4) | ||
descendants_tracker (~> 0.0.4) | ||
faraday (~> 0.8) | ||
hashie (~> 3.5, >= 3.5.2) | ||
oauth2 (~> 1.0) | ||
hashie (3.5.7) | ||
ice_nine (0.11.2) | ||
inflecto (0.0.2) | ||
jwt (1.5.6) | ||
multi_json (1.13.1) | ||
multi_xml (0.6.0) | ||
multipart-post (2.0.0) | ||
oauth2 (1.4.0) | ||
faraday (>= 0.8, < 0.13) | ||
jwt (~> 1.0) | ||
multi_json (~> 1.3) | ||
multi_xml (~> 0.5) | ||
rack (>= 1.2, < 3) | ||
public_suffix (3.0.2) | ||
rack (2.0.4) | ||
redis (4.0.1) | ||
sawyer (0.8.1) | ||
addressable (>= 2.3.5, < 2.6) | ||
faraday (~> 0.8, < 1.0) | ||
telegram-bot-ruby (0.8.6.1) | ||
faraday | ||
inflecto | ||
virtus | ||
thread_safe (0.3.6) | ||
virtus (1.0.5) | ||
axiom-types (~> 0.1) | ||
coercible (~> 1.0) | ||
descendants_tracker (~> 0.0, >= 0.0.3) | ||
equalizer (~> 0.0, >= 0.0.9) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
github_api | ||
octokit! | ||
redis | ||
telegram-bot-ruby | ||
|
||
BUNDLED WITH | ||
1.16.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "redis" | ||
class Base | ||
attr_accessor :bot, :user_id, :messages_array, :last_message | ||
|
||
def initialize(bot, message_chat_id) | ||
@bot = bot | ||
@user_id = message_chat_id | ||
end | ||
|
||
def telegram_send_message(text, answers = nil) | ||
if answers.nil? | ||
@bot.api.send_message(chat_id: @user_id, text: text, parse_mode: 'Markdown') | ||
else | ||
@bot.api.send_message(chat_id: @user_id, text: text, parse_mode: 'Markdown', reply_markup: answers) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require_relative 'base' | ||
|
||
class Help < Base | ||
def send_messages | ||
telegram_send_message('Hello. See what I\'m doing | ||
/help | ||
/set\_repo | ||
/show\_repo | ||
/search | ||
/reset') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require_relative 'base' | ||
|
||
class History < Base | ||
def send_messages | ||
lines = IO.readlines("./chat_ids/#{@user_id}_history") | ||
last = lines.last(10) | ||
telegram_send_message(last.join('')) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require_relative 'base' | ||
require 'octokit' | ||
require 'yaml' | ||
|
||
SETTINGS = YAML.load(File.open('settings.yml')) | ||
|
||
|
||
class Search < Base | ||
def get_repo | ||
url_repo = File.open("./chat_ids/#{@user_id}") {|f| f.readline} | ||
url_repo.gsub(/http(s)?:\/\/github.com\//, '') | ||
end | ||
|
||
def add_history(query) | ||
File.open("./chat_ids/#{@user_id}_history", 'a') do |f| | ||
f.puts query | ||
end | ||
end | ||
|
||
def commits(query) | ||
client = Octokit::Client.new(:login => SETTINGS['login'], :password => SETTINGS['password']) | ||
repo = get_repo | ||
if repo.nil? | ||
telegram_send_message("Your don't set repo!") | ||
else | ||
commits = client.search_commits("repo:#{repo} #{query}", {page: 1, per_page: 10}) | ||
add_history(query) | ||
total_count = commits[:total_count] | ||
commits_all = [] | ||
commits[:items].each_with_index do |commit, index| | ||
commits_all << "#{index}. #{commit[:commit][:message].gsub("\n", ' ')} -> [Link to commit](#{commit[:commit][:url]})" | ||
end | ||
|
||
telegram_send_message(commits_all.join("\n")) | ||
telegram_send_message("*Results #{commits_all.size} from #{total_count}*") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require_relative 'base' | ||
class SetRepo < Base | ||
def save_repo(repo) | ||
File.write("./chat_ids/#{@user_id}", repo) | ||
telegram_send_message("We saved your repo: #{repo}") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require_relative 'base' | ||
class ShowRepo < Base | ||
def get_repo | ||
repo = File.open("./chat_ids/#{@user_id}") {|f| f.readline} | ||
telegram_send_message("Your repo: #{repo}") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require_relative 'base' | ||
class Start < Base | ||
def send_messages | ||
telegram_send_message('Hello! Have a nice day! if you don\'t know what to do enter /help' ) | ||
end | ||
end |
Submodule octokit.rb
added at
f2a5ff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'telegram/bot' | ||
require_relative 'lib/start' | ||
require_relative 'lib/base' | ||
require_relative 'lib/help' | ||
require_relative 'lib/set_repo' | ||
require_relative 'lib/show_repo' | ||
require_relative 'lib/search' | ||
require_relative 'lib/history' | ||
require 'yaml' | ||
|
||
SETTINGS = YAML.load(File.open('settings.yml')) | ||
|
||
token = SETTINGS['token'] | ||
|
||
Telegram::Bot::Client.run(token) do |bot| | ||
bot.listen do |message| | ||
Thread.start(message) do |message| | ||
chat_id = message.chat.id | ||
|
||
begin | ||
case message.text | ||
when "/start" | ||
bot.api.send_message(chat_id: chat_id, text: 'Use /help what see all command') | ||
when /^\/set_repo http(s)?:\/\/github.com(.)*$/i | ||
set_repo = SetRepo.new(bot, chat_id) | ||
repository = message.text.gsub("/set_repo ", '') | ||
set_repo.save_repo(repository) | ||
when "/show_repo" | ||
show_repo = ShowRepo.new(bot, chat_id) | ||
show_repo.get_repo | ||
when "/reset" | ||
set_repo = SetRepo.new(bot, chat_id) | ||
set_repo.save_repo('') | ||
when /^\/search (.)+/ | ||
search = Search.new(bot, chat_id) | ||
query = message.text.gsub("/search ", '') | ||
if query.empty? | ||
bot.api.send_message(chat_id: chat_id, text: 'You don\'t input search query') | ||
else | ||
search.commits(query) | ||
end | ||
when "/history" | ||
History.new(bot, chat_id).send_messages | ||
when "/help" | ||
help = Help.new(bot, chat_id) | ||
help.send_messages | ||
else | ||
bot.api.send_message(chat_id: chat_id, text: 'I don\'t understand you :(') | ||
end | ||
rescue Exception => e | ||
bot.api.send_message(chat_id: chat_id, text: "Something doing wrong!!! #{e.message}") | ||
puts e.backtrace.inspect | ||
end | ||
|
||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Прям вот лишнее что-то затесалось.