Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Add Bot #82

Open
wants to merge 33 commits into
base: node
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
42468ca
Add bot
A-Trash-Coder Dec 2, 2020
b445323
Update url + key on list edit
A-Trash-Coder Dec 2, 2020
b3dcbbf
Different syntax
A-Trash-Coder Dec 2, 2020
040a794
Make CI like ma syntax
A-Trash-Coder Dec 2, 2020
b53691b
Merge branch 'node' into node
A-Trash-Coder Feb 5, 2021
3f470e2
Merge branch 'node' into node
A-Trash-Coder May 4, 2021
3248afc
Fix some spelling errors. Add slash commands toggle.
A-Trash-Coder Jun 9, 2021
2d772d1
Hide `add_bot` & `add_bot_key` from edit log
jacobmitchell04 Jul 3, 2021
9bffb63
Change checkbox when toggling lists to add bot to from 'minus' to 'plus'
A-Trash-Coder Jul 3, 2021
320bc00
Add 'maxlength' attribute to fields with a max length
A-Trash-Coder Jul 3, 2021
e81fba4
Add authentication requirement for post version of '/add'
A-Trash-Coder Jul 3, 2021
a39ec88
Fix eslint
jacobmitchell04 Jul 3, 2021
607bd48
Server side validation with joi
A-Trash-Coder Jul 3, 2021
e3943c7
Fix schema. Remove unneeded else statement.
A-Trash-Coder Jul 3, 2021
559bc2e
Eslint
A-Trash-Coder Jul 3, 2021
f246850
I hate Eslint
A-Trash-Coder Jul 3, 2021
df94d17
I hate Eslint
A-Trash-Coder Jul 3, 2021
76e646d
Fix allowed library strings
A-Trash-Coder Jul 4, 2021
cb35df5
Require auth for POST '/add/:id'
A-Trash-Coder Jul 4, 2021
33351b6
Fix Website.js. Fix if logic in Bot.js
A-Trash-Coder Jul 4, 2021
f805b7e
Add newline to list.pug.
A-Trash-Coder Jul 4, 2021
1c969b5
Add newline to add.pug.
A-Trash-Coder Jul 4, 2021
6230231
Fix id for slash commands input
A-Trash-Coder Jul 4, 2021
4581cec
Fix logic for checking if a bot list has been toggled.
A-Trash-Coder Jul 4, 2021
223f7b7
Fix logic for checking if a bot list has been toggled.
A-Trash-Coder Jul 4, 2021
ffe3d32
Update logic for checking if nsfw and slash_commands checkbox. Eslint.
A-Trash-Coder Jul 4, 2021
4dee710
Eslint
A-Trash-Coder Jul 4, 2021
d782a04
joi now alerts user of error if data illicitly is added client side. …
A-Trash-Coder Jul 4, 2021
6ec10ca
Remove accidental console.log.
A-Trash-Coder Jul 4, 2021
af5d055
Eslint
A-Trash-Coder Jul 4, 2021
b1d49a1
Remove add_bot and add_bot_key in api
A-Trash-Coder Jul 10, 2021
27e6d61
Eslint
A-Trash-Coder Jul 10, 2021
108f442
Fix 500
A-Trash-Coder Jul 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions db/migrations/20201127100038_add-bot-fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
exports.up = async function (knex) {
await knex.schema.table('lists', function (t) {
t.text('add_bot');
t.text('add_bot_key');
});
};

exports.down = async function (knex) {
await knex.schema.table('lists', function (t) {
t.dropColumn('add_bot');
t.dropColumn('add_bot_key');
});
};
30 changes: 30 additions & 0 deletions src/Assets/js/bot/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function isInt(value) {
return !isNaN(value) &&
parseInt(Number(value)) == value &&
!isNaN(parseInt(value, 10));
}

function isSnowflake(value) {
return isInt(value) && value.length >= 16;
}

document.getElementById('add').addEventListener('submit', function (e) {
var value = document.getElementById('botid');
if (!value) {
var inputs = document.querySelectorAll('input[type=checkbox]:checked');
if (inputs.length == 0) {
A-Trash-Coder marked this conversation as resolved.
Show resolved Hide resolved
document.getElementById('error').innerText = 'You must submit to at least one list!';
return e.preventDefault();
} else if (inputs.length == 1) {
if (inputs[0].id == 'nsfw') {
document.getElementById('error').innerText = 'You must submit to at least one list!';
return e.preventDefault();
}
}
A-Trash-Coder marked this conversation as resolved.
Show resolved Hide resolved
}
if (!value.value) { return e.preventDefault(); }
if (!isSnowflake(value.value)) {
document.getElementById('error').innerText = 'Please enter a valid snowflake ID to add';
return e.preventDefault();
}
});
133 changes: 133 additions & 0 deletions src/Dynamic/Includes/forms/addBot.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
form#add(method='POST' action='/bot/add/' + bot.id)
.columns
.column.is-half-desktop.is-full-mobile
.card.is-box-shadow
.card-content
.field
div.media
div.media-left
img(class='image lazyload' src='https://cdn.discordapp.com/avatars/' + bot.id + '/' + bot.avatar + '.png', alt=bot.username + ' Icon')
div.media-content
label.label(for='name') Bot Name *
p (Max Length: 25)
.control
input.input(type='text' id='name' name='name' value=bot.username, required)
label.label(for='id') Bot ID
.control
input.input(type='text' id='id' name='id' value=bot.id, disabled)
label.label(for='owner_id') Owner ID
.control
input.input(type='text' id='owner_id' name='owner_id' value=user.id, disabled)
label.label(for='nsfw') NSFW
p Please tick if the bot (or avatar) is NSFW
div(tabindex='0' role='button' class='checkbox always disallowed')
div(class='checkbox-inner')
input(type='checkbox' id='nsfw' name='nsfw' checked=false)
span
label.label(for='slash_commands') Slash Commands
p Please tick if the bot requires
code applications.commands
div(tabindex='0' role='button' class='checkbox always disallowed')
div(class='checkbox-inner')
input(type='checkbox' id='nsfw' name='nsfw' checked=false)
A-Trash-Coder marked this conversation as resolved.
Show resolved Hide resolved
span
label.label(for='prefix') Prefix *
p (Max Length: 25)
.control
input.input(type='text' id='prefix' name='prefix' required)
label.label(for='library') Library *
.control
.select
select(name='library' id='library', required)
option(value='' selected disabled hidden) Select a library
option(value='' disabled) Clojure
option(value='discljord') discljord
option(value='' disabled) C++
option(value='aegis.cpp') aegis.cpp
option(value='' disabled) Crystal
option(value='discordcr') discordcr
option(value='' disabled) C#
option(value='Discord.Net') Discord.Net
option(value='DSharpPlus') DSharpPlus
option(value='' disabled) D
option(value='dscord') dscord
option(value='' disabled) Go
option(value='DiscordGo') DiscordGo
option(value='DisGord') DisGord
option(value='' disabled) Java
option(value='catnip') catnip
option(value='Discord4J') Discord4J
option(value='Javacord') Javacord
option(value='JDA') JDA
option(value='' disabled) JavaScript
option(value='discord.js') discord.js
option(value='Eris') Eris
option(value='' disabled) Julia
option(value='Discord.jl') Discord.jl
option(value='' disabled) Lua
option(value='Discordia') Discordia
option(value='' disabled) Nim
option(value='discordnim') discordnim
option(value='' disabled) PHP
option(value='RestCord') RestCord
option(value='' disabled) Python
option(value='discord.py') discord.py
option(value='disco') disco
option(value='' disabled) Ruby
option(value='discordrb') discordrb
option(value='' disabled) Rust
option(value='discord-rs') discord-rs
option(value='Serenity') Serenity
option(value='' disabled) Scala
option(value='AckCord') AckCord
option(value='' disabled) Swift
option(value='Sword') Sword
option(value='' disabled) -- TypeScript --
option(value='Discordeno') disco
label.label(for='short_desc') Short Description *
p (Max Length: 100)
.control
input.input(type='text' id='short_desc' name='short_desc' required)
label.label(for='long_dec_plain') Long Description Plain *
p (Max Length: 5000)
p This long description field will be used on bot lists that do not support Markdown or HTML in their long descriptions.
.control
textarea.textarea#long_desc_plain(type='text' name='long_desc_plain' required)
label.label(for='long_desc_rich') Long Description Rich *
p (Max Length: 5000)
p This long description field will be used on bot lists that support Markdown or HTML in their long descriptions.
.control
textarea.textarea#long_desc_rich(type='text' name='long_desc_rich' required)
label.label(for='invite_url') Bot Invite URL *
.control
input.input(type='link' pattern='https?://.+' id='invite_url' name='invite_url' value="https://discord.com/oauth2/authorize?client_id=" + bot.id + "&scope=bot" required)
label.label(for='website_url') Website URL
.control
input.input(type='link' pattern='https?://.+' id='website_url' name='website_url')
label.label(for='support_url') Support (Server) URL
.control
input.input(type='link' pattern='https?://.+' id='support_url' name='support_url')
label.label(for='donate_url') Donate URL
.control
input.input(type='link' pattern='https?://.+' id='donate_url' name='donate_url')
label.label(for='github_url') GitHub URL
.control
input.input(type='link' pattern='https?://.+' id='github_url' name='github_url')

.column.is-half-desktop.is-full-mobile.top
.card.is-box-shadow
.card-content
.hero
.hero-body.hero-slim
.has-text-centered
h1.title.is-size-6#error
h1.title.is-size-4 Supported Lists
for list in supportedLists
.columns(class='has-margin-top')
.checkbox.always(tabindex='0' role='button' class='interactive minus')
A-Trash-Coder marked this conversation as resolved.
Show resolved Hide resolved
div(class='checkbox-inner')
input(type='checkbox', id=list.name, name=list.name checked=true)
span
span #{list.name}
br
input.button.is-brand(type='submit' value='Add bot to all supported bot lists' disabled=supportedLists.length == 0)
11 changes: 9 additions & 2 deletions src/Dynamic/Includes/forms/list.pug
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ form(method='POST')
label.label(for='api_shards') API Post - Shards Array Field Name
.control
input.input#api_shards(type='text', name='api_shards', value=data.api_shards)
.field
label.label(for='add_bot') API Post - Add Bot URL
.control
input.input#add_bot(type='text', name='add_bot', value=data.add_bot)
.field
label.label(for='add_bot_key') API Post - Add Bot Key
.control
input.input#add_bot_key(type='text', name='add_bot_key', value=data.add_bot_key)

.column
.field
Expand All @@ -124,5 +132,4 @@ form(method='POST')
hr
include ../checkboxes
.control(style='margin-top: 10px')
button.button.is-brand Submit

button.button.is-brand Submit
A-Trash-Coder marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 5 additions & 8 deletions src/Dynamic/Includes/navbar.pug
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
form#navbar_lists_search
input#navbar_lists_query.navbar-item.input(type='text', placeholder='Name or URL')
a.navbar-item(onclick='navbar_lists_go()') Search Lists
//.navbar-item.has-dropdown.is-hoverable
// a.navbar-link Bots
// .navbar-dropdown.is-boxed.is-box-shadow
// a.navbar-item Bot Lookup
// a.navbar-item Add New Bot
.navbar-item.has-dropdown.is-hoverable
a.navbar-link Bots
.navbar-dropdown.is-boxed.is-box-shadow
a.navbar-item(href='/bot/add') Add New Bot
//a.navbar-item Bot Lookup
.navbar-item.has-dropdown.is-hoverable
a.navbar-link API
.navbar-dropdown.is-boxed.is-box-shadow
Expand All @@ -53,6 +53,3 @@
else
a.navbar-item(href='/auth') Sign in with Discord
// a.navbar-item Languages (Coming soon... :) )



8 changes: 5 additions & 3 deletions src/Dynamic/Includes/sidebar.pug
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ aside.menu.is-box-shadow(role='navigation', aria-label='main navigation')
form#navbar_lists_search
input#navbar_lists_query.navbar-item.input(type='text', placeholder='Name or URL')
a(onclick='navbar_lists_go()') Search Lists
li
p.menu-label Bots
ul.menu-list
li
a(href='/bot/add') Add Bot

li
p.menu-label API
Expand Down Expand Up @@ -71,6 +76,3 @@ aside.menu.is-box-shadow(role='navigation', aria-label='main navigation')
else
li
a(href='/auth') Sign in with Discord



53 changes: 53 additions & 0 deletions src/Dynamic/bot/add.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
extends ../layout
block content
section.section
.container
- if(!error && bot)
include ../Includes/forms/addBot
- else
.hero
.hero-body.hero-slim
.has-text-centered
h1.title.is-size-4 Add a New Bot
h5.title.is-size-5 Add a new bot to all lists that support BotBlock
h6.title.is-size-6 Submit a bot to all lists that accept BotBlock with standard information for all listings.

- if(after)
.columns
.column.is-half-desktop.is-full-mobile
.card.is-box-shadow
.has-text-centered
.card-content
p.has-text-white
| Submission Status
br
for result in results
if !result.error
p.has-text-success #{result.name}
else
p.has-text-danger #{result.name}
if result.message
p Message: #{result.message}
else
p Message: No message
hr
- else
.columns
.column.is-half-desktop.is-full-mobile
form#add(method="POST")
.card.is-box-shadow
.card-content
p#error
- if(error)
p This bot was not found on Discord
.field
label.label(for='botid') Bot Client ID to add to bot lists
.control
input.input#botid(name='botid' type='text')
h1.is-brand Please make sure to join the bot list servers before adding your bot as many require bot owners to be in the server.
input.button.is-brand(type='submit' value='Begin adding your bot')


block footer
script(defer src='/assets/js/checkboxes/interactive.js')
script(src='/assets/js/bot/add.js')
A-Trash-Coder marked this conversation as resolved.
Show resolved Hide resolved
83 changes: 83 additions & 0 deletions src/Routes/Bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const BaseRoute = require('../Structure/BaseRoute');
const axios = require('axios');
const handleError = require('../Util/handleError');

class BotRoute extends BaseRoute {
constructor(client, db) {
super('/bot');
this.router = require('express').Router();
this.client = client;
this.db = db;
this.routes();
}

async postBot(req, res) {
const responses = [];
return await this.db.select().from('lists').whereNot({ add_bot: null, add_bot_key: null }).then(lists => {
for (var list of lists) {
if (req.body[list.name] == 'on') {
return axios.post(list.add_bot, req.body, {
A-Trash-Coder marked this conversation as resolved.
Show resolved Hide resolved
headers: { Authorization: list.add_bot_key }
}).then(resp => {
responses.push({ ...resp.data, error: false, name: list.name });
return responses;
}).catch(err => {
responses.push({ ...err.response.data, error: true, name: list.name });
return responses;
});
}
delete req.body[list.name];
}
}).catch((e) => {
handleError(this.db, req, res, e.stack);
});
}

routes() {
this.router.get('/add', this.requiresAuth.bind(this), (req, res) => {
res.render('bot/add');
});


this.router.post('/add', async (req, res) => {
A-Trash-Coder marked this conversation as resolved.
Show resolved Hide resolved
try {
const data = await this.client.getUser(req.body.botid);
if (!data['bot']) { res.render('bot/add', { error: true }); }
this.db.select().from('lists').whereNot({ add_bot: null, add_bot_key: null }).then(supportedLists => {
res.render('bot/add', { error: false, bot: data, supportedLists: supportedLists });
}).catch((e) => {
handleError(this.db, req, res, e.stack);
});
} catch {
res.render('bot/add', { error: true });
}
});


this.router.post('/add/:id', async (req, res) => {
A-Trash-Coder marked this conversation as resolved.
Show resolved Hide resolved
const [bot, user] = await Promise.all([this.client.getUser(req.params.id), this.client.getUser(req.session.user.id)]);

user.locale = req.session.user.locale;
user.mfa_enabled = req.session.user.mfa_enabled;
user.premium_type = req.session.user.premium_type;

A-Trash-Coder marked this conversation as resolved.
Show resolved Hide resolved
req.body.nsfw = 'on' ? true : false;
req.body.slash_commands = 'on' ? true : false;
req.body.id = bot.id;
req.body.owner_id = user.id;
req.body.owner_oauth = req.session.user.access_token;
req.body.bot_details = bot;
req.body.owner_details = user;

const results = await this.postBot(req, res);

res.render('bot/add', { after: true, results: results });
});
}

get getRouter() {
return this.router;
}
}

module.exports = BotRoute;