Class: MarxBot

Inherits:
Object
  • Object
show all
Defined in:
lib/marxbot.rb

Instance Method Summary collapse

Constructor Details

#initialize(token:) ⇒ MarxBot

Returns a new instance of MarxBot.



10
11
12
13
14
15
16
# File 'lib/marxbot.rb', line 10

def initialize(token:)
  @token = token
  @bot = Discordrb::Bot.new token: @token
  @noun_path = File.join(File.dirname(__FILE__), "noun.json")
  @adjective_path = File.join(File.dirname(__FILE__), "adjective.json")
  @slogan_path = File.join(File.dirname(__FILE__), "slogans.json")
end

Instance Method Details

#adjective_dictObject



44
45
46
# File 'lib/marxbot.rb', line 44

def adjective_dict
  return JSON.parse(File.read(@adjective_path))
end

#get_adjectiveObject



24
25
26
27
28
# File 'lib/marxbot.rb', line 24

def get_adjective()
  adjectives = adjective_dict["adjs"]
  adj_choice = Random.new.rand(adjectives.length)
  return adjectives[adj_choice]
end

#get_lewdObject



48
49
50
51
52
# File 'lib/marxbot.rb', line 48

def get_lewd()
  lewd_page = Nokogiri::HTML(URI.open('https://rule34.xxx/index.php?page=post&s=random'))
  lewd_link = lewd_page.css('img')[2].attributes["src"].value
  return lewd_link
end

#get_nounObject



30
31
32
33
34
# File 'lib/marxbot.rb', line 30

def get_noun()
  nouns = noun_dict["nouns"]
  noun_choice = Random.new.rand(nouns.length)
  return nouns[noun_choice]
end

#get_sloganObject



18
19
20
21
22
# File 'lib/marxbot.rb', line 18

def get_slogan()
  all_slogans = slogan_dict["slogans"]
  slogan_number = Random.new.rand(all_slogans.length)
  return all_slogans[slogan_number]
end

#noun_dictObject



40
41
42
# File 'lib/marxbot.rb', line 40

def noun_dict
  return JSON.parse(File.read(@noun_path))
end

#runObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/marxbot.rb', line 54

def run()
  @bot.message(content: 'ping') do |event|
    event.respond 'pong'
  end

  @bot.message(containing: '!sleep') do |event|
     event.respond("\"Good night Moon.\"")
     @bot.stop
  end

  @bot.message(containing: '!slogan') do |event|
    puts "event: #{event.user.id.class}"
      event.respond("\"#{get_slogan}\"")
  end

  @bot.message(containing: '!kneel') do |event|
    has_specific = event.message.to_s.include?(">>")
    specific = event.message.to_s.split(">>").last
    puts "event: #{event.user.id.class}"

    event.server.members.each{ |member|
      begin
        current = member.nick
        if has_specific
          new_name = specific
        else
          new_name = "#{get_adjective} #{get_noun}"
        end

        member.set_nickname(new_name)
        if member.online? && false
          member.pm(
            "Know your place! You have been assigned #{new_name}. _All Glory to CHAOS_\n
            \"#{get_slogan}\""
          )
        end
      rescue Exception => e
        puts "big OOPS #{e}"
      end
    }
     event.respond("\"#{get_slogan}\"")
  end

  @bot.message(containing: '!normal') do |event|
    event.server.members.each{ |member|
      begin
         puts member.nick
        current = member.nick
        new_name = member.username
        member.set_nickname(new_name)
      rescue Exception => e
        puts "big OOPS #{e}"
      end
    }

    response_list = [
      "no fun.",
      "Boooooo",
      "BOOOOOO!",
      "GAY",
      "that's not very cash money of you.",
      "Nark.",
      get_lewd
    ]

    event.respond(response_list.sample)
  end

  @bot.message(containing: '!silence') do |event|
    # if event.user.id.to_s == ENV['KEVIN_ID']

      event.server.members.each{ |member|
        begin
          if member.voice_channel
            puts "name: #{member.display_name}"
            member.server_mute
            if member.online? && false
              member.pm(
                "Silence.\n
                \"#{get_slogan}\""
              )
            end
          end
        rescue Exception => e
          puts "big OOPS #{e}"
        end
      }
      event.respond("\"#{get_slogan}\"")
    # end

  end

  @bot.message(containing: '!speak') do |event|
    # if event.user.id.to_s == ENV['KEVIN_ID']

      event.server.members.each{ |member|
        begin
          if member.voice_channel
            puts "name: #{member.display_name}"
            member.server_unmute
            if member.online? && false
              member.pm(
                "You speak because I let you speak.\n
                \"#{get_slogan}\""
              )
            end
          end
        rescue Exception => e
          puts "big OOPS #{e}"
        end
      }
      event.respond("\"#{get_slogan}\"")
    # end

  end

  @bot.message(containing: '!lewd') do |event|
    begin
      if event.channel.name == "super-weenie-hut-juniors"
        event.respond("https://media.giphy.com/media/5ftsmLIqktHQA/giphy.gif")
        event.respond("no lewds in super-weenie-hut-juniors")
      else
        event.respond(get_lewd)
      end
      puts "event: #{event}"
    rescue Exception => e
      puts "big OOPS #{e}"
    end
  end

  @bot.message(containing: '!biglewd') do |event|
    begin
      history = event.channel.history(limit = 100)
      lewd_history = history.select{|message| message.content.include?("!lewd")}
      puts "event: #{lewd_history.length}"
      20.times{ |n|
        sleep(5)
        event.respond(get_lewd)
      }
      event.respond("fine.")
    rescue Exception => e
      puts "big OOPS #{e}"
    end
  end

  @bot.message(containing: '!chaste') do |event|
    begin
      history = event.channel.history(limit = 100)
      lewd_history = history.select{|message| message.content.include?("rule34.xxx")}
      if lewd_history.length < 2
        lewd_history << history.find{|message| message.content.include?("!lewd")}
      end
      puts "event: #{lewd_history.length}"
      event.channel.delete_messages(lewd_history)
      event.respond("fine.")
    rescue Exception => e
      puts "big OOPS #{e}"
    end
  end

  @bot.message(containing: '!fortune') do |event|
    begin
      fortune_teller = ::Tarot::Fortune.new()
      fortune = fortune_teller.tell_fortune()
      card_str = fortune[:cards].map{|card| "#{card.flipped ? "Reversed ":""} #{card.name}"}.join("\n")
      result_str = fortune[:result]
      event.respond("\`\`\`#{card_str}\`\`\`")
      event.respond(result_str)
    rescue Exception => e
      puts "big OOPS #{e}"
      event.respond(e)
    end
  end

  @bot.run
end

#slogan_dictObject



36
37
38
# File 'lib/marxbot.rb', line 36

def slogan_dict
  return JSON.parse(File.read(@slogan_path))
end