rp chars work

master
Kit Kasune 3 years ago
parent 32a3584e7b
commit 501437826f
  1. 4
      bot.js
  2. 25
      commands/fun/rp.js
  3. 13
      events/messageCreate.js
  4. 8
      models/rpconfig.js
  5. 3
      util/cache.js
  6. 25
      util/cache/rp.js

@ -36,7 +36,6 @@ client.misc = {
hasLevelRoles: [],
disabledChannels: new Map()
},
chests: [],
chestsTimeout: new Map(),
chests: {
enabled: [],
@ -56,7 +55,8 @@ client.misc = {
charsLove: new Discord.Collection(),
monners: {},
monnersNames: new Map(),
spin: new spinnies()
spin: new spinnies(),
rp: new Map()
},
loggers: {},
rl: readline.createInterface({input: process.stdin, output: process.stdout}),

@ -1,6 +1,7 @@
const Discord = require('discord.js');
const RP = require("../../models/rpch");
const RPC = require('../../models/rpconfig');
const {Tag} = require('../../util/tag');
const {TagFilter} = require('../../util/tagfilter');
@ -32,7 +33,7 @@ module.exports = {
if (!options.image || !options.name || !options.prefix) {
tags = false;
const name = await ask(message, "What is the character's name?", 60000, false, undefined, true); if (!name) {return;}
if (name.length > 75) {return message.channel.send("That name is a little too long.");}
if (name.length > 50) {return message.channel.send("That name is a little too long.");}
options.name = name;
let prefix = await ask(message, "What is the character's prefix? This is how you will use the character.", 60000, false, undefined, true); if (!prefix) {return;}
@ -134,7 +135,7 @@ module.exports = {
name = await ask(message, "What name would you like to set?", 60000);
if (!name) {return;}
} else {name = args.join(" ");}
if (name.length > 75) {return message.channel.send("That name is a little too long.");}
if (name.length > 50) {return message.channel.send("That name is a little too long.");}
rp.chars[char.prefix].name = name;
rp.markModified(`chars.${char.prefix}`);
rp.save();
@ -154,7 +155,25 @@ module.exports = {
rp.save();
return message.channel.send("I've deleted that character for you.");
} else if (['enable', 'en'].includes(args[0].toLowerCase())) {
if (!message.guild) {return message.channel.send("You must be in a server in order to enable RP character usage for a specific channel.");}
if (!message.member.permissionsIn(message.channel.id).has("MANAGE_WEBHOOKS")) {return message.channel.send("You must have permissions to edit webhooks here in order to do that.");}
if (!message.guild.me.permissions.has("MANAGE_WEBHOOKS")) {return message.channel.send("I don't have permissions to manage webhooks in this server.");}
if (!message.guild.me.permissionsIn(message.channel.id).has("MANAGE_WEBHOOKS")) {return message.channel.send("I don't have the permissions to edit webhooks in this channel.");}
const webhooks = await message.channel.fetchWebhooks();
if (webhooks.find(wh => wh.token)) {return message.channel.send("It would seem RP is already enabled in this channel. If it's not working in this channel, please contact my developers.");}
try {
return message.channel.createWebhook("Natsuki RP Webhook", {avatar: client.user.avatarURL({size: 2048})})
.then(async () => {
const config = await RPC.findOne({gid: message.guild.id}) || new RPC({gid: message.guild.id});
config.channels.push(message.channel.id);
config.markModified('channels');
if (!client.misc.cache.rp.has(message.guild.id)) {client.misc.cache.rp.set(message.guild.id, []);}
client.misc.cache.rp.get(message.guild.id).push(message.channel.id);
config.save();
return message.channel.send("RP features were successfully enabled in this channel.");
})
.catch(message.channel.send("There was an error doing that. Please make sure my permissions are properly set in this channel and try again. If the error persists, please contact my developers."));
} catch {return message.channel.send("There was an error doing that. Please make sure my permissions are properly set in this channel and try again. If the error persists, please contact my developers.");}
}
return message.channel.send(`Invalid arg! Syntax: \`${prefix}rp <add|enable|edit|delete|view|list>\``);

@ -8,6 +8,7 @@ const AR = require('../models/ar');
const LXP = require('../models/localxp');
const Monitors = require('../models/monitor');
const Monners = require('../models/monners');
const RP = require('../models/rpch');
const channelTypes = ["GUILD_MESSAGE", "DM", "GUILD_NEWS_THREAD", "GUILD_PRIVATE_THREAD", "GUILD_PUBLIC_THREAD", "GUILD_NEWS", "GROUP_DM", "GUILD_STORE", "GUILD_TEXT"];
@ -56,6 +57,18 @@ module.exports = async (client, message) => {
message.reply('Hey there! You asked me to clear your status when you send a message next, so I went ahead and did that for you.').then(m => {setTimeout(() => {m.delete().catch(() => {});}, 5000);}).catch(() => {});
}});
if (message.guild && client.misc.cache.rp.has(message.guild.id) && client.misc.cache.rp.get(message.guild.id).includes(message.channel.id)) {
if (!msg.match(/^\w+:/m)) {return;}
const rp = await RP.findOne({uid: message.author.id});
if (!rp || !rp.chars[msg.split(':')[0]]) {return;}
const webhooks = await message.channel.fetchWebhooks();
const webhook = await webhooks.find(wh => wh.token);
if (!webhook) {return}
const char = rp.chars[msg.split(':')[0]];
webhook.send({content: message.content.slice(char.prefix.length + 1), avatarURL: char.image, username: char.name}).catch(() => {});
message.delete().catch(() => {});
}
if (message.guild && client.misc.cache.ar.has(message.guild.id) && client.misc.cache.ar.get(message.guild.id).includes(msg.trim()) && !(client.misc.cache.arIgnore.has(message.guild.id) && client.misc.cache.arIgnore.get(message.guild.id).includes(message.channel.id))) {
AR.findOne({gid: message.guild.id}).then(ar => {
if (ar && ar.triggers.length && ar.triggers.includes(msg.trim())) {return message.channel.send(ar.ars[ar.triggers.indexOf(msg.trim())]).catch(() => {});}

@ -0,0 +1,8 @@
const mongoose = require('mongoose');
const s = new mongoose.Schema({
gid: {type: String, required: true, unique: true},
channels: {type: [String], default: []}
});
module.exports = mongoose.model('rpconfig', s);

@ -34,6 +34,9 @@ module.exports = async (client) => {
let ctCache = spin.add("cht", {text: "Caching Chests..."});
loaders.push(require('./cache/chest')(client, ctCache));
let rpCache = spin.add("rp", {text: "Caching RP..."});
loaders.push(require('./cache/rp')(client, rpCache));
await Promise.all(loaders);
/*console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.bl.guild.length}`)} ${chalk.blueBright(`guild blacklists`)}`);

25
util/cache/rp.js vendored

@ -0,0 +1,25 @@
const Discord = require('discord.js');
const chalk = require('chalk');
const RPC = require('../../models/rpconfig');
module.exports = async (client, spinner) => {
return new Promise(async resolve => {
const st = new Date().getTime();
client.misc.cache.rp = new Map();
let amount = 0;
for await (const rp of RPC.find()) {
client.misc.cache.rp.set(rp.gid, rp.channels);
spinner.update({text: `${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${amount}`)} ${chalk.blueBright(`guilds with RP enabled.`)}`});
amount++;
}
const cacheTime = new Date().getTime() - st;
spinner.update({text: `${spinner.options.text.slice(0, 19).trim()} ${chalk.gray(`${cacheTime}ms >>`.padStart(8, '0').padStart(7, '0'))} ${spinner.options.text.slice(19).trim()}`});
spinner.status('non-spinnable');
resolve(0);
});
}
Loading…
Cancel
Save