Skip to content

Instantly share code, notes, and snippets.

View LighteningCode's full-sized avatar
Working from home

Elvis Agbesi LighteningCode

Working from home
View GitHub Profile
@LighteningCode
LighteningCode / command-line-query-parser.js
Last active March 25, 2022 19:05
Highly performant key=value string parser
// CommonJS
exports.getFlagValues = function (queryCommand = "") {
let FlagValuesObject = {};
const stringParts = queryCommand
.split(" ")
.map((part) => part.replace(/["']/g, ""));
let valueCompleted = true;
let accummulator_key = "";
let accummulator_value = [];
@LighteningCode
LighteningCode / SessionContext.js
Created March 17, 2022 00:47
Managing sessions in a bot locally for NodeJS (wwebjs)
// You can create a new file like this
class Session {
// this is just to make sure you are isolating data that pertains to multiple groups
constructor() {
this.sessions = {};
}
getSession(sessionId) {
const _session = this.sessions[sessionId];
console.log("Getting",sessionId, _session)
// msg.hasMedo
if (msg.hasMedia) {
// impor at the top of file
// import Tesseract from 'tesseract.js';
// pic
const messageMedia = await msg.downloadMedia()
// check if media is png or jpeg
if (messageMedia.mimetype === "image/jpeg" || messageMedia.mimetype === "image/png") {