mirror of
https://gitlab.com/niansa/discordlistforbots.git
synced 2025-03-06 20:49:22 +01:00
Improved main style
This commit is contained in:
parent
e2a0711941
commit
4a4d0dcbf4
6 changed files with 105 additions and 30 deletions
2
config.h
2
config.h
|
@ -14,4 +14,6 @@
|
|||
#define REDIRECT_URI "http://localhost:8082/discordauth"
|
||||
#define BOT_TOKEN "Nzk3NTY1NTkyODM1NDU3MDI0.X_oU1w.fCVL8j58pphoEaU7e3q4yH7cFa4"
|
||||
|
||||
#define MODERATORS {609486822715818000}
|
||||
|
||||
#define COMMUNITY "https://discord.gg/ZMj5ytaQRZ"
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "../config.h"
|
||||
#include "views.h"
|
||||
|
||||
static unordered_map <std::string, trantor::Date> last_votes;
|
||||
#define authenticate(cb) cb(HttpResponse::newRedirectionResponse(OAUTH_URL)); return
|
||||
#define toStartPage(cb) cb(HttpResponse::newRedirectionResponse("/")); return
|
||||
#define voteID(uid, bid) std::to_string(uid)+'-'+std::to_string(bid)
|
||||
|
@ -117,6 +116,7 @@ void LoginFilter::doFilter(const HttpRequestPtr &req, FilterCallback &&fcb, Filt
|
|||
|
||||
views::views() {
|
||||
db = drogon::app().getDbClient();
|
||||
moderators = MODERATORS;
|
||||
}
|
||||
|
||||
void views::start(
|
||||
|
@ -175,7 +175,7 @@ void views::botdetail(
|
|||
uint64_t bot_id)
|
||||
{
|
||||
db->execSqlAsync("SELECT * FROM bots WHERE app_id = '"+std::to_string(bot_id)+"'",
|
||||
[req, callback, bot_id] (const orm::Result &rows) {
|
||||
[this, req, callback, bot_id] (const orm::Result &rows) {
|
||||
if (rows.empty()) {
|
||||
// Bot not found
|
||||
callback(HttpResponse::newNotFoundResponse());
|
||||
|
@ -184,10 +184,7 @@ void views::botdetail(
|
|||
auto sessionData = getSessionData(req->session());
|
||||
auto bot = deserializeBot(rows[0]);
|
||||
auto data = HttpViewDataPrep(sessionData);
|
||||
data.insert("modView", false);
|
||||
data.insert("bot_id", bot.app_id);
|
||||
data.insert("bot", bot);
|
||||
data.insert("owner", sessionData and sessionData->discord_id == bot.owner_id);
|
||||
if (not sessionData) {
|
||||
// Vote button is not grezed out if user isn"t logged in
|
||||
data.insert("canVote", bot.approved);
|
||||
|
@ -213,7 +210,7 @@ void views::botvote(const HttpRequestPtr& req, std::function<void (const HttpRes
|
|||
})
|
||||
// Register vote
|
||||
db->execSqlAsync("UPDATE bots SET votes = votes + 1 WHERE app_id = '"+std::to_string(bot_id)+"'",
|
||||
[vote_id, callback] (const orm::Result &rows) {
|
||||
[this, vote_id, callback] (const orm::Result &rows) {
|
||||
if (rows.affectedRows() == 0) {
|
||||
// Bot not found
|
||||
callback(HttpResponse::newNotFoundResponse());
|
||||
|
@ -227,6 +224,37 @@ void views::botvote(const HttpRequestPtr& req, std::function<void (const HttpRes
|
|||
});
|
||||
}
|
||||
|
||||
void views::botedit(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback,
|
||||
uint64_t bot_id, const std::string& action) {
|
||||
auto sessionData = getSessionData(req->session());
|
||||
db->execSqlAsync("SELECT * FROM bots WHERE app_id = '"+std::to_string(bot_id)+"'",
|
||||
[sessionData, callback, action] (const orm::Result &rows) {
|
||||
if (rows.empty()) {
|
||||
callback(HttpResponse::newNotFoundResponse());
|
||||
} else {
|
||||
auto bot = deserializeBot(rows[0]);
|
||||
// Check if user is botowner or moderator
|
||||
if (sessionData->discord_id == bot.owner_id or sessionData->moderator) {
|
||||
// Get action
|
||||
if (action == "edit") {
|
||||
// TODO
|
||||
} else if (action == "delete") {
|
||||
// TODO
|
||||
} else if (not sessionData->moderator) {
|
||||
goto else_part;
|
||||
} else if (action == "approve") {
|
||||
// TODO
|
||||
} else if (action == "decline") {
|
||||
// TODO
|
||||
} else {
|
||||
else_part:
|
||||
callback(HttpResponse::newNotFoundResponse());
|
||||
}
|
||||
}
|
||||
}
|
||||
}, dbErr);
|
||||
}
|
||||
|
||||
void views::botregister_view(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback,
|
||||
const std::string& error) {
|
||||
// Display page
|
||||
|
@ -309,7 +337,7 @@ void views::discordauth(
|
|||
req->setParameter("scope", "identify");
|
||||
req->setParameter("code", code);
|
||||
}
|
||||
discordapi->sendRequest(req, [discordapi, client_req, callback] (ReqResult, const HttpResponsePtr &response) {
|
||||
discordapi->sendRequest(req, [this, discordapi, client_req, callback] (ReqResult, const HttpResponsePtr &response) {
|
||||
// Check for success
|
||||
if (response->getStatusCode() == HttpStatusCode::k200OK) {
|
||||
// Auth success
|
||||
|
@ -324,13 +352,14 @@ void views::discordauth(
|
|||
req->setPath("/api/v8/users/@me");
|
||||
req->setMethod(HttpMethod::Get);
|
||||
req->addHeader("Authorization", "Bearer "+sessionData->discord_access_token);
|
||||
discordapi->sendRequest(req, [client_req, callback, session, sessionData] (ReqResult, const HttpResponsePtr &response) {
|
||||
discordapi->sendRequest(req, [this, client_req, callback, session, sessionData] (ReqResult, const HttpResponsePtr &response) {
|
||||
if (response->getStatusCode() == HttpStatusCode::k200OK) {
|
||||
// Getting user data success
|
||||
auto &userdata = *response->getJsonObject().get();
|
||||
sessionData->discord_id = std::stoul(userdata["id"].asString());
|
||||
sessionData->discord_username = userdata["username"].asString();
|
||||
sessionData->discord_discriminator = userdata["discriminator"].asString();
|
||||
sessionData->moderator = std::find(moderators.begin(), moderators.end(), sessionData->discord_id) != moderators.end();
|
||||
setSessionData(session, sessionData);
|
||||
// Show success page
|
||||
auto data = HttpViewDataPrep(sessionData);
|
||||
|
|
|
@ -31,6 +31,8 @@ public:
|
|||
using namespace drogon;
|
||||
class views: public drogon::HttpController<views> {
|
||||
orm::DbClientPtr db;
|
||||
std::unordered_map<std::string, trantor::Date> last_votes;
|
||||
std::vector<uint64_t> moderators;
|
||||
public:
|
||||
views();
|
||||
void start(const HttpRequestPtr&, std::function<void (const HttpResponsePtr &)> &&);
|
||||
|
@ -38,6 +40,7 @@ public:
|
|||
void botlist(const HttpRequestPtr&, std::function<void (const HttpResponsePtr &)> &&);
|
||||
void botdetail(const HttpRequestPtr&, std::function<void (const HttpResponsePtr &)> &&, uint64_t);
|
||||
void botvote(const HttpRequestPtr&, std::function<void (const HttpResponsePtr &)> &&, uint64_t);
|
||||
void botedit(const HttpRequestPtr&, std::function<void (const HttpResponsePtr &)> &&, uint64_t, const std::string&);
|
||||
void botregister_view(const HttpRequestPtr&, std::function<void (const HttpResponsePtr &)> &&, const std::string&);
|
||||
void botregister_submit(const HttpRequestPtr&, std::function<void (const HttpResponsePtr &)> &&);
|
||||
void discordauth(const HttpRequestPtr&, std::function<void (const HttpResponsePtr &)> &&, const std::string&);
|
||||
|
@ -51,6 +54,7 @@ public:
|
|||
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, "LoginFilter");
|
||||
ADD_METHOD_TO(views::discordauth, "/discordauth?code={1}", Get);
|
||||
ADD_METHOD_TO(views::discorddeauth, "/discorddeauth", Get);
|
||||
ADD_METHOD_TO(views::menu, "/menu", Get);
|
||||
|
|
|
@ -75,10 +75,53 @@ body {
|
|||
text-align: center;
|
||||
}
|
||||
|
||||
.votesbox {
|
||||
background-color:#39004d;
|
||||
color:#FFFFFF;
|
||||
padding:4px;
|
||||
margin:10px;
|
||||
border-radius:4px;
|
||||
height:min-content;
|
||||
}
|
||||
.votestext {
|
||||
line-height:0px;
|
||||
font-size:10px;
|
||||
}
|
||||
|
||||
.content-desktop {display: block;}
|
||||
.content-mobile {display: none;}
|
||||
|
||||
@media screen and (max-width: 1000px) {
|
||||
.content-desktop {display: none;}
|
||||
.content-mobile {display: block;}
|
||||
.content-desktop {display: none;}
|
||||
.content-mobile {display: block;}
|
||||
}
|
||||
|
||||
|
||||
.tile {
|
||||
max-width: 20vw;
|
||||
min-width: 20vw;
|
||||
}
|
||||
.tilespacer {
|
||||
display:none;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 1580px) {
|
||||
.tile {
|
||||
max-width: 15vw;
|
||||
min-width: 15vw;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 900px) {
|
||||
.tile {
|
||||
border:unset;
|
||||
background-color:transparent !important;
|
||||
max-width: 100%;
|
||||
min-width: 100%;
|
||||
padding:0;
|
||||
margin:0;
|
||||
}
|
||||
.tilespacer {
|
||||
display:block;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<%inc#include "controllers/views.h" %>
|
||||
<%c++ auto bot_id = @@.get<uint64_t>("bot_id");%>
|
||||
<%c++ auto bot = @@.get<Bot>("bot");%>
|
||||
<%c++ auto canVote = @@.get<bool>("canVote");%>
|
||||
<%c++ auto owner = @@.get<bool>("owner");%>
|
||||
<%c++ auto modView = @@.get<bool>("modView");%>
|
||||
<%c++ auto sessionData = @@.get<SessionDataPtr>("sessionData");%>
|
||||
<%layout global_layout%>
|
||||
|
||||
<link rel="stylesheet" href="/botdetail.css">
|
||||
|
@ -18,12 +17,12 @@
|
|||
<div class="bot-text text text-center title">
|
||||
{%bot.name%}
|
||||
</div>
|
||||
<%c++ if (owner or modView) {%>
|
||||
<%c++ if (sessionData and (bot.owner_id == sessionData->discord_id or sessionData->moderator)) {%>
|
||||
<div class="actionsWrapper actions">
|
||||
<a class="special-button" href="edit" style="background-color:yellow;color:black;">Edit</a>
|
||||
<a class="special-button" href="delete" style="background-color:red;color:black;">Delete</a>
|
||||
</div>
|
||||
<%c++ if (modView) {%>
|
||||
<%c++ if (sessionData->moderator and not bot.approved) {%>
|
||||
<div class="actionsWrapper actions">
|
||||
<a class="special-button" href="approve" style="background-color:green;color:white;">Approve</a>
|
||||
<a class="special-button" href="decline" style="background-color:black;color:white;">Decline</a>
|
||||
|
@ -31,7 +30,7 @@
|
|||
<%c++ }%>
|
||||
<%c++ }%>
|
||||
<div class="actionsWrapper actions">
|
||||
<a class="special-button" href="https://discord.com/oauth2/authorize?client_id={%bot_id%}&permissions=8&scope=applications.commands%20bot">Invite</a>
|
||||
<a class="special-button" href="https://discord.com/oauth2/authorize?client_id={%bot.app_id%}&permissions=8&scope=applications.commands%20bot">Invite</a>
|
||||
<a class="special-button" {%(canVote?"href='vote'":"style='color:grey;'")%}>Vote <b>{%bot.votes%}</b></a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -20,21 +20,19 @@
|
|||
<hr>
|
||||
<br>
|
||||
<%c++ for (const auto& [bot_id, bot] : @@.get<std::map<uint64_t, Bot>>("bots")) {%>
|
||||
<a class="special-button" href="{%bot_id%}/detail" {%(bot.approved?"":"style='background-color:red;'")%}>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<img src="{%bot.avatar_url%}" style="width:128px;height:128px;">
|
||||
</td>
|
||||
<td style="padding:10px;">
|
||||
<h1 style="line-height:0px;">{%bot.name%}</h1>
|
||||
<p>{%bot.short_description%}</p>
|
||||
<%c++ if (not bot.approved) {%>
|
||||
<i>Not yet approved</i>
|
||||
<%c++ }%>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a class="special-button tile" href="{%bot_id%}/detail" style="background-color:{%(bot.approved?"#222222":"red")%};color:white;">
|
||||
<img src="{%bot.avatar_url%}" style="width:128px;height:128px;">
|
||||
<center>
|
||||
<div class="votesbox">
|
||||
<p class="votestext">Votes: <b>{%bot.votes%}</b></p>
|
||||
</div>
|
||||
</center>
|
||||
<p style="line-height:0px;font-size:20px;">{%bot.name%}</p>
|
||||
<p>{%bot.short_description%}</p>
|
||||
<%c++ if (not bot.approved) {%>
|
||||
<i>Not yet approved</i>
|
||||
<%c++ }%>
|
||||
</a>
|
||||
<hr class="tilespacer">
|
||||
<%c++ }%>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue