Skip to content

Instantly share code, notes, and snippets.

@thr3a
Last active March 30, 2016 07:22
Show Gist options
  • Save thr3a/161dbc2ac0b47b6e5722724a6ae7c2b5 to your computer and use it in GitHub Desktop.
Save thr3a/161dbc2ac0b47b6e5722724a6ae7c2b5 to your computer and use it in GitHub Desktop.
hoge
require 'slack-ruby-bot'
require 'natto'
require "active_record"
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: 'onsyadb'
)
class Intro < ActiveRecord::Base # for ActiveRecord
end
class Onsya < SlackRubyBot::Bot
match /御社/ do |client, data, match|
words = []
Intro.all.each {|intro| words.concat(Natto::MeCab.new('-O wakati').parse(intro.content).split(' ')) }
words.unshift "BEGIN"
words.push "END"
nodes = words.each_cons(3).to_a
node = nodes.select{|n|n[1] == "私"}.sample
markov_text = node[1]+node[2]
loop do
node = nodes.select{|w| node[1] == w[0] && node[2] == w[1] }.sample
break if(markov_text.count("。")==3 || node.nil?)
markov_text << node.last
end
message = "生成しました!「#{markov_text}」"
client.say(channel: data.channel, text: markov_text)
end
end
Onsya.run
# A sample Gemfile
source "https://rubygems.org"
# gem "rails"
gem 'slack-ruby-bot'
gem 'natto'
gem 'activerecord'
gem 'sqlite3'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment