marxbot 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,48 +1,48 @@
1
- require "json"
2
- require "pry"
3
- require_relative "card"
4
- module Tarot
5
- class Fortune
6
- attr_reader :hand, :hand_size, :deck
7
- def initialize()
8
- @deck = Card.deck_json
9
- @hand_size = 6
10
- @hand = draw_hand()
11
- end
12
-
13
- def draw_hand()
14
- cards = []
15
- hand_size.times do |i|
16
- flipped = [true,false].sample
17
- card_data = deck.sample
18
- deck.reject!{|c| c == card_data}
19
- # binding.pry
20
- cards << Card.new(card_data, flipped)
21
- end
22
-
23
- return cards
24
- end
25
-
26
- def tell_fortune()
27
- puts hand.map{|card| "#{card.flipped} #{card.name}"}
28
- return {
29
- cards: hand,
30
- result: fortune_structures.sample
31
- }
32
- end
33
-
34
- def fortune_structures()
35
- lines = [
36
- "#{hand[0].adjective} #{hand[1].noun} #{maybe_word} #{hand[2].verb} #{link_word} #{hand[3].noun}"
37
- ]
38
- end
39
-
40
- def link_word
41
- ["for", "because of", "thanks to", "and so", "thus, the"].sample
42
- end
43
-
44
- def maybe_word
45
- ["will", "could", "shall", "ought to", "should"].sample
46
- end
47
- end
48
- end
1
+ require "json"
2
+ require "pry"
3
+ require_relative "card"
4
+ module Tarot
5
+ class Fortune
6
+ attr_reader :hand, :hand_size, :deck
7
+ def initialize()
8
+ @deck = Card.deck_json
9
+ @hand_size = 6
10
+ @hand = draw_hand()
11
+ end
12
+
13
+ def draw_hand()
14
+ cards = []
15
+ hand_size.times do |i|
16
+ flipped = [true,false].sample
17
+ card_data = deck.sample
18
+ deck.reject!{|c| c == card_data}
19
+ # binding.pry
20
+ cards << Card.new(card_data, flipped)
21
+ end
22
+
23
+ return cards
24
+ end
25
+
26
+ def tell_fortune()
27
+ puts hand.map{|card| "#{card.flipped} #{card.name}"}
28
+ return {
29
+ cards: hand,
30
+ result: fortune_structures.sample
31
+ }
32
+ end
33
+
34
+ def fortune_structures()
35
+ lines = [
36
+ "#{hand[0].adjective} #{hand[1].noun} #{maybe_word} #{hand[2].verb} #{link_word} #{hand[3].noun}"
37
+ ]
38
+ end
39
+
40
+ def link_word
41
+ ["for", "because of", "thanks to", "and so", "thus, the"].sample
42
+ end
43
+
44
+ def maybe_word
45
+ ["will", "could", "shall", "ought to", "should"].sample
46
+ end
47
+ end
48
+ end
data/lib/marxbot.rb CHANGED
@@ -1,226 +1,242 @@
1
- require 'discordrb'
2
- require 'dotenv/load' # Only for local use
3
- require 'nokogiri'
4
- require 'open-uri'
5
- require_relative 'marxbot/tarot/fortune'
6
- # require 'pry'
7
-
8
-
9
- class MarxBot
10
- def initialize(token:)
11
- @token = token
12
- @bot = Discordrb::Bot.new token: @token
13
- @noun_path = File.join(File.dirname(__FILE__), "noun.json")
14
- @adjective_path = File.join(File.dirname(__FILE__), "adjective.json")
15
- @slogan_path = File.join(File.dirname(__FILE__), "slogans.json")
16
- end
17
-
18
- def get_slogan()
19
- all_slogans = slogan_dict["slogans"]
20
- slogan_number = Random.new.rand(all_slogans.length)
21
- return all_slogans[slogan_number]
22
- end
23
-
24
- def get_adjective()
25
- adjectives = adjective_dict["adjs"]
26
- adj_choice = Random.new.rand(adjectives.length)
27
- return adjectives[adj_choice]
28
- end
29
-
30
- def get_noun()
31
- nouns = noun_dict["nouns"]
32
- noun_choice = Random.new.rand(nouns.length)
33
- return nouns[noun_choice]
34
- end
35
-
36
- def slogan_dict
37
- return JSON.parse(File.read(@slogan_path))
38
- end
39
-
40
- def noun_dict
41
- return JSON.parse(File.read(@noun_path))
42
- end
43
-
44
- def adjective_dict
45
- return JSON.parse(File.read(@adjective_path))
46
- end
47
-
48
- def get_lewd()
49
- lewd_page = Nokogiri::HTML(URI.open('https://rule34.xxx/index.php?page=post&s=random'))
50
- lewd_link = lewd_page.css('img')[2].attributes["src"].value
51
- return lewd_link
52
- end
53
-
54
- def run()
55
- @bot.message(content: 'ping') do |event|
56
- event.respond 'pong'
57
- end
58
-
59
- @bot.message(containing: '!sleep') do |event|
60
- event.respond("\"Good night Moon.\"")
61
- @bot.stop
62
- end
63
-
64
- @bot.message(containing: '!slogan') do |event|
65
- puts "event: #{event.user.id.class}"
66
- event.respond("\"#{get_slogan}\"")
67
- end
68
-
69
- @bot.message(containing: '!kneel') do |event|
70
- has_specific = event.message.to_s.include?(">>")
71
- specific = event.message.to_s.split(">>").last
72
- puts "event: #{event.user.id.class}"
73
-
74
- event.server.members.each{ |member|
75
- begin
76
- current = member.nick
77
- if has_specific
78
- new_name = specific
79
- else
80
- new_name = "#{get_adjective} #{get_noun}"
81
- end
82
-
83
- member.set_nickname(new_name)
84
- if member.online? && false
85
- member.pm(
86
- "Know your place! You have been assigned #{new_name}. _All Glory to CHAOS_\n
87
- \"#{get_slogan}\""
88
- )
89
- end
90
- rescue Exception => e
91
- puts "big OOPS #{e}"
92
- end
93
- }
94
- event.respond("\"#{get_slogan}\"")
95
- end
96
-
97
- @bot.message(containing: '!normal') do |event|
98
- event.server.members.each{ |member|
99
- begin
100
- puts member.nick
101
- current = member.nick
102
- new_name = member.username
103
- member.set_nickname(new_name)
104
- rescue Exception => e
105
- puts "big OOPS #{e}"
106
- end
107
- }
108
-
109
- response_list = [
110
- "no fun.",
111
- "Boooooo",
112
- "BOOOOOO!",
113
- "GAY",
114
- "that's not very cash money of you.",
115
- "Nark.",
116
- get_lewd
117
- ]
118
-
119
- event.respond(response_list.sample)
120
- end
121
-
122
- @bot.message(containing: '!silence') do |event|
123
- # if event.user.id.to_s == ENV['KEVIN_ID']
124
- event.server.members.each{ |member|
125
- begin
126
- if member.voice_channel
127
- puts "name: #{member.display_name}"
128
- member.server_mute
129
- if member.online? && false
130
- member.pm(
131
- "Silence.\n
132
- \"#{get_slogan}\""
133
- )
134
- end
135
- end
136
- rescue Exception => e
137
- puts "big OOPS #{e}"
138
- end
139
- }
140
- event.respond("\"#{get_slogan}\"")
141
- # end
142
- end
143
-
144
- @bot.message(containing: '!speak') do |event|
145
- # if event.user.id.to_s == ENV['KEVIN_ID']
146
- event.server.members.each{ |member|
147
- begin
148
- if member.voice_channel
149
- puts "name: #{member.display_name}"
150
- member.server_unmute
151
- if member.online? && false
152
- member.pm(
153
- "You speak because I let you speak.\n
154
- \"#{get_slogan}\""
155
- )
156
- end
157
- end
158
- rescue Exception => e
159
- puts "big OOPS #{e}"
160
- end
161
- }
162
- event.respond("\"#{get_slogan}\"")
163
- # end
164
- end
165
-
166
- @bot.message(containing: '!lewd') do |event|
167
- begin
168
- if event.channel.name == "super-weenie-hut-juniors"
169
- event.respond("https://media.giphy.com/media/5ftsmLIqktHQA/giphy.gif")
170
- event.respond("no lewds in super-weenie-hut-juniors")
171
- else
172
- event.respond(get_lewd)
173
- end
174
- puts "event: #{event}"
175
- rescue Exception => e
176
- puts "big OOPS #{e}"
177
- end
178
- end
179
-
180
- @bot.message(containing: '!biglewd') do |event|
181
- begin
182
- history = event.channel.history(limit = 100)
183
- lewd_history = history.select{|message| message.content.include?("!lewd")}
184
- puts "event: #{lewd_history.length}"
185
- 20.times{ |n|
186
- sleep(5)
187
- event.respond(get_lewd)
188
- }
189
- event.respond("fine.")
190
- rescue Exception => e
191
- puts "big OOPS #{e}"
192
- end
193
- end
194
-
195
- @bot.message(containing: '!chaste') do |event|
196
- begin
197
- history = event.channel.history(limit = 100)
198
- lewd_history = history.select{|message| message.content.include?("rule34.xxx")}
199
- if lewd_history.length < 2
200
- lewd_history << history.find{|message| message.content.include?("!lewd")}
201
- end
202
- puts "event: #{lewd_history.length}"
203
- event.channel.delete_messages(lewd_history)
204
- event.respond("fine.")
205
- rescue Exception => e
206
- puts "big OOPS #{e}"
207
- end
208
- end
209
-
210
- @bot.message(containing: '!fortune') do |event|
211
- begin
212
- fortune_teller = ::Tarot::Fortune.new()
213
- fortune = fortune_teller.tell_fortune()
214
- card_str = fortune[:cards].map{|card| "#{card.flipped ? "Reversed ":""} #{card.name}"}.join("\n")
215
- result_str = fortune[:result]
216
- event.respond("\`\`\`#{card_str}\`\`\`")
217
- event.respond(result_str)
218
- rescue Exception => e
219
- puts "big OOPS #{e}"
220
- event.respond(e)
221
- end
222
- end
223
-
224
- @bot.run
225
- end
226
- end
1
+ require 'discordrb'
2
+ # require 'dotenv/load' # Only for local use
3
+ require 'nokogiri'
4
+ require 'open-uri'
5
+ require_relative 'marxbot/tarot/fortune'
6
+ # require 'pry'
7
+
8
+
9
+ class MarxBot
10
+ attr_reader :bot, :auto_stop, :stop_time
11
+ def initialize(token:, auto_stop:false, stop_time:60*15)
12
+ @token = token
13
+ @auto_stop = auto_stop
14
+ @stop_time = stop_time
15
+ @bot = Discordrb::Bot.new token: @token
16
+ @noun_path = File.join(File.dirname(__FILE__), "noun.json")
17
+ @adjective_path = File.join(File.dirname(__FILE__), "adjective.json")
18
+ @slogan_path = File.join(File.dirname(__FILE__), "slogans.json")
19
+ end
20
+
21
+ def stop_eventually()
22
+ sleep(@stop_time)
23
+ @bot.stop
24
+ puts "$$$ The Bot should be stopped $$$"
25
+ end
26
+
27
+ def get_slogan()
28
+ all_slogans = slogan_dict["slogans"]
29
+ slogan_number = Random.new.rand(all_slogans.length)
30
+ return all_slogans[slogan_number]
31
+ end
32
+
33
+ def get_adjective()
34
+ adjectives = adjective_dict["adjs"]
35
+ adj_choice = Random.new.rand(adjectives.length)
36
+ return adjectives[adj_choice]
37
+ end
38
+
39
+ def get_noun()
40
+ nouns = noun_dict["nouns"]
41
+ noun_choice = Random.new.rand(nouns.length)
42
+ return nouns[noun_choice]
43
+ end
44
+
45
+ def slogan_dict
46
+ return JSON.parse(File.read(@slogan_path))
47
+ end
48
+
49
+ def noun_dict
50
+ return JSON.parse(File.read(@noun_path))
51
+ end
52
+
53
+ def adjective_dict
54
+ return JSON.parse(File.read(@adjective_path))
55
+ end
56
+
57
+ def get_lewd()
58
+ lewd_page = Nokogiri::HTML(URI.open('https://rule34.xxx/index.php?page=post&s=random'))
59
+ lewd_link = lewd_page.css('img')[2].attributes["src"].value
60
+ return lewd_link
61
+ end
62
+
63
+ def run()
64
+ @bot.message(content: 'ping') do |event|
65
+ event.respond 'pong'
66
+ end
67
+
68
+ @bot.message(containing: '!sleep') do |event|
69
+ event.respond("\"Good night Moon.\"")
70
+ @bot.stop
71
+ end
72
+
73
+ @bot.message(containing: '!slogan') do |event|
74
+ puts "event: #{event.user.id.class}"
75
+ event.respond("\"#{get_slogan}\"")
76
+ end
77
+
78
+ @bot.message(containing: '!kneel') do |event|
79
+ has_specific = event.message.to_s.include?(">>")
80
+ specific = event.message.to_s.split(">>").last
81
+ puts "event: #{event.user.id.class}"
82
+
83
+ event.server.members.each{ |member|
84
+ begin
85
+ current = member.nick
86
+ if has_specific
87
+ new_name = specific
88
+ else
89
+ new_name = "#{get_adjective} #{get_noun}"
90
+ end
91
+
92
+ member.set_nickname(new_name)
93
+ if member.online? && false
94
+ member.pm(
95
+ "Know your place! You have been assigned #{new_name}. _All Glory to CHAOS_\n
96
+ \"#{get_slogan}\""
97
+ )
98
+ end
99
+ rescue Exception => e
100
+ puts "big OOPS #{e}"
101
+ end
102
+ }
103
+ event.respond("\"#{get_slogan}\"")
104
+ end
105
+
106
+ @bot.message(containing: '!normal') do |event|
107
+ event.server.members.each{ |member|
108
+ begin
109
+ puts member.nick
110
+ current = member.nick
111
+ new_name = member.username
112
+ member.set_nickname(new_name)
113
+ rescue Exception => e
114
+ puts "big OOPS #{e}"
115
+ end
116
+ }
117
+
118
+ response_list = [
119
+ "no fun.",
120
+ "Boooooo",
121
+ "BOOOOOO!",
122
+ "GAY",
123
+ "that's not very cash money of you.",
124
+ "Nark.",
125
+ get_lewd
126
+ ]
127
+
128
+ event.respond(response_list.sample)
129
+ end
130
+
131
+ @bot.message(containing: '!silence') do |event|
132
+ # if event.user.id.to_s == ENV['KEVIN_ID']
133
+ event.server.members.each{ |member|
134
+ begin
135
+ if member.voice_channel
136
+ puts "name: #{member.display_name}"
137
+ member.server_mute
138
+ if member.online? && false
139
+ member.pm(
140
+ "Silence.\n
141
+ \"#{get_slogan}\""
142
+ )
143
+ end
144
+ end
145
+ rescue Exception => e
146
+ puts "big OOPS #{e}"
147
+ end
148
+ }
149
+ event.respond("\"#{get_slogan}\"")
150
+ # end
151
+ end
152
+
153
+ @bot.message(containing: '!speak') do |event|
154
+ # if event.user.id.to_s == ENV['KEVIN_ID']
155
+ event.server.members.each{ |member|
156
+ begin
157
+ if member.voice_channel
158
+ puts "name: #{member.display_name}"
159
+ member.server_unmute
160
+ if member.online? && false
161
+ member.pm(
162
+ "You speak because I let you speak.\n
163
+ \"#{get_slogan}\""
164
+ )
165
+ end
166
+ end
167
+ rescue Exception => e
168
+ puts "big OOPS #{e}"
169
+ end
170
+ }
171
+ event.respond("\"#{get_slogan}\"")
172
+ # end
173
+ end
174
+
175
+ @bot.message(containing: '!lewd') do |event|
176
+ begin
177
+ if event.channel.name == "super-weenie-hut-juniors"
178
+ event.respond("https://media.giphy.com/media/5ftsmLIqktHQA/giphy.gif")
179
+ event.respond("no lewds in super-weenie-hut-juniors")
180
+ else
181
+ event.respond(get_lewd)
182
+ end
183
+ puts "event: #{event}"
184
+ rescue Exception => e
185
+ puts "big OOPS #{e}"
186
+ end
187
+ end
188
+
189
+ @bot.message(containing: '!biglewd') do |event|
190
+ begin
191
+ history = event.channel.history(limit = 100)
192
+ lewd_history = history.select{|message| message.content.include?("!lewd")}
193
+ puts "event: #{lewd_history.length}"
194
+ 20.times{ |n|
195
+ sleep(5)
196
+ event.respond(get_lewd)
197
+ }
198
+ event.respond("fine.")
199
+ rescue Exception => e
200
+ puts "big OOPS #{e}"
201
+ end
202
+ end
203
+
204
+ @bot.message(containing: '!chaste') do |event|
205
+ begin
206
+ history = event.channel.history(limit = 100)
207
+ lewd_history = history.select{|message| message.content.include?("rule34.xxx")}
208
+ if lewd_history.length < 2
209
+ lewd_history << history.find{|message| message.content.include?("!lewd")}
210
+ end
211
+ puts "event: #{lewd_history.length}"
212
+ event.channel.delete_messages(lewd_history)
213
+ event.respond("fine.")
214
+ rescue Exception => e
215
+ puts "big OOPS #{e}"
216
+ end
217
+ end
218
+
219
+ @bot.message(containing: '!fortune') do |event|
220
+ begin
221
+ fortune_teller = ::Tarot::Fortune.new()
222
+ fortune = fortune_teller.tell_fortune()
223
+ card_str = fortune[:cards].map{|card| "#{card.flipped ? "Reversed ":""} #{card.name}"}.join("\n")
224
+ result_str = fortune[:result]
225
+ event.respond("\`\`\`#{card_str}\`\`\`")
226
+ event.respond(result_str)
227
+ rescue Exception => e
228
+ puts "big OOPS #{e}"
229
+ event.respond(e)
230
+ end
231
+ end
232
+
233
+ if @auto_stop
234
+ threads = []
235
+ threads << Thread.new { @bot.run }
236
+ threads << Thread.new { self.stop_eventually() }
237
+ threads.each(&:join)
238
+ else
239
+ @bot.run
240
+ end
241
+ end
242
+ end