This file contains hidden or 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
| movies = [ | |
| { | |
| name: 'Vitalina Varela', | |
| year: 2019, | |
| runtime: 124, | |
| categories: [ 'drama' ], | |
| 'release-date': '2019-08-14', | |
| director: 'Pedro Costa', | |
| writer: [ 'Pedro Costa', 'Vitalina Varela' ], | |
| actors: [ |
This file contains hidden or 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
| class OauthController < ApplicationController | |
| def authorize | |
| options = { | |
| site: 'https://slack.com/oauth/authorize' | |
| } | |
| client ||= OAuth2::Client.new( | |
| ENV('SLACK_CLIENT_ID'), | |
| ENV('SLACK_CLIENT_SECRET'), | |
| options | |
| ) |
This file contains hidden or 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
| class CommandsController < ApplicationController | |
| skip_before_action :verify_authenticity_token, :only => :create | |
| protect_from_forgery except: [:create] | |
| def create | |
| quote,random = EffinQuote.find_or_random(command_params[:text]) | |
| HTTParty.post(command_params[:response_url], { body: contents(quote).to_json, headers: { | |
| "Content-Type" => "application/json" | |
| } |
This file contains hidden or 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
| { | |
| "response_type": "in_channel", | |
| "attachments": [ | |
| { | |
| "title": quote.contents, | |
| "title_link": quote.twitter_url, | |
| "image_url": quote.url | |
| } | |
| ] | |
| } |
This file contains hidden or 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
| { | |
| command: "/effin", | |
| team_id: "TEAMTEAM", | |
| channel_id: "ABCDBA", | |
| text: "delight", | |
| team_domain: "yourworkspace", | |
| user_id: "123456789", | |
| response_url: "https://hooks.slack.com/commands/TEAMTEAM/45645446/a12b23c34d45", | |
| channel_name: "directmessage", | |
| token: "lalalala", |
This file contains hidden or 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
| def autocomplete | |
| require "google/cloud/vision" | |
| vision = Google::Cloud::Vision.new(project_id: "effin-bot") | |
| image = vision.image(url) | |
| text = image.text.to_s | |
| text = text.gsub("\n", " ").downcase | |
| self.contents = text | |
| save |
This file contains hidden or 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
| { | |
| "requests": [ | |
| { | |
| "features": [ | |
| { | |
| "type": "LABEL_DETECTION" | |
| } | |
| ], | |
| "image": { | |
| "source": { |
This file contains hidden or 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
| tweets.each do |t| | |
| next unless t.media && t.media.first && t.media.first.uri | |
| image_url = t.media.first.media_uri | |
| tweet_url = t.uri | |
| next if EffinQuote.find_by(url: image_url.to_s) | |
| EffinQuote.create(url: image_url.to_s, twitter_url: tweet_url.to_s) | |
| end |
This file contains hidden or 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
| client = Twitter::REST::Client.new do |config| | |
| config.consumer_key = ENV('TWITTER_CONSUMER_KEY') | |
| config.consumer_secret = ENV('TWITTER_CONSUMER_SECRET') | |
| config.access_token = ENV('TWITTER_ACCESS_TOKEN') | |
| config.access_token_secret = ENV('TWITTER_ACCESS_TOKEN_SECRET') | |
| end | |
| tweets = client.get_all_tweets('effinbirds') |
This file contains hidden or 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
| class EffinQuote < ApplicationRecord | |
| include PgSearch | |
| pg_search_scope :search_by_word, against: [:contents] | |
| def self.find_by_word(word) | |
| complete.search_by_word(word).first | |
| end | |
| def self.find_or_random(text) | |
| quote = EffinQuote.find_by_word(text) | |
| quote ? [quote, false] : [EffinQuote.complete.sample, true] | |
| end |
NewerOlder