Skip to content

Commit e846d73

Browse files
committed
Created verification BOT for the server, finished fakeredir (at least should be) updated the setup SQL file.
1 parent ab8af21 commit e846d73

File tree

6 files changed

+95
-3
lines changed

6 files changed

+95
-3
lines changed

Bot/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM node:lts-alpine3.13
2+
COPY . /srv
3+
RUN ["chmod", "a=rw", "/srv"]
4+
RUN ["chmod", "+x", "/srv/install.sh"]
5+
RUN ["sh", "/srv/install.sh"]
6+
RUN ["chmod", "+x", "/srv/start.sh"]
7+
ENTRYPOINT ["sh", "/srv/start.sh" ]

Bot/bot/bot.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
MADE BY ELPERSON 2021
3+
Name: Raindrop mgmt bot
4+
*/
5+
const discord = require('discord.js')
6+
const bcrypt = require('bcryptjs')
7+
const { Client } = require('pg')
8+
const client = new Client({
9+
user: 'admin',
10+
host: 'db',
11+
database: 'uploader',
12+
password: process.env.DBPASS,
13+
port: 5432
14+
})
15+
const bot = new discord.Client()
16+
const intents = new discord.Intents()
17+
intents.add('GUILD_MEMBERS', 'DIRECT_MESSAGES', 'GUILD_MESSAGES')
18+
// Bot Code
19+
var guild
20+
bot.on('ready', () => {
21+
try {
22+
client.connect()
23+
}catch(error) {
24+
console.error('Could not connect to PSQL database: ' + error)
25+
}
26+
guild = bot.guilds.resolve('821106583928832031')
27+
console.log('BOT RDY')
28+
})
29+
bot.on('message', msg => {
30+
if ( msg.channel.type == 'dm' && !(msg.author.bot) ) {
31+
var split = msg.content.split(':')
32+
client.query('SELECT duserid WHERE duserid = $1', [msg.author.id], (err, res) => {
33+
if (res.rows[0]) {
34+
msg.reply(`You're already linked to an account!`)
35+
}
36+
})
37+
client.query('SELECT username, passwd, duserid FROM users WHERE username = $1', [split[0]], (err, res) => {
38+
if (err) {
39+
console.log(err.stack)
40+
}else if (!res.rows[0]) {
41+
msg.reply('USER NOT FOUND')
42+
}
43+
else if (res.rows[0].duserid == null) {
44+
if (bcrypt.compareSync(split[1], res.rows[0].passwd)) {
45+
msg.reply('Credentials successfully verified!\nFor security reasons it is advised for you to delete your message.')
46+
guild.members.fetch(msg.author.id).then(mem => {
47+
mem.roles.add('856534805533818900', 'Passed Credential Verification')
48+
})
49+
50+
client.query('UPDATE users SET duserid = $1 WHERE username = $2', [msg.author.id, split[0]], (err, res) => {
51+
if (err) {
52+
console.error(err.stack)
53+
}
54+
})
55+
56+
}else{
57+
msg.reply('Wrong credentials!')
58+
}
59+
60+
}else if (res.rows[0].duserid != null) {
61+
msg.reply('This account has been already linked!')
62+
}
63+
})
64+
}
65+
})
66+
bot.login(process.env.TOKEN)

Bot/install.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apk update
2+
npm install discord.js
3+
npm install pg
4+
npm install bcryptjs

Bot/start.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
node /srv/bot/bot.js

SQL/Setup.sql

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ CREATE TABLE IF NOT EXISTS users (
1010
username TEXT NOT NULL,
1111
passwd TEXT NOT NULL,
1212
apikey TEXT NOT NULL,
13-
perms TEXT NOT NULL,
13+
perms SMALLINT NOT NULL,
14+
quota BIGINT NOT NULL,
15+
duserid BIGINT NOT NULL,
1416
PRIMARY KEY (userid)
1517
);
1618
CREATE TABLE IF NOT EXISTS sessions
@@ -23,6 +25,7 @@ CREATE TABLE IF NOT EXISTS images (
2325
imgurl TEXT NOT NULL,
2426
uploader TEXT NOT NULL,
2527
upstamp BIGINT NOT NULL,
28+
lastvisited BIGINT NOT NULL,
2629
PRIMARY KEY (imgurl)
2730
);
2831
CREATE TABLE IF NOT EXISTS shorturl (
@@ -34,4 +37,4 @@ CREATE TABLE IF NOT EXISTS shorturl (
3437
ALTER SEQUENCE users_userid_seq
3538
MINVALUE 0
3639
START WITH 0
37-
RESTART WITH 0;
40+
RESTART WITH 0;

docker-compose.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
environment:
1111
- POSTGRES_DB=uploader # Use lowercase.
1212
- POSTGRES_USER=admin # Use lowercase.
13-
- POSTGRES_PASSWORD=Pj+5K]hDT:FT>(8. # CHANGE THIS TO SOMETHING LONG.
13+
- POSTGRES_PASSWORD=dqRcBKPe2Kjov0mHvXGQ # CHANGE THIS TO SOMETHING LONG.
1414
web:
1515
volumes:
1616
- ./Uploader:/srv
@@ -19,3 +19,13 @@ services:
1919
- "80:8080"
2020
depends_on:
2121
- db
22+
bot:
23+
volumes:
24+
- ./Bot:/srv
25+
build: ./Bot
26+
environment:
27+
- TOKEN=ODUyNTY1NjQ1ODYxMzIyNzgy.YMIroQ.W2JWOjK_p2QLFjidadfbzlx_g7s
28+
- DBPASS=dqRcBKPe2Kjov0mHvXGQ
29+
depends_on:
30+
- db
31+
- web

0 commit comments

Comments
 (0)