Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revuc2022 #2

Open
wants to merge 66 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
85bffd3
Merge pull request #1 from sahupr/main
devagrawal09 Jan 23, 2021
711fa50
timer update
sahupr Jan 23, 2021
4785be2
getting started with checkin
devagrawal09 Jan 23, 2021
17b1725
role assignment and email verification - no authentication
sahupr Jan 27, 2021
e16c68e
added checkin using revuc api
devagrawal09 Jan 31, 2021
bde2fa9
levelling
sahupr Feb 8, 2021
929ae50
env variables
devagrawal09 Feb 8, 2021
aaf1ff1
Merge branch 'main' of https://github.com/RevolutionUC/RevUC-discord-…
devagrawal09 Feb 8, 2021
18f6293
checkin
sahupr Feb 8, 2021
63d5550
using nodemon
devagrawal09 Feb 8, 2021
c462a1e
checkin complete
devagrawal09 Feb 8, 2021
6d553b5
added prod script
devagrawal09 Feb 8, 2021
4c36180
claim participation points
devagrawal09 Feb 8, 2021
5788eec
checkin attendee role
devagrawal09 Feb 8, 2021
e4dd7f3
updates
devagrawal09 Feb 9, 2021
6855e7c
kicked out atendees
devagrawal09 Feb 9, 2021
9a56beb
leaderboard working now
devagrawal09 Feb 9, 2021
bbc7e0c
minor role access + multiple checkins blocked
sahupr Feb 11, 2021
c066572
Delete revvit.pem
sahupr Feb 11, 2021
a31d352
help update
sahupr Feb 11, 2021
2664859
Merge branch 'main' of https://github.com/RevolutionUC/RevUC-discord-…
sahupr Feb 11, 2021
f60a70d
now reading from env
devagrawal09 Feb 11, 2021
408e6bf
Merge branch 'main' of https://github.com/RevolutionUC/RevUC-discord-…
devagrawal09 Feb 11, 2021
66477da
typo
sahupr Feb 11, 2021
4a590ee
Merge branch 'main' of https://github.com/RevolutionUC/RevUC-discord-…
sahupr Feb 11, 2021
fa9617a
Delete revvit.pem
sahupr Feb 11, 2021
444d15b
phrase change
sahupr Feb 11, 2021
3ec9511
checkin responses
sahupr Feb 15, 2021
c20ed54
checkin responses resolved
sahupr Feb 15, 2021
ac3ccd2
responses added
sahupr Feb 15, 2021
a9ad44a
responses added
sahupr Feb 15, 2021
392f688
Merge pull request #2 from RevolutionUC/responses
sahupr Feb 15, 2021
c23cb85
fixed random int issue
devagrawal09 Feb 17, 2021
e59f944
claim points custom responses
sahupr Feb 17, 2021
894e175
fixed the .name issue
devagrawal09 Feb 18, 2021
db50e3f
Merge branch 'responses' into main
devagrawal09 Feb 18, 2021
a493cf2
intro added
sahupr Feb 18, 2021
2819b4c
private checkin
sahupr Feb 18, 2021
78a3afe
updates
devagrawal09 Feb 18, 2021
9ad1dc0
added minor create attendee capability
devagrawal09 Feb 19, 2021
57e8ebb
modular, added daily update
devagrawal09 Dec 28, 2021
3f6797f
moved database into folder
devagrawal09 Dec 28, 2021
e4c1fc6
fixed embed send
devagrawal09 Dec 28, 2021
cc711cb
rich presence
devagrawal09 Dec 28, 2021
77fc88a
creating participant entry at checkin, prettier
Jan 30, 2022
82bf041
added lattice command
Feb 7, 2022
33afe64
added basic lattice message
devagrawal09 Feb 13, 2022
546bd7f
fixed datatypes import
devagrawal09 Feb 13, 2022
063c8b4
fixed bugs
devagrawal09 Feb 13, 2022
e26b543
updated lattice stuff
devagrawal09 Feb 13, 2022
817c6e9
Bump discord.js version
Feb 16, 2022
63bc250
Add embed functionality to lattice command
Feb 16, 2022
5e5934b
lattice profile embed + upgrading discordjs to 13
sahupr Feb 17, 2022
3f7a96d
Merge pull request #4 from RevolutionUC/lattice
sahupr Feb 17, 2022
572dfe6
message deletion on checkin and checkin errors
sahupr Feb 19, 2022
12e4430
Merge pull request #5 from RevolutionUC/checkin-fix
sahupr Feb 19, 2022
38115a9
timeout-for 30 seconds
sahupr Feb 24, 2022
671efea
timeout-for 30 seconds - removed the unused function
sahupr Feb 24, 2022
ad8b57a
Merge pull request #6 from RevolutionUC/timeout-fix
sahupr Feb 24, 2022
309c836
one of the error messages were deleting instantly
devagrawal09 Feb 24, 2022
4cb667e
removed timestamps from event
devagrawal09 Feb 26, 2022
05160a7
example code
devagrawal09 Feb 26, 2022
4d09f5d
added lattice help
devagrawal09 Feb 26, 2022
997a795
updated claim responses
devagrawal09 Feb 26, 2022
ec13103
fixed help
devagrawal09 Feb 26, 2022
be7f074
claim deletes all messages
devagrawal09 Feb 26, 2022
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
token.js
node_modules/
node_modules/
.env
57 changes: 57 additions & 0 deletions database/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const { Sequelize, DataTypes } = require(`sequelize`);

const sequelize = new Sequelize(process.env.DATABASE_URL, {
dialect: "postgres",
dialectOptions: { ssl: { require: true, rejectUnauthorized: false } },
});
exports.sequelize = sequelize;

exports.User = sequelize.define(`participants`, {
userID: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
primaryKey: true,
},
username: {
type: DataTypes.STRING,
allowNull: false,
},
email: {
type: DataTypes.STRING,
allowNull: false,
},
score: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
},
});

exports.Event = sequelize.define(`event`, {
code: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
points: {
type: DataTypes.INTEGER,
allowNull: false,
},
}, { timestamps: false });

exports.Claim = sequelize.define("claim", {
userID: {
type: DataTypes.STRING,
allowNull: false,
},
eventCode: {
type: DataTypes.STRING,
allowNull: false,
},
});
6 changes: 6 additions & 0 deletions discord/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function background(arguments, receivedMessage){
const intro = "Oh you wanna know about my background... okay, here goes.\nI was conceived by one Super User Dev Olpowerful (SUDO), and I was brought to life by one Piyush Rap!d Sahu (PRS)."
receivedMessage.channel.send(intro)
}

module.exports=background
168 changes: 168 additions & 0 deletions discord/checkin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
const Discord = require("discord.js");
const emailValidator = require("email-validator");
const Axios = require("axios").default;
const { User } = require("../database");

const API_TOKEN = process.env.API_TOKEN;
const HACKER_ROLE = process.env.HACKER_ROLE;
const JUDGE_ROLE = process.env.JUDGE_ROLE;
const MENTOR_ROLE = process.env.MENTOR_ROLE;
const SPONSOR_ROLE = process.env.SPONSOR_ROLE;
const CHECKIN_CHANNEL_ID = process.env.CHECKIN_CHANNEL_ID;
const MINOR_ROLE = process.env.MINOR_ROLE;

/**
*
* @param {string} email
*/
const censorEmail = (email) => {
const ptEmail = email;
let letter = "";
let stars = "";
let i = 0;
while (letter != "@" && i < email.length) {
letter = ptEmail[i];
i += 1;
stars += "*";
}
let censor = ptEmail.slice(1, i - 2);
stars = stars.substr(1, i - 3);
return ptEmail.replace(censor, stars);
};

const getRandomInt = (max) => {
return Math.floor(Math.random() * Math.floor(max));
};

const responses_success = [
"is checked in!",
", welcome to the main event!",
"is here!",
"welcome onboard!",
"has arrived!",
];

const responses_404 = [
"does not exist",
"cannot be found",
", are you using the right email?",
];

const responses_403 = [
"you're already checked in.",
"already exists, is this a clone?",
"you've already signed up!",
];

/**
*
* @param {Discord.Message} message
*/
module.exports = async function (message) {
const email = message.toString();

const max_success = responses_success.length;
const max_404 = responses_404.length;
const max_403 = responses_403.length;

const censoredEmail = censorEmail(email);

if (
emailValidator.validate(email) &&
message.channel.id == CHECKIN_CHANNEL_ID
) {
try {
// send a request to revuc api to check in the email
const res = await Axios.post(
`https://revolutionuc-api.herokuapp.com/api/v2/attendee/checkin`,
{ email },
{
headers: {
Authorization: `Bearer ${API_TOKEN}`,
},
}
);

const { name, role, isMinor } = res.data;

let roleToBeAdded;

switch (role) {
case `HACKER`:
roleToBeAdded = HACKER_ROLE;
break;
case `JUDGE`:
roleToBeAdded = JUDGE_ROLE;
break;
case `SPONSOR`:
roleToBeAdded = SPONSOR_ROLE;
break;
case `MENTOR`:
roleToBeAdded = MENTOR_ROLE;
break;
default:
throw new Error(`Invalid role`);
}

// check in succeeded
const user = message.author.id;

// grant the hacker role
const member = message.guild.members.cache.find(
(member) => member.id === user
);
const Role = message.guild.roles.cache.find(
(role) => role.id === roleToBeAdded
);
member.roles.add(Role);

if (isMinor == true) {
const minorRole = message.guild.roles.cache.find(
(role) => role.id == MINOR_ROLE
);
member.roles.add(minorRole);
}

if (role === `HACKER`) {
await User.create({
userID: message.author.id,
username: message.author.username,
email
});
}

var checkin_success = await message.channel.send(
`${name} <${censoredEmail}> ${
responses_success[getRandomInt(max_success)]
}`
);
setTimeout(() => checkin_success.delete(), 30000);
} catch (err) {
console.error(err);
if (err.response?.status === 404) {
var err_404 = await message.channel.send(
`${censoredEmail} ${
responses_404[getRandomInt(max_404)]
}, please make sure you are registered with us or contact an organizer`
);
setTimeout(() => err_404.delete(), 30000);
} else if (err.response?.status === 403) {
var err_403 = await message.channel.send(
`${censoredEmail} ${responses_403[getRandomInt(max_403)]}`
);
setTimeout(() => err_403.delete(), 30000);
} else {
var err_other = await message.channel.send(
`Error checking in ${censoredEmail}, please try again later or contact an organizer`
);
setTimeout(() => err_other.delete(), 30000);
}
}

message.delete();
} else {
var invalid_email = await message.channel.send(`${censoredEmail} is not a valid email`);
message.delete();
setTimeout(() => invalid_email.delete(), 30000);
}
};
46 changes: 46 additions & 0 deletions discord/checkin_prv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const Discord = require('discord.js')
const Axios = require('axios').default

const API_TOKEN = process.env.API_TOKEN
const TOP_CHANNEL_ID = process.env.TOP_CHANNEL_ID

/**
*
* @param {string[]} args
* @param {Discord.Message} message
* @param {'sponsor' | 'mentor' | 'judge' | 'minor'} primaryCommand
*/
module.exports = async function (args, message, primaryCommand) {
if (args.length < 2) {
message.channel.send(`Invalid command format! Please specify role, email and name.`)
} else {
const email = args.shift()
const name = args.join(` `)
let role = primaryCommand.toUpperCase()
let isMinor = false

if(primaryCommand === 'minor') {
role = `HACKER`
isMinor = true
}

if (message.channel.id == TOP_CHANNEL_ID) {
try {
await Axios.post(
`https://revolutionuc-api.herokuapp.com/api/v2/attendee`,
{ email, name, role, isMinor },
{ headers: { Authorization: `Bearer ${API_TOKEN}` } }
)

message.channel.send(`Created ${primaryCommand} ${name} <${email}>`)
} catch (err) {
console.error(err)
if (err.response?.status === 400) {
message.channel.send(`Attendee with email ${email} already exists!`)
} else {
message.channel.send(`Error creating attendee ${email}, please try again later or contact the Super User Dev Olpowerful (SUDO).`)
}
}
}
}
}
9 changes: 9 additions & 0 deletions discord/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { Discord, Client, Intents } = require('discord.js')

const DISCORD_TOKEN = process.env.DISCORD_TOKEN

const client = new Client({intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]})

client.login(DISCORD_TOKEN)

module.exports = client
File renamed without changes.
34 changes: 34 additions & 0 deletions discord/daily-update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const Discord = require('discord.js')
const { TextChannel } = require('discord.js')
const client = require('./client')

const ADMIN_CHANNEL_ID = process.env.ADMIN_CHANNEL_ID

module.exports = async (data) => {
const adminChannel = await client.channels.fetch(ADMIN_CHANNEL_ID)

const update = new Discord.MessageEmbed()
.setTitle('Daily Regstration Update')
.setURL(`https://stats.revolutionuc.com/`)
.addFields([
{
name: 'Total Registrants',
value: data.total.registrants,
},
{
name: 'Registered in last 24hrs',
value: data.last24hrs.registrants,
},
{
name: 'Total Confirmed',
value: data.total.confirmed,
},
{
name: 'Confirmed in last 24hrs',
value: data.last24hrs.confirmed,
}
])
.setTimestamp()

await adminChannel.send(update)
}
39 changes: 39 additions & 0 deletions discord/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const TOP_CHANNEL_ID = process.env.TOP_CHANNEL_ID

function helpCommand(args, receivedMessage) {
const isAdminChannel = receivedMessage.channel.id == TOP_CHANNEL_ID;

if(args.length < 1){
isAdminChannel ?
receivedMessage.channel.send('specify what you need help for:\n `!revvit` \n `!help checkin` \n `!help codes` \n `!help sponsor` \n `!help mentor` \n `!help judge` \n `!help minor` \nor `!background` to know more about me! ') :
receivedMessage.channel.send('specify what you need help for:\n `!revvit` \n `!help checkin` \n `!help codes` \n `!help lattice` \nor `!background` to know more about me! ')
}
else {
const topic = args[0]
switch(topic) {
case 'checkin':
console.log('checkin prompt')
receivedMessage.channel.send('Type the email you registered with out on the checkin channel to check in to RevolutionUC. Ex: `[email protected]`')
break
case 'codes':
receivedMessage.channel.send('Use the bot command `!claim EXAMPLECODE` to claim your participation points')
break
case 'sponsor':
case 'mentor':
case 'judge':
case 'minor':
if(isAdminChannel) {
receivedMessage.channel.send(`Use the bot command \`!${topic} <email> <name>\` to add an attendee to the database and allow them to check in to the discord server`)
break
}
case 'lattice':
receivedMessage.channel.send('Use the bot command `!lattice` to show your Lattice hacker profile')
break
default:
receivedMessage.channel.send('Invalid bot command')
throw new Error(`Invalid command`)
}
}
}

module.exports=helpCommand
Loading