Finish prefixes and fixed bugs

master
WubzyGD 4 years ago
parent 73ee25a5f7
commit e8ed30dd0e
  1. 3
      bot.js
  2. 12
      commands/prefix.js
  3. 2
      commands/staffrole.js
  4. 2
      events/message.js
  5. 11
      events/ready.js
  6. 3
      models/guild.js

@ -15,5 +15,8 @@ async function init() {
client.developers = ["330547934951112705", "673477059904929802"];
client.utils = {};
client.utils.logch = async () => {return client.guilds.cache.get('762707532417335296').channels.cache.get('762732961753595915');};
client.guildconfig = {};
client.guildconfig.prefixes = new Map();
}
init();

@ -1,5 +1,5 @@
const Discord = require('discord.js');
const GuildSettings = require('../util/guild');
const GuildSettings = require('../models/guild');
module.exports = {
name: "prefix",
@ -14,14 +14,20 @@ module.exports = {
let tguild = await GuildSettings.findOne({gid: message.guild.id})
? await GuildSettings.findOne({gid: message.guild.id})
: new GuildSettings({gid: message.guild.id});
if (!tguild.prefix) {tguild.prefix = '';}
if (!message.member.permissions.has("ADMINISTRATOR") && (!tguild.staffrole.length || !message.guild.roles.cache.has(tguild.staffrole) || !message.member.roles.cache.has(tguild.staffrole))) {return message.reply("You don't have the permissions to use this command here.");}
if (!args.length) {return message.channel.send(`Syntax: \`${prefix} <newPrefix|clear>\`. My current prefix in this server is \`${tguild.prefix.length ? tguild.prefix : 'n?'}\``);}
let np = args[0];
if (np.length > 7) {return message.reply("Hmmm, that prefix is a bit long. Try making something smaller!");}
if (!np.match(/^[a-zA-Z0-9,.!?<>\-_+=/;$#%^&*]$/m)) {return message.reply('Your custom prefix contains some *wonky* characters. Please use only alphanumerics and basic symbols.');}
if (!np.match(/^[a-zA-Z0-9,.!?<>\-_+=/;$#%^&*]+$/)) {return message.reply('Your custom prefix contains some *wonky* characters. Please use only alphanumerics and basic symbols.');}
tguild.prefix = ['c', 'clear', 'n', 'none'].includes(np.trim().toLowerCase()) ? '' : np;
tguild.save();
let upm = message.reply("sure thing!");
if (['c', 'clear', 'n', 'none'].includes(np.trim().toLowerCase())) {
client.guildconfig.prefixes.set(message.guild.id, null);
return message.reply('this server\'s prefix has been reset to the default, `n?`.');
}
client.guildconfig.prefixes.set(message.guild.id, np);
let upm = await message.reply("sure thing!");
await require('../util/wait')(1750);
return upm.edit(new Discord.MessageEmbed()
.setAuthor('Prefix updated!', message.author.avatarURL())

@ -32,7 +32,7 @@ module.exports = {
} else {
tguild.staffrole = role.id;
tguild.save();
let upm = message.reply("sure thing!");
let upm = await message.reply("sure thing!");
await require('../util/wait')(1750);
return upm.edit(new Discord.MessageEmbed()
.setAuthor('Staff role updated!', message.author.avatarURL())

@ -11,7 +11,7 @@ module.exports = async (client, message) => {
if (message.guild && !message.member.permissions.has("SEND_MESSAGES")) {return undefined;}
var prefix = 'n?';
var prefix = message.guild ? client.guildconfig.prefixes.has(message.guild.id) ? client.guildconfig.prefixes.get(message.guild.id) !== null ? client.guildconfig.prefixes.get(message.guild.id) : 'n?' : 'n?' : 'n?';
var msg = message.content.toLowerCase();
var mention = message.mentions.users.first();

@ -2,6 +2,7 @@ const Discord = require('discord.js');
const chalk = require('chalk');
const moment = require('moment');
const mongoose = require('mongoose');
const GuildSettings = require('../models/guild');
var prefix = 'n?';
@ -16,6 +17,9 @@ module.exports = async client => {
console.error(`\n${chalk.red('[ERROR]')} >> ${chalk.yellow(`At [${date}] | Occurred while trying to connect to Mongo Cluster`)}`, e);
}
/*let db = mongoose.connection;
await db.guild.update({}, {"$set": {'prefix': ''}}, false, true);*/
console.log(`\n${chalk.green('[BOOT]')} >> [${moment().format('L LTS')}] -> ${chalk.greenBright("Connected to Discord")}.`);
let date = new Date; date = date.toString().slice(date.toString().search(":") - 2, date.toString().search(":") + 6);
console.log(`\n${chalk.gray('[INFO]')} >> ${chalk.white(`Logged in at ${date}.`)}`);
@ -41,6 +45,13 @@ module.exports = async client => {
const BotDataSchema = require('../models/bot');
const setP = async () => {let tg; for (tg of Array.from(client.guilds.cache.values)) {
let tguild = await GuildSettings.findOne({gid: tg.id});
if (tguild && tguild.prefix && tguild.prefix.length) {client.guildconfig.prefixes.set(tg.id, tguild.prefix);}
}};
setP();
setInterval(setP, 120000);
let botData = await BotDataSchema.findOne({finder: 'lel'})
? await BotDataSchema.findOne({finder: 'lel'})
: new BotDataSchema({

@ -13,7 +13,8 @@ const guildSchema = new mongoose.Schema({
joinrole: {type: String, default: ''},
cooldowns: {type: Boolean, default: false},
levelmessage: {type: String, default: '**{{u}}** has reached level **{{l}}**! :tada:'},
levelmessages: {type: Boolean, default: false}
levelmessages: {type: Boolean, default: false},
prefix: {type: String, default: ''}
});
module.exports = mongoose.model("guild", guildSchema);
Loading…
Cancel
Save