Skip to content

Commit

Permalink
fix spelling errors and db errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ikifar2012 committed Jul 8, 2022
1 parent dc43c43 commit ac6945d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
8 changes: 4 additions & 4 deletions commands/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = {
global.client.channels.cache.get(env.discord.logs_channel).send({
embeds: [ embedcreator.setembed(
{
title: 'Incedent Detected',
title: 'Incident Detected',
description: `${interaction.member.user} tried to use the notify command but did not have the correct role.
Detailed information:
User ID : ${userId}`,
Expand All @@ -62,7 +62,7 @@ module.exports = {
return interaction.reply({
embeds: [ embedcreator.setembed(
{
title: 'Incedent Reported',
title: 'Incident Reported',
description: 'You do not have permission to use this command. This incident has been reported.',
color: '#e74c3c',
},
Expand Down Expand Up @@ -104,7 +104,7 @@ module.exports = {
embeds: [ embedcreator.setembed(
{
title: 'Error',
description: 'An error occured while adding the user to the notify list',
description: 'An error occurred while adding the user to the notify list',
color: '#e74c3c',
},
)], ephemeral: true,
Expand Down Expand Up @@ -145,7 +145,7 @@ module.exports = {
embeds: [ embedcreator.setembed(
{
title: 'Error',
description: 'An error occured while removing the user from the notify list',
description: 'An error occurred while removing the user from the notify list',
color: '#e74c3c',
},
)], ephemeral: true,
Expand Down
14 changes: 9 additions & 5 deletions commands/reaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
global.client.channels.cache.get(env.discord.logs_channel).send({
embeds: [ embedcreator.setembed(
{
title: 'Incedent Detected',
title: 'Incident Detected',
description: `${interaction.member.user} tried to use the addrole command but did not have the Founders role.
Detailed information:
Message Link : ${messageLink}
Expand All @@ -59,7 +59,7 @@ module.exports = {
return interaction.reply({
embeds: [ embedcreator.setembed(
{
title: 'Incedent Reported',
title: 'Incident Reported',
description: 'You do not have permission to use this command. This incident has been reported.',
color: '#e74c3c',
},
Expand Down Expand Up @@ -104,8 +104,9 @@ module.exports = {
const channel = global.client.channels.cache.get(channelId);
const message = await channel.messages.fetch(messageId);
// Add to roles table if it doesn't exist
const db = await mariadb.getConnection();
db = await mariadb.getConnection();
await db.query('INSERT INTO roles (id, emoji, raw_emoji, message_id, channel_id) VALUES (?, ?, ?, ?, ?)', [roleid, emojiname, emoji, messageId, channelId]);
db.end();
message.react(emoji).then(() => {
console.log(`Added ${emojiname} to database`);
interaction.reply({
Expand Down Expand Up @@ -167,9 +168,10 @@ module.exports = {
return;
}
console.log(`roleId: ${roleid}`);
const db = await mariadb.getConnection();
// get messige id from the role database
db = await mariadb.getConnection();
// get message id from the role database
const result = await db.query('SELECT * FROM roles WHERE id = ?', [roleid]);
db.end();
if (result.length === 0) {
interaction.reply({
embeds: [ embedcreator.setembed(
Expand All @@ -195,7 +197,9 @@ module.exports = {
const message = await global.client.channels.cache.get(channel).messages.fetch(messageId);
// remove the role from the message
// remove the role from the table roles if it exists

await db.query('DELETE FROM roles WHERE id = ?', [roleid]);
db.end();
// lookup emoji id in guild
message.reactions.cache.get(emojiId).remove().then(() => {
console.log(`Removed ${roleName} from database`);
Expand Down
4 changes: 2 additions & 2 deletions commands/vc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
global.client.channels.cache.get(env.discord.logs_channel).send({
embeds: [ embedcreator.setembed(
{
title: 'Incedent Detected',
title: 'Incident Detected',
description: `${interaction.member.user} tried to use the vc move command but did not have the correct role.`,
color: '#e74c3c',
},
Expand All @@ -36,7 +36,7 @@ module.exports = {
return interaction.reply({
embeds: [ embedcreator.setembed(
{
title: 'Incedent Reported',
title: 'Incident Reported',
description: 'You do not have permission to use this command. This incident has been reported.',
color: '#e74c3c',
},
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ global.client.once('ready', async () => {
await db.query('CREATE TABLE IF NOT EXISTS roles (id BIGINT PRIMARY KEY, emoji VARCHAR(255), raw_emoji VARCHAR(255), message_id BIGINT, channel_id BIGINT)');
// create notify table if it doesn't exist
await db.query('CREATE TABLE IF NOT EXISTS notify (user_id VARCHAR(255) PRIMARY KEY, name VARCHAR(255))');
db.end();
}
)();
const commands = [];
Expand Down Expand Up @@ -95,7 +96,9 @@ global.client.on('messageReactionAdd', async (reaction, user) => {
const guild = channel.guild;
const emoji = reaction.emoji.name;
// query db for role
db = await mariadb.getConnection();
const role = await db.query('SELECT * FROM roles WHERE emoji = ? AND message_id = ?', [emoji, message.id]);
db.end();
if (role.length === 0) return;
const roleId = String(role[0].id);
const roleName = guild.roles.cache.get(roleId).name;
Expand All @@ -122,7 +125,9 @@ global.client.on('messageReactionRemove', async (reaction, user) => {
const guild = channel.guild;
const emoji = reaction.emoji.name;
// query db for role
db = await mariadb.getConnection();
const role = await db.query('SELECT * FROM roles WHERE emoji = ? AND message_id = ?', [emoji, message.id]);
db.end();
if (role.length === 0) return;
const roleId = String(role[0].id);
const member = guild.members.cache.get(user.id);
Expand Down

0 comments on commit ac6945d

Please sign in to comment.