Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from RevolutionUC/lattice
Browse files Browse the repository at this point in the history
Add embed functionality to lattice command
  • Loading branch information
sahupr authored Feb 17, 2022
2 parents e26b543 + 5e5934b commit 3f7a96d
Show file tree
Hide file tree
Showing 5 changed files with 479 additions and 394 deletions.
4 changes: 2 additions & 2 deletions discord/client.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const Discord = require('discord.js')
const { Discord, Client, Intents } = require('discord.js')

const DISCORD_TOKEN = process.env.DISCORD_TOKEN

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

client.login(DISCORD_TOKEN)

Expand Down
2 changes: 1 addition & 1 deletion discord/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const client = require("./client");
const help = require("./help");
const multiply = require("./multiply");
const react = require("./react");
const countdown = require("./countdown");
// const countdown = require("./countdown");
const checkin = require("./checkin");
const { score, top } = require("./score");
const revvit = require("./revvit");
Expand Down
30 changes: 19 additions & 11 deletions discord/lattice.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Discord = require("discord.js");
const Axios = require("axios").default;
const { User } = require("../database");
const { MessageEmbed } = require('discord.js');

const API_TOKEN = process.env.API_TOKEN;

Expand All @@ -17,10 +18,11 @@ Axios.get(`https://revolutionuc-api.herokuapp.com/api/v2/lattice/skills`).then(
async function latticeCommand(receivedMessage) {
try {
let user = await User.findByPk(receivedMessage.author.id);
const discordUsername = receivedMessage.author.username;

if (!user) {
receivedMessage.channel.send(
`Hey ${receivedMessage.author.username}, you are not checked in to RevUC, so either you hacked into the server, in which case you will be banned shortly, or you are an organizer, in which case, stop smurfing!`
`Hey ${discordUsername}, you are not checked in to RevUC, so either you hacked into the server, in which case you will be banned shortly, or you are an organizer, in which case, stop smurfing!`
);
} else {
const { data: profile } = await Axios.get(
Expand All @@ -32,20 +34,26 @@ async function latticeCommand(receivedMessage) {
}
);

// name and idea are strings, skills and lookingFor are arrays of strings
// `name` and `idea` are strings, `skills` and `lookingFor` are arrays of strings
const { name, skills, idea, lookingFor, visible } = profile;

if (visible) {
receivedMessage.channel.send(
`${name}\nSkills: ${skills.join(
", "
)}\nIdea: ${idea}\nLooking for: ${lookingFor.join(", ")}`
);
if (!visible) {
receivedMessage.channel.send(`Hey ${discordUsername}, your lattice profile is hidden. If you want to show it here, please go to https://lattice.revolutionuc.com/profile and click on "Mark Visible".`)
} else {
receivedMessage.channel.send(
`Hey ${receivedMessage.author.username}, your lattice profile is hidden. If you want to show it here, please go to https://lattice.revolutionuc.com/profile and click on "Mark Visible".`
);
// Else, send an embed with the Hacker's profile info
const discordFullUsername = `${discordUsername}#${receivedMessage.author.discriminator}`;
const infoEmbed = new MessageEmbed()
.setColor("#008C8C") // Mars Green color
.setAuthor({ name: "RevUC Hacker Profile", iconURL: "https://assets.revolutionuc.com/logo-128.png" })
.setTitle(`${name} @${discordFullUsername}`)
.addFields(
{ name: "Idea", value: idea },
{ name: "Skills", value: skills.join(", ") },
{ name: "Looking for", value: lookingFor.join(", ") }
)
receivedMessage.channel.send({ embeds: [infoEmbed] })
}

}
} catch (err) {
console.error(err);
Expand Down
Loading

0 comments on commit 3f7a96d

Please sign in to comment.