3 def rot_string(str, n=13):
4 """Return a rotated version of a string
6 Specifically, this functions returns a version of the input string
7 where each uppercase letter has been advanced 'n' positions in the
8 alphabet (wrapping around). Lowercase letters and any non-alphabetic
9 characters will be unchanged."""
14 result += chr(ord("A") + (ord(letter) - ord("A") + n) % 26)
20 """Implements logic for /rot slash command in Slack, returning a string
22 This implements the /rot command of our Slack bot. The format of this
23 command is as follows:
25 /rot [count|*] String to be rotated
27 The optional count indicates an amount to rotate each character in the
28 string. If the count is '*' or is not present, then the string will
29 be rotated through all possible 25 values.
31 The result of the rotation is returned as a string (with Slack
34 match = re.match(r'^([0-9]+|\*) (.*)$', args)
37 count = int(match.group(1))
47 reply = "```/rot {} {}\n".format(count if count else '*', text)
50 reply += rot_string(text, count)
52 reply += "\n".join(["{:02d} ".format(count) + rot_string(text, count)
53 for count in range(1, 26)])
59 def lambda_handler(event, context):
60 """Top-level entry point for our lambda function.
62 Currently only calls into the rot() function but may become more
63 sophisticated later on."""
65 result = rot(event['args'])