python-zulip-api/contrib_bots/bots/encrypt_bot/encrypt_bot.py
Abhijeet Kaur 9a8dc7c622 Remove triage_message() function from all the contrib-bots.
To make all bots consistent add shared function in bot_lib.py
to check if this bot is called. All bots respond to at-mention of
the bot instead of their specific names.
2017-02-17 06:51:48 -08:00

48 lines
1.5 KiB
Python
Executable file

def encrypt(text):
# This is where the actual ROT13 is applied
# WHY IS .JOIN NOT WORKING?!
textlist = list(text)
newtext = ''
firsthalf = 'abcdefghijklmABCDEFGHIJKLM'
lasthalf = 'nopqrstuvwxyzNOPQRSTUVWXYZ'
for char in textlist:
if char in firsthalf:
newtext += lasthalf[firsthalf.index(char)]
elif char in lasthalf:
newtext += firsthalf[lasthalf.index(char)]
else:
newtext += char
return newtext
class EncryptHandler(object):
'''
This bot allows users to quickly encrypt messages using ROT13 encryption.
It encrypts/decrypts messages starting with @mention-bot.
'''
def usage(self):
return '''
This bot uses ROT13 encryption for its purposes.
It responds to me starting with @mention-bot.
Feeding encrypted messages into the bot decrypts them.
'''
def handle_message(self, message, client, state_handler):
original_content = message['content']
temp_content = encrypt(original_content)
send_content = "Encrypted/Decrypted text: " + temp_content
client.send_message(dict(
type='stream',
to=message['display_recipient'],
subject=message['subject'],
content = send_content
))
handler_class = EncryptHandler
if __name__ == '__main__':
assert encrypt('ABCDabcd1234') == 'NOPQnopq1234'
assert encrypt('NOPQnopq1234') == 'ABCDabcd1234'