Skip to content

Commit 8bec5c9

Browse files
committed
Add webinterface config options
1 parent 5cfc284 commit 8bec5c9

5 files changed

Lines changed: 48 additions & 8 deletions

File tree

cloudbot/bot.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def __init__(self, loop=asyncio.get_event_loop()):
9898
self.db_base = declarative_base(metadata=self.db_metadata, bind=self.db_engine)
9999

100100
# create web interface
101-
self.web = WebInterface(self)
101+
if self.config.get("web", {}).get("enabled", False):
102+
self.web = WebInterface(self)
102103

103104
# set botvars so plugins can access when loading
104105
database.metadata = self.db_metadata
@@ -204,7 +205,8 @@ def _init_routine(self):
204205
yield from asyncio.gather(*[conn.connect() for conn in self.connections.values()], loop=self.loop)
205206

206207
# Activate web interface.
207-
self.web.start()
208+
if self.config.get("web", {}).get("enabled", False):
209+
self.web.start()
208210

209211
# Run a manual garbage collection cycle, to clean up any unused objects created during initialization
210212
gc.collect()

cloudbot/web/main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import cloudbot
2+
13
from tornado import gen
24
from tornado.web import Application, RequestHandler, StaticFileHandler
35
from tornado.platform.asyncio import AsyncIOMainLoop
@@ -25,18 +27,21 @@ class TestHandler(RequestHandler):
2527
def get(self):
2628
template = wi.env.get_template('basic.html')
2729
args = {
28-
'main_title': 'CloudBot',
30+
'bot_name': wi.config.get('bot_name', 'CloudBot'),
31+
'bot_version': cloudbot.__version__,
2932
'heading': 'Placeholder Page',
3033
'text': 'Lorem ipsum!'
3134
}
3235
self.write(template.render(**args))
3336

3437

3538
class WebInterface():
36-
def __init__(self, bot, port=8090, address="0.0.0.0"):
39+
def __init__(self, bot):
3740
self.bot = bot
38-
self.port = port
39-
self.address = address
41+
self.config = bot.config.get('web', {})
42+
43+
self.port = self.config.get('port', 8090)
44+
self.address = self.config.get('address', '0.0.0.0')
4045

4146
self.env = get_template_env()
4247

cloudbot/web/static/css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ body {
55
.placeholder {
66
padding: 40px 15px;
77
text-align: center;
8+
}
9+
10+
#about-dialog {
11+
top:20%;
812
}

cloudbot/web/templates/layout.html

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<meta name="author" content="">
1616
<link rel="icon" href="../../favicon.ico">
1717

18-
<title>{% block title %}{{ main_title }}{% endblock %}</title>
18+
<title>{% block title %}{{ bot_name }}{% endblock %}</title>
1919

2020
<link href="./s/css/bootstrap.min.css" rel="stylesheet">
2121
<link href="./s/css/style.css" rel="stylesheet">
@@ -40,7 +40,7 @@
4040
<span class="icon-bar"></span>
4141
<span class="icon-bar"></span>
4242
</button>
43-
<a class="navbar-brand" href="#">{{ main_title }}</a>
43+
<a class="navbar-brand" href="#">{{ bot_name }}</a>
4444
</div>
4545
<div id="navbar" class="collapse navbar-collapse">
4646
<ul class="nav navbar-nav">
@@ -49,6 +49,11 @@
4949
</li>
5050
{% endfor %}
5151
</ul>
52+
<ul class="nav navbar-nav navbar-right">
53+
<li>
54+
<a href="#" data-toggle="modal" data-target="#about-dialog">About</a>
55+
</li>
56+
</ul>
5257
</div>
5358
<!--/.nav-collapse -->
5459
</div>
@@ -58,6 +63,24 @@
5863
{% block content %}{% endblock %}
5964
</div>
6065

66+
<div class="modal fade" id="about-dialog">
67+
<div class="modal-dialog">
68+
<div class="modal-content">
69+
<div class="modal-header">
70+
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
71+
<h4 class="modal-title">About Me</h4>
72+
</div>
73+
<div class="modal-body">
74+
<p><strong>{{ bot_name }}</strong> is running version <strong>{{ bot_version }}</strong> of CloudBot.
75+
</p>
76+
</div>
77+
<div class="modal-footer">
78+
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
79+
</div>
80+
</div>
81+
</div>
82+
</div>
83+
6184
<!-- javascript -->
6285
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
6386
<script src="./s/js/bootstrap.min.js"></script>

config.default.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@
9191
],
9292
"whitelist": []
9393
},
94+
"web": {
95+
"enabled": true,
96+
"address": "0.0.0.0",
97+
"port": 8090,
98+
"bot_name": "CloudBot"
99+
},
94100
"reloading": {
95101
"config_reloading": true,
96102
"plugin_reloading": false

0 commit comments

Comments
 (0)