├── Rakefile ├── Gemfile ├── lib └── ruboty │ ├── ganbare │ └── version.rb │ ├── ganbare.rb │ ├── actions │ └── ganbare │ │ ├── remove.rb │ │ ├── add.rb │ │ ├── tsurami.rb │ │ └── base.rb │ └── handlers │ └── ganbare.rb ├── .gitignore ├── .travis.yml ├── .rubocop.yml ├── ruboty-ganbare.gemspec └── README.md /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | task default: :spec 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in ruboty-ganbare.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /lib/ruboty/ganbare/version.rb: -------------------------------------------------------------------------------- 1 | module Ruboty 2 | module Ganbare 3 | VERSION = '0.1.0'.freeze 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | cache: bundler 3 | rvm: 4 | - 2.3.0 5 | before_install: 6 | - gem install bundler 7 | script: 8 | - bundle exec rubocop 9 | 10 | -------------------------------------------------------------------------------- /lib/ruboty/ganbare.rb: -------------------------------------------------------------------------------- 1 | require 'ruboty/ganbare/version' 2 | require 'ruboty/actions/ganbare/base' 3 | require 'ruboty/actions/ganbare/add' 4 | require 'ruboty/actions/ganbare/remove' 5 | require 'ruboty/actions/ganbare/tsurami' 6 | require 'ruboty/handlers/ganbare' 7 | -------------------------------------------------------------------------------- /lib/ruboty/actions/ganbare/remove.rb: -------------------------------------------------------------------------------- 1 | module Ruboty 2 | module Actions 3 | module Ganbare 4 | class Remove < Base 5 | def call 6 | emoji = message[:emoji] 7 | return unless store[emoji] 8 | store.delete(emoji) 9 | message.reply("removed #{emoji}") 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | Exclude: 3 | - tmp/**/* 4 | - vendor/**/* 5 | 6 | SpecialGlobalVars: 7 | Enabled: false 8 | 9 | AsciiComments: 10 | Enabled: false 11 | 12 | ClassLength: 13 | Max: 200 14 | 15 | Documentation: 16 | Enabled: false 17 | 18 | LineLength: 19 | Max: 120 20 | 21 | MethodLength: 22 | Max: 30 23 | 24 | TrailingCommaInLiteral: 25 | EnforcedStyleForMultiline: comma 26 | 27 | -------------------------------------------------------------------------------- /lib/ruboty/actions/ganbare/add.rb: -------------------------------------------------------------------------------- 1 | module Ruboty 2 | module Actions 3 | module Ganbare 4 | class Add < Base 5 | def call 6 | emoji = message[:emoji] 7 | store[emoji] = avatar 8 | post_by_avatar(avatar) 9 | end 10 | 11 | def avatar 12 | @avatar ||= { 13 | emoji: message[:emoji], 14 | name: (message[:name] || ENV['GANBARE_DEFAULT_NAME'] || 'ganbare_bot'), 15 | content: (message[:content] || ganbare_default_message), 16 | } 17 | end 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/ruboty/handlers/ganbare.rb: -------------------------------------------------------------------------------- 1 | module Ruboty 2 | module Handlers 3 | class Ganbare < Base 4 | on(/(?:つら|辛|ツラ)(?:い|み|ミ|すぎ|たん|ぽよ)/, 5 | name: 'tsurami', 6 | all: true, 7 | missing: true) 8 | 9 | on(/ganbare\s+(?:add|push)\s+(?:[A-Za-z0-9\-_]+:)(?:\s+(?[^\s]+)(\s+(?.+))?)?$/, 10 | name: 'add', 11 | description: 'add to ganbare name list') 12 | 13 | on(/ganbare\s+(?:rm|del|remove|delete)\s+(?:[A-Za-z0-9\-_]+:)$/, 14 | name: 'remove', 15 | description: 'remove from ganbare name list') 16 | 17 | def tsurami(message) 18 | ::Ruboty::Actions::Ganbare::Tsurami.new(message).call 19 | end 20 | 21 | def add(message) 22 | ::Ruboty::Actions::Ganbare::Add.new(message).call 23 | end 24 | 25 | def remove(message) 26 | ::Ruboty::Actions::Ganbare::Remove.new(message).call 27 | end 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /ruboty-ganbare.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'ruboty/ganbare/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'ruboty-ganbare' 8 | spec.version = Ruboty::Ganbare::VERSION 9 | spec.authors = ['ru_shalm'] 10 | spec.email = ['ru_shalm@hazimu.com'] 11 | 12 | spec.summary = 'Ganbare handler for Ruboty. This is a joke plugin :)' 13 | spec.homepage = 'https://github.com/rutan/ruboty-ganbare' 14 | 15 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 16 | spec.bindir = 'exe' 17 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 18 | spec.require_paths = ['lib'] 19 | 20 | spec.add_dependency 'ruboty' 21 | spec.add_development_dependency 'bundler', '~> 1.12' 22 | spec.add_development_dependency 'rake', '~> 10.0' 23 | spec.add_development_dependency 'rubocop', '~> 0.40.0' 24 | end 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ruboty::Ganbare 2 | 3 | [![Build Status](https://travis-ci.org/rutan/ruboty-ganbare.svg?branch=master)](https://travis-ci.org/rutan/ruboty-ganbare) 4 | 5 | Cheering handler for [Ruboty](https://github.com/r7kamura/ruboty). 6 | 7 | ## Installation 8 | 9 | Add this line to your application's Gemfile: 10 | 11 | ```ruby 12 | gem 'ruboty-ganbare' 13 | ``` 14 | 15 | ## Usage 16 | 17 | in shell and other adapter. 18 | 19 | ``` 20 | $ be ruboty 21 | Type `exit` or `quit` to end the session. 22 | > @ruboty ganbare add :ito_life: 23 | ganbare_bot: がんばれ♥がんばれ♥ 24 | > つらいよぉ 25 | ganbare_bot: がんばれ♥がんばれ♥ 26 | ``` 27 | 28 | in Slack adapter. ( [ruboty-slack](https://github.com/r7kamura/ruboty-slack) or [ruboty-slack_rtm](https://github.com/rosylilly/ruboty-slack_rtm) ) 29 | 30 | TODO: screen shot 31 | 32 | ## ENV 33 | 34 | - `SLACK_TOKEN` : Slack API Token (optional. only use in Slack Adapter) 35 | - `GANBARE_SYSTEM_MESSAGE` : cheering message by system (optional. default: `がんばれ♥がんばれ♥`) 36 | - `GANBARE_DEFAULT_MESSAGE` : default cheering message (optional. default: `がんばれ♥がんばれ♥`) 37 | 38 | ## License 39 | 40 | MIT 41 | -------------------------------------------------------------------------------- /lib/ruboty/actions/ganbare/tsurami.rb: -------------------------------------------------------------------------------- 1 | module Ruboty 2 | module Actions 3 | module Ganbare 4 | class Tsurami < Base 5 | def call 6 | return unless permit_from? 7 | 8 | avatar = select_avatar 9 | if avatar 10 | if from_slack? 11 | post_to_slack( 12 | channel: message.to, 13 | name: avatar[:name], 14 | emoji: avatar[:emoji], 15 | text: avatar[:content] 16 | ) 17 | else 18 | message.reply(generate_message(avatar)) 19 | end 20 | else 21 | message.reply(ganbare_system_message) 22 | end 23 | end 24 | 25 | private 26 | 27 | def select_avatar 28 | key = store.keys.sample 29 | key ? store[key] : nil 30 | end 31 | 32 | def permit_from? 33 | return true if permit_channels.empty? 34 | permit_channels.include?(message.from) 35 | end 36 | 37 | def permit_channels 38 | @permit_channels ||= (ENV['GANBARE_PERMIT_CHANNEL'] || '').split(/\s*,\s*/) 39 | end 40 | end 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /lib/ruboty/actions/ganbare/base.rb: -------------------------------------------------------------------------------- 1 | module Ruboty 2 | module Actions 3 | module Ganbare 4 | class Base < ::Ruboty::Actions::Base 5 | private 6 | 7 | def store 8 | message.robot.brain.data['ganbare'] ||= {} 9 | end 10 | 11 | def post_by_avatar(avatar) 12 | if from_slack? 13 | post_to_slack( 14 | channel: message.to, 15 | name: avatar[:name], 16 | emoji: avatar[:emoji], 17 | text: avatar[:content] 18 | ) 19 | else 20 | message.reply(generate_message(avatar)) 21 | end 22 | end 23 | 24 | def post_to_slack(channel: nil, name: nil, emoji: nil, text: nil) 25 | slack_client.chat_postMessage( 26 | channel: channel, 27 | username: name, 28 | icon_emoji: emoji, 29 | text: text, 30 | parse: true, 31 | unfurl_links: true 32 | ) 33 | end 34 | 35 | def generate_message(avatar) 36 | "#{avatar[:name]}: #{avatar[:content]}" 37 | end 38 | 39 | def slack_client 40 | @slack_client ||= Slack.client(token: ENV['SLACK_TOKEN']) 41 | end 42 | 43 | def from_slack? 44 | message.robot.__send__(:adapter).class.name.downcase.include?('slack') 45 | end 46 | 47 | def ganbare_system_message 48 | (ENV['GANBARE_SYSTEM_MESSAGE'] || 'がんばれ♥がんばれ♥') 49 | end 50 | 51 | def ganbare_default_message 52 | (ENV['GANBARE_DEFAULT_MESSAGE'] || 'がんばれ♥がんばれ♥') 53 | end 54 | end 55 | end 56 | end 57 | end 58 | --------------------------------------------------------------------------------