Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zyno-bot-addons

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zyno-bot-addons - npm Package Compare versions

Comparing version 1.0.24 to 1.1.0

src/classes/builders/formBuilder.js

2

index.js

@@ -17,3 +17,5 @@ const { PermissionFlagsBits, EmbedBuilder } = require('discord.js');

SelectMenuOptionBuilder: require('./src/classes/builders/selectMenuOptionBuilder.js'),
FormBuilder: require('./src/classes/builders/formBuilder.js'),
InputBuilder: require('./src/classes/builders/inputBuilder.js'),
ActionRowBuilder: require('./src/classes/builders/actionRowBuilder.js')
}

8

package.json
{
"name": "zyno-bot-addons",
"version": "1.0.24",
"version": "1.1.0",
"description": "Create easily addons for Zyno Bot",

@@ -16,6 +16,6 @@ "main": "index.js",

"dependencies": {
"discord.js": "^14.11.0",
"discord.js": "^14.13.0",
"valuesaver": "^1.9.3",
"ws": "^8.13.0",
"yt-stream": "^1.4.5"
"ws": "^8.14.2",
"yt-stream": "^1.4.8"
},

@@ -22,0 +22,0 @@ "readme": "readme.MD",

const EventEmitter = require('events');
const Save = require('./save.js');
const { createBitfield, validatePermission, getAddonPermission } = require('../utils/functions.js');
const { commandListeners, eventListeners, addons, addonCreate, botClasses } = require('../utils/saves.js');
const { commandListeners, eventListeners, addons, botClasses } = require('../utils/saves.js');
const { registerAddon, commandRegistrant } = require('./handlers/addonHandler.js');

@@ -69,4 +69,27 @@ const Bot = require('./structures/bot.js');

const addonInfo = addons.get(this.name);
let nextAddonCallback = null;
if(!addonInfo){
try{
nextAddonCallback = await clientParser.emitAddon(this);
} catch (err){
console.log(err);
return;
}
} else if(addonInfo.addon.author !== this.author || addonInfo.addon.version !== this.version){
try{
nextAddonCallback = await clientParser.emitAddon(this);
} catch (err){
console.log(err);
return;
}
}
this.created = new Date();
const registrant = await registerAddon(this);
if(typeof nextAddonCallback === 'function') nextAddonCallback();
if(registrant === true){

@@ -125,35 +148,22 @@ Object.defineProperty(this, 'ready', {

let addonInfo = addons.get(this.name);
new Promise((resolve, _reject) => {
if(addonInfo) resolve();
else {
addonCreate.once(this.name, (allowed) => {
if(allowed === true){
addonInfo = addons.get(this.name);
resolve();
} else {
_reject('The addon has been declined by the bot\'s owner');
}
});
if(!addonInfo) return reject('Addon hasn\'t been enabled by the owner of the bot');
if(addonInfo.verified === false || addonInfo.allowed === false) return reject('Addon hasn\'t been enabled by the owner of the bot');
new Promise((parse) => {
if(clientParser.ready === false){
clientParser.once('ready', () => {
parse()
})
} else {
parse();
}
}).then(() => {
if(addonInfo.verified === false || addonInfo.allowed === false) return reject('Addon hasn\'t been enabled by the owner of the bot');
new Promise((parse) => {
if(clientParser.ready === false){
clientParser.once('ready', () => {
parse()
})
} else {
parse();
}
}).then(() => {
const filter = botClasses.filter(b => b.addonName === this.name);
if(filter.length > 0){
resolve(filter[0].bot);
} else {
const bot = new Bot(this);
botClasses.push({addonName: this.name, bot: bot});
resolve(bot);
}
});
}).catch(reject)
const filter = botClasses.filter(b => b.addonName === this.name);
if(filter.length > 0){
resolve(filter[0].bot);
} else {
const bot = new Bot(this);
botClasses.push({addonName: this.name, bot: bot});
resolve(bot);
}
});
});

@@ -164,34 +174,21 @@ }

let addonInfo = addons.get(this.name);
new Promise((resolve, _reject) => {
if(addonInfo) resolve();
else {
addonCreate.once(this.name, (allowed) => {
if(allowed === true){
addonInfo = addons.get(this.name);
resolve();
} else {
_reject('The addon has been declined by the bot\'s owner');
}
});
if(!addonInfo) return reject('Addon hasn\'t been enabled by the owner of the bot');
if(addonInfo.verified === false || addonInfo.allowed === false) return reject('Addon hasn\'t been enabled by the owner of the bot');
if(!validatePermission(getAddonPermission(this.name), scopes.bitfield.SERVERS)) return reject('The addon doesn\'t have permissions to make use of the HTTP server');
new Promise((parse) => {
if(clientParser.ready === false){
clientParser.once('ready', () => {
parse(clientParser.getClient());
})
} else {
parse(clientParser.getClient());
}
}).then(() => {
if(addonInfo.verified === false || addonInfo.allowed === false) return reject('Addon hasn\'t been enabled by the owner of the bot');
if(!validatePermission(getAddonPermission(this.name), scopes.bitfield.SERVERS)) return reject('The addon doesn\'t have permissions to make use of the HTTP server');
new Promise((parse) => {
if(clientParser.ready === false){
clientParser.once('ready', () => {
parse(clientParser.getClient());
})
} else {
parse(clientParser.getClient());
}
}).then(client => {
const port = client.config.port;
if(typeof port === 'string' || typeof port === 'number'){
resolve(HttpServerHandler.startHTTPServer(parseInt(port)));
} else {
return reject('The owner of the bot hasn\'t set a port for the HTTP server');
}
});
}).catch(reject);
}).then(client => {
const port = client.config.port;
if(typeof port === 'string' || typeof port === 'number'){
resolve(HttpServerHandler.startHTTPServer(parseInt(port)));
} else {
return reject('The owner of the bot hasn\'t set a port for the HTTP server');
}
});
});

@@ -202,34 +199,21 @@ }

let addonInfo = addons.get(this.name);
new Promise((resolve, reject) => {
if(addonInfo) resolve();
else {
addonCreate.once(this.name, (allowed) => {
if(allowed === true){
addonInfo = addons.get(this.name);
resolve();
} else {
reject('The addon has been declined by the bot\'s owner');
}
});
if(!addonInfo) return reject('Addon hasn\'t been enabled by the owner of the bot');
if(addonInfo.verified === false || addonInfo.allowed === false) return reject('Addon hasn\'t been enabled by the owner of the bot');
if(!validatePermission(getAddonPermission(this.name), scopes.bitfield.SERVERS)) return reject('The addon doesn\'t have permissions to make use of the WebSocket server');
new Promise((parse) => {
if(clientParser.ready === false){
clientParser.once('ready', () => {
parse(clientParser.getClient());
})
} else {
parse(clientParser.getClient());
}
}).then(() => {
if(addonInfo.verified === false || addonInfo.allowed === false) return reject('Addon hasn\'t been enabled by the owner of the bot');
if(!validatePermission(getAddonPermission(this.name), scopes.bitfield.SERVERS)) return reject('The addon doesn\'t have permissions to make use of the WebSocket server');
new Promise((parse) => {
if(clientParser.ready === false){
clientParser.once('ready', () => {
parse(clientParser.getClient());
})
} else {
parse(clientParser.getClient());
}
}).then(client => {
const port = client.config.port;
if(typeof port === 'string' || typeof port === 'number'){
resolve(HttpServerHandler.startWSServer(parseInt(port)));
} else {
return reject('The owner of the bot hasn\'t set a port for the HTTP server');
}
});
}).catch(reject);
}).then(client => {
const port = client.config.port;
if(typeof port === 'string' || typeof port === 'number'){
resolve(HttpServerHandler.startWSServer(parseInt(port)));
} else {
return reject('The owner of the bot hasn\'t set a port for the HTTP server');
}
});
});

@@ -240,39 +224,26 @@ }

let addonInfo = addons.get(this.name);
new Promise((resolve, reject) => {
if(addonInfo) resolve();
else {
addonCreate.once(this.name, (allowed) => {
if(allowed === true){
addonInfo = addons.get(this.name);
resolve();
} else {
reject('The addon has been declined by the bot\'s owner');
}
});
if(!addonInfo) return reject('Addon hasn\'t been enabled by the owner of the bot');
if(addonInfo.verified === false || addonInfo.allowed === false) return reject('Addon hasn\'t been enabled by the owner of the bot');
if(!validatePermission(getAddonPermission(this.name), scopes.bitfield.SAVES)) return reject('The addon doesn\'t have permissions to read the saves');
new Promise((parse) => {
if(clientParser.ready === false){
clientParser.once('ready', () => {
parse(clientParser.getClient());
})
} else {
parse(clientParser.getClient());
}
}).then(() => {
if(addonInfo.verified === false || addonInfo.allowed === false) return reject('Addon hasn\'t been enabled by the owner of the bot');
if(!validatePermission(getAddonPermission(this.name), scopes.bitfield.SAVES)) return reject('The addon doesn\'t have permissions to read the saves');
new Promise((parse) => {
if(clientParser.ready === false){
clientParser.once('ready', () => {
parse(clientParser.getClient());
})
} else {
parse(clientParser.getClient());
}
}).then(client => {
resolve({
tickets: new Save(client.tickets),
level: new Save(client.xp),
economy: new Save(client.economy),
afk: new Save(client.afk),
badwords: new Save(client.badwords),
giveaways: new Save(client.giveaways),
reactrole: new Save(client.reactrole),
suggestions: new Save(client.suggestions),
warns: new Save(client.warns)
});
}).then(client => {
resolve({
tickets: new Save(client.tickets),
level: new Save(client.xp),
economy: new Save(client.economy),
afk: new Save(client.afk),
badwords: new Save(client.badwords),
giveaways: new Save(client.giveaways),
reactrole: new Save(client.reactrole),
suggestions: new Save(client.suggestions),
warns: new Save(client.warns)
});
}).catch(reject);
});
})

@@ -279,0 +250,0 @@ }

@@ -23,2 +23,9 @@ const CommandOptionsBuilder = require('./commandOptionsBuilder');

}
setCategory(category){
if(typeof category !== 'string') throw new Error(`Invalid command: Category must be a string`);
const validCategories = ["general", "polls", "games", "fun", "giveaway", "music", "moderation", "economy", "level", "tickets", "bot", "admin"];
if(validCategories.indexOf(category.toLowerCase()) < 0) throw new Error(`Invalid command: Category must be one of options ${validCategories.join(', ')}`);
this.category = category.toLowerCase();
return this;
}
addOptions(...options){

@@ -79,3 +86,4 @@ for(var i = 0; i < options.length; i++){

nsfw: this.nsfw,
overwrite: this.overwrite
overwrite: this.overwrite,
category: this.category
};

@@ -91,4 +99,5 @@ return commandObject;

overwrite = false;
category = "general";
}
module.exports = CommandBuilder;

@@ -5,3 +5,3 @@ const Save = require('./save.js');

const Role = require('./structures/role.js');
const { getClient } = require('../utils/functions.js');
const { getClientParser, getClient } = require('../utils/functions.js');
const { getMessageContent } = require('../utils/messageFunctions.js');

@@ -94,2 +94,20 @@ const { ApplicationCommandOptionType, ChannelType } = require('discord.js');

}
this.executeCommand = (commandName, args) => {
return new Promise((resolve, reject) => {
if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.COMMANDS)) return reject(`Missing commands scope in bitfield`);
if(typeof commandName !== 'string') return reject(`Command name must be a type of string`);
if(!Array.isArray(args)){
args = this.args;
}
let clientParser = getClientParser();
let client = clientParser.getClient();
const cmd = client.commands.get(commandName);
if(cmd){
cmd.run(client, args, data, true);
} else {
client.clientParser.interactionHandler.emit('execute', data, false);
}
resolve();
});
}
}

@@ -96,0 +114,0 @@ name = null;

@@ -5,7 +5,7 @@ const { ValueSaver } = require('valuesaver');

const CommandBuilder = require('../builders/commandBuilder.js');
const { getPermissionsString, generateId } = require('../../utils/functions.js');
const { generateId } = require('../../utils/functions.js');
const { getClientParser } = require('../../utils/parser.js');
const { createStructures } = require('./eventHandler.js');
const structureHandler = require('./structureHandler.js');
const { addons, addonCreate } = require('../../utils/saves.js');
const { addons, addonCreate, commandListeners, eventListeners } = require('../../utils/saves.js');
const EventEmitter = require('events');

@@ -23,5 +23,135 @@ const fs = require('fs/promises');

if(addon.permissions !== registrant.bitfield) return false;
if(addon.resolveablePath !== registrant.resolveablePath) return false;
return true;
}
class AddonRegistar{
constructor(){}
disableAddon(addonName, force = true, restart = false){
return new Promise(async (resolve, reject) => {
await new Promise(resolve => {
if(clientParser.ready === false){
clientParser.once('ready', () => {
resolve();
});
} else {
resolve();
}
});
const addon = addons.get(addonName);
if(!addon) return reject(`The addon was not found in the registar`);
if(addon.verified === false || addon.allowed === false) return reject(`The addon has already been disabled`);
const baseName = `${addon.addon.name}@${addon.addon.version}-${addon.addon.author}`;
const registeredAddon = registeredAddons.get(baseName);
if(registeredAddon){
registeredAddons.delete(baseName);
}
addons.set(addonName, {
...addon,
verified: false,
allowed: false,
restarting: restart,
stopping: true,
starting: false
});
try{
let addonValuesaver = registeredAddons.toReadableArray();
await fs.writeFile(path.join(__dirname, `../../addons.json`), JSON.stringify(addonValuesaver), {encoding: 'utf-8'});
} catch {}
const registeredCommands = commandRegistrant.addonCommands.filter(c => c.addon === addonName);
const keys = registeredCommands.toReadableArray().map(c => c.key);
for(let i = 0; i < keys.length; i++){
let key = keys[i];
commandRegistrant.addonCommands.delete(key);
}
clientParser.getClient().addons.writeValueSaver(commandRegistrant.addonCommands.toReadableArray());
delete require.cache[require.resolve(addon.resolveablePath)];
addon.addon.channels.clear();
addon.addon.guilds.clear();
addon.addon.commands.clear();
addon.addon.removeAllListeners();
const _commandListeners = commandListeners.filter(c => c.addonName === addonName);
for(let i = 0; i < _commandListeners.length; i++){
_commandListeners[i].listener.removeAllListeners();
commandListeners.splice(commandListeners.indexOf(_commandListeners[i]), 1);
}
const _eventListeners = eventListeners.filter(e => e.addonName === addonName);
for(let i = 0; i < _eventListeners.length; i++){
_eventListeners[i].listener.removeAllListeners();
eventListeners.splice(eventListeners.indexOf(_eventListeners[i]), 1);
}
const commandHandlers = registeredCommands.toReadableArray().map(a => a.value.passedClass);
for(let i = 0; i < commandHandlers.length; i++){
commandHandlers[i].removeAllListeners();
}
if(force === true){
let commands = [...registeredCommands.toReadableArray().map(a => new CommandBuilder(a.value.command).toJSON())];
for(var i = 0; i < commands.length; i++){
delete commands[i]['overwrite'];
}
await clientParser.getClient().updateCommands(commands);
}
addons.set(addonName, {
...addon,
verified: false,
allowed: false,
restarting: restart,
stopping: false,
starting: false
});
resolve();
});
}
enableAddon(addonName){
return new Promise(async (resolve, reject) => {
const addon = addons.get(addonName);
if(!addon) return reject(`The addon was not found in the registar`);
const baseName = `${addon.addon.name}@${addon.addon.version}-${addon.addon.author}`;
registeredAddons.set(baseName, {
name: addon.addon.name,
bitfield: addon.permissions,
resolveablePath: addon.resolveablePath
});
addons.set(addonName, {
...addon,
verified: true,
allowed: true,
restarting: false,
stopping: false,
starting: true
});
try{
let addonValuesaver = registeredAddons.toReadableArray();
await fs.writeFile(path.join(__dirname, `../../addons.json`), JSON.stringify(addonValuesaver), {encoding: 'utf-8'});
} catch {}
try{
require(require.resolve(addon.resolveablePath));
} catch (err){
return reject(`There was an error while registering the addon '${addon}': ${err}`);
}
resolve();
});
}
restartAddon(addonName){
return new Promise((resolve, reject) => {
this.disableAddon(addonName, true, true).then(() => {
this.enableAddon(addonName).then(resolve).catch(reject);
}).catch(reject);
});
}
}
const addonRegistar = new AddonRegistar();
clientParser.parseAddonRegistar(addonRegistar);
class CommandRegister extends EventEmitter{

@@ -143,6 +273,9 @@ constructor(){

this.timeout = undefined;
var commands = this.queue.map(q => q.command);
var commands = [...this.queue.map(q => {
return {...q.command}
})];
commands.push(...this.addonCommands.toReadableArray().map(a => new CommandBuilder(a.value.command).toJSON()));
for(var i = 0; i < commands.length; i++){
delete commands[i]['overwrite'];
delete commands[i]['category'];
}

@@ -222,5 +355,3 @@ try{

if(typeof addon.name === 'string'){
if(addons.get(addon.name)){
resolve({error: 'Invalid addon: Another addon with the same name already exists'});
} else {
if(!addons.get(addon.name)){
var getRegistrant = registeredAddons.get(baseName);

@@ -233,3 +364,7 @@ if(validateRegistrant(addon, getRegistrant)){

verified: true,
allowed: true
allowed: true,
resolveablePath: addon.resolveablePath,
restarting: false,
stopping: false,
starting: false
});

@@ -247,46 +382,36 @@ addonCreate.emit(addon.name, true);

} else {
new Promise(async _resolve => {
var permissionsString = getPermissionsString(addon.permissions);
if(clientParser.ready === true){
const addonRegistrant = await clientParser.getClient().registerAddon(addon, permissionsString);
_resolve(addonRegistrant);
} else {
clientParser.once('ready', async () => {
const addonRegistrant = await clientParser.getClient().registerAddon(addon, permissionsString);
_resolve(addonRegistrant);
});
}
}).then(async val => {
if(val === true){
addons.set(addon.name, {
baseName: baseName,
addon: addon,
permissions: addon.permissions,
verified: true,
allowed: true
});
registeredAddons.set(baseName, {
name: addon.name,
bitfield: addon.permissions
});
addonCreate.emit(addon.name, true);
try{
let addonValuesaver = registeredAddons.toReadableArray();
await fs.writeFile(path.join(__dirname, `../../addons.json`), JSON.stringify(addonValuesaver), {encoding: 'utf-8'});
} catch {}
await createStructures(clientParser.getClient(), addons.toReadableArray());
resolve(true);
} else {
addons.set(addon.name, {
baseName: baseName,
addon: addon,
permissions: addon.permissions,
verified: false,
allowed: false
});
addonCreate.emit(addon.name, false);
resolve(false);
}
addons.set(addon.name, {
baseName: baseName,
addon: addon,
permissions: addon.permissions,
verified: true,
allowed: true,
resolveablePath: addon.resolveablePath,
restarting: false,
stopping: false,
starting: false
});
addonRegistar.disableAddon(addon.name, false, false).then(() => {
resolve(false);
}).catch(err => {
resolve({error: err});
});
}
} else {
if(typeof addon.resolveablePath === 'string') throw new Error(`Another addon with the name '${addon.name}' has already been registered`);
const addonInfo = addons.get(addon.name);
addons.set(addon.name, {
baseName: addonInfo.baseName,
addon: addon,
permissions: addon.permissions,
verified: true,
allowed: true,
resolveablePath: addon.resolveablePath,
restarting: false,
stopping: false,
starting: false
});
await createStructures(clientParser.getClient(), addons.toReadableArray());
addonCreate.emit(addon.name, true);
resolve(true);
}

@@ -293,0 +418,0 @@ } else {

@@ -6,9 +6,12 @@ const EventEmitter = require('events');

const { handleEvents, createStructures } = require('./eventHandler.js');
const { validatePermission } = require('../../utils/functions.js');
const { validatePermission, passClientParser } = require('../../utils/functions.js');
const bitfields = require('../../bitfields/scopes.js');
var client = null;
let receivedAddons = [];
class ClientParser extends EventEmitter{
constructor(){
super();
passClientParser(this);
this.once('ready', async () => {

@@ -42,2 +45,6 @@ this.client_ready = true;

}
parseAddonRegistar(addonRegistar){
this.addonRegistar = addonRegistar;
this.emit('addonRegistarReady', this.addonRegistar);
}
commandAvailability(data, interaction){

@@ -80,2 +87,55 @@ return new Promise(async (resolve, reject) => {

}
parseAddons(addons, force = false){
return new Promise(async (resolve, reject) => {
if(!Array.isArray(addons)) return reject(`Invalid addon array`);
const addonsArr = this.addons.toReadableArray();
for(let i = 0; i < addons.length; i++){
await new Promise(_resolve => {
let addonName = addons[i];
let resolveableName = require.resolve(addonName);
if(addonsArr.filter(a => a.value.resolveablePath === resolveableName).length > 0){
_resolve(true);
} else {
this.once('addonEmit',async (addon, callback) => {
clearTimeout(this.waitableTimeout[resolveableName]);
Object.defineProperty(addon, 'resolveablePath', {
value: resolveableName,
writable: false,
configurable: false
});
this.removeAllListeners('addonEmit');
receivedAddons.push(resolveableName);
callback(addon.name, true, function(){
if(force) _resolve(true);
});
if(!force) _resolve(true);
});
try{
require(resolveableName);
} catch (err){
console.log(`Error while starting addon:`, err);
}
setTimeout(() => {
if(receivedAddons.indexOf(resolveableName) >= 0) return;
delete require.cache[resolveableName];
this.removeAllListeners('addonEmit');
_resolve(false);
}, 3e3);
}
});
}
resolve();
});
}
emitAddon(addon){
return new Promise((resolve, reject) => {
this.emit('addonEmit', addon, function(name, bool, callback){
if(name === addon.name && bool) resolve(callback);
else{
callback();
reject(`Due to security reasons, this addon was blocked`);
}
});
});
}
client_ready = false;

@@ -85,4 +145,7 @@ ready = false;

event = new EventEmitter();
waitableTimeout = {}
addons = addons;
addonRegistar = undefined;
}
module.exports = ClientParser;

@@ -5,14 +5,17 @@ const structureHandler = require('./structureHandler.js');

const GuildManager = require('../managers/guildManager.js');
const inviteManager = require('../managers/inviteManager.js');
const { getAddonPermission, validatePermission, passClient, wait } = require('../../utils/functions.js');
const { eventListeners, addons } = require('../../utils/saves.js');
const { eventListeners, addons, emojiCollectors, interactionCollectors } = require('../../utils/saves.js');
const scopes = require('../../bitfields/scopes.js');
const { ChannelType, AuditLogEvent } = require('discord.js');
const MessageManager = require('../managers/messageManager.js');
function createStructures(client, addons){
function createStructures(client, _addons){
return new Promise(async resolve => {
const readableAddons = addons.toReadableArray();
const guilds = Object.values(client.mainguilds);
for(var i = 0; i < guilds.length; i++){
var guild = guilds[i];
for(var z = 0; z < addons.length; z++){
var addonInfo = addons[z].value;
for(var z = 0; z < readableAddons.length; z++){
var addonInfo = readableAddons[z].value;
structureHandler.createStructure('Guild', [guild, addonInfo.addon]);

@@ -39,3 +42,3 @@ if(addonInfo.verified === true && addonInfo.allowed === true){

listener.listener.emit(eventName, ...args);
}
} else;
}

@@ -49,2 +52,43 @@

client.on('inviteCreate', invite => {
if(!invite) return;
if(client.config.guilds.indexOf(invite.guild.id) < 0) return;
_addons = addons.toReadableArray();
for(var z = 0; z < _addons.length; z++){
let addonInfo = _addons[z].value;
if(addonInfo.verified === true && addonInfo.allowed === true){
if(validatePermission(getAddonPermission(addonInfo.addon.name), scopes.bitfield.GUILDS)){
const addonGuilds = GuildManager.get(addonInfo.addon.name) || structureHandler.createStructure('Save');
const cachedGuild = addonGuilds.get(invite.guild.id);
if(!cachedGuild) continue;
const cachedInvite = structureHandler.createStructure('Invite', [invite, cachedGuild, addonInfo.addon]);
emitEvent(addonInfo.addon.name, 'inviteCreate', scopes.bitfield.GUILDS, cachedInvite);
}
}
}
});
client.on('inviteDelete', invite => {
if(!invite) return;
if(client.config.guilds.indexOf(invite.guild.id) < 0) return;
_addons = addons.toReadableArray();
for(var z = 0; z < _addons.length; z++){
let addonInfo = _addons[z].value;
if(addonInfo.verified === true && addonInfo.allowed === true){
if(validatePermission(getAddonPermission(addonInfo.addon.name), scopes.bitfield.GUILDS)){
const addonInviteManager = inviteManager.get(addonInfo.addon.name) || structureHandler.createStructure('Save');
const guildInviteManager = addonInviteManager.get(invite.guild.id) || structureHandler.createStructure('Save');
const cachedInvite = guildInviteManager.get(invite.code);
guildInviteManager.delete(invite.code);
addonInviteManager.set(invite.guild.id, guildInviteManager);
inviteManager.set(addonInfo.addon.name, addonInviteManager);
emitEvent(addonInfo.addon.name, 'inviteDelete', scopes.bitfield.GUILDS, cachedInvite);
}
}
}
});
parser.on('voiceStateUpdate', (_oldState, _newState) => {

@@ -298,3 +342,3 @@ if(!_newState || !_oldState) return;

parser.on('ticketClose', (_channel, transcript) => {
parser.on('ticketClose', (_channel, transcript, rawInfo) => {
if(!_channel) return;

@@ -324,3 +368,3 @@ if(client.config.guilds.indexOf(_channel.guild.id) < 0) return;

}
emitEvent(addonInfo.addon.name, 'ticketClose', scopes.bitfield.MEMBERS, channel, transcript);
emitEvent(addonInfo.addon.name, 'ticketClose', scopes.bitfield.CHANNELS, channel, transcript, rawInfo);
}

@@ -385,2 +429,13 @@ }

const msg = structureHandler.createStructure('Message', [message, addonInfo.addon]);
if(msg.channel){
if(validatePermission(getAddonPermission(addonInfo.addon.name), scopes.bitfield.MESSAGES) && (msg.channel.isVoiceStage() || msg.channel.isTextChannel() || msg.channel.isThread() || msg.channel.isVoiceChannel())){
const addonMessageManager = MessageManager.get(addonInfo.addon.name) || structureHandler.createStructure('Save');
const guildMessageManager = addonMessageManager.get(message.guild.id) || structureHandler.createStructure('Save');
const channelMessageManager = guildMessageManager.get(message.channel.id) || structureHandler.createStructure('Save');
channelMessageManager.set(message.id, msg);
guildMessageManager.set(message.channel.id, channelMessageManager);
addonMessageManager.set(message.guild.id, guildMessageManager);
MessageManager.set(addonInfo.addon.name, addonMessageManager);
}
}
emitEvent(addonInfo.addon.name, 'message', scopes.bitfield.MESSAGES, msg);

@@ -405,2 +460,11 @@ }

const message = structureHandler.createStructure('Message', [_message, addonInfo.addon]);
if(validatePermission(getAddonPermission(addonInfo.addon.name), scopes.bitfield.MESSAGES)){
const addonMessageManager = MessageManager.get(addonInfo.addon.name) || structureHandler.createStructure('Save');
const guildMessageManager = addonMessageManager.get(_message.guild.id) || structureHandler.createStructure('Save');
const channelMessageManager = guildMessageManager.get(_message.channel.id) || structureHandler.createStructure('Save');
channelMessageManager.delete(_message.id);
guildMessageManager.set(_message.channel.id, channelMessageManager);
addonMessageManager.set(_message.guild.id, guildMessageManager);
MessageManager.set(addonInfo.addon.name, addonMessageManager);
}
emitEvent(addonInfo.addon.name, 'messageDelete', scopes.bitfield.MESSAGES, message, executor);

@@ -429,2 +493,11 @@ }

const newMessage = structureHandler.createStructure('Message', [_newMessage, addonInfo.addon]);
if(validatePermission(getAddonPermission(addonInfo.addon.name), scopes.bitfield.MESSAGES)){
const addonMessageManager = MessageManager.get(addonInfo.addon.name) || structureHandler.createStructure('Save');
const guildMessageManager = addonMessageManager.get(_newMessage.guild.id) || structureHandler.createStructure('Save');
const channelMessageManager = guildMessageManager.get(_newMessage.channel.id) || structureHandler.createStructure('Save');
channelMessageManager.set(newMessage.id, newMessage);
guildMessageManager.set(_newMessage.channel.id, channelMessageManager);
addonMessageManager.set(_newMessage.guild.id, guildMessageManager);
MessageManager.set(addonInfo.addon.name, addonMessageManager);
}
emitEvent(addonInfo.addon.name, 'messageUpdate', scopes.bitfield.MESSAGES, oldMessage, newMessage);

@@ -444,2 +517,35 @@ }

const reaction = structureHandler.createStructure('Reaction', [_reaction, addonInfo.addon, user]);
const addonEmojiCollectors = emojiCollectors.get(addonInfo.addon.name);
if(addonEmojiCollectors){
const messageCollectors = addonEmojiCollectors.get(_reaction.message.id);
if(messageCollectors){
const collectors = messageCollectors.filter(c => {
return c.filter(reaction, user);
});
const removeCollectors = [];
for(let i = 0; i < collectors.length; i++){
let collector = collectors[i];
++collector.count;
if(collector.max <= collector.count){
removeCollectors.push(collector);
}
if(collector.time < (new Date()).getTime()){
removeCollectors.push(collector);
continue;
}
collector.emit('collect', reaction, user);
}
for(let i = 0; i < removeCollectors.length; i++){
let removeCollector = removeCollectors[i];
removeCollector.emit('end');
removeCollector.removeAllListeners();
let collectorIndex = messageCollectors.indexOf(removeCollector);
if(collectorIndex >= 0){
messageCollectors.splice(collectorIndex, 1);
}
}
addonEmojiCollectors.set(_reaction.message.id, messageCollectors);
emojiCollectors.set(addonInfo.addon.name, addonEmojiCollectors);
}
}
emitEvent(addonInfo.addon.name, 'reactionAdd', scopes.bitfield.EMOJIS, reaction);

@@ -734,2 +840,9 @@ }

addonInfo.addon.channels.delete(_channel.id);
if(validatePermission(getAddonPermission(addonInfo.addon.name), scopes.bitfield.MESSAGES)){
const addonMessageManager = MessageManager.get(addonInfo.addon.name) || structureHandler.createStructure('Save');
const guildMessageManager = addonMessageManager.get(_channel.guild.id) || structureHandler.createStructure('Save');
guildMessageManager.delete(_channel.id);
addonMessageManager.set(_channel.guild.id, guildMessageManager);
MessageManager.set(addonInfo.addon.name, addonMessageManager);
}
_channel.guild.fetchAuditLogs({

@@ -868,2 +981,35 @@ limit: 1,

const buttonInteraction = structureHandler.createStructure('ButtonInteraction', [interaction, addonInfo.addon]);
const addonInteractionCollectors = interactionCollectors.get(addonInfo.addon.name);
if(addonInteractionCollectors){
const messageCollectors = addonInteractionCollectors.get(interaction.message.id);
if(messageCollectors){
const collectors = messageCollectors.filter(c => {
return c.filter(buttonInteraction);
});
const removeCollectors = [];
for(let i = 0; i < collectors.length; i++){
let collector = collectors[i];
++collector.count;
if(collector.max <= collector.count){
removeCollectors.push(collector);
}
if(collector.time < (new Date()).getTime()){
removeCollectors.push(collector);
continue;
}
collector.emit('collect', buttonInteraction);
}
for(let i = 0; i < removeCollectors.length; i++){
let removeCollector = removeCollectors[i];
removeCollector.emit('end');
removeCollector.removeAllListeners();
let collectorIndex = messageCollectors.indexOf(removeCollector);
if(collectorIndex >= 0){
messageCollectors.splice(collectorIndex, 1);
}
}
addonInteractionCollectors.set(interaction.message.id, messageCollectors);
interactionCollectors.set(addonInfo.addon.name, addonInteractionCollectors);
}
}
emitEvent(addonInfo.addon.name, 'buttonClick', scopes.bitfield.INTERACTIONS, buttonInteraction);

@@ -883,2 +1029,35 @@ }

const menuInteraction = structureHandler.createStructure('MenuInteraction', [interaction, addonInfo.addon]);
const addonInteractionCollectors = interactionCollectors.get(addonInfo.addon.name);
if(addonInteractionCollectors){
const messageCollectors = addonInteractionCollectors.get(interaction.message.id);
if(messageCollectors){
const collectors = messageCollectors.filter(c => {
return c.filter(menuInteraction);
});
const removeCollectors = [];
for(let i = 0; i < collectors.length; i++){
let collector = collectors[i];
++collector.count;
if(collector.max <= collector.count){
removeCollectors.push(collector);
}
if(collector.time < (new Date()).getTime()){
removeCollectors.push(collector);
continue;
}
collector.emit('collect', menuInteraction);
}
for(let i = 0; i < removeCollectors.length; i++){
let removeCollector = removeCollectors[i];
removeCollector.emit('end');
removeCollector.removeAllListeners();
let collectorIndex = messageCollectors.indexOf(removeCollector);
if(collectorIndex >= 0){
messageCollectors.splice(collectorIndex, 1);
}
}
addonInteractionCollectors.set(interaction.message.id, messageCollectors);
interactionCollectors.set(addonInfo.addon.name, addonInteractionCollectors);
}
}
emitEvent(addonInfo.addon.name, 'menuSelect', scopes.bitfield.INTERACTIONS, menuInteraction);

@@ -889,2 +1068,16 @@ }

parser.on('modal', (interaction) => {
if(!interaction) return;
if(!interaction.inGuild()) return;
if(client.config.guilds.indexOf(interaction.guild?.id) < 0) return;
_addons = addons.toReadableArray();
for(var z = 0; z < _addons.length; z++){
let addonInfo = _addons[z].value;
if(addonInfo.verified === true && addonInfo.allowed === true){
const modalInteraction = structureHandler.createStructure('FormInteraction', [interaction, addonInfo.addon]);
emitEvent(addonInfo.addon.name, 'formSubmit', scopes.bitfield.INTERACTIONS, modalInteraction);
}
}
});
resolve();

@@ -891,0 +1084,0 @@ });

@@ -19,4 +19,6 @@ const Member = require('../structures/member.js');

const Reaction = require('../structures/reaction.js');
const Invite = require('../structures/invite.js');
const ButtonInteraction = require('../structures/interactions/buttonInteraction.js');
const MenuInteraction = require('../structures/interactions/menuInteraction.js');
const FormInteraction = require('../structures/interactions/formInteraction.js');
const Mentions = require('../structures/mentions.js');

@@ -43,4 +45,6 @@

Reaction: Reaction,
Invite: Invite,
ButtonInteraction: ButtonInteraction,
MenuInteraction: MenuInteraction,
FormInteraction: FormInteraction,
Mentions: Mentions

@@ -47,0 +51,0 @@ }

@@ -15,3 +15,20 @@ const http = require('http');

if((req.method || '').toLowerCase() === 'get'){
this.get.emit((req.url || '').split('?')[0], new RequestInfo(req, null), new ResponseInfo(res));
let getEvents = [...this.get.eventNames()];
let placeholderEvents = getEvents.filter(e => e.indexOf("{*}") >= 0).filter(e => {
let placeholderRegEx = new RegExp(e.split("{*}").join("(.+)"));
return placeholderRegEx.test((req.url || ''));
});
if(placeholderEvents.length > 0){
for(let i = 0; i < placeholderEvents.length; i++){
let placeholders = [];
let eventName = placeholderEvents[i];
let eventRegEx = new RegExp(eventName.split("{*}").join("(\\w+)"), "i");
let regExRes = eventRegEx.exec((req.url || ''));
placeholders.push(...regExRes.slice(1, regExRes.length));
this.get.emit(eventName, new RequestInfo(req, null, placeholders), new ResponseInfo(res));
}
}
if(getEvents.indexOf((req.url || '')) >= 0){
this.get.emit((req.url || '').split('?')[0], new RequestInfo(req, null, []), new ResponseInfo(res));
}
} else if((req.method || '').toLowerCase() === 'post'){

@@ -23,3 +40,20 @@ let body = [];

req.on('end', () => {
this.post.emit((req.url || '').split('?')[0], new RequestInfo(req, body.join('')), new ResponseInfo(res));
let postEvents = [...this.post.eventNames()];
let placeholderPostEvents = postEvents.filter(e => e.indexOf("{*}") >= 0).filter(e => {
let placeholderRegEx = new RegExp(e.split("{*}").join("(.+)"));
return placeholderRegEx.test((req.url || ''));
});
if(placeholderPostEvents.length > 0){
for(let i = 0; i < placeholderPostEvents.length; i++){
let placeholders = [];
let eventName = placeholderPostEvents[i];
let eventRegEx = new RegExp(eventName.split("{*}").join("(\\w+)"), "i");
let regExRes = eventRegEx.exec((req.url || ''));
placeholders.push(...regExRes.slice(1, regExRes.length));
this.post.emit(eventName, new RequestInfo(req, body.join(''), placeholders), new ResponseInfo(res));
}
}
if(postEvents.indexOf((req.url || '')) >= 0){
this.post.emit((req.url || '').split('?')[0], new RequestInfo(req, body.join(''), []), new ResponseInfo(res));
}
})

@@ -26,0 +60,0 @@ } else {

const { URLSearchParams } = require('url');
class RequestInfo{
constructor(data, body){
constructor(data, body, placeholders){
const params = new URLSearchParams((data.url || '').split('?').slice(1).join('?'));

@@ -15,2 +15,3 @@ this.url = (data.url || '').split('?')[0];

this.ip = data.socket.remoteAddress;
this.placeholders = placeholders || [];
}

@@ -17,0 +18,0 @@ }

const EventEmitter = require('events');
const http = require('http');
const WebSocket = require('./websocket.js');
const RequestInfo = require('./requestInfo.js');
const { WebSocketServer } = require('ws');
const { ValueSaver } = require('valuesaver');
class WebSocket extends EventEmitter{
constructor(socket, handler){
const websockets = new ValueSaver();
class WebSocketHandler extends EventEmitter{
constructor(httpServer = http.Server.prototype){
super();
let id = Math.round(new Date().getTime() / 1000).toString() + Math.round(Math.random() * 9999).toString();
while(handler.sockets.filter(ws => ws.id === id).length > 0){
id = Math.round(new Date().getTime() / 1000).toString() + Math.round(Math.random() * 9999).toString();
}
this.id = id;
this.send = function(data){
socket.send(data);
};
this.close = () => {
socket.close();
this.emit('close');
this.removeAllListeners();
};
socket.on('message', msg => {
this.emit('message', Buffer.from(msg).toString());
const wsServer = new WebSocketServer({
server: httpServer
});
socket.on('close', () => {
this.emit('close');
this.removeAllListeners();
wsServer.on('connection', (_ws, req) => {
const reqInfo = new RequestInfo(req, null);
const ws = new WebSocket(_ws, this);
websockets.set(ws.id, _ws);
this.sockets.push(ws);
this.emit('connection', ws, reqInfo);
});
socket.on('error', err => {
var errorMessage = err.message.toString();
handler.errorMessages.push(errorMessage);
})
}
sockets = [];
errorMessages = [];
}
module.exports = WebSocket;
module.exports = WebSocketHandler;

@@ -14,3 +14,116 @@ const { getChannelType, getClient } = require('../../../utils/functions.js');

this.createdTimestamp = data.createdTimestamp;
this.string = `<#${this.id}>`;
this.string = `<#${this.id}>`;const { getChannelType, getClient } = require('../../../utils/functions.js');
const GuildMemberManager = require('../../managers/guildMemberManager.js');
const Save = require('../../save.js');
let client = getClient();
class BaseChannel{
constructor(data, addon){
client = getClient();
this.id = data.id;
this.type = getChannelType(data.type);
this.created = new Date(data.createdTimestamp);
this.createdTimestamp = data.createdTimestamp;
this.string = `<#${this.id}>`;
this.url = data.url;
this.isTextChannel = () => {
return this.type === 'GuildText' || this.type === 'GuildAnnouncement';
};
this.isVoiceChannel = () => {
return this.type === 'GuildVoice';
};
this.isVoiceStage = () => {
return this.type === 'GuildVoiceStage';
};
this.isDM = () => {
return this.type === 'DM';
};
this.isThread = () => {
return this.type === 'PublicThread' || this.type === 'PrivateThread' || this.type === 'AnnouncementThread';
};
this.isTicket = () => {
if(!this.isDM()){
const ticketFilter = client.tickets.filter(t => {
if(Array.isArray(t.value)){
return t.value.filter(t => typeof t === 'string' ? t === data.id : t.channel === data.id && t.guild === data.guild.id).length > 0;
} else if(typeof t.value === 'string'){
return t.value === data.id;
} else {
return false;
}
});
return ticketFilter.size > 0;
} else {
return false;
}
}
this.getTicketOwner = () => {
if(!this.isTicket()){
return undefined;
}
const ticketFilter = client.tickets.filter(t => {
if(Array.isArray(t.value)){
return t.value.filter(t => typeof t === 'string' ? t === data.id : t.channel === data.id && t.guild === data.guild.id).length > 0;
} else if(typeof t.value === 'string'){
return t.value === data.id;
} else {
return false;
}
});
if(ticketFilter.size === 0) return undefined;
const addonGuildMemberManager = GuildMemberManager.get(addon.name) || new Save();
const guildMembers = addonGuildMemberManager.get(data.guild.id) || new Save();
return guildMembers.get(ticketFilter.firstKey());
}
this.getTicketInfo = () => {
if(!this.isTicket()){
return undefined;
}
const ticketFilter = client.tickets.filter(t => {
if(Array.isArray(t.value)){
return t.value.filter(t => typeof t === 'string' ? t === data.id : t.channel === data.id && t.guild === data.guild.id).length > 0;
} else if(typeof t.value === 'string'){
return t.value === data.id;
} else {
return false;
}
});
if(ticketFilter.size === 0) return undefined;
let ticketInfoObj = ticketFilter.first();
const addonGuildMemberManager = GuildMemberManager.get(addon.name) || new Save();
const guildMembers = addonGuildMemberManager.get(data.guild.id) || new Save();
if(typeof ticketInfoObj === 'string'){
return {
channelId: ticketInfoObj,
claimed: undefined,
category: undefined,
owner: guildMembers.get(ticketFilter.firstKey()),
closed: false
}
} else if(Array.isArray(ticketInfoObj)) {
ticketInfoObj = ticketInfoObj.filter(t => typeof t === 'string' ? t === data.id : t.channel === data.id && t.guild === data.guild.id)[0];
if(typeof ticketInfoObj === 'object'){
return {
channelId: ticketInfoObj.channel,
claimed: typeof ticketInfoObj.claimed === 'string' ? (guildMembers.get(ticketInfoObj.claimed) || undefined) : undefined,
category: ticketInfoObj.category || undefined,
owner: guildMembers.get(ticketFilter.firstKey()),
closed: ticketInfoObj.closed
}
} else {
return {
channelId: ticketInfoObj,
claimed: undefined,
category: undefined,
owner: guildMembers.get(ticketFilter.firstKey()),
closed: false
}
}
}
}
}
}
module.exports = BaseChannel;
this.url = data.url;

@@ -17,0 +130,0 @@ this.isTextChannel = () => {

@@ -15,2 +15,3 @@ const BaseChannel = require('./base.js');

this.guild = guild;
this.guildId = guild.id;
this.manageable = data.manageable;

@@ -17,0 +18,0 @@ this.permissions = new Save();

@@ -6,2 +6,4 @@ const BaseChannel = require('./base.js');

const Permissions = require('../permissions.js');
const User = require('../user.js');
const Invite = require('../invite.js');
const Save = require('../../save.js');

@@ -15,2 +17,3 @@

this.guild = guild;
this.guildId = guild.id;
this.manageable = data.manageable;

@@ -30,2 +33,46 @@ this.position = data.position;

}
this.createInvite = (options) => {
return new Promise((resolve, reject) => {
if(typeof options !== 'object' || Array.isArray(options) || options === null) options = {};
let _options = {...options};
if(typeof _options.targetType === 'string'){
switch(_options.targetType.toLowerCase()){
case 'stream':
_options.targetType = 1;
break;
case 'application':
_options.targetType = 2;
break;
case 'embeddedapplication':
_options.targetType = 2;
break;
}
if(_options.targetUser instanceof User){
_options.targetUser = _options.targetUser.id;
}
} else if(typeof _options.targetType === 'number'){
if(_options.targetType < 1 || _options.targetType > 2){
return reject(`Invalid target type for invite`);
}
if(_options.targetUser instanceof User){
_options.targetUser = _options.targetUser.id;
}
} else if(typeof _options.targetType !== 'undefined'){
return reject(`Invalid target type for invite`);
}
data.createInvite({
temporary: !!_options.temporary,
maxAge: typeof _options.maxAge === 'number' ? Math.round(_options.maxAge / 1000) : 0,
maxUses: typeof _options.maxUses === 'number' ? _options.maxUses : 0,
unique: !!_options.unique,
targetUser: typeof _options.targetUser === 'string' ? _options.targetUser : undefined,
targetApplication: typeof _options.targetApplication === 'string' ? _options.targetApplication : undefined,
targetType: typeof _options.targetType === 'number' ? _options.targetType : undefined,
reason: typeof _options.reason === 'string' ? _options.reason : undefined
}).then(invite => {
resolve(new Invite(invite, this.guild, addon));
}).catch(reject);
});
};
this.setNSFW = (nsfw, reason) => {

@@ -32,0 +79,0 @@ return new Promise((resolve, reject) => {

@@ -8,2 +8,3 @@ const GuildChannel = require('./guildChannel.js');

const MemberManager = require('../../managers/memberManager.js');
const MessageManager = require('../../managers/messageManager.js');

@@ -13,2 +14,3 @@ class StageChannel extends GuildChannel{

super(data, addon, guild);
this.addon = addon;
this.joinable = data.joinable;

@@ -34,3 +36,3 @@ this.full = data.full;

}
this.deleteMessages = function(amount){
this.deleteMessages = function(amount, filter){
return new Promise((resolve, reject) => {

@@ -41,3 +43,7 @@ if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.MESSAGES)) return reject(`Missing messages scope in bitfield`);

else if(amount > 100) amount = 100;
data.bulkDelete(amount).then(() => resolve()).catch(reject);
let messageDelete = amount;
if(typeof filter === 'function'){
messageDelete = Array.from(this.messages.filter(m => filter(m)).values()).map(m => m.id).slice(0, amount);
}
data.bulkDelete(messageDelete).then(() => resolve()).catch(reject);
});

@@ -147,4 +153,10 @@ }

}
get messages(){
const addonMessageManager = MessageManager.get(this.addon.name) || new Save();
const guildMessageManager = addonMessageManager.get(this.guildId) || new Save();
const channelMessageManager = guildMessageManager.get(this.id) || new Save();
return channelMessageManager;
}
};
module.exports = StageChannel;

@@ -7,2 +7,3 @@ const GuildChannel = require('./guildChannel.js');

const Save = require('../../save.js');
const MessageManager = require('../../managers/messageManager.js');

@@ -14,2 +15,3 @@ const validAutoArchiveDates = [60, 1440, 10080, 4320];

super(data, addon, guild);
this.addon = addon;
this.topic = data.topic;

@@ -60,3 +62,3 @@ this.autoArchiveThreads = typeof data.defaultAutoArchiveDuration === 'number' ? data.defaultAutoArchiveDuration * 60 * 1000 : 0;

}
this.deleteMessages = function(amount){
this.deleteMessages = function(amount, filter){
return new Promise((resolve, reject) => {

@@ -67,3 +69,7 @@ if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.MESSAGES)) return reject(`Missing messages scope in bitfield`);

else if(amount > 100) amount = 100;
data.bulkDelete(amount).then(() => resolve()).catch(reject);
let messageDelete = amount;
if(typeof filter === 'function'){
messageDelete = Array.from(this.messages.filter(m => filter(m)).values()).map(m => m.id).slice(0, amount);
}
data.bulkDelete(messageDelete).then(() => resolve()).catch(reject);
});

@@ -173,3 +179,3 @@ }

}).then(thread => {
resolve(structureHandler.createStructure('ThreadChannel', [thread, addon, this.guild]));
resolve(structureHandler.createStructure('ThreadChannel', [thread, addon, guild]));
}).catch(reject);

@@ -179,4 +185,10 @@ });

}
get messages(){
const addonMessageManager = MessageManager.get(this.addon.name) || new Save();
const guildMessageManager = addonMessageManager.get(this.guildId) || new Save();
const channelMessageManager = guildMessageManager.get(this.id) || new Save();
return channelMessageManager;
}
}
module.exports = TextChannel;

@@ -7,2 +7,3 @@ const BaseChannel = require('./base.js');

const GuildMemberManager = require('../../managers/guildMemberManager.js');
const MessageManager = require('../../managers/messageManager.js');

@@ -12,3 +13,5 @@ class ThreadChannel extends BaseChannel{

super(data, addon);
this.addon = addon;
this.guild = guild;
this.guildId = guild.id;
this.name = data.name;

@@ -29,3 +32,3 @@ this.threadArchived = data.archived;

this.parentId = data.parentId || null;
this.parent = typeof this.parentId === 'string' ? this.guild.channels.get(this.parentId) : undefined;
this.parent = typeof this.parentId === 'string' ? guild.channels.get(this.parentId) : undefined;
if(typeof this.parent !== 'undefined'){

@@ -36,3 +39,3 @@ this.parent.threads.set(this.id, this);

const addonGuildMemberManager = GuildMemberManager.get(addon.name) || new Save();
const guildMemberManager = addonGuildMemberManager.get(this.guild.id) || new Save();
const guildMemberManager = addonGuildMemberManager.get(guild.id) || new Save();
const guildMembers = Array.from(data.members.cache.values());

@@ -68,3 +71,3 @@ for(var i = 0; i < guildMembers.length; i++){

}
this.deleteMessages = function(amount){
this.deleteMessages = function(amount, filter){
return new Promise((resolve, reject) => {

@@ -75,3 +78,7 @@ if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.MESSAGES)) return reject(`Missing messages scope in bitfield`);

else if(amount > 100) amount = 100;
data.bulkDelete(amount).then(() => resolve()).catch(reject);
let messageDelete = amount;
if(typeof filter === 'function'){
messageDelete = Array.from(this.messages.filter(m => filter(m)).values()).map(m => m.id).slice(0, amount);
}
data.bulkDelete(messageDelete).then(() => resolve()).catch(reject);
});

@@ -231,4 +238,10 @@ }

}
get messages(){
const addonMessageManager = MessageManager.get(this.addon.name) || new Save();
const guildMessageManager = addonMessageManager.get(this.guildId) || new Save();
const channelMessageManager = guildMessageManager.get(this.id) || new Save();
return channelMessageManager;
}
}
module.exports = ThreadChannel;

@@ -9,2 +9,3 @@ const GuildChannel = require('./guildChannel.js');

const MemberManager = require('../../managers/memberManager.js');
const MessageManager = require('../../managers/messageManager.js');
const ytstream = require('yt-stream');

@@ -18,2 +19,3 @@

client = getClient();
this.addon = addon;
this.joinable = data.joinable;

@@ -40,3 +42,3 @@ this.speakable = data.speakable;

}
this.deleteMessages = function(amount){
this.deleteMessages = function(amount, filter){
return new Promise((resolve, reject) => {

@@ -47,3 +49,7 @@ if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.MESSAGES)) return reject(`Missing messages scope in bitfield`);

else if(amount > 100) amount = 100;
data.bulkDelete(amount).then(() => resolve()).catch(reject);
let messageDelete = amount;
if(typeof filter === 'function'){
messageDelete = Array.from(this.messages.filter(m => filter(m)).values()).map(m => m.id).slice(0, amount);
}
data.bulkDelete(messageDelete).then(() => resolve()).catch(reject);
});

@@ -304,4 +310,10 @@ }

}
get messages(){
const addonMessageManager = MessageManager.get(this.addon.name) || new Save();
const guildMessageManager = addonMessageManager.get(this.guildId) || new Save();
const channelMessageManager = guildMessageManager.get(this.id) || new Save();
return channelMessageManager;
}
}
module.exports = VoiceChannel;

@@ -5,2 +5,3 @@ const { validatePermission, getAddonPermission, getColorCode, getChannelId, getResolvableDate, getClient, getVideoQualityMode } = require('../../utils/functions.js');

const GuildMemberManager = require('../managers/guildMemberManager.js');
const inviteManager = require('../managers/inviteManager.js');
const VoiceStateManager = require('../managers/voiceStateManager.js');

@@ -11,2 +12,3 @@ const Member = require('./member.js');

const CategoryChannel = require('./channel/categoryChannel.js');
const Save = require('../save.js');
const { ChannelType } = require('discord.js');

@@ -45,2 +47,8 @@

}
const invites = guild.invites.cache.map(i => i);
for(var i = 0; i < invites.length; i++){
if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.GUILDS)) continue;
let invite = invites[i];
structureHandler.createStructure('Invite', [invite, this, addon]);
}
this.iconURL = guild.iconURL({size: 256, dynamic: true});

@@ -265,4 +273,4 @@ this.description = guild.description;

get members(){
const addonGuildMemberManager = GuildMemberManager.get(this.addon.name) || structureHandler.createStructure('Save');
const guildMembers = addonGuildMemberManager.get(this.id) || structureHandler.createStructure('Save');
const addonGuildMemberManager = GuildMemberManager.get(this.addon.name) || new Save();
const guildMembers = addonGuildMemberManager.get(this.id) || new Save();
return guildMembers;

@@ -280,8 +288,13 @@ }

get owner(){
const addonGuildMemberManager = GuildMemberManager.get(this.addon.name) || structureHandler.createStructure('Save');
const guildMembers = addonGuildMemberManager.get(this.id) || structureHandler.createStructure('Save');
const addonGuildMemberManager = GuildMemberManager.get(this.addon.name) || new Save();
const guildMembers = addonGuildMemberManager.get(this.id) || new Save();
return guildMembers.get(this.ownerId);
}
get invites(){
const addonInviteManager = inviteManager.get(this.addon.name) || new Save();
const guildInviteManager = addonInviteManager.get(this.id) || new Save();
return guildInviteManager;
}
}
module.exports = Guild;

@@ -5,2 +5,4 @@ const GuildManager = require('../../managers/guildManager.js');

const Save = require('../../save.js');
const FormBuilder = require('../../builders/formBuilder.js');
const { ModalBuilder, ActionRowBuilder, TextInputBuilder } = require('discord.js');

@@ -10,2 +12,3 @@ class ButtonInteraction{

const addonGuildManager = GuildManager.get(addon.name) || new Save();
this.type = "Button";
this.guild = addonGuildManager.get(data.guildId);

@@ -22,2 +25,11 @@ this.guildId = data.guildId;

this.id = data.id;
this.isButton = () => {
return this.type === "Button";
};
this.isMenu = () => {
return this.type === "Menu";
};
this.isForm = () => {
return this.type === "Form";
};
this.deferUpdate = function(){

@@ -60,2 +72,13 @@ return new Promise((resolve, reject) => {

};
this.sendForm = function(form){
return new Promise((resolve, reject) => {
if(!(form instanceof FormBuilder)) return reject(`The form must be an instance of the FormBuilder class`);
let formJSON = form.toJSON();
formJSON.components = formJSON.components.map(c => new ActionRowBuilder().addComponents(new TextInputBuilder(c)));
const modal = new ModalBuilder(formJSON);
data.showModal(modal).then(() => {
resolve();
}).catch(reject);
});
};
}

@@ -62,0 +85,0 @@ }

@@ -5,2 +5,4 @@ const GuildManager = require('../../managers/guildManager.js');

const Save = require('../../save.js');
const FormBuilder = require('../../builders/formBuilder.js');
const { ModalBuilder } = require('discord.js');

@@ -10,2 +12,3 @@ class MenuInteraction{

const addonGuildManager = GuildManager.get(addon.name) || new Save();
this.type = "Menu";
this.guild = addonGuildManager.get(data.guildId);

@@ -23,2 +26,12 @@ this.guildId = data.guildId;

this.values = [...data.values];
this.isButton = () => {
return this.type === "Button";
};
this.isMenu = () => {
return this.type === "Menu";
};
this.isForm = () => {
return this.type === "Form";
};
this.deferUpdate = function(){

@@ -61,2 +74,13 @@ return new Promise((resolve, reject) => {

};
this.sendForm = function(form){
return new Promise((resolve, reject) => {
if(!(form instanceof FormBuilder)) return reject(`The form must be an instance of the FormBuilder class`);
let formJSON = form.toJSON();
formJSON.components = formJSON.components.map(c => new ActionRowBuilder().addComponents(new TextInputBuilder(c)));
const modal = new ModalBuilder(formJSON);
data.showModal(modal).then(() => {
resolve();
}).catch(reject);
});
};
}

@@ -63,0 +87,0 @@ }

@@ -53,2 +53,15 @@ const { validatePermission, getResolvableDate, getAddonPermission, wait, getClient } = require('../../utils/functions.js');

this.voice = new VoiceState(guildMember.voice, addon);
this.getInviteInfo = () => {
if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.MEMBERS)) throw new Error(`Missing members scope in bitfield`);
const userinfo = client.userinfo.get(guildMember.id) || [];
const guildUserInfo = userinfo.filter(i => i.guild === this.guildId) || {invitedBy: undefined, invites: 0, inviteleaves: 0};
const addonGuildMemberManager = GuildMemberManager.get(addon.name) || new Save();
const guildMembers = addonGuildMemberManager.get(guildMember.guild.id) || new Save();
return {
invitedBy: typeof guildUserInfo.invitedBy === 'string' ? guildMembers.get(guildUserInfo.invitedBy) : undefined,
invites: guildUserInfo.invites ?? 0,
leaves: guildUserInfo.inviteleaves ?? 0,
total: (guildUserInfo.invites ?? 0) - (guildUserInfo.inviteleaves ?? 0)
};
};
this.getWarns = () => {

@@ -55,0 +68,0 @@ if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.MEMBERS)) throw new Error(`Missing members scope in bitfield`);

@@ -1,2 +0,2 @@

const { validatePermission, getAddonPermission } = require('../../utils/functions.js');
const { validatePermission, getAddonPermission, getClientParser } = require('../../utils/functions.js');
const { getMessageContent } = require('../../utils/messageFunctions.js');

@@ -8,2 +8,4 @@ const scopes = require('../../bitfields/scopes.js');

const Emoji = require('./emoji.js');
const EmojiCollector = require('./collectors/emojiCollector.js');
const InteractionCollector = require('./collectors/interactionCollector.js');

@@ -103,2 +105,30 @@ const validAutoArchiveDates = [60, 1440, 10080, 4320];

}
this.executeCommand = (commandName, args) => {
return new Promise((resolve, reject) => {
if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.COMMANDS)) return reject(`Missing commands scope in bitfield`);
if(typeof commandName !== 'string') return reject(`Command name must be a type of string`);
if(!Array.isArray(args)){
args = (this.content || '').startsWith(client.config.prefix) ? (this.content || '').slice(client.config.prefix.length).split(" ") : (this.content || '').split(" ");
}
let clientParser = getClientParser();
let client = clientParser.getClient();
const cmd = client.commands.get(commandName);
if(cmd){
cmd.run(client, args, data, false);
} else {
client.clientParser.interactionHandler.emit('execute', data, false);
}
resolve();
});
}
this.createReactionCollector = (options) => {
if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.EMOJIS)) throw new Error(`Missing emojis scope in bitfield`);
const collector = new EmojiCollector(options, this, addon);
return collector;
};
this.createInteractionCollector = (options) => {
if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.INTERACTIONS)) throw new Error(`Missing interactions scope in bitfield`);
const collector = new InteractionCollector(options, this, addon);
return collector;
};
}

@@ -105,0 +135,0 @@ }

const Save = require('../save.js');
const { validatePermission, getAddonPermission } = require('../../utils/functions.js');
const GuildMemberManager = require('../managers/guildMemberManager.js');
const Member = require('../structures/member.js');
const VoiceChannel = require('./channel/voiceChannel.js');
const StageChannel = require('./channel/stageChannel.js');
const VoiceStateManager = require('../managers/voiceStateManager.js');

@@ -61,2 +62,13 @@ const scopes = require('../../bitfields/scopes.js');

}
this.setChannel = function(channel, reason){
return new Promise((resolve, reject) => {
if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.MEMBERS)) return reject(`Missing members scope in bitfield`);
if(typeof channel !== 'string' && !(channel instanceof VoiceChannel) && !(channel instanceof StageChannel)) return reject(`The channel is not a resolvable channel`);
if(typeof reason !== 'string') reason = undefined;
if(typeof channel !== 'string') channel = channel.id;
voiceState.setChannel(channel, reason).then(m => {
resolve();
}).catch(reject);
})
}
}

@@ -63,0 +75,0 @@ }

@@ -1,2 +0,1 @@

const bitfieldInfo = require('../bitfields/scopes.js');
const colors = require('./colors.json');

@@ -7,2 +6,3 @@ const types = require('./channelTypes.js');

var _client;
var _clientParser;

@@ -27,16 +27,2 @@ function generateId(length = 20){

function getPermissionsString(bitfield){
var permissionString = [];
if(typeof bitfield !== 'number') throw new Error(`Invalid bitfied: Bitfield is not a number`);
var bitfieldKeys = Object.keys(bitfieldInfo.bitfield);
var bitfieldValues = Object.values(bitfieldInfo.bitfield);
for(var i = 0; i < bitfieldValues.length; i++){
var bitValue = bitfieldValues[i];
if(bitfield & bitValue){
permissionString.push(bitfieldInfo.strings[bitfieldKeys[i]])
}
}
return permissionString;
}
function validatePermission(bitfield, bitvalue){

@@ -102,2 +88,10 @@ return bitfield & bitvalue;

function passClientParser(clientParser){
_clientParser = clientParser;
}
function getClientParser(){
return _clientParser;
}
function passClient(client){

@@ -178,3 +172,2 @@ _client = client;

createBitfield,
getPermissionsString,
validatePermission,

@@ -186,3 +179,5 @@ getResolvableDate,

passClient,
passClientParser,
getClient,
getClientParser,
getChannelType,

@@ -189,0 +184,0 @@ getChannelId,

@@ -9,2 +9,4 @@ const { ValueSaver } = require('valuesaver');

const addons = new ValueSaver();
const emojiCollectors = new ValueSaver();
const interactionCollectors = new ValueSaver();

@@ -16,3 +18,5 @@ module.exports = {

addonCreate,
botClasses
botClasses,
emojiCollectors,
interactionCollectors
};

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc