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

Converted all bot messages into embeds #37

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 11 additions & 5 deletions commands/user-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const {
spreadsheetId,
sheetName,
} = require('../services/googleSheetsService.js');

const Discord = require('discord.js');
const messageEmbed= new Discord.MessageEmbed();
// Id of the spreadsheet file (it is in the url of the google sheet)
const logThemes = require("../theme.js");

Expand Down Expand Up @@ -58,15 +59,18 @@ async function getDetails(message) {
} else if (house === 'D') {
house = 'Darco';
}

message.channel.send(`Your Name is ${realName}\nYour Roll No is ${rollNumber}\nYour house is ${house}`);
messageEmbed.setTitle(`Your Name is ${realName}\nYour Roll No is ${rollNumber}\nYour house is ${house}`)
.setColor('ORANGE');
message.channel.send(messageEmbed);
// TODO Do not print the roll number
// TODO Assign a role based on the roll number like give `role-a` if rollNumber starts with 1901
return;
}
};
message.reply("Sorry we couldn't find you in our database. \
messageEmbed.setTitle("Sorry we couldn't find you in our database. \
Please ping"+ "<@&" + modRole.id + "> to identify you.")
.setColor('RED');
message.reply(messageEmbed);
return;
}

Expand All @@ -80,7 +84,9 @@ module.exports = {
// If someone runs !user-info @dhushyanth in the message
// then identify the mentioned user and fetch the
// roll number of that user
message.channel.send(`Your username: ${userName}\n`);
messageEmbed.setTitle(`Your username: ${userName}\n`)
.setColor('GREEN');
message.channel.send(messageEmbed);
getDetails(message);
// var role = message.guild.roles.find(role => role.name === "role-b");
// message.member.addRole(role);
Expand Down
27 changes: 18 additions & 9 deletions commands/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ const {
spreadsheetId,
sheetName,
} = require('../services/googleSheetsService.js');



const Discord = require('discord.js');
const messageEmbed= new Discord.MessageEmbed();
async function assignRole(branch, gradYear, message) {
let { cache } = message.guild.roles;
let modRole = cache.find(role => role.name === "moderator");

let yearRole = cache.find(role => role.name.includes(gradYear));
if (!yearRole) {
message.reply("Year role could not be assigned. \
messageEmbed.setTitle("Year role could not be assigned. \
Please ping"+ "<@&" + modRole.id + "> to identify you.")
.setColor('RED');
message.reply(messageEmbed);
}
else {
await message.member.roles.add(yearRole);
Expand All @@ -23,8 +24,10 @@ async function assignRole(branch, gradYear, message) {

let branchRole = cache.find(role => role.name.includes(branch));
if (!branchRole) {
message.reply("Branch role could not be assigned. \
messageEmbed.setTitle("Branch role could not be assigned. \
Please ping"+ "<@&" + modRole.id + "> to identify you.")
.setColor('RED');
message.reply(messageEmbed);
}
else {
await message.member.roles.add(branchRole);
Expand Down Expand Up @@ -77,16 +80,20 @@ async function getDetails(message, username) {
if (message.author.id === message.guild.ownerID) return message.reply('I can\'t change your nickname.');

await message.member.setNickname(`${username}-${part[0]} ${lastName}`);
messageString += "Nickname Changed\n"
message.reply(messageString)
messageString += "Nickname Changed\n";
messageEmbed.setTitle(messageString)
.setColor('GOLD');
message.reply(messageEmbed);
} catch (err) {
console.error(err);
}
// console.log(message.guild.roles);
return;
}
}
message.reply("User not found");
messageEmbed.setTitle("User not found")
.setColor('RED');
message.reply(messageEmbed);
return;
}

Expand All @@ -100,7 +107,9 @@ module.exports = {
getDetails(message, username);
}
else {
message.reply("The command you are looking for is-!verify me");
messageEmbed.setTitle("The command you are looking for is-!verify me")
.setColor('YELLOW');
message.reply(messageEmbed);
}
}
}
4 changes: 3 additions & 1 deletion commands/welcome-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Canvas = require('canvas');
const Discord = require('discord.js');
const messageEmbed= new Discord.MessageEmbed();

// Pass the entire Canvas object because you'll need to access its width, as well its context
const applyText = (canvas, text) => {
Expand Down Expand Up @@ -61,6 +62,7 @@ module.exports = {
ctx.drawImage(avatar, (0.5 + (canvas.width / 2 - 100)) | 0, (0.5 + 50) | 0, 200, 200);

const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png');
message.channel.send(attachment);
messageEmbed.attachFiles([attachment]);
message.channel.send(messageEmbed);
},
};
10 changes: 7 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Canvas = require('canvas');
const client = new Discord.Client();
const console = require("./theme.js");
const { prefix, token } = require('./configs/config.json');

const messageEmbed= new Discord.MessageEmbed();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

Expand Down Expand Up @@ -98,7 +98,9 @@ client.on('message', message => {
const command = args.shift().toLowerCase();

if (message.channel.type === 'dm' || message.channel.name !== 'testing') {
message.reply('Hello there');
messageEmbed.setTitle("Hello there")
.setColor('AQUA');
message.reply(messageEmbed);
return;
}

Expand All @@ -109,7 +111,9 @@ client.on('message', message => {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
messageEmbed.setTitle("there was an error trying to execute that command!")
.setColor('RED');
message.reply(messageEmbed);
}
});

Expand Down