Skip to content

Commit

Permalink
Merge pull request #41 from DJKnaeckebrot/botLogs
Browse files Browse the repository at this point in the history
Added BotLogs Features
  • Loading branch information
iMidnights authored Jan 26, 2023
2 parents 3c70930 + 6e455f9 commit 336e9eb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pages/get/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const db = require('quick.db')

module.exports = {
page: '/admin',
execute: async (req, res, app, config, themeConfig, info) => {
execute: async (req, res, app, config, themeConfig, info, database) => {
const pterodactyl = new Nodeactyl.NodeactylClient(
themeConfig.admin.pterodactyl.panelLink,
themeConfig.admin.pterodactyl.apiKey
Expand Down Expand Up @@ -40,6 +40,7 @@ module.exports = {
res.render('admin', {
req,
sData: d,
ldata: await database.get('logs'),
themeConfig: req.themeConfig,
node: pterodactyl,
bot: config.bot,
Expand All @@ -48,4 +49,4 @@ module.exports = {
require
})
}
}
}
23 changes: 23 additions & 0 deletions pages/post/logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
page: '/stats/logs/update',
execute: async (req, res, app, config, themeConfig, info, db) => {
if (
'Bearer ' + themeConfig.admin.logs?.key !==
req.headers.authorization
)
return res.json({ status: 'Invalid sharding key' })

const logs = await db.get('logs')

let newLogs = []

if (!logs || !logs.length || !logs[0])
newLogs = [req.body]
else
newLogs = [req.body, ...logs]

await db.set('logs', newLogs)

res.json({ status: 'Completed' })
}
}
21 changes: 21 additions & 0 deletions views/admin.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,27 @@
</div>
</div>
</div>
<br>
<% } %>
<% if (themeConfig.admin.logs?.enabled) { %>
<div class="card h-100">
<div class="card-header pb-0 p-3">
<h6 class="mb-0">Bot Logs</h6>
</div>
<div class="card-body p-3">
<h6 class="text-uppercase text-body text-xs font-weight-bolder">Current Logs</h6>
<form>
<div class="form-group">
<% if (ldata !== undefined) { %>
<textarea disabled readonly class="form-control" id="botLogsText" rows="12"><%= ldata.map(x => x.description).join("\n")%></textarea>
<% } else { %>
<textarea disabled readonly class="form-control" id="botLogsText" rows="12">No logs found.</textarea>
<% } %>
</div>
</form>
</div>
</div>
<br>
<% } %>
<div class="row">
<div class="col-12 col-xl-6" style="margin-bottom: 20px;">
Expand Down

0 comments on commit 336e9eb

Please sign in to comment.