bots: Move contrib_bots to api/bots*.
This will make it convenient to include these bots in Zulip API releases on pypi. Fix #5009.
This commit is contained in:
parent
7531c4fb26
commit
894adb1e43
110 changed files with 36 additions and 27 deletions
0
bots/encrypt/__init__.py
Normal file
0
bots/encrypt/__init__.py
Normal file
BIN
bots/encrypt/assets/EncryptBot-terminal.png
Normal file
BIN
bots/encrypt/assets/EncryptBot-terminal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 287 KiB |
BIN
bots/encrypt/assets/EncryptBot-test.png
Normal file
BIN
bots/encrypt/assets/EncryptBot-test.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 180 KiB |
BIN
bots/encrypt/assets/EncryptBot-test2.png
Normal file
BIN
bots/encrypt/assets/EncryptBot-test2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 160 KiB |
BIN
bots/encrypt/assets/EncryptBot-test3.png
Normal file
BIN
bots/encrypt/assets/EncryptBot-test3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 170 KiB |
45
bots/encrypt/encrypt.py
Executable file
45
bots/encrypt/encrypt.py
Executable 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, client, state_handler):
|
||||
bot_response = self.get_bot_encrypt_response(message)
|
||||
client.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'
|
16
bots/encrypt/readme.md
Normal file
16
bots/encrypt/readme.md
Normal 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.
|
27
bots/encrypt/test_encrypt.py
Normal file
27
bots/encrypt/test_encrypt.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
our_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.insert(0, os.path.normpath(os.path.join(our_dir)))
|
||||
# For dev setups, we can find the API in the repo itself.
|
||||
if os.path.exists(os.path.join(our_dir, '..')):
|
||||
sys.path.insert(0, '..')
|
||||
from 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)
|
Loading…
Add table
Add a link
Reference in a new issue