Skip to content

Instantly share code, notes, and snippets.

View MaksimAbramchuk's full-sized avatar

Maksim Abramchuk MaksimAbramchuk

View GitHub Profile
$PULL_REQUEST_URL | grep -o -E ‘[0–9]+$’ | head -1 | sed -e ‘s/^0\+//’
dependencies:
post:
— bin/cisetup
checkout:
post:
— git fetch origin — depth=1000000
export GITHUB_ACCESS_TOKEN=<your_github_access_token>
export PULL_REQUEST_URL=${CI_PULL_REQUEST}
export PULL_REQUEST_ID=`echo $PULL_REQUEST_URL | grep -o -E ‘[0–9]+$’ | head -1 | sed -e ‘s/^0\+//’`
((bin/bundle exec pronto run -f github_pr -c origin/master)) || true
class WebhooksController < ApplicationController
skip_before_action :verify_authenticity_token
def callback
dispatcher.new(webhook, user).process
render nothing: true, head: :ok
end
def webhook
params['webhook']
class User < ActiveRecord::Base
validates_uniqueness_of :telegram_id
def set_next_bot_command(command)
self.bot_command_data[‘command’] = command
save
end
def get_next_bot_command
bot_command_data[‘command’]
class BotMessageDispatcher
attr_reader :message, :user
def initialize(message, user)
@message = message
@user = user
end
def process
if user.get_next_bot_command
development:
bot_token: bot220521163:AAHNZe-njGuJz_6-zwOyR1BKkhyJoGpNPyo
require ‘telegram/bot’
module BotCommand
class Base
attr_reader :user, :message, :api
def initialize(user, message)
@user = user
@message = message
token = Rails.application.secrets.bot_token
module BotCommand
class Start < Base
def should_start?
text =~ /\A\/start/
end
def start
send_message('Hello! Here is a simple quest game! Type /born to start your interesting journey to the Rails rockstar position!')
user.reset_next_bot_command
user.set_next_bot_command('BotCommand::Born')
module BotCommand
class AccomplishTutorial < Base
def should_start?
text =~ /\A\/accomplish_tutorial/
end
def start
send_message("It was hard, but it’s over! Models, controllers, views, wow, a lot stuff! Let’s practice now. What do you think about writing a Rails blog? Type /write_blog to continue.")
user.set_next_bot_command(‘BotCommand::WriteBlog’)
end