Socket
Socket
Sign inDemoInstall

@conflict/beta

Package Overview
Dependencies
Maintainers
1
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@conflict/beta - npm Package Compare versions

Comparing version 0.1.7 to 0.2.0

components_dist/ActionRow.js

92

bot.js

@@ -15,10 +15,12 @@ import Discord, {

import stump from './logger.js'
import { _setClient, onInteractionCreate } from './events.js'
import { _setClient, onInteractionCreate, onDebug, onReady } from './events.js'
import Command, { InteractionResponse } from './commands.js'
import View from './view.js'
import State from './state.js'
import { getFile } from './utils.js'
import State, { managers } from './state.js'
import { getFile, cleanLines } from './utils.js'
global.__ConflictViewParser = View.createElement;
if (!global.__ConflictENV) global.__ConflictENV = {};
(async () => {

@@ -31,2 +33,4 @@

if (process.env.CONFLICT_VERBOSE) global.__ConflictENV.verbose = true;
let config;

@@ -44,3 +48,7 @@ try {

client.on('ready', () => {
if (process.env.CONFLICT_VERBOSE === "TRUE") onDebug(message => {
stump.verbose(message);
});
onReady(() => {
stump.success('Logged in as ' + client.user.tag);

@@ -68,3 +76,3 @@ initCommands();

if (fs.existsSync(path.join(process.cwd(), '.conflict', '.guilds.commands.cache'))) {
previousGuilds = fs.readFileSync(path.join(process.cwd(), '.conflict', '.guilds.commands.cache'), 'utf8').split('^');
previousGuilds = fs.readFileSync(path.join(process.cwd(), '.conflict', '.guilds.commands.cache'), 'utf8').split('^').filter(guild => guild);
}

@@ -137,3 +145,3 @@

console.error(err);
stump.error(err);
try {

@@ -146,14 +154,20 @@ if (errorHandler) return errorHandler(err, interaction);

.setTitle('Command Error')
.setDescription(file + ' ```' + err.stack + '```')
.setDescription(file + ' ```' + cleanLines(err.stack, 4) + '```')
.setTimestamp()
] });
} catch (nestedErr) {
stump.error('Conflict had a hard time figuring this one out.', nestedErr);
if (errorHandler) return errorHandler(err, interaction);
interaction.channel.send(
new MessageEmbed()
.setColor('#ff4444')
.setTitle('Command Error')
.setDescription('```' + err.stack + '```')
.setTimestamp()
);
try {
interaction.channel.send(
new MessageEmbed()
.setColor('#ff4444')
.setTitle('Command Error')
.setDescription('```' + err.stack + '```')
.setTimestamp()
);
} catch (nestedNestedErr) {
stump.error('Nested error handling failed.');
}
}

@@ -172,9 +186,45 @@ }

let { customId } = interaction;
interaction.reply({ embeds: [
new MessageEmbed()
.setColor('#ff4444')
.setTitle('Feature in Development')
.setDescription('```' + `Conflict Erorr: FeatureNotReady\n at ${customId}.component:1:1` + '```')
.setTimestamp()
] });
let code = managers.components.select('*').fetch(customId);
if (code) {
try {
let output = await code(new InteractionResponse(interaction));
if (output instanceof Promise) output = await output;
} catch (err) {
stump.error(err);
try {
if (errorHandler) return errorHandler(err, interaction);
const file = getFile(err);
interaction.reply({ embeds: [
new MessageEmbed()
.setColor('#ff4444')
.setTitle('Command Error')
.setDescription(file + ' ```' + cleanLines(err.stack, 4) + '```')
.setTimestamp()
] });
} catch (nestedErr) {
stump.error('Conflict had a hard time figuring this one out.', nestedErr);
if (errorHandler) return errorHandler(err, interaction);
try {
interaction.channel.send(
new MessageEmbed()
.setColor('#ff4444')
.setTitle('Command Error')
.setDescription('```' + err.stack + '```')
.setTimestamp()
);
} catch (nestedNestedErr) {
stump.error('Nested error handling failed.');
}
}
}
} else {
interaction.reply({ embeds: [
new MessageEmbed()
.setColor('#ff4444')
.setTitle('Button Expired')
.setDescription('This button is expired.')
.setTimestamp()
] });
}
}

@@ -181,0 +231,0 @@ });

@@ -21,14 +21,16 @@ import View from './view.js'

this.interaction = interaction;
let optionsArray = interaction.options.data;
let options = {};
let rawOptions = {};
if (interaction.options) {
let optionsArray = interaction.options.data;
let options = {};
let rawOptions = {};
for (const option of optionsArray) {
options[option.name] = option.value;
rawOptions[option.name] = option;
for (const option of optionsArray) {
options[option.name] = option.value;
rawOptions[option.name] = option;
}
this.options = options;
this.rawOptions = rawOptions;
}
this.options = options;
this.rawOptions = rawOptions;
this.user = interaction.user;

@@ -35,0 +37,0 @@ this.id = interaction.id;

@@ -9,2 +9,3 @@ #!/usr/bin/env node

import stump from './logger.js'
import { detectFlag } from './utils.js'

@@ -14,4 +15,21 @@ process.argv.shift();

global.__ConflictENV = {};
(async () => {
if (process.argv[0] == 'start' || !process.argv[0]) {
if (process.argv[0] == 'dev') {
await import(__dirname + '/devserver/index.js');
} else if (process.argv[0] == 'build') {
stump.info('Starting build...');
exec('npx babel bot --out-dir .conflict/build', { cwd: process.cwd() }, (error, stdout, stderr) => {
if (error) return stump.error(error);
stdout.trim().split('\n').filter(line => line).forEach(line => stump.info(line));
stderr = stderr.trim().split('\n').filter(line => line);
stderr.forEach(line => stump.warn(line));
stump.info(`Build completed with ${stderr.length} errors`);
});
} else {
global.__ConflictENV.verbose = detectFlag(process.argv, 'verbose') || detectFlag(process.argv, 'detailed');
if (global.__ConflictENV.verbose) stump.verbose('Running verbose');
if (global.__ConflictENV.verbose) process.env.CONFLICT_VERBOSE = "TRUE";
let config;

@@ -29,15 +47,4 @@ try {

manager.spawn();
} else if (process.argv[0] == 'dev') {
await import(__dirname + '/devserver/index.js');
} else if (process.argv[0] == 'build') {
stump.info('Starting build...');
exec('npx babel bot --out-dir .conflict/build', { cwd: process.cwd() }, (error, stdout, stderr) => {
if (error) return stump.error(error);
stdout.trim().split('\n').filter(line => line).forEach(line => stump.info(line));
stderr = stderr.trim().split('\n').filter(line => line);
stderr.forEach(line => stump.warn(line));
stump.info(`Build completed with ${stderr.length} errors`);
});
} else stump.error('Unknown command', process.argv[0]);
}
})();
{
"name": "@conflict/beta",
"version": "0.1.7",
"version": "0.2.0",
"description": "The first and only UI framework for Discord bots",

@@ -42,5 +42,7 @@ "main": "exports.js",

"./utils": "./utils.js",
"./state": "./state.js"
"./state": "./state.js",
"./components": "./components.js",
"./Components": "./components.js"
},
"type": "module"
}
import { uuid, queryString } from './utils.js'
const managers = {
command: new StateManager('command'),
guild: new StateManager('guild'),
user: new StateManager('user'),
kv: new StateManager('kv'),
components: new ComponentManager('components'),
};
class StateManager {

@@ -17,2 +10,3 @@ constructor (type) {

this.items[item] = new State(item, this.type);
return this.items[item];
}

@@ -30,2 +24,3 @@ drop (item) {

this.items[item] = new ComponentState(item, this.type);
return this.items[item];
}

@@ -73,3 +68,3 @@ }

let id = uuid();
let queryString = 'c?type=code&id:' + encodeURIComponent(id);
let queryString = 'c?type=code&id=' + encodeURIComponent(id);
this.set(id, code);

@@ -79,3 +74,3 @@ return queryString;

fetch (url) {
let id = decodeURIComponent(queryString('https://conflict.local/' + url, id));
let id = decodeURIComponent(queryString('https://conflict.local/' + url, 'id'));
return this.get(id);

@@ -85,2 +80,10 @@ }

export { State as default, State }
const managers = {
command: new StateManager('command'),
guild: new StateManager('guild'),
user: new StateManager('user'),
kv: new StateManager('kv'),
components: new ComponentManager('components'),
};
export { State as default, State, managers }

@@ -46,3 +46,3 @@ import fs from 'fs';

lines[3],
'//' + ' '.repeat(col - 3) + '^ ' + error.split('\n')[0] + ' (:' + line + ':' + col + ')',
'//' + ' '.repeat(col - 3) + '^ ' + error.stack.split('\n')[0] + ' (:' + line + ':' + col + ')',
lines[4],

@@ -55,2 +55,16 @@ lines[5],

return "```js\n" + snippet + "```";
}
export function cleanLines (input, lines) {
return input.split('\n').splice(0, input.split('\n').length - lines).join('\n');
}
export function detectFlag (args, flag, allFlags = []) {
let flagLetters = allFlags.map(flagItem => flagItem[0]);
return (
args.includes('-' + flag) ||
args.includes('--' + flag) ||
args.includes('-' + ( flagLetters.includes(flag[0]) ? flag[0].toUpperCase() : flag[0] )) ||
args.includes('--' + ( flagLetters.includes(flag[0]) ? flag[0].toUpperCase() : flag[0] ))
);
}

@@ -28,3 +28,3 @@ import Discord from 'discord.js';

let object = props;
children.forEach(child => {
children.forEach((child, index) => {
let childObject;

@@ -40,3 +40,9 @@ if (child.children && child.children instanceof Array && child.children.filter(newChild => typeof newChild === 'string' || typeof newChild === 'number').length == child.children.length) {

if (child.tag.endsWith('_arr')) child.tag = child.tag.substring(0, child.tag.length - 4) + ('$' + Date.now() + index + 'R' + '$'); // Allow for multiple elements with the same tag, so long as it ends with _arr
if (!object[child.tag] && child.tag === 'embeds') object[child.tag] = [];
if (!object[child.tag] && child.tag === 'components') object[child.tag] = [];
else if (!object[child.tag] && child.tag === 'vstack') object[child.tag] = [];
if (object[child.tag] && !(object[child.tag] instanceof Array)) object[child.tag] = [object[child.tag]];

@@ -51,5 +57,5 @@

if (keys.length == 1 && keys[0] === 'embed' && tag === 'embeds') object = object[keys[0]];
if (keys.length == 1 && keys[0] === 'hstack' && tag === 'vstack') object = object[keys[0]];
//console.log('isComponent', keys.length == 1 && keys[0] === 'component' && tag === 'components');
if (keys.length == 1 && keys[0] === 'component' && tag === 'components') object = [object[keys[0]]];
//console.log(object);
// if (keys.length == 1 && keys[0] === 'component' && tag === 'components') object = [object[keys[0]]];
if (object.components && object.components[0]) {

@@ -61,5 +67,43 @@ //console.log(object.components[0])

export function recursiveArray (tree) {
console.log('[recursiveArray]', tree);
for (const key in tree) {
console.log(key, key.includes('$'));
let newName;
if (key.includes('$')) {
newName = key.substring(0, key.indexOf('$'));
if (tree[newName]) tree[newName].push(Object.values(tree[key])[0]);
else {
console.log('[value]', (tree[key]));
console.log('[values]', Object.values(tree[key]));
tree[newName] = [Object.values(tree[key])[0]];
}
delete tree[key];
}
if (tree[key] instanceof Array) {
console.log('[typeArray]', tree[key]);
tree[key] = tree[key].map(item => recursiveArray(item));
} else if (newName && tree[newName] instanceof Array) {
console.log('[typeArray]', tree[newName]);
tree[newName] = tree[newName].map(item => recursiveArray(item));
} else if (typeof tree[key] == 'object') tree[key] = recursiveArray(tree[key]);
}
return tree;
}
export function parseTree (tree) {
/**
* Parses a tree of elements to deal with syntax
* @param {object} A tree of JSX elements
* @returns {object} A parsed message ready to be sent
*/
tree = recursiveArray(tree);
console.log(JSON.stringify(tree, null, 4));
return tree;
}
export class View {
constructor (target) {
let parsed = parseView(target);
parsed = parseTree(parsed);
let $hooks = [];

@@ -66,0 +110,0 @@ for (const key in parsed) {

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