contrib_bots: Restructure bots to follow a consistent structure.

Now all the bots that are stored in contrib_bots are in the
same file/directory format.
The format is specified here #3427. Add tests.py file for encrypt_bot as well.
Fixes #3427.
This commit is contained in:
Abhijeet Kaur 2017-02-09 02:35:24 +05:30 committed by showell
parent 92219aa3dd
commit 87e8d9036f
43 changed files with 80 additions and 46 deletions

View File

@ -6,7 +6,7 @@ from os.path import expanduser
from six.moves import configparser as cp
home = expanduser('~')
CONFIG_PATH = home + '/google-commute.ini'
CONFIG_PATH = home + '/commute_bot.config'
class CommuteHandler(object):
'''
@ -89,10 +89,10 @@ class CommuteHandler(object):
# adds API Authentication Key to url request
def get_api_key(self):
# google-commute.ini must have been moved from
# ~/zulip/contrib_bots/bots/commute_bot/CommuteBot/google-commute.ini into
# /google-commute.ini for program to work
# see doc.md for more information
# commute_bot.config must have been moved from
# ~/zulip/contrib_bots/bots/commute_bot/commute_bot.config into
# /commute_bot.config for program to work
# see readme.md for more information
with open(CONFIG_PATH) as settings:
config = cp.ConfigParser()
config.readfp(settings)

View File

@ -11,24 +11,24 @@ units and information in various languages.
The bot will respond to the same stream input was in. And if called as
private message, the bot will reply with a private message.
To setup the bot, you will first need to move google-commute.ini into
To setup the bot, you will first need to move commute_bot.config into
the user home directory and add an API key.
Move
```
~/zulip/contrib_bots/bots/commute_bot/CommuteBot/google-commute.ini
~/zulip/contrib_bots/bots/commute_bot/commute_bot.config
```
into
```
~/google-commute.ini
~/commute_bot.config
```
To add an API key, please visit:
https://developers.google.com/maps/documentation/distance-matrix/start
to retrieve a key and copy your api key into google-commute.ini
to retrieve a key and copy your api key into commute_bot.config
Sample input and output:

View File

@ -20,6 +20,7 @@ def test():
expected: %s
but got : %s
''' % (cmd, expected_response, client_dummy.output))
def sample_conversation():
return [
('@convert 2 m cm', '2.0 m = 200.0 cm\n'),

View File

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 73 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 287 KiB

After

Width:  |  Height:  |  Size: 287 KiB

View File

Before

Width:  |  Height:  |  Size: 180 KiB

After

Width:  |  Height:  |  Size: 180 KiB

View File

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 160 KiB

View File

Before

Width:  |  Height:  |  Size: 170 KiB

After

Width:  |  Height:  |  Size: 170 KiB

View File

@ -0,0 +1,33 @@
import encrypt_bot
def test():
for cmd, expected_response in sample_conversation():
message = {'content': cmd, 'subject': 'foo',
'display_recipient': 'bar'}
class ClientDummy(object):
def __init__(self):
self.output = ''
def send_message(self, params):
self.output = params['content']
handler = encrypt_bot.EncryptHandler()
client_dummy = ClientDummy()
handler.handle_message(message, client_dummy, '')
if client_dummy.output != expected_response:
raise AssertionError('''
cmd: %s
expected: %s
but got : %s
''' % (cmd, expected_response, client_dummy.output))
def sample_conversation():
return [
('@encrypt Please encrypt this', 'Encrypted/Decrypted text: Cyrnfr rapelcg guvf'),
('@encrypt Let\'s Do It', 'Encrypted/Decrypted text: Yrg\'f Qb Vg'),
('@encrypt ', 'Encrypted/Decrypted text: '),
('@encrypt me&mom together..!!', 'Encrypted/Decrypted text: zr&zbz gbtrgure..!!'),
]
if __name__ == '__main__':
test()

View File

@ -9,13 +9,13 @@ from six.moves import configparser as cp
from six.moves import range
home = expanduser('~')
CONFIG_PATH = home + '/zulip/contrib_bots/bots/foursquare/FourSquareBot/settings.ini'
CONFIG_PATH = home + '/zulip/contrib_bots/bots/foursquare/foursquare.config'
def get_api_key():
# settings.ini must have been moved from
# ~/zulip/contrib_bots/bots/foursquare/FourSquareBot/settings.ini into
# ~/settings.ini for program to work
# see doc.md for more information
# foursquare.config must have been moved from
# ~/zulip/contrib_bots/bots/foursquare/foursquare.config into
# ~/foursquare.config for program to work
# see readme.md for more information
with open(CONFIG_PATH) as settings:
config = cp.ConfigParser()
config.readfp(settings)

View File

@ -1,4 +1,4 @@
# See readme-github-comment-bot.md for instructions on running this code.
# See readme.md for instructions on running this code.
from __future__ import absolute_import
from __future__ import print_function
from . import github

View File

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 56 KiB

View File

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 56 KiB

View File

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

View File

@ -23,24 +23,24 @@ answer will be formatted differently depending the chosen command.
Question -> `@howdowe use supervisor in elixir`
![howdowe question](question_howdowe.png)
![howdowe question](assets/question_howdowe.png)
Answer -> Howdoi would try to **only** respond with the coding section
of the answer.
![howdowe answer](answer_howdowe.png)
![howdowe answer](assets/answer_howdowe.png)
#### Example 2
Question -> `@howdoi! stack vs heap`
![howdoi! question](question_howdoi_all.png)
![howdoi! question](assets/question_howdoi_all.png)
Answer -> Howdoi would return the **full** stackoverflow answer via
**private message** to the original sender. The URL of the answer can be
seen at the bottom of the message.
![howdoi! answer](answer_howdoi_all.png)
![howdoi! answer](assets/answer_howdoi_all.png)
**Note:**

View File

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 83 KiB

View File

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

View File

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -15,10 +15,10 @@ CONTRIB_BOTS_DIR = os.path.dirname(os.path.abspath(__file__))
os.chdir(os.path.dirname(CONTRIB_BOTS_DIR))
sys.path.insert(0, os.path.dirname(CONTRIB_BOTS_DIR))
JOKES_PATH = os.path.join(CONTRIB_BOTS_DIR, 'John/var/jokes.json')
DATABASE_PATH = os.path.join(CONTRIB_BOTS_DIR, 'John/var/database.db')
DIRECTORY_PATH = os.path.join(CONTRIB_BOTS_DIR, 'John')
VAR_PATH = os.path.join(CONTRIB_BOTS_DIR, 'John/var')
JOKES_PATH = os.path.join(CONTRIB_BOTS_DIR, 'assets/var/jokes.json')
DATABASE_PATH = os.path.join(CONTRIB_BOTS_DIR, 'assets/var/database.db')
DIRECTORY_PATH = os.path.join(CONTRIB_BOTS_DIR, 'assets')
VAR_PATH = os.path.join(CONTRIB_BOTS_DIR, 'assets/var')
if not os.path.exists(DIRECTORY_PATH):
os.makedirs(DIRECTORY_PATH)

View File

@ -10,7 +10,7 @@ interactive bot that uses machine learning heuristics to simulate a
conversation with the user. He has a great sense of humor and
is also powered by Open Source code!
![Joke John](joke.png)
![Joke John](assets/joke.png)
How it works?
John is initially trained with Corpus files, or large text files.
@ -20,11 +20,11 @@ try to find the response that best matches the input according to the Levenshtei
which is a string metric for measuring the difference between two sequences. If several
responses have the same acurracy, he will choose one at random.
![Meet John](greetings.png)
![Meet John](assets/greetings.png)
Can he learn by himself?
John's engine allows him to learn from his conversations with people. However,
without strict supervision bots that learn from people can do harm, so learning
is currently restricted to his initial corpus.
![Assist](assist.png)
![Assist](assets/assist.png)

View File

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 43 KiB

View File

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 45 KiB

View File

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -12,29 +12,29 @@ xkcd bot has four commands:
1. `help`
This command is used to list all commands that can be used with this bot.
You can use this command by typing `@xkcd help` in a stream.
![](xkcd-help.png)
![](assets/xkcd-help.png)
2. `latest`
This command is used to fetch the latest comic strip from xkcd. You can use
this command by typing `@xkcd latest` in a stream.
![](xkcd-latest.png)
![](assets/xkcd-latest.png)
3. `random`
This command is used to fetch a random comic strip from xkcd. You can use
this command by typing `@xkcd random` in a stream, xkcd bot will post a
random xkcd comic strip.
![](xkcd-random.png)
![](assets/xkcd-random.png)
4. `<comic_id>`
To fetch a comic strip based on id, you can directly use `@xkcd <comic_id>`,
for example if you want to fetch a comic strip with id 1234, you can type
`@xkcd 1234`, xkcd bot will post a comic strip with id 1234.
![](xkcd-specific-id.png)
![](assets/xkcd-specific-id.png)
If you type a wrong command to xkcd bot, xkcd bot will post information
you'd get from `@xkcd help`.
![](xkcd-wrong-command.png)
![](assets/xkcd-wrong-command.png)
And if you type a wrong id, xkcd bot will post a message that an xkcd comic
strip with that id is not available.
![](xkcd-wrong-id.png)
![](assets/xkcd-wrong-id.png)

View File

Before

Width:  |  Height:  |  Size: 229 KiB

After

Width:  |  Height:  |  Size: 229 KiB

View File

@ -17,7 +17,7 @@ Go to this link:
This is the API that powers the `yoda_bot`. You can read more about it
on this page.
![yoda api overview](yoda-speak-api.png)
![yoda api overview](assets/yoda-speak-api.png)
Click on the **Sign Up Free** button at the top and create
an account. Then click on the **Documentation** tab. Scroll down to the
@ -29,9 +29,9 @@ the Yoda Speak API to. Click on the blue **GET THE KEYS** button.
On the pop-up that comes up, click on the **COPY** button.
This is your Mashape API Key. It is used
to authenticate. Store it in the `yoda_api_key.txt` file.
to authenticate. Store it in the `yoda_bot.config` file.
The `yoda_api_key.txt` file should be located at `~/yoda_api_key.txt`.
The `yoda_bot.config` file should be located at `~/yoda_bot.config`.
Example input:

View File

@ -1,4 +1,4 @@
# See readme-yoda-bot.md for instructions on running this code.
# See readme.md for instructions on running this code.
from __future__ import print_function
import os
@ -17,9 +17,9 @@ HELP_MESSAGE = '''
Users should preface messages with '@yoda'.
Before running this, make sure to get a Mashape Api token.
Instructions are in the 'readme-yoda-bot.md' file.
Store it in the 'yoda_api_key.txt' file.
The 'yoda_api_key.txt' file should be located at '~/yoda_api_key.txt'.
Instructions are in the 'readme.md' file.
Store it in the 'yoda_bot.config' file.
The 'yoda_bot.config' file should be located at '~/yoda_bot.config'.
Example input:
@yoda You will learn how to speak like me someday.
'''
@ -42,9 +42,9 @@ class YodaSpeakHandler(object):
Users should preface messages with '@yoda'.
Before running this, make sure to get a Mashape Api token.
Instructions are in the 'readme-yoda-bot.md' file.
Store it in the 'yoda_api_key.txt' file.
The 'yoda_api_key.txt' file should be located at '~/yoda_api_key.txt'.
Instructions are in the 'readme.md' file.
Store it in the 'yoda_bot.config' file.
The 'yoda_bot.config' file should be located at '~/yoda_bot.config'.
Example input:
@yoda You will learn how to speak like me someday.
'''
@ -85,7 +85,7 @@ def send_to_yoda_api(sentence, api_key):
logging.error(error_message)
error_code = response.status_code
error_message = error_message + 'Error code: ' + error_code +\
' Did you follow the instructions in the `readme-yoda-bot.md` file?'
' Did you follow the instructions in the `readme.md` file?'
return error_message
@ -115,7 +115,7 @@ def handle_input(client, original_content, stream, subject):
except ApiKeyError:
reply_message = 'Invalid Api Key. Did you follow the instructions in the ' \
'`readme-yoda-bot.md` file?'
'`readme.md` file?'
logging.error(reply_message)
send_message(client, reply_message, stream, subject)
@ -124,7 +124,7 @@ def handle_input(client, original_content, stream, subject):
def get_api_key():
# function for getting Mashape api key
home = os.path.expanduser('~')
with open(home + '/yoda_api_key.txt') as api_key_file:
with open(home + '/yoda_bot.config') as api_key_file:
api_key = api_key_file.read().strip()
return api_key

View File

@ -542,7 +542,7 @@ def build_custom_checkers(by_lang):
failed = True
markdown_docs_length_exclude = {
"contrib_bots/bots/converter/docs.md",
"contrib_bots/bots/converter/readme.md",
"docs/bots-guide.md",
"docs/dev-env-first-time-contributors.md",
"docs/webhook-walkthrough.md",