diff --git a/app/assets/javascripts/standardpage.coffee b/app/assets/javascripts/standardpage.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/standardpage.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/standardpage.scss b/app/assets/stylesheets/standardpage.scss new file mode 100644 index 0000000..f1c3473 --- /dev/null +++ b/app/assets/stylesheets/standardpage.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the standardpage controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/message_controller.rb b/app/controllers/message_controller.rb index 3a7ef83..7dda6d2 100644 --- a/app/controllers/message_controller.rb +++ b/app/controllers/message_controller.rb @@ -1,135 +1,120 @@ -class MessageController < ApplicationController +class MessageController < ActionController::API def message_process bot_api_key = ENV['BOT_API_KEY'] + byebug return false if params[:message].blank? message = params[:message].to_unsafe_h if message[:chat][:type] == 'group' || message[:chat][:type] == 'supergroup' if message[:text].downcase =~ /asd/ multiplevalue = message[:text].downcase.scan(/asd/).count unless Group.find_by(chat_id: message[:chat][:id]) @group = Group.create(chat_id: message[:chat][:id], username: message[:chat][:username]) else @group = Group.find_by(chat_id: message[:chat][:id]) end - unless @group.welcomesent HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{@group.chat_id}&text=Bella zio! Sono il bot asdoso creato da Ferdinando Traversa (ferdinando.me) da idea di Valerio Bozzolan, asd! Digita /grafico per ricevere il link ad un grafico, anche in privato per averne uno personale, asd o /classifca per scoprire cose interessanti. L'impostazione automatica è che io invii il conto degli ASD alla fine della serata, così però ti perdi cose belle come la faccina dell'ASD di mezzanotte. Per modificare questa impostazione, basta digitare /nightsend ed invierò il messaggio di conteggio appena invii un asd")) @group.update_attribute(:welcomesent, true) end unless Sender.find_by(chat_id: message[:from][:id]) @sender = Sender.create(chat_id: message[:from][:id], username: message[:from][:username]) else @sender = Sender.find_by(chat_id: message[:from][:id]) end defmultiplevalue = multiplevalue - 1 @asd = Asd.new(group: @group, sender: @sender, text: message[:text], update_id: params[:update_id], multiple_value: defmultiplevalue) defmultiplevalue.each do |multiple| multiple = Asd.new(group: @group, sender: @sender, text: message[:text]) end asdcount = @group.asds.count case asdcount when 1 addtext = 'Il primo asd. Benvenuto nella grande famiglia di asdbot' SpecialEvent.create(text: addtext, group: @group, asd: @asd) when 10 addtext = 'Il decimo asd! Complimenti, asd.' SpecialEvent.create(text: addtext, group: @group, asd: @asd) when 100 addtext = 'IL CENTESIMO ASD, ASD! COMPLIMENTS CONGRATULATIONS AUF WIDERSHEN' SpecialEvent.create(text: addtext, group: @group, asd: @asd) when 1000 addtext = '1000 asd, wow! Questo gruppo, così asdoso, asd' SpecialEvent.create(text: addtext, group: @group, asd: @asd) when 10000 addtext = '10000 è un record mondiale, asd' SpecialEvent.create(text: addtext, group: @group, asd: @asd) end unless @group.nightsend if SpecialEvent.find_by(asd: @asd) HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendPhoto?chat_id=#{@group.chat_id}&photo=http://www.lanciano.it/faccine/asdone.gif&caption=Così asdoso, asd. #{SpecialEvent.find_by(asd: @asd).text}")) SpecialEvent.find_by(asd: @asd).destroy end position = Group.all.sort_by{|group| group.asds.count}.pluck(:id).reverse.find_index(@group.id) + 1 HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{@group.chat_id}&text=Il contasd conta ben #{asdcount} (+ #{defmultiplevalue}), asd. Sei il #{position}º gruppo per ASD inviati.")) if @asd.created_at.strftime('%H:%M') == '00:00' HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{@group.chat_id}&text=Asd di mezzanotte 🌚")) end end end end if message[:text] == '/start' && (message[:chat][:type] == 'group' || message[:chat][:type] == 'supergroup') unless Group.find_by(chat_id: message[:chat][:id]) @group = Group.create(chat_id: message[:chat][:id], username: message[:chat][:username]) else @group = Group.find_by(chat_id: message[:chat][:id]) end HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{@group.chat_id}&text=Bella zio! Sono il bot asdoso creato da Ferdinando Traversa (ferdinando.me) da idea di Valerio Bozzolan, asd! Digita /grafico per ricevere il link ad un grafico, anche in privato per averne uno personale, asd o /classifca per scoprire cose interessanti. L'impostazione automatica è che io invii il conto degli ASD alla fine della serata, così però ti perdi cose belle come la faccina dell'ASD di mezzanotte. Per modificare questa impostazione, basta digitare /nightsend ed invierò il messaggio di conteggio appena invii un asd.")) @group.update_attribute(:welcomesent, true) end if message[:text] == '/classifica' HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{message[:chat][:id]}&text=Vai su #{ENV['DOMAIN']}/classifica per vedere la classifica. Ci sono #{Group.count} che usano questo bot, comunque.")) end if message[:text] == '/start' && message[:chat][:type] == 'private' HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{message[:chat][:id]}&text=Bella zio! Sono il bot asdoso creato da Ferdinando Traversa (ferdinando.me @ferdi2005) da idea di Valerio Bozzolan, asd! Aggiungimi ad un bel gruppo e conterò gli asd, altrimenti digita /grafico per il tuo grafico personal personal.")) end if message[:text] == '/grafico' && message[:chat][:type] == 'private' unless Sender.find_by(chat_id: message[:from][:id]) HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{message[:chat][:id]}&text=Non ho ancora un grafico per te, sei nuovo per me, non ti conosco. Iscriviti in qualche gruppo con questo bot e manda asd a ripetizione, poi torna da me.")) else @sender = Sender.find_by(chat_id: message[:from][:id]) position = 'primo in assoluto' position = Sender.all.sort_by{|sender| sender.asds.count}.pluck(:id).reverse.find_index(@sender.id) + 1 if Sender.count > 0 HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{message[:chat][:id]}&text=Guarda il tuo grafico personalizzato per il gruppo su #{ENV['DOMAIN']}/grafico?s=#{@sender.chat_id}")) end end if message[:text] == '/grafico' && (message[:chat][:type] == 'group' || message[:chat][:type] == 'supergroup') unless Group.find_by(chat_id: message[:chat][:id]) HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{message[:chat][:id]}&text=Non ho ancora un grafico per te, sei nuovo per me, non ti conosco. Invia qualche asd e prova questo comando.")) else @group = Group.find_by(chat_id: message[:chat][:id]) position = Group.all.sort_by{|group| group.asds.count}.pluck(:id).reverse.find_index(@group.id) + 1 HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{message[:chat][:id]}&text=Guarda il tuo grafico personalizzato per il gruppo su #{ENV['DOMAIN']}/grafico?g=#{@group.chat_id}")) end end if message[:text] == '/nightsend' && (message[:chat][:type] == 'group' || message[:chat][:type] == 'supergroup') unless Group.find_by(chat_id: message[:chat][:id]) HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{message[:chat][:id]}&text=Ok, l'impostazione predefinita è che l'invio del conto degli asd avvenga a mezzanotte, ma con questo comando la modifico. Procedo, asd.")) @group.update_attribute(:nightsend, false) else @group = Group.find_by(chat_id: message[:chat][:id]) if @group.nightsend HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{message[:chat][:id]}&text=Ok, l'impostazione predefinita è che l'invio del conto degli asd avvenga a mezzanotte, ma con questo comando la modifico. Procedo, ora avrai un messaggio ogni asd, asd.")) @group.update_attribute(:nightsend, false) else HTTParty.get(CGI.escape("http://api.telegram.org/bot#{bot_api_key}/sendMessage?chat_id=#{message[:chat][:id]}&text=Sei una persona triste, asd. Vuoi che il conteggio venga inviato a mezzanotte. Bozzolan dice sì, Ferdi dice no. Tu dici sì, allora conteggio a mezzanotte sia, asd")) @group.update_attribute(:nightsend, true) end end end - end - - def classifica - @groups = Group.all.sort_by{|sender| sender.asds.count}.reverse - @senders = Sender.all.sort_by{|sender| sender.asds.count}.reverse - end - - def grafico - if !params[:s].nil? - @sender = Sender.find_by(chat_id: params[:s]) - elsif !params[:g].nil? - @group = Group.find_by(chat_id: params[:g]) - end - end - - def home + render status: 200 end end \ No newline at end of file diff --git a/app/controllers/standardpage_controller.rb b/app/controllers/standardpage_controller.rb new file mode 100644 index 0000000..300ad91 --- /dev/null +++ b/app/controllers/standardpage_controller.rb @@ -0,0 +1,17 @@ +class StandardpageController < ApplicationController + def classifica + @groups = Group.all.sort_by{|sender| sender.asds.count}.reverse + @senders = Sender.all.sort_by{|sender| sender.asds.count}.reverse + end + + def grafico + if !params[:s].nil? + @sender = Sender.find_by(chat_id: params[:s]) + elsif !params[:g].nil? + @group = Group.find_by(chat_id: params[:g]) + end + end + + def home + end +end diff --git a/app/helpers/standardpage_helper.rb b/app/helpers/standardpage_helper.rb new file mode 100644 index 0000000..d89f253 --- /dev/null +++ b/app/helpers/standardpage_helper.rb @@ -0,0 +1,2 @@ +module StandardpageHelper +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 7d337ad..e820bae 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,15 +1,20 @@