Ejemplo n.º 1
0
 def run_dice_format(self, num_dice, num_sides):
     """Rolls numDice number of dice, each with numSides number of sides"""
     if num_dice == 0 or num_dice > 100:
         return "Invalid number of dice."
     if num_sides == 0 or num_sides > 1000000:
         return "Invalid number of sides."
     if num_dice == 1:
         rand = Commons.get_random_int(1, num_sides)[0]
         return "I roll {}!!!".format(rand)
     else:
         dice_rolls = Commons.get_random_int(1, num_sides, num_dice)
         output_string = "I roll {}. The total is {}.".format(
             ", ".join([str(x) for x in dice_rolls]), sum(dice_rolls))
         return output_string
Ejemplo n.º 2
0
 def run(self, event):
     word_list = Commons.read_file_to_list("store/ouija_wordlist.txt")
     num_words = Commons.get_random_int(1, 3)[0]
     rand_words = Commons.get_random_choice(word_list, num_words)
     output_string = "I'm getting a message from the other side... {}.".format(
         " ".join(rand_words)
     )
     return event.create_response(output_string)
Ejemplo n.º 3
0
def test_get_random_int():
    for count in range(1, 3):
        for max_int in range(2, 10):
            for min_int in range(1, 5):
                if min_int > max_int:
                    continue
                rand_list = Commons.get_random_int(min_int, max_int, count)
                assert len(rand_list) == count, (
                    "Random integer list is the wrong length. " +
                    str(rand_list) + " not " + str(count) + " elements")
                for rand in rand_list:
                    assert rand >= min_int, ("Random integer was too small. " +
                                             str(rand) + " < " + str(min_int))
                    assert rand <= max_int, ("Random integer was too big. " +
                                             str(rand) + " > " + str(max_int))
Ejemplo n.º 4
0
 def run(self, event):
     rgb_list = Commons.get_random_int(0, 255, 3)
     hex_code = "{}{}{}".format(
         hex(rgb_list[0])[2:].zfill(2),
         hex(rgb_list[1])[2:].zfill(2),
         hex(rgb_list[2])[2:].zfill(2),
     ).upper()
     url = "https://www.thecolorapi.com/id?hex={}".format(hex_code)
     human_url = "{}&format=html".format(url)
     colour_data = Commons.load_url_json(url)
     colour_name = colour_data["name"]["value"]
     output = "Randomly chosen colour is: {} #{} or rgb({},{},{}) {}".format(
         colour_name, hex_code, rgb_list[0], rgb_list[1], rgb_list[2], human_url
     )
     return event.create_response(output)
Ejemplo n.º 5
0
 def run(self, event):
     """FOOOOOOOOOF. Format: foof"""
     rand = Commons.get_random_int(0, 60)[0]
     if rand <= 20:
         return event.create_response("doof")
     elif rand <= 40:
         return event.create_response("doooooof")
     else:
         if rand == 40 + 15:
             server_obj = event.server
             server_obj.send(event.create_response("Powering up..."))
             time.sleep(5)
             return event.create_response(
                 "d" * 100 + "o" * 1000 + "f" * 200 + "!" * 50
             )
         else:
             return event.create_response("ddddoooooooooooooooooooooffffffffff.")
Ejemplo n.º 6
0
    def run(self, event):
        """Prints ascii dragon. Format: dragon"""
        dragon_deer = r"""hmm.. nah. have another deer.
       ""\/ \/""
         "\__/"
          (oo)
 -. ______-LJ
  ,'        |
  |.____..  /
  \\      /A\
  |A      |//"""
        dragon_one = r"""                     _ _
              _     //` `\
          _,-"\%   // /``\`\
     ~^~ >__^  |% // /  } `\`\
            )  )%// / }  } }`\`\
           /  (%/'/.\_/\_/\_/\`/
          (    '         `-._`
           \   ,     (  \   _`-.__.-;%>
          /_`\ \      `\ \." `-..-'`
         ``` /_/`"-=-'`/_/
    jgs     ```       ```"""
        dragon_two = r"""           ____ __
          { --.\  |          .)%%%)%%
           '-._\\ | (\___   %)%%(%%(%%%
               `\\|{/ ^ _)-%(%%%%)%%;%%%
           .'^^^^^^^  /`    %%)%%%%)%%%'
  jgs     //\   ) ,  /       '%%%%(%%'
    ,  _.'/  `\<-- \<
     `^^^`     ^^   ^^"""
        rand = Commons.get_random_int(0, 100)[0]
        if rand == 15:
            dragon = dragon_deer
        elif rand % 2 == 0:
            dragon = dragon_one
        else:
            dragon = dragon_two
        return event.create_response(dragon)
Ejemplo n.º 7
0
 def run_range_format(self, range_min, range_max):
     """Generates a random number between rangeMin and rangeMax"""
     rand = Commons.get_random_int(range_min, range_max)[0]
     return "I roll {}!!!".format(rand)