Skip to content

Commit

Permalink
beard related handlers moved to beards.py to avoid cyclic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
LanceMaverick committed Feb 5, 2017
1 parent d1191e0 commit 3390846
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
20 changes: 0 additions & 20 deletions skybeard/api.py

This file was deleted.

21 changes: 18 additions & 3 deletions skybeard/beards.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .bearddbtable import BeardDBTable
from .logging import TelegramHandler
from .predicates import command_predicate
from .server import async_post, async_get
from skybeard.server import async_post, async_get, web

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -68,7 +68,6 @@ class Beard(type):
beards = list()

def __new__(mcs, name, bases, dct):
print(mcs, name, bases, dct)
if "__userhelp__" not in dct:
dct["__userhelp__"] = ("The author has not defined a "
"<code>__userhelp__</code> for this beard.")
Expand Down Expand Up @@ -280,5 +279,21 @@ async def on_chat_message(self, msg):
cmd.coro(msg)
else:
await getattr(self, cmd.coro)(msg)


@async_get('/loadedBeards')
async def loaded_beards(request):
return web.json_response([str(x) for x in Beard.beards])

@async_get('/availableCommands')
async def available_commands(request):
d = {}
for beard in Beard.beards:
cmds = []
for cmd in beard.__commands__:
if isinstance(cmd, SlashCommand):
cmds.append(dict(command = cmd.cmd, hint = cmd.hlp))
if cmds:
d[beard.__name__] = cmds

return web.json_response(d)

3 changes: 1 addition & 2 deletions skybeard/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from aiohttp import web
from functools import wraps, partial
#from skybeard.beards import Beard, SlashCommand
from aiohttp import web

app = web.Application()

Expand Down

0 comments on commit 3390846

Please sign in to comment.