marxbot 0.0.4 → 0.0.6

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,242 +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
- 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
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