-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rb
More file actions
42 lines (36 loc) · 886 Bytes
/
main.rb
File metadata and controls
42 lines (36 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# coding: utf-8
require './register'
require './senryu_detector'
require './stream'
require 'json'
require 'pp'
class Main
include Register
def initialize
@client = init_app
@detector = SenryuDetector.new
MstdnStream.set_stream do |msg|
if msg.data.size > 0
begin
remove_tag = -> (str) { str.gsub(/<([^>]+)>/, '') }
info = JSON.parse(msg.data)
if info['event'] == 'update'
body = JSON.parse(info['payload'])
p remove_tag.call(body['content'])
senryu = nil
senryu = @detector.senryu?(remove_tag.call(body['content'])) unless body['content'].include?('川柳検知bot')
if senryu
p @detector.senryu?(senryu.join)
end
end
rescue => e
p e
end
end
end
end
end
Main.new
loop do
sleep 1
end