zyno-bot-addons
Advanced tools
Comparing version 1.1.3 to 1.1.4-beta
{ | ||
"name": "zyno-bot-addons", | ||
"version": "1.1.3", | ||
"version": "1.1.4-beta", | ||
"description": "Create easily addons for Zyno Bot", | ||
@@ -19,3 +19,3 @@ "main": "index.js", | ||
"ws": "^8.14.2", | ||
"yt-stream": "^1.4.8" | ||
"yt-stream": "^1.4.10" | ||
}, | ||
@@ -22,0 +22,0 @@ "readme": "readme.MD", |
@@ -11,2 +11,3 @@ const EventEmitter = require('events'); | ||
const HttpServerHandler = require('./server/handler.js'); | ||
const DiscordJS = require('discord.js'); | ||
@@ -125,2 +126,9 @@ const clientParser = getClientParser(); | ||
} | ||
removeCommand(commandName){ | ||
return new Promise((resolve, reject) => { | ||
if(!validatePermission(getAddonPermission(this.name), scopes.bitfield.COMMANDS)) return reject(`The addon doesn't have the permissions to create a command`); | ||
if(typeof commandName !== 'string') return reject(`Invalid command name: Command name must be a type of string`); | ||
commandRegistrant.removeCommand(commandName, this.name).then(resolve).catch(reject); | ||
}); | ||
} | ||
createEventListener(){ | ||
@@ -248,2 +256,29 @@ const filterEventListener = eventListeners.filter(e => e.addonName === this.name); | ||
} | ||
getCommandData(commandName){ | ||
return new Promise((resolve, reject) => { | ||
let addonInfo = addons.get(this.name); | ||
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.COMMANDS)) return reject('The addon doesn\'t have permissions to get information about commands'); | ||
if(typeof commandName !== 'string') return reject('A command name is required to provide'); | ||
let client = clientParser.getClient(); | ||
const botCommand = client.commands.get(commandName); | ||
const addonCommand = client.addons.get(commandName); | ||
if(!botCommand && !addonCommand) return resolve(undefined); | ||
else if(!botCommand) return resolve({...addonCommand}) | ||
else { | ||
let commandData = { | ||
name: botCommand.data.name, | ||
description: botCommand.data.description, | ||
options: botCommand.data.options, | ||
category: botCommand.data.category.toLowerCase(), | ||
nsfw: botCommand.data.nsfw || false, | ||
dm_permission: false, | ||
permissions: typeof botCommand.data.permissions === 'string' ? DiscordJS.PermissionFlagsBits[permissions].toString() : null, | ||
overwrite: false | ||
}; | ||
return resolve(commandData); | ||
} | ||
}); | ||
} | ||
name = null; | ||
@@ -250,0 +285,0 @@ description = null; |
const Save = require('./save.js'); | ||
const Member = require('./structures/member.js'); | ||
const User = require('./structures/user.js'); | ||
@@ -8,4 +7,15 @@ const Role = require('./structures/role.js'); | ||
const { ApplicationCommandOptionType, ChannelType } = require('discord.js'); | ||
const channelManager = require('./managers/channelManager.js'); | ||
const roleManager = require('./managers/roleManager.js'); | ||
const userManager = require('./managers/userManager.js'); | ||
const memberManager = require('./managers/guildMemberManager.js'); | ||
const guildManager = require('./managers/guildManager.js'); | ||
const messageManager = require('./managers/messageManager.js'); | ||
function commandResolver(data, save, structureHandler, addonData){ | ||
function commandResolver(data, save, structureHandler, addonData, defaultData){ | ||
const addonChannelManager = channelManager.get(addonData.addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(defaultData.guild.id) || new Save(); | ||
const addonRoleManager = roleManager.get(addonData.addon.name) || new Save(); | ||
const guildRoleManager = addonRoleManager.get(defaultData.guild.id) || new Save(); | ||
const addonUserManager = userManager.get(addonData.addon.name) || new Save(); | ||
return data.reduce((arr, item) => { | ||
@@ -27,13 +37,13 @@ var add; | ||
if(item.channel.type === ChannelType.GuildText || item.channel.type === ChannelType.GuildAnnouncement){ | ||
channel = structureHandler.createStructure('TextChannel', [item.channel, addonData.addon, this.guild]); | ||
channel = guildChannelManager.get(item.channel.id) ?? structureHandler.createStructure('TextChannel', [item.channel, addonData.addon, this.guild]); | ||
} else if(item.channel.type === ChannelType.GuildCategory){ | ||
channel = structureHandler.createStructure('CategoryChannel', [item.channel, addonData.addon, this.guild]); | ||
channel = guildChannelManager.get(item.channel.id) ?? structureHandler.createStructure('CategoryChannel', [item.channel, addonData.addon, this.guild]); | ||
} else if(item.channel.type === ChannelType.GuildVoice){ | ||
channel = structureHandler.createStructure('VoiceChannel', [item.channel, addonData.addon, this.guild]); | ||
channel = guildChannelManager.get(item.channel.id) ?? structureHandler.createStructure('VoiceChannel', [item.channel, addonData.addon, this.guild]); | ||
} else if(item.channel.type === ChannelType.GuildStageVoice){ | ||
channel = structureHandler.createStructure('StageChannel', [item.channel, addonData.addon, this.guild]); | ||
channel = guildChannelManager.get(item.channel.id) ?? structureHandler.createStructure('StageChannel', [item.channel, addonData.addon, this.guild]); | ||
} else if(item.channel.type === ChannelType.GuildForum){ | ||
channel = structureHandler.createStructure('ForumChannel', [item.channel, addonData.addon, this.guild]); | ||
channel = guildChannelManager.get(item.channel.id) ?? structureHandler.createStructure('ForumChannel', [item.channel, addonData.addon, this.guild]); | ||
} else if(item.channel.type === ChannelType.GuildDirectory){ | ||
channel = structureHandler.createStructure('DirectoryChannel', [item.channel, addonData.addon, this.guild]); | ||
channel = guildChannelManager.get(item.channel.id) ?? structureHandler.createStructure('DirectoryChannel', [item.channel, addonData.addon, this.guild]); | ||
} | ||
@@ -43,7 +53,7 @@ add = channel.string; | ||
} else if(item.type === ApplicationCommandOptionType.Role){ | ||
let role = new Role(item.role, addonData.addon, this.guild) | ||
let role = guildRoleManager.get(item.role.id) ?? new Role(item.role, addonData.addon, this.guild) | ||
add = role.string; | ||
save.set(item.name, role); | ||
} else if(item.type === ApplicationCommandOptionType.User){ | ||
let user = new User(item.user, addonData.addon, false, structureHandler); | ||
let user = addonUserManager.get(item.user.id) ?? new User(item.user, addonData.addon, false, structureHandler); | ||
add = user.string; | ||
@@ -64,6 +74,8 @@ save.set(item.name, user); | ||
let client = getClient(); | ||
this.addon = addonData.addon; | ||
this.name = registeredCommandData.name; | ||
this.description = registeredCommandData.description; | ||
this.slashCommand = interaction === true; | ||
this.member = new Member(data.member, addonData.addon, structureHandler); | ||
this.memberId = data.member?.id; | ||
this.guildId = data.guild?.id; | ||
this.created = new Date(); | ||
@@ -86,8 +98,7 @@ this.createdTimestamp = this.created.getTime(); | ||
} | ||
this.guild = this.member.guild; | ||
this.channel = this.guild.channels.get(data.channelId); | ||
this.message = interaction === false ? structureHandler.createStructure('Message', [data, addonData.addon]) : undefined; | ||
this.channelId = data.channelId; | ||
this.messageId = interaction === false ? data.id : undefined; | ||
if(interaction === false) this.args.push(...(data.content || '').substring(client.config.prefix.length).split(' ')); | ||
else { | ||
let args = commandResolver(data.options.data, this.options, structureHandler, addonData); | ||
let args = commandResolver(data.options.data, this.options, structureHandler, addonData, data); | ||
this.args = [registeredCommandData.name, ...args]; | ||
@@ -117,2 +128,23 @@ } | ||
} | ||
get channel(){ | ||
const addonChannelManager = channelManager.get(this.addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(this.guildId) || new Save(); | ||
return guildChannelManager.get(this.channelId); | ||
} | ||
get guild(){ | ||
const addonGuildManager = guildManager.get(this.addon.name) || new Save(); | ||
return addonGuildManager.get(this.guildId); | ||
} | ||
get member(){ | ||
const addonMemberManager = memberManager.get(this.addon.name) || new Save(); | ||
const guildMemberManager = addonMemberManager.get(this.guildId) || new Save(); | ||
return guildMemberManager.get(this.memberId); | ||
} | ||
get message(){ | ||
if(this.slashCommand === true) return undefined; | ||
const addonMessageManager = messageManager.get(this.addon.name) || new Save(); | ||
const guildMessageManager = addonMessageManager.get(this.guildId) || new Save(); | ||
const channelMessageManager = guildMessageManager.get(this.channelId) || new Save(); | ||
return channelMessageManager.get(this.messageId); | ||
} | ||
name = null; | ||
@@ -119,0 +151,0 @@ description = null; |
@@ -9,3 +9,3 @@ const { ValueSaver } = require('valuesaver'); | ||
const structureHandler = require('./structureHandler.js'); | ||
const { addons, addonCreate, commandListeners, eventListeners } = require('../../utils/saves.js'); | ||
const { addons, addonCreate, commandListeners, eventListeners, builtStructures } = require('../../utils/saves.js'); | ||
const EventEmitter = require('events'); | ||
@@ -49,2 +49,4 @@ const fs = require('fs/promises'); | ||
delete builtStructures[addonName]; | ||
addons.set(addonName, { | ||
@@ -187,2 +189,6 @@ ...addon, | ||
var addon = addons.get(addonName); | ||
Object.defineProperty(commandJSON, 'creator', { | ||
value: addonName, | ||
writable: false | ||
}); | ||
if(!addon){ | ||
@@ -291,3 +297,3 @@ var abortTooLong = setTimeout(function(){ | ||
} | ||
commandQueue.command['id'] = cmdId; | ||
commandQueue.command['id'] = cmdId | ||
var cmd = new CommandHandler(commandQueue.command); | ||
@@ -310,2 +316,12 @@ commandQueue.functions.resolve(cmd); | ||
} | ||
removeCommand(commandName, addonName){ | ||
return new Promise((resolve, reject) => { | ||
let addonCommand = this.addonCommands.get(commandName); | ||
if(!addonCommand) return reject(`There was no such command found`); | ||
if(addonCommand.command.creator !== addonName) return reject(`The command was not created by this addon`); | ||
this.addonCommands.delete(commandName); | ||
this.registerCommands(); | ||
resolve(); | ||
}); | ||
} | ||
timeout = undefined; | ||
@@ -408,3 +424,3 @@ ready = false; | ||
allowed: true, | ||
resolveablePath: addon.resolveablePath, | ||
resolveablePath: addonInfo.resolveablePath, | ||
restarting: false, | ||
@@ -411,0 +427,0 @@ stopping: false, |
@@ -18,2 +18,26 @@ const { EventEmitter } = require('events'); | ||
writable: false | ||
}, | ||
options: { | ||
value: data.options, | ||
writable: false | ||
}, | ||
category: { | ||
value: data.category, | ||
writable: false | ||
}, | ||
dm_permission: { | ||
value: data.dm_permission, | ||
writable: false | ||
}, | ||
permissions: { | ||
value: data.default_member_permissions, | ||
writable: false | ||
}, | ||
nsfw: { | ||
value: data.nsfw, | ||
writable: false | ||
}, | ||
overwrite: { | ||
value: data.overwrite, | ||
writable: false | ||
} | ||
@@ -25,4 +49,10 @@ }); | ||
id = null; | ||
options = []; | ||
category = null; | ||
dm_permission = false; | ||
permissions = null; | ||
nsfw = false; | ||
overwrite = false; | ||
} | ||
module.exports = CommandHandler; |
@@ -24,2 +24,3 @@ const Member = require('../structures/member.js'); | ||
const Mentions = require('../structures/mentions.js'); | ||
const VoiceState = require('../structures/voiceState.js'); | ||
@@ -49,3 +50,4 @@ const structures = { | ||
FormInteraction: FormInteraction, | ||
Mentions: Mentions | ||
Mentions: Mentions, | ||
VoiceState: VoiceState | ||
} | ||
@@ -59,3 +61,3 @@ | ||
let _arguments = [...(args || [])]; | ||
if(name !== 'Save') _arguments.push(this); | ||
if(name !== 'Save') _arguments.push(this, true); | ||
const structure = new structures[name](..._arguments); | ||
@@ -62,0 +64,0 @@ return structure; |
@@ -9,3 +9,3 @@ const { validatePermission, getAddonPermission, getClient, validateURL } = require('../../utils/functions.js'); | ||
let client, presenceTimeout = undefined, presenceOptions = {}, presenceFunctions = [], editTimeout = undefined, editOptions = {}, editFunctions = []; | ||
let client = null, presenceTimeout = undefined, presenceOptions = {}, presenceFunctions = [], editTimeout = undefined, editOptions = {}, editFunctions = []; | ||
function updatePresence(){ | ||
@@ -65,3 +65,3 @@ if(presenceTimeout !== undefined){ | ||
constructor(addon){ | ||
client = getClient(); | ||
if(!client) client = getClient(); | ||
this.setActivity = function(activity){ | ||
@@ -68,0 +68,0 @@ return new Promise((resolve, reject) => { |
@@ -6,6 +6,14 @@ const BaseChannel = require('./base.js'); | ||
const Save = require('../../save.js'); | ||
const channelManager = require('../../managers/channelManager.js'); | ||
class CategoryChannel extends BaseChannel{ | ||
constructor(data, addon, guild, structureHandler){ | ||
constructor(data, addon, guild, structureHandler, cache){ | ||
super(data, addon); | ||
if(cache){ | ||
const addonChannelManager = channelManager.get(addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(guild.id) || new Save(); | ||
guildChannelManager.set(data.id, this); | ||
addonChannelManager.set(guild.id, guildChannelManager); | ||
channelManager.set(addon.name, addonChannelManager); | ||
} | ||
this.viewable = data.viewable; | ||
@@ -24,3 +32,2 @@ this.name = data.name; | ||
} | ||
if(guild) guild.channels.set(this.id, this); | ||
if(validatePermission(getAddonPermission(addon.name), scopes.bitfield.CHANNELS)){ | ||
@@ -27,0 +34,0 @@ addon.channels.set(this.id, this); |
const BaseChannel = require('./base.js'); | ||
const { validatePermission, getAddonPermission } = require('../../../utils/functions.js'); | ||
const scopes = require('../../../bitfields/scopes.js'); | ||
const channelManager = require('../../managers/channelManager.js'); | ||
const Save = require('../../save.js'); | ||
class DirectoryChannel extends BaseChannel{ | ||
constructor(data, addon, guild, structureHandler){ | ||
constructor(data, addon, guild, structureHandler, cache){ | ||
super(data, addon); | ||
if(cache){ | ||
const addonChannelManager = channelManager.get(addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(guild.id) || new Save(); | ||
guildChannelManager.set(data.id, this); | ||
addonChannelManager.set(guild.id, guildChannelManager); | ||
channelManager.set(addon.name, addonChannelManager); | ||
} | ||
this.guild = guild; | ||
this.name = data.name; | ||
if(guild) guild.channels.set(this.id, this); | ||
if(validatePermission(getAddonPermission(addon.name), scopes.bitfield.CHANNELS)){ | ||
@@ -12,0 +20,0 @@ addon.channels.set(this.id, this); |
@@ -6,2 +6,3 @@ const GuildChannel = require('./guildChannel.js'); | ||
const Save = require("../../save.js"); | ||
const channelManager = require('../../managers/channelManager.js'); | ||
@@ -11,4 +12,11 @@ const validAutoArchiveDates = [60, 1440, 10080, 4320]; | ||
class ForumChannel extends GuildChannel{ | ||
constructor(data, addon, guild, structureHandler){ | ||
constructor(data, addon, guild, structureHandler, cache){ | ||
super(data, addon, guild); | ||
if(cache){ | ||
const addonChannelManager = channelManager.get(addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(guild.id) || new Save(); | ||
guildChannelManager.set(data.id, this); | ||
addonChannelManager.set(guild.id, guildChannelManager); | ||
channelManager.set(addon.name, addonChannelManager); | ||
} | ||
this.topic = data.topic; | ||
@@ -22,3 +30,2 @@ this.autoArchiveThreads = typeof data.defaultAutoArchiveDuration === 'number' ? data.defaultAutoArchiveDuration * 60 * 1000 : 0; | ||
} | ||
if(guild) guild.channels.set(this.id, this); | ||
if(validatePermission(getAddonPermission(addon.name), scopes.bitfield.CHANNELS)){ | ||
@@ -25,0 +32,0 @@ addon.channels.set(this.id, this); |
@@ -9,6 +9,14 @@ const GuildChannel = require('./guildChannel.js'); | ||
const MessageManager = require('../../managers/messageManager.js'); | ||
const channelManager = require('../../managers/channelManager.js'); | ||
class StageChannel extends GuildChannel{ | ||
constructor(data, addon, guild, structureHandler){ | ||
constructor(data, addon, guild, structureHandler, cache){ | ||
super(data, addon, guild); | ||
if(cache){ | ||
const addonChannelManager = channelManager.get(addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(guild.id) || new Save(); | ||
guildChannelManager.set(data.id, this); | ||
addonChannelManager.set(guild.id, guildChannelManager); | ||
channelManager.set(addon.name, addonChannelManager); | ||
} | ||
this.addon = addon; | ||
@@ -31,3 +39,2 @@ this.joinable = data.joinable; | ||
} | ||
if(guild) guild.channels.set(this.id, this); | ||
if(validatePermission(getAddonPermission(addon.name), scopes.bitfield.CHANNELS)){ | ||
@@ -34,0 +41,0 @@ addon.channels.set(this.id, this); |
@@ -8,2 +8,3 @@ const GuildChannel = require('./guildChannel.js'); | ||
const MessageManager = require('../../managers/messageManager.js'); | ||
const channelManager = require('../../managers/channelManager.js'); | ||
@@ -13,4 +14,11 @@ const validAutoArchiveDates = [60, 1440, 10080, 4320]; | ||
class TextChannel extends GuildChannel{ | ||
constructor(data, addon, guild, structureHandler){ | ||
constructor(data, addon, guild, structureHandler, cache){ | ||
super(data, addon, guild); | ||
if(cache){ | ||
const addonChannelManager = channelManager.get(addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(guild.id) || new Save(); | ||
guildChannelManager.set(data.id, this); | ||
addonChannelManager.set(guild.id, guildChannelManager); | ||
channelManager.set(addon.name, addonChannelManager); | ||
} | ||
this.addon = addon; | ||
@@ -25,3 +33,2 @@ this.topic = data.topic; | ||
} | ||
if(guild) guild.channels.set(this.id, this); | ||
if(validatePermission(getAddonPermission(addon.name), scopes.bitfield.CHANNELS)){ | ||
@@ -28,0 +35,0 @@ addon.channels.set(this.id, this); |
@@ -8,6 +8,14 @@ const BaseChannel = require('./base.js'); | ||
const MessageManager = require('../../managers/messageManager.js'); | ||
const channelManager = require('../../managers/channelManager.js'); | ||
class ThreadChannel extends BaseChannel{ | ||
constructor(data, addon, guild, structureHandler){ | ||
constructor(data, addon, guild, structureHandler, cache){ | ||
super(data, addon); | ||
if(cache){ | ||
const addonChannelManager = channelManager.get(addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(guild.id) || new Save(); | ||
guildChannelManager.set(data.id, this); | ||
addonChannelManager.set(guild.id, guildChannelManager); | ||
channelManager.set(addon.name, addonChannelManager); | ||
} | ||
this.addon = addon; | ||
@@ -45,3 +53,2 @@ this.guild = guild; | ||
this.owner = guildMemberManager.get(data.ownerId) || null; | ||
if(guild) guild.channels.set(this.id, this); | ||
if(validatePermission(getAddonPermission(addon.name), scopes.bitfield.CHANNELS)){ | ||
@@ -48,0 +55,0 @@ addon.channels.set(this.id, this); |
@@ -11,9 +11,17 @@ const GuildChannel = require('./guildChannel.js'); | ||
const ytstream = require('yt-stream'); | ||
const channelManager = require('../../managers/channelManager.js'); | ||
let client; | ||
let client = null; | ||
class VoiceChannel extends GuildChannel{ | ||
constructor(data, addon, guild, structureHandler){ | ||
constructor(data, addon, guild, structureHandler, cache){ | ||
super(data, addon, guild); | ||
client = getClient(); | ||
if(cache){ | ||
const addonChannelManager = channelManager.get(addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(guild.id) || new Save(); | ||
guildChannelManager.set(data.id, this); | ||
addonChannelManager.set(guild.id, guildChannelManager); | ||
channelManager.set(addon.name, addonChannelManager); | ||
} | ||
if(!client) client = getClient(); | ||
this.addon = addon; | ||
@@ -37,3 +45,2 @@ this.joinable = data.joinable; | ||
} | ||
if(guild) guild.channels.set(this.id, this); | ||
if(validatePermission(getAddonPermission(addon.name), scopes.bitfield.CHANNELS)){ | ||
@@ -40,0 +47,0 @@ addon.channels.set(this.id, this); |
@@ -6,9 +6,17 @@ const { validatePermission, getAddonPermission } = require('../../utils/functions.js'); | ||
const Save = require('../save.js'); | ||
const emojiManager = require('../managers/emojiManager.js'); | ||
class Emoji{ | ||
constructor(emoji, addon, guild){ | ||
constructor(emoji, addon, guild, structureHandler, cache){ | ||
if(cache){ | ||
const addonEmojiManager = emojiManager.get(addon.name) || new Save(); | ||
const guildEmojiManager = addonEmojiManager.get(guild.id) || new Save(); | ||
guildEmojiManager.set(emoji.id, this); | ||
addonEmojiManager.set(guild.id, guildEmojiManager); | ||
emojiManager.set(addon.name, addonEmojiManager); | ||
} | ||
this.addon = addon; | ||
this.creatorId = emoji.author ? emoji.author.id : null; | ||
this.animated = emoji.animated; | ||
this.guild = guild; | ||
const addonUserManager = UserManager.get(addon.name) || new Save(); | ||
this.creator = (typeof emoji.author === 'object' && !Array.isArray(emoji.author) && emoji.author !== null) ? addonUserManager.get(emoji.author.id) : null; | ||
this.created = new Date(emoji.createdTimestamp); | ||
@@ -49,4 +57,8 @@ this.createdTimestamp = emoji.createdTimestamp; | ||
} | ||
get creator(){ | ||
const addonUserManager = UserManager.get(this.addon.name) || new Save(); | ||
return typeof this.creatorId === 'string' ? addonUserManager.get(this.creatorId) : null; | ||
} | ||
} | ||
module.exports = Emoji; |
@@ -1,7 +0,9 @@ | ||
const User = require('../user.js'); | ||
const userManager = require('../../managers/userManager.js'); | ||
const Save = require('../../save.js'); | ||
class BanEntry{ | ||
constructor(user, guild, entry, addon){ | ||
this.executor = new User(entry.executor, addon, false); | ||
this.user = new User(user, addon, false); | ||
const addonUserManager = userManager.get(addon.name) || new Save(); | ||
this.executor = addonUserManager.get(entry.executor.id); | ||
this.user = addonUserManager.get(user.id); | ||
this.banned = new Date(entry.createdTimestamp); | ||
@@ -8,0 +10,0 @@ this.bannedTimestamp = entry.createdTimestamp; |
@@ -1,7 +0,9 @@ | ||
const User = require('../user.js'); | ||
const userManager = require('../../managers/userManager.js'); | ||
const Save = require('../../save.js'); | ||
class BaseEntry{ | ||
constructor(data, member, guild, addon){ | ||
this.executor = new User(data.executor, addon, false); | ||
this.user = member ? new User(data.target, addon, false) : undefined; | ||
const addonUserManager = userManager.get(addon.name) || new Save(); | ||
this.executor = addonUserManager.get(data.executor.id); | ||
this.user = member ? addonUserManager.get(data.target.id) : undefined; | ||
this.reason = data.reason; | ||
@@ -8,0 +10,0 @@ this.changed = new Date(data.createdTimestamp); |
@@ -1,7 +0,9 @@ | ||
const User = require('../user.js'); | ||
const userManager = require('../../managers/userManager.js'); | ||
const Save = require('../../save.js'); | ||
class KickEntry{ | ||
constructor(user, guild, entry, addon){ | ||
this.executor = new User(entry.executor, addon, false); | ||
this.user = new User(user, addon, false); | ||
const addonUserManager = userManager.get(addon.name) || new Save(); | ||
this.executor = addonUserManager.get(entry.executor.id); | ||
this.user = addonUserManager.get(user.id); | ||
this.kicked = new Date(entry.createdTimestamp); | ||
@@ -8,0 +10,0 @@ this.kickedTimestamp = entry.createdTimestamp; |
@@ -1,7 +0,9 @@ | ||
const User = require('../user.js'); | ||
const userManager = require('../../managers/userManager.js'); | ||
const Save = require('../../save.js'); | ||
class MuteEntry{ | ||
constructor(data, member, addon){ | ||
this.executor = new User(data.executor, addon, false); | ||
this.user = new User(data.target, addon, false); | ||
const addonUserManager = userManager.get(addon.name) || new Save(); | ||
this.executor = addonUserManager.get(data.executor.id); | ||
this.user = addonUserManager.get(data.target.id); | ||
this.reason = data.reason; | ||
@@ -8,0 +10,0 @@ this.muted = new Date(data.createdTimestamp); |
@@ -13,2 +13,5 @@ const { validatePermission, getAddonPermission, getColorCode, getChannelId, getResolvableDate, getClient, getVideoQualityMode } = require('../../utils/functions.js'); | ||
const { ChannelType } = require('discord.js'); | ||
const channelManager = require('../managers/channelManager.js'); | ||
const roleManager = require('../managers/roleManager.js'); | ||
const emojiManager = require('../managers/emojiManager.js'); | ||
@@ -20,6 +23,8 @@ const validAutoArchiveDates = [60, 1440, 10080, 4320]; | ||
class Guild{ | ||
constructor(guild, addon, structureHandler){ | ||
const addonGuildManager = GuildManager.get(addon.name) || structureHandler.createStructure('Save'); | ||
addonGuildManager.set(guild.id, this); | ||
GuildManager.set(addon.name, addonGuildManager); | ||
constructor(guild, addon, structureHandler, cache){ | ||
if(cache){ | ||
const addonGuildManager = GuildManager.get(addon.name) || structureHandler.createStructure('Save'); | ||
addonGuildManager.set(guild.id, this); | ||
GuildManager.set(addon.name, addonGuildManager); | ||
} | ||
client = getClient(); | ||
@@ -29,25 +34,9 @@ this.addon = addon; | ||
this.name = guild.name; | ||
this.channels = structureHandler.createStructure('Save'); | ||
const guildChannels = Array.from(guild.channels.cache.values()); | ||
for(var i = 0; i < guildChannels.length; i++){ | ||
var guildChannel = guildChannels[i]; | ||
if(guildChannel.type === ChannelType.GuildText || guildChannel.type === ChannelType.GuildAnnouncement){ | ||
structureHandler.createStructure('TextChannel', [guildChannel, addon, this]); | ||
} else if(guildChannel.type === ChannelType.GuildCategory){ | ||
structureHandler.createStructure('CategoryChannel', [guildChannel, addon, this]); | ||
} else if(guildChannel.type === ChannelType.GuildVoice){ | ||
structureHandler.createStructure('VoiceChannel', [guildChannel, addon, this]); | ||
} else if(guildChannel.type === ChannelType.GuildStageVoice){ | ||
structureHandler.createStructure('StageChannel', [guildChannel, addon, this]); | ||
} else if(guildChannel.type === ChannelType.GuildForum){ | ||
structureHandler.createStructure('ForumChannel', [guildChannel, addon, this]); | ||
} else if(guildChannel.type === ChannelType.GuildDirectory){ | ||
structureHandler.createStructure('DirectoryChannel', [guildChannel, addon, this]); | ||
} | ||
} | ||
const invites = guild.invites.cache.map(i => i); | ||
const invites = Array.from(guild.invites.cache.values()); | ||
const addonInviteManager = inviteManager.get(addon.name) || new Save(); | ||
const guildInviteManager = addonInviteManager.get(guild.id) || new Save(); | ||
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]); | ||
if(!guildInviteManager.get(invite.id)) structureHandler.createStructure('Invite', [invite, this, addon]); | ||
} | ||
@@ -59,15 +48,2 @@ this.iconURL = guild.iconURL({size: 256, dynamic: true}); | ||
this.verificationLevel = guild.verificationLevel; | ||
this.emojis = structureHandler.createStructure('Save'); | ||
const guildEmojis = Array.from(guild.emojis.cache.values()); | ||
for(var i = 0; i < guildEmojis.length; i++){ | ||
var guildEmoji = guildEmojis[i]; | ||
this.emojis.set(guildEmoji.id, new Emoji(guildEmoji, addon, this)); | ||
} | ||
this.roles = structureHandler.createStructure('Save'); | ||
const guildRoles = Array.from(guild.roles.cache.values()); | ||
for(var i = 0; i < guildRoles.length; i++){ | ||
var guildRole = guildRoles[i]; | ||
this.roles.set(guildRole.id, new Role(guildRole, addon, this)); | ||
} | ||
this.everyoneRole = this.roles.filter(role => role.value.id === guild.roles.everyone.id).first(); | ||
this.memberCount = guild.memberCount; | ||
@@ -78,3 +54,3 @@ this.botAdded = new Date(guild.joinedTimestamp); | ||
this.createdTimestamp = guild.createdTimestamp; | ||
this.voiceStates = VoiceStateManager.get(addon.name) || structureHandler.createStructure('Save'); | ||
this.everyoneRoleId = guild.roles.everyone.id; | ||
if(validatePermission(getAddonPermission(addon.name), scopes.bitfield.GUILDS)){ | ||
@@ -298,4 +274,27 @@ addon.guilds.set(this.id, this); | ||
} | ||
get channels(){ | ||
const addonChannelManager = channelManager.get(this.addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(this.id) || new Save(); | ||
return guildChannelManager; | ||
} | ||
get emojis(){ | ||
const addonEmojiManager = emojiManager.get(this.addon.name) || new Save(); | ||
const guildEmojiManager = addonEmojiManager.get(this.id) || new Save(); | ||
return guildEmojiManager; | ||
} | ||
get roles(){ | ||
const addonRoleManager = roleManager.get(this.addon.name) || new Save(); | ||
const guildRoleManager = addonRoleManager.get(this.id) || new Save(); | ||
return guildRoleManager; | ||
} | ||
get everyoneRole(){ | ||
return this.roles.filter(role => role.value.id === this.everyoneRoleId).first(); | ||
} | ||
get voiceStates(){ | ||
const addonVoiceStateManager = VoiceStateManager.get(this.addon.name) || new Save(); | ||
const guildVoiceStateManager = addonVoiceStateManager.get(this.id) || new Save(); | ||
return guildVoiceStateManager; | ||
} | ||
} | ||
module.exports = Guild; |
const GuildManager = require('../../managers/guildManager.js'); | ||
const GuildMemberManager = require('../../managers/guildMemberManager.js'); | ||
const channelManager = require('../../managers/channelManager.js'); | ||
const userManager = require('../../managers/userManager.js'); | ||
const messageManager = require('../../managers/messageManager.js'); | ||
const { getMessageContent } = require('../../../utils/messageFunctions.js'); | ||
@@ -10,13 +13,8 @@ const Save = require('../../save.js'); | ||
constructor(data, addon, structureHandler){ | ||
const addonGuildManager = GuildManager.get(addon.name) || new Save(); | ||
this.addon = addon; | ||
this.type = "Button"; | ||
this.guild = addonGuildManager.get(data.guildId); | ||
this.guildId = data.guildId; | ||
this.channel = this.guild ? this.guild.channels.get(data.channelId) : null; | ||
this.channelId = data.channelId; | ||
const addonGuildMemberManager = GuildMemberManager.get(addon.name) || new Save(); | ||
const GuildMembers = addonGuildMemberManager.get(this.guildId) || new Save(); | ||
this.member = GuildMembers.get(data.member.id); | ||
this.user = structureHandler.createStructure('User', [data.user, addon, false]); | ||
this.message = structureHandler.createStructure('Message', [data.message, addon]); | ||
this.memberId = data.member?.id; | ||
this.messageId = data.message?.id; | ||
this.customId = data.customId; | ||
@@ -82,4 +80,28 @@ this.id = data.id; | ||
} | ||
get member(){ | ||
const addonGuildMemberManager = GuildMemberManager.get(this.addon.name) || new Save(); | ||
const GuildMembers = addonGuildMemberManager.get(this.guildId) || new Save(); | ||
return GuildMembers.get(this.memberId); | ||
} | ||
get guild(){ | ||
const addonGuildManager = GuildManager.get(this.addon.name) || new Save(); | ||
return addonGuildManager.get(this.guildId); | ||
} | ||
get channel(){ | ||
const addonChannelManager = channelManager.get(this.addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(this.guildId) || new Save(); | ||
return guildChannelManager.get(this.channelId); | ||
} | ||
get user(){ | ||
const addonUserManager = userManager.get(this.addon.name) || new Save(); | ||
return addonUserManager.get(this.memberId); | ||
} | ||
get message(){ | ||
const addonMessageManager = messageManager.get(this.addon.name) || new Save(); | ||
const guildMessageManager = addonMessageManager.get(this.guildId) || new Save(); | ||
const channelMessageManager = guildMessageManager.get(this.channelId) || new Save(); | ||
return channelMessageManager.get(this.messageId); | ||
} | ||
} | ||
module.exports = ButtonInteraction; |
const GuildManager = require('../../managers/guildManager.js'); | ||
const GuildMemberManager = require('../../managers/guildMemberManager.js'); | ||
const channelManager = require('../../managers/channelManager.js'); | ||
const userManager = require('../../managers/userManager.js'); | ||
const messageManager = require('../../managers/messageManager.js'); | ||
const { getMessageContent } = require('../../../utils/messageFunctions.js'); | ||
@@ -9,13 +12,8 @@ const Save = require('../../save.js'); | ||
constructor(data, addon, structureHandler){ | ||
const addonGuildManager = GuildManager.get(addon.name) || new Save(); | ||
this.addon = addon; | ||
this.type = "Form"; | ||
this.guild = addonGuildManager.get(data.guildId); | ||
this.guildId = data.guildId; | ||
this.channel = this.guild ? this.guild.channels.get(data.channelId) : null; | ||
this.channelId = data.channelId; | ||
const addonGuildMemberManager = GuildMemberManager.get(addon.name) || new Save(); | ||
const GuildMembers = addonGuildMemberManager.get(this.guildId) || new Save(); | ||
this.member = GuildMembers.get(data.member.id); | ||
this.user = structureHandler.createStructure('User', [data.user, addon, false]); | ||
this.message = structureHandler.createStructure('Message', [data.message, addon]); | ||
this.memberId = data.member?.id; | ||
this.messageId = data.message?.id; | ||
this.customId = data.customId; | ||
@@ -74,4 +72,28 @@ this.id = data.id; | ||
} | ||
get member(){ | ||
const addonGuildMemberManager = GuildMemberManager.get(this.addon.name) || new Save(); | ||
const GuildMembers = addonGuildMemberManager.get(this.guildId) || new Save(); | ||
return GuildMembers.get(this.memberId); | ||
} | ||
get guild(){ | ||
const addonGuildManager = GuildManager.get(this.addon.name) || new Save(); | ||
return addonGuildManager.get(this.guildId); | ||
} | ||
get channel(){ | ||
const addonChannelManager = channelManager.get(this.addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(this.guildId) || new Save(); | ||
return guildChannelManager.get(this.channelId); | ||
} | ||
get user(){ | ||
const addonUserManager = userManager.get(this.addon.name) || new Save(); | ||
return addonUserManager.get(this.memberId); | ||
} | ||
get message(){ | ||
const addonMessageManager = messageManager.get(this.addon.name) || new Save(); | ||
const guildMessageManager = addonMessageManager.get(this.guildId) || new Save(); | ||
const channelMessageManager = guildMessageManager.get(this.channelId) || new Save(); | ||
return channelMessageManager.get(this.messageId); | ||
} | ||
} | ||
module.exports = FormInteraction; |
const GuildManager = require('../../managers/guildManager.js'); | ||
const GuildMemberManager = require('../../managers/guildMemberManager.js'); | ||
const channelManager = require('../../managers/channelManager.js'); | ||
const userManager = require('../../managers/userManager.js'); | ||
const messageManager = require('../../managers/messageManager.js'); | ||
const { getMessageContent } = require('../../../utils/messageFunctions.js'); | ||
@@ -10,17 +13,11 @@ const Save = require('../../save.js'); | ||
constructor(data, addon, structureHandler){ | ||
const addonGuildManager = GuildManager.get(addon.name) || new Save(); | ||
this.addon = addon; | ||
this.type = "Menu"; | ||
this.guild = addonGuildManager.get(data.guildId); | ||
this.guildId = data.guildId; | ||
this.channel = this.guild ? this.guild.channels.get(data.channelId) : null; | ||
this.channelId = data.channelId; | ||
const addonGuildMemberManager = GuildMemberManager.get(addon.name) || new Save(); | ||
const GuildMembers = addonGuildMemberManager.get(this.guildId) || new Save(); | ||
this.member = GuildMembers.get(data.member.id); | ||
this.user = structureHandler.createStructure('User', [data.user, addon, false]); | ||
this.message = structureHandler.createStructure('Message', [data.message, addon]); | ||
this.memberId = data.member?.id; | ||
this.messageId = data.message?.id; | ||
this.customId = data.customId; | ||
this.id = data.id; | ||
this.values = [...data.values]; | ||
this.isButton = () => { | ||
@@ -84,4 +81,28 @@ return this.type === "Button"; | ||
} | ||
get member(){ | ||
const addonGuildMemberManager = GuildMemberManager.get(this.addon.name) || new Save(); | ||
const GuildMembers = addonGuildMemberManager.get(this.guildId) || new Save(); | ||
return GuildMembers.get(this.memberId); | ||
} | ||
get guild(){ | ||
const addonGuildManager = GuildManager.get(this.addon.name) || new Save(); | ||
return addonGuildManager.get(this.guildId); | ||
} | ||
get channel(){ | ||
const addonChannelManager = channelManager.get(this.addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(this.guildId) || new Save(); | ||
return guildChannelManager.get(this.channelId); | ||
} | ||
get user(){ | ||
const addonUserManager = userManager.get(this.addon.name) || new Save(); | ||
return addonUserManager.get(this.memberId); | ||
} | ||
get message(){ | ||
const addonMessageManager = messageManager.get(this.addon.name) || new Save(); | ||
const guildMessageManager = addonMessageManager.get(this.guildId) || new Save(); | ||
const channelMessageManager = guildMessageManager.get(this.channelId) || new Save(); | ||
return channelMessageManager.get(this.messageId); | ||
} | ||
} | ||
module.exports = MenuInteraction; |
@@ -5,3 +5,3 @@ const inviteManager = require('../managers/inviteManager.js'); | ||
class Invite{ | ||
constructor(data, guild, addon){ | ||
constructor(data, guild, addon, structureHandler, cache){ | ||
this.code = data.code; | ||
@@ -33,7 +33,9 @@ this.createdTimestamp = data.createdTimestamp; | ||
const addonInviteManager = inviteManager.get(addon.name) || new Save(); | ||
const guildInviteManager = addonInviteManager.get(guild.id) || new Save(); | ||
guildInviteManager.set(this.code, this); | ||
addonInviteManager.set(guild.id, guildInviteManager); | ||
inviteManager.set(addon.name, addonInviteManager); | ||
if(cache){ | ||
const addonInviteManager = inviteManager.get(addon.name) || new Save(); | ||
const guildInviteManager = addonInviteManager.get(guild.id) || new Save(); | ||
guildInviteManager.set(this.code, this); | ||
addonInviteManager.set(guild.id, guildInviteManager); | ||
inviteManager.set(addon.name, addonInviteManager); | ||
} | ||
} | ||
@@ -40,0 +42,0 @@ } |
const { validatePermission, getResolvableDate, getAddonPermission, wait, getClient } = require('../../utils/functions.js'); | ||
const scopes = require('../../bitfields/scopes.js'); | ||
const User = require('./user.js'); | ||
const VoiceState = require('./voiceState.js'); | ||
const MemberManager = require('../managers/memberManager.js'); | ||
@@ -12,2 +11,4 @@ const GuildMemberManager = require('../managers/guildMemberManager.js'); | ||
const Level = require('./saves/level.js'); | ||
const roleManager = require('../managers/roleManager.js'); | ||
const voiceStateManager = require('../managers/voiceStateManager.js'); | ||
@@ -17,24 +18,21 @@ let client; | ||
class Member extends User{ | ||
constructor(guildMember, addon, structureHandler){ | ||
constructor(guildMember, addon, structureHandler, cache){ | ||
client = getClient(); | ||
super((guildMember.user || client.users.cache.get(guildMember.id)), addon, false, structureHandler); | ||
const addonMemberManager = MemberManager.get(addon.name) || new Save(); | ||
const memberManager = addonMemberManager.get(guildMember.id) || new Save(); | ||
memberManager.set(guildMember.guild.id, this); | ||
addonMemberManager.set(guildMember.id, memberManager); | ||
MemberManager.set(addon.name, addonMemberManager); | ||
const addonGuildMemberManager = GuildMemberManager.get(addon.name) || new Save(); | ||
const guildMemberManager = addonGuildMemberManager.get(guildMember.guild.id) || new Save(); | ||
guildMemberManager.set(guildMember.id, this); | ||
addonGuildMemberManager.set(guildMember.guild.id, guildMemberManager); | ||
GuildMemberManager.set(addon.name, addonGuildMemberManager); | ||
this.guildId = guildMember.guild.id; | ||
const addonGuildManager = GuildManager.get(addon.name) || new Save(); | ||
this.guild = addonGuildManager.get(guildMember.guild.id); | ||
this.roles = new Save(); | ||
const guildRoles = Array.from(guildMember.roles.cache.values()); | ||
for(var i = 0; i < guildRoles.length; i++){ | ||
let guildRole = guildRoles[i]; | ||
this.roles.set(guildRole.id, new Role(guildRole, addon, this.guild)); | ||
super((guildMember.user ?? client.users.cache.get(guildMember.id)), addon, false, structureHandler, cache); | ||
this.addon = addon; | ||
if(cache){ | ||
const addonMemberManager = MemberManager.get(addon.name) || new Save(); | ||
const memberManager = addonMemberManager.get(guildMember.id) || new Save(); | ||
memberManager.set(guildMember.guild.id, this); | ||
addonMemberManager.set(guildMember.id, memberManager); | ||
MemberManager.set(addon.name, addonMemberManager); | ||
const addonGuildMemberManager = GuildMemberManager.get(addon.name) || new Save(); | ||
const guildMemberManager = addonGuildMemberManager.get(guildMember.guild.id) || new Save(); | ||
guildMemberManager.set(guildMember.id, this); | ||
addonGuildMemberManager.set(guildMember.guild.id, guildMemberManager); | ||
GuildMemberManager.set(addon.name, addonGuildMemberManager); | ||
} | ||
this.guildId = guildMember.guild?.id; | ||
const guildRoles = Array.from(guildMember.roles.cache.keys()); | ||
this._roles = guildRoles; | ||
this.nickname = guildMember.nickname; | ||
@@ -54,3 +52,2 @@ this.displayName = this.nickname || this.username; | ||
this.voiceConnected = typeof guildMember.voice.channelId === 'string'; | ||
this.voice = new VoiceState(guildMember.voice, addon); | ||
this.getInviteInfo = () => { | ||
@@ -245,4 +242,24 @@ if(!validatePermission(getAddonPermission(addon.name), scopes.bitfield.MEMBERS)) throw new Error(`Missing members scope in bitfield`); | ||
} | ||
get guild(){ | ||
const addonGuildManager = GuildManager.get(this.addon.name) || new Save(); | ||
return addonGuildManager.get(this.guildId); | ||
} | ||
get roles(){ | ||
const addonRoleManager = roleManager.get(this.addon.name) || new Save(); | ||
const guildRoleManager = addonRoleManager.get(this.guildId) || new Save(); | ||
const roles = new Save(); | ||
for(let i = 0; i < this._roles.length; i++){ | ||
var role = guildRoleManager.get(this._roles[i]); | ||
if(role) roles.set(this._roles[i], role); | ||
else continue; | ||
} | ||
return roles; | ||
} | ||
get voiceState(){ | ||
const addonVoiceStateManager = voiceStateManager.get(this.addon.name) || new Save(); | ||
const guildVoiceStateManager = addonVoiceStateManager.get(this.guildId) || new Save(); | ||
return guildVoiceStateManager.get(this.id); | ||
} | ||
} | ||
module.exports = Member; |
@@ -5,2 +5,3 @@ const Save = require('../save.js'); | ||
const UserManager = require('../managers/userManager.js'); | ||
const channelManager = require('../managers/channelManager.js'); | ||
const { ChannelType } = require('discord.js'); | ||
@@ -36,14 +37,16 @@ | ||
let channel = null; | ||
const addonChannelManager = channelManager.get(addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(guild.id) || new Save(); | ||
if(guildChannel.type === ChannelType.GuildText || guildChannel.type === ChannelType.GuildAnnouncement){ | ||
channel = structureHandler.createStructure('TextChannel', [guildChannel, addon, guild]); | ||
channel = guildChannelManager.get(guildChannel.id) ?? structureHandler.createStructure('TextChannel', [guildChannel, addon, guild]); | ||
} else if(guildChannel.type === ChannelType.GuildCategory){ | ||
channel = structureHandler.createStructure('CategoryChannel', [guildChannel, addon, guild]); | ||
channel = guildChannelManager.get(guildChannel.id) ?? structureHandler.createStructure('CategoryChannel', [guildChannel, addon, guild]); | ||
} else if(guildChannel.type === ChannelType.GuildVoice){ | ||
channel = structureHandler.createStructure('VoiceChannel', [guildChannel, addon, guild]); | ||
channel = guildChannelManager.get(guildChannel.id) ?? structureHandler.createStructure('VoiceChannel', [guildChannel, addon, guild]); | ||
} else if(guildChannel.type === ChannelType.GuildStageVoice){ | ||
channel = structureHandler.createStructure('StageChannel', [guildChannel, addon, guild]); | ||
channel = guildChannelManager.get(guildChannel.id) ?? structureHandler.createStructure('StageChannel', [guildChannel, addon, guild]); | ||
} else if(guildChannel.type === ChannelType.GuildForum){ | ||
channel = structureHandler.createStructure('ForumChannel', [guildChannel, addon, guild]); | ||
channel = guildChannelManager.get(guildChannel.id) ?? structureHandler.createStructure('ForumChannel', [guildChannel, addon, guild]); | ||
} else if(guildChannel.type === ChannelType.GuildDirectory){ | ||
channel = structureHandler.createStructure('DirectoryChannel', [guildChannel, addon, guild]); | ||
channel = guildChannelManager.get(guildChannel.id) ?? structureHandler.createStructure('DirectoryChannel', [guildChannel, addon, guild]); | ||
} | ||
@@ -50,0 +53,0 @@ return { |
@@ -7,2 +7,3 @@ const { validatePermission, getAddonPermission, getClientParser } = require('../../utils/functions.js'); | ||
const UserManager = require('../managers/userManager.js'); | ||
const channelManager = require('../managers/channelManager.js'); | ||
const Emoji = require('./emoji.js'); | ||
@@ -35,3 +36,5 @@ const EmojiCollector = require('./collectors/emojiCollector.js'); | ||
this.url = data.url; | ||
this.channel = data.channel.isDMBased() ? structureHandler.createStructure('DMChannel', [data.channel, addon]) : (this.guild !== null && this.guild !== undefined ? this.guild.channels.get(data.channelId) : null); | ||
const addonChannelManager = channelManager.get(addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(data.channel.isDMBased() ? undefined : data.guild.id) || new Save(); | ||
this.channel = data.channel.isDMBased() ? structureHandler.createStructure('DMChannel', [data.channel, addon]) : (guildChannelManager.get(data.id) ?? null); | ||
this.deletable = data.deletable; | ||
@@ -38,0 +41,0 @@ this.mentions = structureHandler.createStructure('Mentions', [data, addon, this.guild]); |
@@ -5,6 +5,10 @@ const User = require('./user.js'); | ||
const GuildMemberManager = require('../managers/guildMemberManager.js'); | ||
const messageManager = require('../managers/messageManager.js'); | ||
class Reaction{ | ||
constructor(data, addon, _user, structureHandler){ | ||
this.message = structureHandler.createStructure('Message', [data.message, addon]); | ||
const addonMessageManager = messageManager.get(addon.name) || structureHandler.createStructure('Save'); | ||
const guildMessageManager = addonMessageManager.get(data.message.guild.id) || structureHandler.createStructure('Save'); | ||
const channelMessageManager = guildMessageManager.get(data.message.channel.id) || structureHandler.createStructure('Save'); | ||
this.message = channelMessageManager.get(data.message.id) ?? structureHandler.createStructure('Message', [data.message, addon]); | ||
this.guild = this.message.guild; | ||
@@ -11,0 +15,0 @@ this.id = data.emoji.id; |
const { validatePermission, getAddonPermission, getColorCode } = require('../../utils/functions.js'); | ||
const scopes = require('../../bitfields/scopes.js'); | ||
const roleManager = require('../managers/roleManager.js'); | ||
const guildManager = require('../managers/guildManager.js'); | ||
const Save = require('../save.js'); | ||
class Role{ | ||
constructor(data, addon, guild){ | ||
this.data = data; | ||
constructor(data, addon, guild, structureHandler, cache){ | ||
if(cache){ | ||
const addonRoleManager = roleManager.get(addon.name) || new Save(); | ||
const guildRoleManager = addonRoleManager.get(guild.id) || new Save(); | ||
guildRoleManager.set(data.id, this); | ||
addonRoleManager.set(guild.id, guildRoleManager); | ||
roleManager.set(addon.name, addonRoleManager); | ||
} | ||
this.addon = addon; | ||
try{ | ||
this.editable = data.editable; | ||
} catch (err){ | ||
this.editable = false; | ||
} | ||
this.id = data.id; | ||
@@ -18,6 +33,5 @@ this.string = `<@&${this.id}>`; | ||
this.createdTimestamp = data.createdTimestamp; | ||
this.guild = guild; | ||
this.guildId = guild.id; | ||
this.permissions = data.permissions; | ||
this.mentionable = data.mentionable; | ||
if(guild) this.guild.roles.set(this.id, this); | ||
this.setName = function(name, reason){ | ||
@@ -115,4 +129,5 @@ return new Promise((resolve, reject) => { | ||
} | ||
get editable(){ | ||
return this.data.editable; | ||
get guild(){ | ||
const addonGuildManager = guildManager.get(this.addon.name) || new Save(); | ||
return addonGuildManager.get(this.guildId); | ||
} | ||
@@ -119,0 +134,0 @@ } |
@@ -25,6 +25,6 @@ const UserManager = require('../managers/userManager.js'); | ||
class User{ | ||
constructor(user, addon, loop, structureHandler){ | ||
if(loop === false){ | ||
constructor(user, addon, loop, structureHandler, cache){ | ||
if(loop === false && cache){ | ||
const addonUserManager = UserManager.get(addon.name) || new Save(); | ||
addonUserManager.set(user.id, new User(user, addon, true)); | ||
addonUserManager.set(user.id, new User(user, addon, true, structureHandler, false)); | ||
UserManager.set(addon.name, addonUserManager); | ||
@@ -31,0 +31,0 @@ } |
@@ -8,13 +8,11 @@ const Save = require('../save.js'); | ||
const scopes = require('../../bitfields/scopes.js'); | ||
const guildManager = require('../managers/guildManager.js'); | ||
const channelManager = require('../managers/channelManager.js'); | ||
class VoiceState{ | ||
constructor(voiceState, addon){ | ||
constructor(voiceState, addon, structureHandler, cache){ | ||
this.addon = addon; | ||
if(typeof voiceState.member === 'object' && !Array.isArray(voiceState.member) && voiceState.member !== null){ | ||
const addonVoiceStateManager = VoiceStateManager.get(addon.name) || new Save(); | ||
addonVoiceStateManager.set(voiceState.member.id, this); | ||
VoiceStateManager.set(addon.name, addonVoiceStateManager); | ||
this.member = ((GuildMemberManager.get(addon.name) || new Save()).get(voiceState.member.guild.id) || new Save()).get(voiceState.member.id); | ||
this.id = voiceState.member.id; | ||
} else { | ||
this.member = null; | ||
this.id = null; | ||
@@ -32,4 +30,11 @@ } | ||
this.deaf = this.selfDeaf || this.serverDeaf || false; | ||
this.guildId = (voiceState.member ?? voiceState.channel)?.guild?.id; | ||
this.channelId = voiceState.channelId || null; | ||
this.channel = typeof this.channelId === 'string' ? (this.member.guild.channels.get(this.channelId) || null) : null; | ||
if(cache){ | ||
const addonVoiceStateManager = VoiceStateManager.get(addon.name) || new Save(); | ||
const guildVoiceStateManager = addonVoiceStateManager.get(this.guildId) || new Save(); | ||
guildVoiceStateManager.set(this.id, this); | ||
addonVoiceStateManager.set(this.guildId, guildVoiceStateManager); | ||
VoiceStateManager.set(addon.name, addonVoiceStateManager); | ||
} | ||
this.disconnect = function(reason){ | ||
@@ -76,4 +81,17 @@ return new Promise((resolve, reject) => { | ||
} | ||
get member(){ | ||
return ((GuildMemberManager.get(addon.name) || new Save()).get(this.guildId) || new Save()).get(this.id); | ||
} | ||
get channel(){ | ||
if(this.channelId === null) return null; | ||
const addonChannelManager = channelManager.get(this.addon.name) || new Save(); | ||
const guildChannelManager = addonChannelManager.get(this.guildId) || new Save(); | ||
return guildChannelManager.get(this.channelId); | ||
} | ||
get guild(){ | ||
const addonGuildManager = guildManager.get(this.addon.name) || new Save(); | ||
return addonGuildManager.get(this.guildId); | ||
} | ||
} | ||
module.exports = VoiceState; |
@@ -11,2 +11,3 @@ const { ValueSaver } = require('valuesaver'); | ||
const interactionCollectors = new ValueSaver(); | ||
const builtStructures = {}; | ||
@@ -20,3 +21,4 @@ module.exports = { | ||
emojiCollectors, | ||
interactionCollectors | ||
interactionCollectors, | ||
builtStructures | ||
}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
468553
81
9675
2
Updatedyt-stream@^1.4.10