This module contains code that reads tweet text and figures out how the bot should do in response.
More...
|
def | _represents_int (s) |
| Returns true if the given string represents an integer value. More...
|
|
def | _clamp (n, smallest, largest) |
| Clamps the given number within the range smallest, largest. More...
|
|
def | _add_shape_type_for_keywords (dict, shape_keywords, shape_name) |
| Adds the given items to the given dictionary, mapping each keyword to the given shape name. More...
|
|
def | _make_shape_keyword_dictionary () |
| Creates a dictionary mapping shape keywords to canonical shape names used by ChaiScript scripts Provides a convenient way to map words in tweets like "rects" to the shape type "RECTANGLE". More...
|
|
def | _max_quantity_for_shape_type (shape_type) |
| Gets the maximum number of shapes allowed for the given shape type This to to set a sensible limit on the length of time the bot will spend on a single image. More...
|
|
def | _plural_name_for_shape_type (shape_type) |
| Gets a human-readable name for the given shape type. More...
|
|
def | _make_loop_body (shape_type) |
| Helper for constructing a ChaiScript script for geometrizing shapes. More...
|
|
def | _make_for_loop (step_count, shape_type) |
| Helper for constructing a ChaiScript script for geometrizing shapes. More...
|
|
def | _make_shape_code (dict) |
| Helper for constructing a ChaiScript script for geometrizing shapes. More...
|
|
def | make_shape_quantity_dictionary (message) |
| Parses a tweet message and returns a dictionary of the shape types and quantities that were requested. More...
|
|
def | make_code_for_shape_tweet (message) |
| Parses the given tweet, returning the ChaiScript code for Geometrize to run based on the contents of the tweet. More...
|
|
def | make_message_for_shape_dictionary (shape_quantity_dictionary) |
| Creates a message for the given shape dictionary, suitable for tweeting along with the result of running the script. More...
|
|
|
list | _rect_keywords = [ "rect", "rects", "rectangle", "rectangles" ] |
|
list | _rotated_rect_keywords = [ "rotated_rect", "rotated_rects", "rotated_rectangle", "rotated_rectangles" ] |
|
list | _triangle_keywords = [ "tri", "tris", "triangle", "triangles" ] |
|
list | _ellipse_keywords = [ "ellipse", "ellipses" ] |
|
list | _rotated_ellipse_keywords = [ "rotated_ellipse", "rotated_ellipses" ] |
|
list | _circle_keywords = [ "circ", "circs", "circle", "circles" ] |
|
list | _line_keywords = [ "line", "lines" ] |
|
list | _quadratic_bezier_keywords = [ "bezier", "beziers", "quadratic_bezier", "quadratic_beziers" ] |
|
list | _polyline_keywords = [ "polyline", "polylines" ] |
|
This module contains code that reads tweet text and figures out how the bot should do in response.
def tweet_parser.make_code_for_shape_tweet |
( |
|
message | ) |
|
Parses the given tweet, returning the ChaiScript code for Geometrize to run based on the contents of the tweet.
The shapes are added in the order they are specified in the message. Message examples: "@Geometrizer triangles=30 and rectangles=20, thanks bot!" - produces an image with 30 triangles, then 20 rectangles. Or: "@Geometrizer triangles=30 circles=500, triangles=20, nice bot!" - produces an image with 30 triangles, 500 circles, 20 triangles. Or: "@Geometrizer tris=300 circs=200" - produces an image with 300 triangles, 200 circles. Or: "@Geometrize rotated_rects=500" - produces an image with 500 rotated rectangles. Or: "@Geometrizer this is a really cool bot!" - produces an image with a random selection and quantity of shapes. :return A chunk of ChaiScript code that adds the shapes that the tweet requests (must be combined with a larger script to work).
137 if shape_quantity_dictionary:
140 print(
"Creating specific shapes and quantities code for tweet")
141 return code, shape_quantity_dictionary
144 print(
"Creating random shapes code for tweet")
147 shape_types = [
'ROTATED_RECTANGLE',
'ROTATED_ELLIPSE',
'TRIANGLE',
'CIRCLE',
'ELLIPSE']
148 shape_type = random.choice(shape_types)
149 shape_quantity = random.randint(200, 500)
150 shape_quantity_dictionary[shape_type] = shape_quantity
153 return code, shape_quantity_dictionary