Skip to content

Commit d0738d7

Browse files
committed
Add commands page
1 parent 8bec5c9 commit d0738d7

3 files changed

Lines changed: 73 additions & 4 deletions

File tree

cloudbot/web/main.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from jinja2 import Environment, PackageLoader
88

9+
from operator import attrgetter
10+
911
wi = None
1012

1113

@@ -17,6 +19,7 @@ def get_template_env():
1719
def get_application():
1820
app = Application([
1921
(r'/', TestHandler),
22+
(r'/commands/', CommandsHandler),
2023
(r"/s/(.*)", StaticFileHandler, {"path": "./cloudbot/web/static"}),
2124
])
2225
return app
@@ -35,6 +38,45 @@ def get(self):
3538
self.write(template.render(**args))
3639

3740

41+
class CommandsHandler(RequestHandler):
42+
@gen.coroutine
43+
def get(self):
44+
template = wi.env.get_template('commands.html')
45+
commands = []
46+
47+
for plugin in sorted(set(wi.bot.plugin_manager.commands.values()), key=attrgetter("name")):
48+
# use set to remove duplicate commands (from multiple aliases), and sorted to sort by name
49+
command = plugin.name
50+
51+
aliases = ", ".join([i for i in plugin.aliases if not i == command])
52+
53+
if aliases:
54+
cmd = "{} ({})".format(command, aliases)
55+
else:
56+
cmd = "{}".format(command)
57+
58+
if plugin.doc:
59+
if plugin.doc.split()[0].isalpha():
60+
doc = plugin.doc
61+
else:
62+
doc = "{} {}".format(command, plugin.doc)
63+
else:
64+
doc = "Command has no documentation.".format(command)
65+
66+
if plugin.permissions:
67+
doc += " (Permission required: {})\n\n".format(", ".join(plugin.permissions))
68+
69+
commands.append((cmd, doc))
70+
71+
args = {
72+
'bot_name': wi.config.get('bot_name', 'CloudBot'),
73+
'bot_version': cloudbot.__version__,
74+
'commands': commands
75+
}
76+
77+
self.write(template.render(**args))
78+
79+
3880
class WebInterface():
3981
def __init__(self, bot):
4082
self.bot = bot
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% extends "layout.html" %}
2+
{% set active_page = "commands" %}
3+
{% block title %}Commands - {{ super() }}{% endblock %}
4+
{% block content %}
5+
<div class="row">
6+
<div class="col-lg-12">
7+
<div class="page-header">
8+
<h2 id="container">Commands</h2>
9+
</div>
10+
<!--<p class="lead">How to use {{ bot_name }} commands.</p>-->
11+
<table class="table table-striped table-hover ">
12+
<thead>
13+
<tr>
14+
<th>Command</th>
15+
<th>Description</th>
16+
</tr>
17+
</thead>
18+
{% for cmd, doc in commands %}
19+
<tr>
20+
<td>{{ cmd }}</td>
21+
<td>{{ doc }}</td>
22+
</tr>
23+
{% endfor %}
24+
</table>
25+
</div>
26+
</div>
27+
{% endblock %}

cloudbot/web/templates/layout.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
<title>{% block title %}{{ bot_name }}{% endblock %}</title>
1919

20-
<link href="./s/css/bootstrap.min.css" rel="stylesheet">
21-
<link href="./s/css/style.css" rel="stylesheet">
20+
<link href="/s/css/bootstrap.min.css" rel="stylesheet">
21+
<link href="/s/css/style.css" rel="stylesheet">
2222

2323
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
2424
<!--[if lt IE 9]>
@@ -83,7 +83,7 @@ <h4 class="modal-title">About Me</h4>
8383

8484
<!-- javascript -->
8585
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
86-
<script src="./s/js/bootstrap.min.js"></script>
86+
<script src="/s/js/bootstrap.min.js"></script>
8787
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
88-
<script src="./s/js/ie10-viewport-bug-workaround.js"></script>
88+
<script src="/s/js/ie10-viewport-bug-workaround.js"></script>
8989
</body>

0 commit comments

Comments
 (0)