bots: Move all bots and the bots API to separate package.

This commit is contained in:
Eeshan Garg 2017-07-18 01:47:16 -02:30
parent 928d5ca16d
commit 879f44ab3a
130 changed files with 183 additions and 144 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

View file

@ -0,0 +1,45 @@
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, bot_handler, state_handler):
bot_response = self.get_bot_encrypt_response(message)
bot_handler.send_reply(message, bot_response)
def get_bot_encrypt_response(self, message):
original_content = message['content']
temp_content = encrypt(original_content)
send_content = "Encrypted/Decrypted text: " + temp_content
return send_content
handler_class = EncryptHandler
if __name__ == '__main__':
assert encrypt('ABCDabcd1234') == 'NOPQnopq1234'
assert encrypt('NOPQnopq1234') == 'ABCDabcd1234'

View file

@ -0,0 +1,16 @@
About EncryptBot:
EncryptBot Allows for quick ROT13 encryption in the middle of a chat.
What It Does:
The bot encrypts any message sent to it on any stream it is subscribed to with ROT13.
How It Works:
The bot will Use ROT13(A -> N, B -> O... and vice-versa) in a python
implementation to provide quick and easy encryption.
How to Use:
-Send the message you want to encrypt, add @encrypt to the beginning.
-The Encrypted message will be sent back to the stream the original
message was posted in to the topic <sender-email>'s encrypted text.
-Messages can be decrypted by sending them to EncryptBot in the same way.

View file

@ -0,0 +1,19 @@
#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import print_function
from zulip_bots.test_lib import BotTestCase
class TestEncryptBot(BotTestCase):
bot_name = "encrypt"
def test_bot(self):
expected = {
"": "Encrypted/Decrypted text: ",
"Let\'s Do It": "Encrypted/Decrypted text: Yrg\'f Qb Vg",
"me&mom together..!!": "Encrypted/Decrypted text: zr&zbz gbtrgure..!!",
"foo bar": "Encrypted/Decrypted text: sbb one",
"Please encrypt this": "Encrypted/Decrypted text: Cyrnfr rapelcg guvf",
}
self.check_expected_responses(expected)