diff --git a/bot/traductions.py b/bot/traductions.py index ce446ee..f02e7dd 100644 --- a/bot/traductions.py +++ b/bot/traductions.py @@ -28,7 +28,7 @@ tr = { }, "list_modules": { "title": "Liste des modules", - }, + }, "load": { }, "unload": { diff --git a/log_config.json b/log_config.json index 91e469e..fa7d94a 100644 --- a/log_config.json +++ b/log_config.json @@ -18,7 +18,7 @@ "level": "INFO", "formatter": "simple", "filename": "info.log", - "maxBytes": 10485760, + "maxBytes": 1048576, "backupCount": 20, "encoding": "utf8" }, @@ -27,7 +27,7 @@ "level": "ERROR", "formatter": "simple", "filename": "errors.log", - "maxBytes": 10485760, + "maxBytes": 1048576, "backupCount": 20, "encoding": "utf8" }, diff --git a/main.py b/main.py index 21cf92a..0e39547 100644 --- a/main.py +++ b/main.py @@ -73,7 +73,6 @@ setup_logging() eventloop = asyncio.get_event_loop() foBot = FoBot(db_connection=db_connection) - foWeb = FoWeb(bot=None, db=db_connection) bot_app = foBot.start(os.environ['FOBOT_DISCORD_TOKEN'], max_messages=100000000) diff --git a/web/server.py b/web/server.py index 4e9b744..a2f3c90 100644 --- a/web/server.py +++ b/web/server.py @@ -11,7 +11,7 @@ import tornado.web def maybe_create_tables(db): with db.cursor() as cur: - #cur.execute("DROP TABLE users ") + # cur.execute("DROP TABLE users ") cur.execute("CREATE TABLE IF NOT EXISTS users (" " id int(5) NOT NULL AUTO_INCREMENT PRIMARY KEY," " email VARCHAR(100) NOT NULL UNIQUE," @@ -146,7 +146,6 @@ class AuthLoginHandler(BaseHandler): try: user = self.queryone("SELECT * FROM users WHERE email = %s", self.get_argument("email")) - print(user) except NoResultError: get_arg = self.get_argument self.render("auth/login.html", error="Email not found or bad password", get_arg=get_arg) @@ -171,18 +170,21 @@ class AuthLogoutHandler(BaseHandler): class AuthCreateHandler(BaseHandler): async def get(self): get_arg = self.get_argument - self.render("auth/create_user.html", get_arg=get_arg) + self.render("auth/create_user.html", error=None, get_arg=get_arg) async def post(self): hashed_password = await tornado.ioloop.IOLoop.current().run_in_executor( None, bcrypt.hashpw, tornado.escape.utf8(self.get_argument("password")), bcrypt.gensalt() ) - self.execute("INSERT INTO users (email, name, hashed_password) VALUES (%s, %s, %s)", - self.get_argument("email"), self.get_argument("name"), - tornado.escape.to_unicode(hashed_password)) - users = self.queryone("SELECT * FROM users WHERE email = %s", self.get_argument("email")) - print(users) + try: + get_arg = self.get_argument + self.execute("INSERT INTO users (email, name, hashed_password) VALUES (%s, %s, %s)", + self.get_argument("email"), self.get_argument("name"), + tornado.escape.to_unicode(hashed_password)) + users = self.queryone("SELECT * FROM users WHERE email = %s", self.get_argument("email")) + except: + self.render("auth/create_user.html", error="Email already exists.", get_arg=get_arg) self.set_secure_cookie("blogdemo_user", str(users.id)) self.redirect(self.get_argument("next", "/")) @@ -193,7 +195,7 @@ class BlogHomeHandler(BaseHandler): if not entries: self.redirect("/blog/compose") return - self.render("blog\\index.html", entries=entries) + self.render("blog/index.html", entries=entries) class BlogPostHandler(BaseHandler): @@ -202,7 +204,7 @@ class BlogPostHandler(BaseHandler): if not entry: raise tornado.web.HTTPError(404) - self.render("blog\\entry.html", entry=entry) + self.render("blog/entry.html", entry=entry) class BotConnectHandler(BaseHandler): @@ -213,9 +215,14 @@ class BotConfigureHandler(BaseHandler): pass +class BotHelpHandler(BaseHandler): + async def get(self): + self.render("bot/help.html") + + class BlogEntryModule(tornado.web.UIModule): def render(self, entry): - return self.render_string("blog\\modules\\entry.html", entry=entry) + return self.render_string("blog/modules/entry.html", entry=entry) class FoWeb(tornado.web.Application): @@ -231,7 +238,8 @@ class FoWeb(tornado.web.Application): (r"/blog", BlogHomeHandler), (r"/blog/entry/([^/]+)", BlogPostHandler), (r"/bot/connect", BotConnectHandler), - (r"/bot/configure", BotConfigureHandler) + (r"/bot/configure", BotConfigureHandler), + (r"/bot/help", BotHelpHandler) ] settings = dict( website_title=u"FoBot", diff --git a/web/static/base.css b/web/static/base.css index 712959f..3d14c3d 100644 --- a/web/static/base.css +++ b/web/static/base.css @@ -1,137 +1,136 @@ body { - background: white; - color: black; - margin: 15px; - margin-top: 0; + background: white; + color: black; + margin: 15px; + margin-top: 0; } body, input, textarea { - font-family: Georgia, serif; - font-size: 12pt; + font-family: Georgia, serif; + font-size: 12pt; } table { - border-collapse: collapse; - border: 0; + border-collapse: collapse; + border: 0; } td { - border: 0; - padding: 0; + border: 0; + padding: 0; } h1, h2, h3, h4 { - font-family: "Helvetica Nue", Helvetica, Arial, sans-serif; - margin: 0; + font-family: "Helvetica Nue", Helvetica, Arial, sans-serif; + margin: 0; } h1 { - font-size: 20pt; + font-size: 20pt; } pre, code { - font-family: monospace; - color: #060; + font-family: monospace; + color: #060; } pre { - margin-left: 1em; - padding-left: 1em; - border-left: 1px solid silver; - line-height: 14pt; + margin-left: 1em; + padding-left: 1em; + border-left: 1px solid silver; + line-height: 14pt; } a, a code { - color: #00c; + color: #060; } #body { - max-width: 800px; - margin: auto; + margin: auto; } #header { - background-color: #3b5998; - padding: 5px; - padding-left: 10px; - padding-right: 10px; - margin-bottom: 1em; + background-color: #359; + padding: 5px; + padding-left: 10px; + padding-right: 10px; + margin-bottom: 1em; } #header, #header a { - color: white; + color: white; } #header h1 a { - text-decoration: none; + text-decoration: none; } #footer, #content { - margin-left: 10px; - margin-right: 10px; + margin-left: 10px; + margin-right: 10px; } #footer { - margin-top: 3em; + margin-top: 3em; } .entry h1 a { - color: black; - text-decoration: none; + color: black; + text-decoration: none; } .entry { - margin-bottom: 2em; + margin-bottom: 2em; } .entry .date { - margin-top: 3px; + margin-top: 3px; } .entry p { - margin: 0; - margin-bottom: 1em; + margin: 0; + margin-bottom: 1em; } .entry .body { - margin-top: 1em; - line-height: 16pt; + margin-top: 1em; + line-height: 16pt; } .compose td { - vertical-align: middle; - padding-bottom: 5px; + vertical-align: middle; + padding-bottom: 5px; } .compose td.field { - padding-right: 10px; + padding-right: 10px; } .compose .title, .compose .submit { - font-family: "Helvetica Nue", Helvetica, Arial, sans-serif; - font-weight: bold; + font-family: "Helvetica Nue", Helvetica, Arial, sans-serif; + font-weight: bold; } .compose .title { - font-size: 20pt; + font-size: 20pt; } .compose .title, .compose .markdown { - width: 100%; + width: 100%; } .compose .markdown { - height: 500px; - line-height: 16pt; + height: 500px; + line-height: 16pt; } \ No newline at end of file diff --git a/web/static/documentation.css b/web/static/documentation.css new file mode 100644 index 0000000..46f74ae --- /dev/null +++ b/web/static/documentation.css @@ -0,0 +1,74 @@ +.documentation { + +} + +.documentation .summary { + margin:0; + padding: 0; + border: 0.25em solid #3b5998; + position: fixed; + overflow: auto; + width: 25%; + margin:0; +} + +.documentation .summary h2 { + background-color: #3b5998; + padding: 0.4em; +} + +.documentation .summary ul { + list-style-type: none; + padding: 0; + margin: 0; +} + +.documentation .summary ul li { + display: block; + padding: 0; +} + +.documentation .summary ul li ul { + display: none; +} + +.documentation .summary ul li:hover ul { + display: block; +} + +.documentation .summary a { + background-color: #5889ef; + color: black; + display: block; + padding: 0.3em; + text-decoration: none; +} + +.documentation .summary a:hover { + background-color: #496ebc; +} + +.documentation .summary a:active { + background-color: #4CAF50; /* Add a green color to the "active/current" link */ + color: white; +} + +.documentation .content { + margin-left: 28%; +} + +.documentation .content h2 { + padding: 1em; +} + +.documentation .content h3 { + padding: 0.5em; +} + +.documentation .content h4 { + padding: 0.25em; +} + +.documentation .content ul { + list-style-type: none; +} \ No newline at end of file diff --git a/web/templates/auth/create_user.html b/web/templates/auth/create_user.html index 2770e9f..932bb43 100644 --- a/web/templates/auth/create_user.html +++ b/web/templates/auth/create_user.html @@ -1,11 +1,14 @@ {% extends "../base.html" %} {% block body %} -
- Email:
- Name:
- Password:
- {% module xsrf_form_html() %} - -
+ {% if error %} + Error: {{ error }}

+ {% end %} +

+ Email:
+ Name:
+ Password:
+ {% module xsrf_form_html() %} + +
{% end %} \ No newline at end of file diff --git a/web/templates/bot/help.html b/web/templates/bot/help.html new file mode 100644 index 0000000..776e09c --- /dev/null +++ b/web/templates/bot/help.html @@ -0,0 +1,108 @@ +{% extends "../base.html" %} + +{% block head %} + +{% end %} + +{% block title %} {{ escape(handler.settings["website_title"]) }} - Help{% end %} + +{% block body %} +
+
+

Summary

+ +
+
+

Modules (modules)

+
+

Liste des modules (list_modules)

+
+

Commande permettant de lister les modules disponibles. (réservé aux administrateurs)

+
+

Exemples:

+
    +
  • list_modules: retourne la liste des modules disponibles
  • +
+
+
+

Charger un module (load)

+
+

Commande permettant de charger des modules. (réservé aux administrateurs)

+
+

Exemples:

+
    +
  • load help: charge le module help
  • +
  • load help module1 module2 ...: charger les modules help, + module1, + module2, + ... +
  • +
+
+
+

Décharger un module (unload)

+
+

Commande permettant de décharger des modules. (réservé aux administrateurs)

+
+

Exemples:

+
    +
  • unload module: décharge le module module
  • +
  • unload module1 module2 module3 ...: décharge les modules module1, + module2, + module3, ... +
  • +
+
+
+
+

Help (help)

+
+

Aide générale

+
+

Commande permettant de lister les différentes commandes actives sur le bot.

+
+

Exemples:

+
    +
  • help: Afficher la liste des commandes
  • +
+
+
+

Aide d'un module précit

+
+

Commande permmetant d'afficher la description de toutes les commandes d'un module.

+
+

Exemples:

+
    +
  • help modules: Affiche la description de toutes les commandes du module + modules +
  • +
+
+
+
+
+
+{% end %} \ No newline at end of file