-
Notifications
You must be signed in to change notification settings - Fork 3
/
comment_scan.rb
61 lines (49 loc) · 2.09 KB
/
comment_scan.rb
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'logger'
require 'yaml'
require './db'
require 'pry-byebug'
require_relative 'comment_scan/message_collection'
require_relative 'comment_scan/chatter'
require_relative 'comment_scan/seclient'
require_relative 'comment_scan/commander'
require_relative 'comment_scan/replier'
require_relative 'comment_scan/comment_scanner'
IO.write("bot.pid", Process.pid.to_s)
setup_db("db/db.sqlite3")
settings = File.exists?('./settings.yml') ? YAML.load_file('./settings.yml') : ENV
bot_names = settings['names'] || Array(settings['name'])
ignore_users = Array(settings['ignore_user_ids'] || WhitelistedUser.all.map(&:user_id))
#setup Rooms in DB
settings['rooms'].each do |room_id|
Room.find_or_create_by(room_id: room_id)
end
if ENV['SHORT_LOGS']
$stdout.sync = true #Do we really need this??
log_formatter = proc do |severity, datetime, progname, msg|
"#{msg}\n"
end
else
log_formatter = nil
end
master_logger = Logger.new(STDOUT, level: Logger::DEBUG, formatter: log_formatter)
chatter = Chatter.new(settings["ChatXUsername"], settings["ChatXPassword"],
settings["hq_room_id"].to_i, master_logger, settings["rooms"])
seclient = SEClient.new(settings["APIKey"], settings["site"], master_logger)
scanner = CommentScanner.new(seclient, chatter, settings["all_comments"], ignore_users,
master_logger, hot_secs: settings["hot_seconds"], hot_comment_num: settings["hot_comment_num"],
perspective_key: settings['perspective_key'],
perspective_log: Logger.new('perspective.log'))
commander = Commander.new(chatter, seclient, scanner, bot_names, master_logger)
replier = Replier.new(chatter, seclient, scanner, bot_names, master_logger)
commander.setup_basic_commands
commander.setup_HQ_commands
replier.setup_reply_actions
replier.setup_mention_actions
replier.setup_fall_through_actions
sleep 1 # So we don't get chat errors for 3 messages in a row
post_on_startup = ARGV[0].to_i || 0
scanner.scan_last_n_comments(post_on_startup)
loop do
scanner.scan_new_comments
sleep 1 while scanner.tick
end