Skip to content

Commit

Permalink
Merge pull request #8 from Project-Coda/dev
Browse files Browse the repository at this point in the history
1.2.0
  • Loading branch information
ikifar2012 authored Jul 14, 2022
2 parents 76095fd + 9c11228 commit 414beb4
Show file tree
Hide file tree
Showing 8 changed files with 708 additions and 9 deletions.
114 changes: 114 additions & 0 deletions commands/botgate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const mariadb = require('../db.js');
const env = require('../env.js');
const embedcreator = require('../embed.js');
const botgate = require('../utilities/botgate.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('botgate')
.setDescription('botgate command')
.addSubcommand(subcommand =>
subcommand
.setName('status')
.setDescription('Get the status of the botgate'),
)
.addSubcommand(subcommand =>
subcommand
.setName('set')
.setDescription('Set the status of the botgate')
.addBooleanOption(option =>
option.setName('botgate')
.setDescription('Enable or disable botgate')
.setRequired(true),
),
),
async execute(interaction) {
// Limit command to Founders and Mods
if (!(interaction.member.roles.cache.has(env.discord.admin_role) || interaction.member.roles.cache.has(env.discord.mod_role))) {
global.client.channels.cache.get(env.discord.logs_channel).send({
embeds: [ embedcreator.setembed(
{
title: 'Incident Detected',
description: `${interaction.member.user} tried to use the botgate command but did not have the correct role.`,
color: '#e74c3c',
},
)],
},
);
return interaction.reply({
embeds: [ embedcreator.setembed(
{
title: 'Incident Reported',
description: 'You do not have permission to use this command. This incident has been reported.',
color: '#e74c3c',
},
),
], ephemeral: true,
});
}
const subcommand = interaction.options.getSubcommand();
if (subcommand === 'set') {
if (interaction.options.get('botgate')) {
const botgatevalue = interaction.options.get('botgate').value;
// check if botgate setting exists
db = await mariadb.getConnection();
const exists = await db.query('SELECT * FROM settings WHERE setting = ?', ['botgate']);
db.end();
if (exists.length == 0) {
// create botgate setting
db = await mariadb.getConnection();
await db.query('INSERT INTO settings (setting, value) VALUES (?, ?)', ['botgate', 0]);
db.end();
}
if (botgatevalue === true) {
db = await mariadb.getConnection();
db.query('UPDATE settings SET value = ? WHERE setting = ?', [1, 'botgate']);
db.end();
embedcreator.alert(`Botgate Enabled by ${interaction.member.user}`);
return interaction.reply({
embeds: [embedcreator.setembed({
title: 'Botgate Enabled',
description: 'Botgate is now enabled.',
color: '#2ecc71',
})], ephemeral: true,
});
}
if (botgatevalue === false) {
db = await mariadb.getConnection();
db.query('UPDATE settings SET value = ? WHERE setting = ?', [0, 'botgate']);
db.end();
embedcreator.alert(`Botgate Disabled by ${interaction.member.user}`);
return interaction.reply({
embeds: [embedcreator.setembed({
title: 'Botgate Disabled',
description: 'Botgate is now disabled.',
color: '#e74c3c',
})], ephemeral: true,
});
}
}
}
if (subcommand === 'status') {
// check if botgate is enabled
botgatestatus = await botgate.status();
if (botgatestatus) {
return interaction.reply({
embeds: [embedcreator.setembed({
title: 'Botgate Status',
description: 'Botgate is enabled.',
color: '#2ecc71',
})], ephemeral: true,
});
}
else {
return interaction.reply({
embeds: [embedcreator.setembed({
title: 'Botgate Status',
description: 'Botgate is disabled.',
color: '#e74c3c',
})], ephemeral: true,
});
}
}
},
};
36 changes: 36 additions & 0 deletions commands/chord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const embedcreator = require('../embed.js');
const { Chord } = require('@tonaljs/tonal');

module.exports = {
data: new SlashCommandBuilder()
.setName('chord')
.setDescription('Get chord info')
.addStringOption(option =>
option.setName('chord')
.setDescription('Chord to get info for')
.setRequired(true),
),
async execute(interaction) {
const chord = interaction.options.get('chord').value;
const chordInfo = Chord.get(chord);
if (chordInfo && chordInfo.type) {
console.log(chordInfo);
return interaction.reply({
embeds: [embedcreator.setembed({
title: `${chordInfo.name}`,
description: `**Notes:** ${chordInfo.notes.join(' ')}
**Intervals:** ${chordInfo.intervals.join(' ')}`,
})],
});
}
embedcreator.log(`${interaction.member.user} used the chord command\nparameters: ${chord}\n error: ${JSON.stringify(chordInfo)}`);
return interaction.reply({
embeds: [embedcreator.setembed({
title: 'Error',
description: `Could not find chord ${chord}`,
color: '#e74c3c',
})],
});
},
};
16 changes: 12 additions & 4 deletions embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const merge = require('lodash.merge');
var setembed = function(opts){
var embed = {
// Discord Embed Template Coda
color: 0x00ff00,
title: '',
description: '',
color: '#19ebfe',
url: '',
timestamp: `${new Date()}`,
footer: {
Expand All @@ -17,7 +17,7 @@ var setembed = function(opts){
};
var sendError = function(message){
try {
const embed = setembed({
var embed = setembed({
title: 'Error',
description: `${message}`,
color: '#e74c3c',
Expand All @@ -29,11 +29,19 @@ var sendError = function(message){
}
};
var log = function(message){
const embed = setembed({
var embed = setembed({
title: 'Log',
description: `${message}`,
color: '#19ebfe',
});
global.client.channels.cache.get(env.discord.logs_channel).send({ embeds: [embed] });
};
module.exports = { setembed, sendError, log };
var alert = function(message){
var embed = setembed({
title: '🚨 Alert 🚨',
description: `${message}`,
color: '#e74c3c',
});
global.client.channels.cache.get(env.discord.logs_channel).send({ content: '🚨 Critical Alert 🚨' + '\n<@&' + env.discord.admin_role + '> <@&' + env.discord.mod_role + '>', embeds: [embed] });
};
module.exports = { setembed, sendError, log, alert };
34 changes: 33 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ const mariadb = require('./db.js');
const greet = require('./utilities/greet.js');
const embedcreator = require('./embed.js');
const emojiUnicode = require('emoji-unicode');
const figlet = require('figlet');
const botgate = require('./utilities/botgate.js');
const pkg = require('./package.json');
global.client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES],
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
});
global.client.login(env.discord.token);
console.log(figlet.textSync('CODA UTILITIES', {
font: 'Standard',
horizontalLayout: 'default',
verticalLayout: 'default',
}));
console.log(`Version: ${pkg.version}`);
console.log(`Author: ${pkg.author}`);
console.log(`GitHub: ${pkg.repository.url}`);
global.client.once('ready', async () => {
console.log('Ready!');
// get the number of users in the server
Expand All @@ -30,6 +41,8 @@ global.client.once('ready', async () => {
await db.query('CREATE TABLE IF NOT EXISTS roles (id VARCHAR(255) PRIMARY KEY, emoji VARCHAR(255), raw_emoji VARCHAR(255), message_id VARCHAR(255), channel_id VARCHAR(255)) COLLATE utf8mb4_general_ci CHARSET utf8mb4;');
// 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))');
// create settings table if it doesn't exist
await db.query('CREATE TABLE IF NOT EXISTS settings (setting VARCHAR(255) PRIMARY KEY, value BOOLEAN)');
db.end();
}
)();
Expand Down Expand Up @@ -66,10 +79,29 @@ const rest = new REST({ version: '9' }).setToken(env.discord.token);
})();

global.client.on('guildMemberAdd', async member => {
const guild = global.client.guilds.cache.get(env.discord.guild);

// check if member is a bot
if (member.user.bot) {
botgatestatus = await botgate.status();
console.log(`${member.user.tag} is a bot.`);
if (botgatestatus === true) {
console.log('Botgate is enabled.');
console.log('Kicking bot...');
member.kick('Botgate is enabled.');
console.log('Kicked bot.');
return greet.sendKickAlert(member);
}
else {
console.log('Botgate is disabled.');
const guild = global.client.guilds.cache.get(env.discord.guild);
const members = await guild.members.fetch();
global.client.user.setActivity(`${members.size} members`, { type: 'WATCHING' });
return greet.SendNewBotAlert(member);
}
}
greet.sendNotify(member);
// Update presence
const guild = global.client.guilds.cache.get(env.discord.guild);
const members = await guild.members.fetch();
global.client.user.setActivity(`${members.size} members`, { type: 'WATCHING' });
},
Expand Down
Loading

0 comments on commit 414beb4

Please sign in to comment.