/* * discordlistforbots * Copyright (C) 2021 niansa * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include #include using namespace std; struct Bot { string name, short_description, long_description, avatar_url, owner, support_server, prefix; uint64_t owner_id, app_id; int64_t votes = 0; bool approved = false; }; struct SessionData { uint64_t discord_id; std::string discord_access_token, discord_username, discord_discriminator; bool moderator; std::string discord_fullname(); }; using SessionDataPtr = std::shared_ptr; class LoginFilter:public drogon::HttpFilter { public: virtual void doFilter(const drogon::HttpRequestPtr &, drogon::FilterCallback &&, drogon::FilterChainCallback &&) override; }; using namespace drogon; class views: public drogon::HttpController { orm::DbClientPtr db; std::unordered_map last_votes; std::vector moderators; public: views(); static std::string htmlBr(const std::string&); void start(const HttpRequestPtr&, std::function &&); void imprint(const HttpRequestPtr&, std::function &&); void menu(const HttpRequestPtr&, std::function &&); void botlist(const HttpRequestPtr&, std::function &&); void botdetail(const HttpRequestPtr&, std::function &&, uint64_t); void botvote(const HttpRequestPtr&, std::function &&, uint64_t); void botedit(const HttpRequestPtr&, std::function &&, uint64_t, const std::string&); void botregister_view(const HttpRequestPtr&, std::function &&, const std::string&); void botregister_submit(const HttpRequestPtr&, std::function &&); void discordauth(const HttpRequestPtr&, std::function &&, const std::string&); void discorddeauth(const HttpRequestPtr&, std::function &&); METHOD_LIST_BEGIN ADD_METHOD_TO(views::start, "/", Get); ADD_METHOD_TO(views::imprint, "/imprint", Get); ADD_METHOD_TO(views::botlist, "/bots/@all", Get); ADD_METHOD_TO(views::botlist, "/bots/@me", Get, "LoginFilter"); ADD_METHOD_TO(views::botlist, "/bots/@unapproved", Get, "LoginFilter"); ADD_METHOD_TO(views::botregister_view, "/bots/register?error={1}", Get, "LoginFilter"); ADD_METHOD_TO(views::botregister_submit, "/bots/register", Post, "LoginFilter"); ADD_METHOD_TO(views::botdetail, "/bots/{1}/detail", Get); ADD_METHOD_TO(views::botvote, "/bots/{1}/vote", Get, "LoginFilter"); ADD_METHOD_TO(views::botedit, "/bots/{1}/edit/{2}", Get, Post, "LoginFilter"); ADD_METHOD_TO(views::discordauth, "/discordauth?code={1}", Get); ADD_METHOD_TO(views::discorddeauth, "/discorddeauth", Get); ADD_METHOD_TO(views::menu, "/menu", Get); METHOD_LIST_END };