marxbot 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +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
data/lib/marxbot.rb ADDED
@@ -0,0 +1,221 @@
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: '!slogan') do |event|
60
+ puts "event: #{event.user.id.class}"
61
+ event.respond("\"#{get_slogan}\"")
62
+ end
63
+
64
+ @bot.message(containing: '!kneel') do |event|
65
+ has_specific = event.message.to_s.include?(">>")
66
+ specific = event.message.to_s.split(">>").last
67
+ puts "event: #{event.user.id.class}"
68
+
69
+ event.server.members.each{ |member|
70
+ begin
71
+ current = member.nick
72
+ if has_specific
73
+ new_name = specific
74
+ else
75
+ new_name = "#{get_adjective} #{get_noun}"
76
+ end
77
+
78
+ member.set_nickname(new_name)
79
+ if member.online? && false
80
+ member.pm(
81
+ "Know your place! You have been assigned #{new_name}. _All Glory to CHAOS_\n
82
+ \"#{get_slogan}\""
83
+ )
84
+ end
85
+ rescue Exception => e
86
+ puts "big OOPS #{e}"
87
+ end
88
+ }
89
+ event.respond("\"#{get_slogan}\"")
90
+ end
91
+
92
+ @bot.message(containing: '!normal') do |event|
93
+ event.server.members.each{ |member|
94
+ begin
95
+ puts member.nick
96
+ current = member.nick
97
+ new_name = member.username
98
+ member.set_nickname(new_name)
99
+ rescue Exception => e
100
+ puts "big OOPS #{e}"
101
+ end
102
+ }
103
+
104
+ response_list = [
105
+ "no fun.",
106
+ "Boooooo",
107
+ "BOOOOOO!",
108
+ "GAY",
109
+ "that's not very cash money of you.",
110
+ "Nark.",
111
+ get_lewd
112
+ ]
113
+
114
+ event.respond(response_list.sample)
115
+ end
116
+
117
+ @bot.message(containing: '!silence') do |event|
118
+ # if event.user.id.to_s == ENV['KEVIN_ID']
119
+ event.server.members.each{ |member|
120
+ begin
121
+ if member.voice_channel
122
+ puts "name: #{member.display_name}"
123
+ member.server_mute
124
+ if member.online? && false
125
+ member.pm(
126
+ "Silence.\n
127
+ \"#{get_slogan}\""
128
+ )
129
+ end
130
+ end
131
+ rescue Exception => e
132
+ puts "big OOPS #{e}"
133
+ end
134
+ }
135
+ event.respond("\"#{get_slogan}\"")
136
+ # end
137
+ end
138
+
139
+ @bot.message(containing: '!speak') do |event|
140
+ # if event.user.id.to_s == ENV['KEVIN_ID']
141
+ event.server.members.each{ |member|
142
+ begin
143
+ if member.voice_channel
144
+ puts "name: #{member.display_name}"
145
+ member.server_unmute
146
+ if member.online? && false
147
+ member.pm(
148
+ "You speak because I let you speak.\n
149
+ \"#{get_slogan}\""
150
+ )
151
+ end
152
+ end
153
+ rescue Exception => e
154
+ puts "big OOPS #{e}"
155
+ end
156
+ }
157
+ event.respond("\"#{get_slogan}\"")
158
+ # end
159
+ end
160
+
161
+ @bot.message(containing: '!lewd') do |event|
162
+ begin
163
+ if event.channel.name == "super-weenie-hut-juniors"
164
+ event.respond("https://media.giphy.com/media/5ftsmLIqktHQA/giphy.gif")
165
+ event.respond("no lewds in super-weenie-hut-juniors")
166
+ else
167
+ event.respond(get_lewd)
168
+ end
169
+ puts "event: #{event}"
170
+ rescue Exception => e
171
+ puts "big OOPS #{e}"
172
+ end
173
+ end
174
+
175
+ @bot.message(containing: '!biglewd') do |event|
176
+ begin
177
+ history = event.channel.history(limit = 100)
178
+ lewd_history = history.select{|message| message.content.include?("!lewd")}
179
+ puts "event: #{lewd_history.length}"
180
+ 20.times{ |n|
181
+ sleep(5)
182
+ event.respond(get_lewd)
183
+ }
184
+ event.respond("fine.")
185
+ rescue Exception => e
186
+ puts "big OOPS #{e}"
187
+ end
188
+ end
189
+
190
+ @bot.message(containing: '!chaste') do |event|
191
+ begin
192
+ history = event.channel.history(limit = 100)
193
+ lewd_history = history.select{|message| message.content.include?("rule34.xxx")}
194
+ if lewd_history.length < 2
195
+ lewd_history << history.find{|message| message.content.include?("!lewd")}
196
+ end
197
+ puts "event: #{lewd_history.length}"
198
+ event.channel.delete_messages(lewd_history)
199
+ event.respond("fine.")
200
+ rescue Exception => e
201
+ puts "big OOPS #{e}"
202
+ end
203
+ end
204
+
205
+ @bot.message(containing: '!fortune') do |event|
206
+ begin
207
+ fortune_teller = ::Tarot::Fortune.new()
208
+ fortune = fortune_teller.tell_fortune()
209
+ card_str = fortune[:cards].map{|card| "#{card.flipped ? "Reversed ":""} #{card.name}"}.join("\n")
210
+ result_str = fortune[:result]
211
+ event.respond("\`\`\`#{card_str}\`\`\`")
212
+ event.respond(result_str)
213
+ rescue Exception => e
214
+ puts "big OOPS #{e}"
215
+ event.respond(e)
216
+ end
217
+ end
218
+
219
+ @bot.run
220
+ end
221
+ end