moobooks 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/plushies +22 -3
- data/lib/moobooks/plush.rb +35 -4
- data/lib/moobooks/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aaa9529fe1bfe59525e5d430f4a19a1c84a7dc3a46d01c061df8364b4fd91858
|
4
|
+
data.tar.gz: 771da7e487722882357836263fa047370850ac54729263051e20a17c5e82d212
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5b31138a9cbc966fdb882e77d213a7a9573b69e616b45f71aff80d71b9166a32e0183a487d1e7bb1d624ad9bab3a90aa42a85c2224df84603b85d129bede54f
|
7
|
+
data.tar.gz: 9bd25c6a54d4081d22ecd7094544c971b70ef865c4e46489e53a5f91a43f9124421ea0d87d1015c963b262443034ae1219b816f450c9965e9271f2361a7b521a
|
data/bin/plushies
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
require_relative '../lib/moobooks'
|
22
22
|
|
23
23
|
require 'logger'
|
24
|
+
require 'thread'
|
24
25
|
|
25
26
|
def print_help(help_param = false)
|
26
27
|
puts 'Usage:',
|
@@ -62,10 +63,28 @@ when ['-h']
|
|
62
63
|
when 'post'
|
63
64
|
plushies.shuffle.each do |plush|
|
64
65
|
log.info "Plush \"#{plush.name}\" said: \"#{plush.post_status!}\""
|
65
|
-
r = rand(
|
66
|
+
r = rand(60..209)
|
66
67
|
log.info("Sleeping for #{r} seconds.")
|
67
68
|
sleep r
|
68
69
|
end
|
70
|
+
when 'reply'
|
71
|
+
mt = Mutex.new
|
72
|
+
threads = []
|
73
|
+
plushies.shuffle.each do |pl|
|
74
|
+
threads << Thread.new(pl) do |plush|
|
75
|
+
mt.synchronize do
|
76
|
+
log.debug "Plush \"#{plush.name}\" starts replying."
|
77
|
+
end
|
78
|
+
plush.clients[:twitter].mentions_timeline(count: 200).reverse.each do |m|
|
79
|
+
unless (reply = plush.reply!(m)).nil?
|
80
|
+
log.info "Plush \"#{plush.name}\" said: \"#{reply}\""
|
81
|
+
r = rand(3..6)
|
82
|
+
sleep r
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
threads.each(&:join)
|
69
88
|
when 'update'
|
70
89
|
plushies.each do |plush|
|
71
90
|
corpus = JSON.parse(File.read("#{__dir__}/../corpora/#{plush.name}.json"),
|
@@ -101,7 +120,7 @@ when 'update'
|
|
101
120
|
log.info("Updated model for \"#{plush.name}\" ")
|
102
121
|
end
|
103
122
|
else
|
104
|
-
warn "Unknown command: #{cmd
|
105
|
-
log.warn "Unknown command: #{cmd
|
123
|
+
warn "Unknown command: #{cmd}"
|
124
|
+
log.warn "Unknown command: #{cmd}"
|
106
125
|
print_help
|
107
126
|
end
|
data/lib/moobooks/plush.rb
CHANGED
@@ -56,6 +56,7 @@ module Moobooks
|
|
56
56
|
raise UnsupportedEngineError unless %w[rng markov].include?(@engine)
|
57
57
|
@originals = {}
|
58
58
|
twitter_login(apps, conf[:twitter]) unless conf[:twitter].nil?
|
59
|
+
add_dnp_words(conf)
|
59
60
|
@model = Ebooks::Model.from_json(
|
60
61
|
File.read("#{__dir__}/../../models/#{@name}.json")
|
61
62
|
)
|
@@ -65,18 +66,25 @@ module Moobooks
|
|
65
66
|
#
|
66
67
|
# Method to post statuses to all available social platforms
|
67
68
|
def post_status!
|
68
|
-
@status =
|
69
|
-
@
|
69
|
+
@status = 'trap'
|
70
|
+
@status = @model.update(280) while @status =~ /#{@bad_words.join('|')}/
|
71
|
+
@twitter_client&.update(@status)
|
70
72
|
@status
|
71
73
|
end
|
72
|
-
|
74
|
+
|
73
75
|
# @author Maxine Michalski
|
74
76
|
#
|
75
77
|
# Let's this plush reply to messages.
|
76
78
|
#
|
77
79
|
# @notice This can cause endless reply loops, use with caution!
|
78
80
|
def reply!(status)
|
79
|
-
|
81
|
+
return if replied?(status)
|
82
|
+
@status = 'trap'
|
83
|
+
while @status =~ /#{@bad_words.join('|')}/
|
84
|
+
@status = @model.reply(status.text, 200)
|
85
|
+
end
|
86
|
+
@twitter_client&.update("@#{status.user.screen_name} #{@status}",
|
87
|
+
in_reply_to_status: status)
|
80
88
|
@status
|
81
89
|
end
|
82
90
|
|
@@ -93,6 +101,29 @@ module Moobooks
|
|
93
101
|
|
94
102
|
private
|
95
103
|
|
104
|
+
def replied?(status)
|
105
|
+
return true if Time.now - status.created_at > 900
|
106
|
+
if File.exist?("#{__dir__}/../../replies/#{@name}.json")
|
107
|
+
ids = JSON.parse(File.read("#{__dir__}/../../replies/#{@name}.json"))
|
108
|
+
replied = ids.include?(status.id)
|
109
|
+
unless replied
|
110
|
+
ids << status.id
|
111
|
+
ids = ids.to_json
|
112
|
+
File.write("#{__dir__}/../../replies/#{@name}.json", ids)
|
113
|
+
end
|
114
|
+
replied
|
115
|
+
else
|
116
|
+
ids = [status.id].to_json
|
117
|
+
File.write("#{__dir__}/../../replies/#{@name}.json", ids)
|
118
|
+
return false
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def add_dnp_words(conf)
|
123
|
+
@bad_words = %w[swastika genocide behead trap dead death woadedfox]
|
124
|
+
@bad_words += conf[:dnp] unless conf[:dnp].nil?
|
125
|
+
end
|
126
|
+
|
96
127
|
def twitter_login(apps, conf)
|
97
128
|
app = apps[conf[:api].to_sym]
|
98
129
|
@twitter_client = Twitter::REST::Client.new do |config|
|
data/lib/moobooks/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moobooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxine Michalski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
187
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.
|
188
|
+
rubygems_version: 2.7.8
|
189
189
|
signing_key:
|
190
190
|
specification_version: 4
|
191
191
|
summary: Mooing bots for your friends.
|