Skip to content

Commit

Permalink
Merge pull request #109 from LanceMaverick/improve-newbeard
Browse files Browse the repository at this point in the history
Improve newbeard
  • Loading branch information
LanceMaverick committed Mar 2, 2017
2 parents ddf87b6 + 769e5ff commit 728402e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ telepot<=10.4
pyconfig<=3.1.1
dataset<=0.7.0
dill<=0.2.6
stringcase==1.0.6
20 changes: 14 additions & 6 deletions utils/newbeard.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python

import argparse

from pathlib import Path

import stringcase


def make_readme(dir_, name):
readme_text = """A beard named {} for skybeard-2.""".format(name)
Expand All @@ -16,23 +17,30 @@ def make_init(dir_, name):
python_path.mkdir(parents=True)
init_text = '''
from skybeard.beards import BeardChatHandler
from skybeard.decorators import onerror
from skybeard.utils import get_args
class Echo(BeardChatHandler):
class {beardclassname}(BeardChatHandler):
__userhelp__ = """A simple echo beard. Echos whatever it is sent."""
__userhelp__ = """Default help message."""
__commands__ = [
# command, callback coro, help text
("echo", 'echo', 'Echos command and args')
("echo", 'echo', 'Echos arguments. e.g. <code>/echo [arg1 [arg2 ... ]]</code>')
]
# __init__ is implicit
@onerror
async def echo(self, msg):
await self.sender.sendMessage(msg['text'])
args = get_args(msg)
if args:
await self.sender.sendMessage("Args: {{}}".format(args))
else:
await self.sender.sendMessage("No arguments given.")
'''.strip()
'''.strip().format(beardclassname=stringcase.pascalcase(name))

with (python_path / Path("__init__.py")).open("w") as f:
f.write(init_text)
Expand Down

0 comments on commit 728402e

Please sign in to comment.