Skip to content

Commit

Permalink
Remove CAS and Covid
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander committed Jan 20, 2024
1 parent 4b3f001 commit 49f0dfb
Show file tree
Hide file tree
Showing 49 changed files with 78 additions and 1,367 deletions.
4 changes: 2 additions & 2 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ PUMA_MIN_THREADS=2
PUMA_MAX_THREADS=5
WEB_CONCURRENCY=0

DATABASE_HOST=postgres
DATABASE_HOST=database
DATABASE_NAME=shizoid
DATABASE_PASSWORD=WoZ7w2e3
DATABASE_PORT=5432
DATABASE_USERNAME=shizoid
DB_POOL_SIZE=40

SIDEKIQ_CONCURRENCY=25
REDIS_HOST=redis
REDIS_HOST=cache
REDIS_PORT=6379
REDIS_SIDEKIQ_DB=1
REDIS_CONTEXT_DB=2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/shizoid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Perform specs
runs-on: ubuntu-latest
services:
postgres:
database:
image: postgres:alpine
env:
POSTGRES_USER: shizoid
Expand All @@ -20,7 +20,7 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
cache:
image: redis:alpine
ports:
- 6379:6379
Expand All @@ -31,7 +31,7 @@ jobs:
- name: 'Setup Ruby'
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
ruby-version: 3.3.0
- name: "Install required system packages"
run: sudo apt-get update -y && sudo apt-get install openssh-client rsync libpq-dev cmake -y
- name: "Bundle install"
Expand Down
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ group :development, :test do
gem 'factory_bot_rails'
gem 'ffaker'
gem 'guard'
gem 'guard-rake'
gem 'guard-rspec'
gem 'guard-bundler', require: false
gem 'guard-rake', require: false
gem 'guard-rspec', require: false
gem 'guard-rubocop', require: false
gem 'listen'
gem 'rack-test'
gem 'rspec'
Expand Down
41 changes: 26 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ GEM
pry (>= 0.13.0)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-bundler (3.0.1)
bundler (>= 2.1, < 3)
guard (~> 2.2)
guard-compat (~> 1.1)
guard-compat (1.2.1)
guard-rake (1.0.0)
guard
Expand All @@ -161,13 +165,18 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
guard-rubocop (1.5.0)
guard (~> 2.0)
rubocop (< 2.0)
hashdiff (1.0.1)
i18n (1.10.0)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
io-console (0.5.11)
irb (1.4.1)
reline (>= 0.3.0)
json (2.7.1)
language_server-protocol (3.17.0.3)
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -205,9 +214,10 @@ GEM
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
parallel (1.22.1)
parser (3.1.2.0)
parallel (1.24.0)
parser (3.3.0.4)
ast (~> 2.4.1)
racc
pg (1.3.5)
pry (0.14.1)
coderay (~> 1.1)
Expand Down Expand Up @@ -252,10 +262,10 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (4.6.0)
regexp_parser (2.5.0)
regexp_parser (2.9.0)
reline (0.3.1)
io-console (~> 0.5)
rexml (3.2.5)
rexml (3.2.6)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
Expand All @@ -280,17 +290,19 @@ GEM
rspec-core (~> 3.0, >= 3.0.0)
sidekiq (>= 2.4.0)
rspec-support (3.11.0)
rubocop (1.30.1)
rubocop (1.60.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.1.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.18.0, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.18.0)
parser (>= 3.1.1.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-performance (1.14.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
Expand All @@ -300,7 +312,7 @@ GEM
rubocop (>= 1.7.0, < 2.0)
rubocop-rspec (2.11.1)
rubocop (~> 1.19)
ruby-progressbar (1.11.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sentry-rails (5.3.1)
railties (>= 5.0)
Expand Down Expand Up @@ -339,7 +351,7 @@ GEM
timeout (0.3.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.1.0)
unicode-display_width (2.5.0)
virtus (2.0.0)
axiom-types (~> 0.1)
coercible (~> 1.0)
Expand All @@ -364,8 +376,10 @@ DEPENDENCIES
faraday
ffaker
guard
guard-bundler
guard-rake
guard-rspec
guard-rubocop
listen
pg
puma
Expand Down Expand Up @@ -393,6 +407,3 @@ DEPENDENCIES

RUBY VERSION
ruby 3.3.0p0

BUNDLED WITH
2.3.7
12 changes: 10 additions & 2 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# frozen_string_literal: true

guard :bundler do
watch('Gemfile')
watch('Gemfile.lock')
end

guard :rubocop do
watch(%r{.+\.rb$})
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end

guard :rspec, cmd: 'bundle exec rspec' do
require 'guard/rspec/dsl'
dsl = Guard::RSpec::Dsl.new(self)
Expand All @@ -17,8 +27,6 @@ guard :rspec, cmd: 'bundle exec rspec' do
dsl.watch_spec_files_for(rails.views)

watch(rails.controllers) { |m| [rspec.spec.call("controllers/#{m[1]}_controller")] }
watch(rails.controllers) { |m| [rspec.spec.call("request/#{m[1]}")] }

watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
end
6 changes: 0 additions & 6 deletions app/models/chat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class Chat < ApplicationRecord
scope :not_personal, -> { where.not(kind: 'private') }
scope :with_winners, -> { where.not(winner: nil) }

enum covid_region: CovidStat.regions

def winner_enabled?
winner.present?
end
Expand Down Expand Up @@ -51,10 +49,6 @@ def disable!
update!(active_at: nil)
end

def casbanhammer?
casbanhammer_at.present?
end

def self.learn(message)
chat_payload = message.chat
chat = Chat.find_or_initialize_by(telegram_id: chat_payload.id)
Expand Down
88 changes: 0 additions & 88 deletions app/models/covid_stat.rb

This file was deleted.

19 changes: 0 additions & 19 deletions app/models/participation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ class Participation < ApplicationRecord

scope :scored, -> { where.not(score: 0) }

def ban
Rails.application.secrets[:telegram][:owners].each do |owner_id|
respose = "CASBAN #{user.to_link} at #{chat.title}"
# SendPayloadWorker.perform_async(:ban_chat_member, revoke_messages: true, chat_id: chat.telegram_id, user_id: user.id)
SendPayloadWorker.perform_async('send_message', 'chat_id' => owner_id, 'parse_mode' => 'html', 'text' => respose)
end
update!(left: true)
end

def learn(message)
self.experience += rand(3) if active_at.nil? || 5.minutes.ago > active_at
self.active_at = Time.current
Expand All @@ -32,16 +23,6 @@ class << self
# (level * (level - 1) / 2.to_f) * 100
# end

def ban_all
ban_list = Participation.joins(:chat, :user)
.where(participations: { left: false })
.where.not(chats: { casbanhammer_at: nil })
.where.not(users: { casbanned_at: nil })

ban_list.each(&:ban)
ban_list
end

def learn(message)
chat = Chat.find_by(telegram_id: message&.chat&.id)
user = User.find_by(id: message&.from&.id)
Expand Down
23 changes: 0 additions & 23 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class User < ApplicationRecord
has_many :participations, dependent: :destroy
has_many :chats, through: :participations

scope :casbanned, -> { where.not(casbanned_at: nil) }

def to_s
username || first_name || last_name
end
Expand All @@ -14,31 +12,10 @@ def to_link
"<a href='tg://user?id=#{id}'>#{self}</a>"
end

def casban!
update!(casbanned_at: Time.current)
end

def casbanned?
casbanned_at.present?
end

def self.learn(tg_user)
user = User.find_by(id: tg_user.id) || User.new(id: tg_user.id)
user.update(tg_user.to_h.slice(:username, :first_name, :last_name, :is_bot))
user.save!
user
end

def update_casban
return if casbanchecked_at.present? && casbanchecked_at < 1.week.since

banned = CasService.banned?(id)
return if banned.nil?

self.casbanchecked_at = Time.current
self.casbanned_at = banned ? Time.current : nil

save!
self
end
end
4 changes: 1 addition & 3 deletions app/processors/message_processor.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# frozen_string_literal: true

module MessageProcessor
AVAILABLE_PROCESSORS = %w[CasBanner
Me
AVAILABLE_PROCESSORS = %w[Me
Say
BinaryDice
CovidStats
CoolStory
Databank
Eightball
Expand Down
Loading

0 comments on commit 49f0dfb

Please sign in to comment.