Restructure contrib_bots bots to new layout.
In order to make the layout of all bots consistent, this commit moves each bot into a folder with its name and modifies 'run.py' so that only bots with such a structure can be executed. 'lib' gets renamed to 'bots'.
|
@ -17,7 +17,7 @@ the user home directory and add an API key.
|
||||||
Move
|
Move
|
||||||
|
|
||||||
```
|
```
|
||||||
~/zulip/contrib_bots/lib/CommuteBot/google-commute.ini
|
~/zulip/contrib_bots/bots/commute_bot/CommuteBot/google-commute.ini
|
||||||
```
|
```
|
||||||
|
|
||||||
into
|
into
|
|
@ -62,7 +62,9 @@ class CommuteHandler(object):
|
||||||
|
|
||||||
Please note:
|
Please note:
|
||||||
Fare information can be derived, though is solely dependent on the
|
Fare information can be derived, though is solely dependent on the
|
||||||
availability of the informatipython run.py lib/followup.py --config-file ~/.zuliprc-localon released by public transport operators.
|
availability of the information
|
||||||
|
python run.py bots/followup/followup.py --config-file ~/.zuliprc-local
|
||||||
|
released by public transport operators.
|
||||||
Duration in traffic can only be derived if a departure time is set.
|
Duration in traffic can only be derived if a departure time is set.
|
||||||
If a location has spaces in its name, please use a + symbol in the
|
If a location has spaces in its name, please use a + symbol in the
|
||||||
place of the space/s.
|
place of the space/s.
|
||||||
|
@ -88,7 +90,7 @@ class CommuteHandler(object):
|
||||||
# adds API Authentication Key to url request
|
# adds API Authentication Key to url request
|
||||||
def get_api_key(self):
|
def get_api_key(self):
|
||||||
# google-commute.ini must have been moved from
|
# google-commute.ini must have been moved from
|
||||||
# ~/zulip/contrib_bots/lib/CommuteBot/google-commute.ini into
|
# ~/zulip/contrib_bots/bots/commute_bot/CommuteBot/google-commute.ini into
|
||||||
# /google-commute.ini for program to work
|
# /google-commute.ini for program to work
|
||||||
# see doc.md for more information
|
# see doc.md for more information
|
||||||
with open(CONFIG_PATH) as settings:
|
with open(CONFIG_PATH) as settings:
|
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 54 KiB |
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 73 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 287 KiB After Width: | Height: | Size: 287 KiB |
Before Width: | Height: | Size: 180 KiB After Width: | Height: | Size: 180 KiB |
Before Width: | Height: | Size: 160 KiB After Width: | Height: | Size: 160 KiB |
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 170 KiB |
|
@ -9,11 +9,11 @@ from six.moves import configparser as cp
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
home = expanduser('~')
|
home = expanduser('~')
|
||||||
CONFIG_PATH = home + '/zulip/contrib_bots/lib/FourSquareBot/settings.ini'
|
CONFIG_PATH = home + '/zulip/contrib_bots/bots/foursquare/FourSquareBot/settings.ini'
|
||||||
|
|
||||||
def get_api_key():
|
def get_api_key():
|
||||||
# settings.ini must have been moved from
|
# settings.ini must have been moved from
|
||||||
# ~/zulip/contrib_bots/lib/FourSquareBot/settings.ini into
|
# ~/zulip/contrib_bots/bots/foursquare/FourSquareBot/settings.ini into
|
||||||
# ~/settings.ini for program to work
|
# ~/settings.ini for program to work
|
||||||
# see doc.md for more information
|
# see doc.md for more information
|
||||||
with open(CONFIG_PATH) as settings:
|
with open(CONFIG_PATH) as settings:
|
|
@ -27,7 +27,7 @@ Here is an example of running the `git_hub_comment` bot from
|
||||||
inside a Zulip repo:
|
inside a Zulip repo:
|
||||||
|
|
||||||
`cd ~/zulip/contrib_bots`
|
`cd ~/zulip/contrib_bots`
|
||||||
`./run.py lib/git_hub_comment.py --config-file ~/.zuliprc-prod`
|
`./run.py bots/git_hub_comment/git_hub_comment.py --config-file ~/.zuliprc-prod`
|
||||||
|
|
||||||
Once the bot code starts running, you will see a
|
Once the bot code starts running, you will see a
|
||||||
message explaining how to use the bot, as well as
|
message explaining how to use the bot, as well as
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 83 KiB |
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 49 KiB |
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
|
@ -33,7 +33,7 @@ Here is an example of running the "follow-up" bot from
|
||||||
inside a Zulip repo (and in your remote instance):
|
inside a Zulip repo (and in your remote instance):
|
||||||
|
|
||||||
cd ~/zulip/contrib_bots
|
cd ~/zulip/contrib_bots
|
||||||
./run.py lib/followup.py --config-file ~/.zuliprc-prod
|
./run.py bots/followup/followup.py --config-file ~/.zuliprc-prod
|
||||||
|
|
||||||
Once the bot code starts running, you will see a
|
Once the bot code starts running, you will see a
|
||||||
message explaining how to use the bot, as well as
|
message explaining how to use the bot, as well as
|
|
@ -1,4 +1,4 @@
|
||||||
# See zulip/contrib_bots/lib/readme.md for instructions on running this code.
|
# See zulip/contrib_bots/bots/readme.md for instructions on running this code.
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
@ -55,7 +55,7 @@ Here is an example of running the "yoda_bot" bot from
|
||||||
inside a Zulip repo:
|
inside a Zulip repo:
|
||||||
|
|
||||||
cd ~/zulip/contrib_bots
|
cd ~/zulip/contrib_bots
|
||||||
./run.py lib/yoda_bot.py --config-file ~/.zuliprc-prod
|
./run.py bots/yoda_bot/yoda_bot.py --config-file ~/.zuliprc-prod
|
||||||
|
|
||||||
Once the bot code starts running, you will see a
|
Once the bot code starts running, you will see a
|
||||||
message explaining how to use the bot, as well as
|
message explaining how to use the bot, as well as
|
Before Width: | Height: | Size: 229 KiB After Width: | Height: | Size: 229 KiB |
|
@ -12,36 +12,31 @@ sys.path.insert(0, our_dir)
|
||||||
|
|
||||||
from bot_lib import run_message_handler_for_bot
|
from bot_lib import run_message_handler_for_bot
|
||||||
|
|
||||||
def get_lib_module(lib_fn):
|
def get_lib_module(bots_fn):
|
||||||
lib_fn = os.path.abspath(lib_fn)
|
bots_fn = os.path.abspath(bots_fn)
|
||||||
if not os.path.dirname(lib_fn).startswith(os.path.join(our_dir, 'lib')):
|
if not os.path.dirname(bots_fn).startswith(os.path.join(our_dir, 'bots')):
|
||||||
print('Sorry, we will only import code from contrib_bots/lib.')
|
print('Sorry, we will only import code from contrib_bots/bots.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not lib_fn.endswith('.py'):
|
if not bots_fn.endswith('.py'):
|
||||||
print('Please use a .py extension for library files.')
|
print('Please use a .py extension for library files.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
base_bots_fn = os.path.basename(os.path.splitext(bots_fn)[0])
|
||||||
sys.path.append('lib')
|
sys.path.append('bots/{}'.format(base_bots_fn))
|
||||||
base_lib_fn = os.path.basename(os.path.splitext(lib_fn)[0])
|
module_name = base_bots_fn
|
||||||
module_name = 'lib.' + base_lib_fn
|
|
||||||
module = importlib.import_module(module_name)
|
module = importlib.import_module(module_name)
|
||||||
return module
|
return module
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
usage = '''
|
usage = '''
|
||||||
./run.py <lib file>
|
./run.py <lib file>
|
||||||
|
|
||||||
Example: ./run.py lib/followup.py
|
Example: ./run.py lib/followup.py
|
||||||
|
|
||||||
(This program loads bot-related code from the
|
(This program loads bot-related code from the
|
||||||
library code and then runs a message loop,
|
library code and then runs a message loop,
|
||||||
feeding messages to the library code to handle.)
|
feeding messages to the library code to handle.)
|
||||||
|
|
||||||
Please make sure you have a current ~/.zuliprc
|
Please make sure you have a current ~/.zuliprc
|
||||||
file with the credentials you want to use for
|
file with the credentials you want to use for
|
||||||
this bot.
|
this bot.
|
||||||
|
|
||||||
See lib/readme.md for more context.
|
See lib/readme.md for more context.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -58,7 +53,7 @@ def run():
|
||||||
print('You must specify a library!')
|
print('You must specify a library!')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
lib_module = get_lib_module(lib_fn=args[0])
|
lib_module = get_lib_module(bots_fn=args[0])
|
||||||
|
|
||||||
if not options.quiet:
|
if not options.quiet:
|
||||||
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
|
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
|
||||||
|
|
|
@ -457,7 +457,7 @@ def build_custom_checkers(by_lang):
|
||||||
failed = True
|
failed = True
|
||||||
|
|
||||||
markdown_docs_length_exclude = {
|
markdown_docs_length_exclude = {
|
||||||
"contrib_bots/lib/ConverterBot/docs.md",
|
"contrib_bots/bots/converter/ConverterBot/docs.md",
|
||||||
"docs/bots-guide.md",
|
"docs/bots-guide.md",
|
||||||
"docs/dev-env-first-time-contributors.md",
|
"docs/dev-env-first-time-contributors.md",
|
||||||
"docs/integration-guide.md",
|
"docs/integration-guide.md",
|
||||||
|
|