Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev 2020 09 24 #118

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .yarn/build-state.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@

# core-js-pure@npm:3.6.5
"c634b57d825318aaf25531579115cf09e2ff2e66bb3bd91622453ecd2b2358a66d44010bc4e9f0407d3252ba4d0548ebe0327ec589e6d8603b97711bd4ff735e":
4ec1c7a0d1e37be44d93dcc6b251bc74bd2a513d1c5dec96cfaf340a19458273aa02075d0ad59e70c7a77841d320ba4788d6d4175b551697be9f84efacf96670
d802546da742b468640303ed3fe25dabda33593741d6f2a9ba5398f6ea459a7595ed76569b31f3771d60709584095ac2e661b5b252c8aefefd45dd056f5bcab6

# core-js@npm:2.6.11
"15178ded27ab674ae2054269453d809bdb1d00b98392a34947b5d43ea7a5811e5674c2fda7d48bb653b24a3506b0a8aa126bbac861bdeba93438ec6c7efb2d9d":
6bd06c3f7c920a62432b977b02f8cdcdc3f6bda406178daaa30315ec86aec4a91b5d17feed0707de020974043fdad88d58f0dc8618632820e9164a3bf446534a
e608f25ab75a2d0a3a7fa274c834d5036be8a420ce14d74035e4df6481aece4345e620b26cf82be517f104f8e4f5b1bdc570a565d321819a8d14bba09d69d995

# core-js@npm:3.6.5
"5941340066f775d2694fe1955bef9a66af767bfade2eca6ca442d82a68a5c999e76165c38ab532c125bf81c66c151d83d8e96f86a3f7af2d755000b3e2d48171":
2844790c45edca8fdfdc16dafeed1bf661509094d87756932159c9caf483b1db946b252238c941996d711de60c403b8b5497d18d4b72d292e646568582b5b637
a5bd88279815223d7702157afb35588e500d547d79aa68646bc877725f5da1c327297512b7afc3e29b98fcd174d40e332ea9802ae43b1891d110037a821c84a4

# husky@npm:4.3.0
"b6c2d49d0eb0ccd03cd8d5c01a23823972e91724d5313135fb55c2090a54e63449ce42dc64f102e84407ec8464d7ed38e2521f28cf82d313cbe7425fc5f1bffc":
498f7a43fa7770eab3d14f6ad19eb9a56b4887db88dd2359e84b150e6f402f18a6703e11946f64a24a3eb0dd04ff6d6ef56c28e6b2fa9cae9276e3d9d97f67ac
c986423106acd7dc4c24a7c96ac2b91429cff6ff015611f5ffc7d4316a10ee3c630dcc33d2a6dc84d006dd24ddba27ad5045d1c16e05facaf0367df2bdcf2935

# ngrok@npm:3.3.0
"ff8d3edfc102644aede24f64f24ecc6f1413c56504b495530c0accac5996e432fe0a73b846523a8793b787244d14a94c7c8aeed45b0fafd79cc83c0a5c46eaf3":
3aa3b050b74791d7f237b141afb19eb3fae727a567c803112b358bd4efacf9f637bc4f9fb280d2d89149f4b609164c0f0a4e46e3ce579ad22cedf4acf3b2ebb6
ba5b47b03d545bba2ac42335108e49b44b1e3afb472e437f7e2d5e1e284fb0d54ba00e9ed7bc8bb3f8631902894477f77c80e4d1a1e3f7b105d6ccd259b6ce5e

# nodejieba@npm:2.4.1
"b31459e749e9f0ca6cca9a349656e327426c25b053958d12fd08ce3af4fb7dba30d07531ed48eeab9496504ecfa9e15c87d03ab6b9bb9c2d7b5d80704f691f8b":
b44442f9d6ae869c198d2d8af2205b18de014e94d8abd2ae4f3a38758f0ab94691d6a5bbd6e3198afcf5ec8c6400ac94f6235c2d81a1cbe15d75009e2e4867c7
d1fd49f1f3bf86a874e49d3c3d8df8bf5a17f8d3b7832ce017ffec907b77ec2ab6acf36642c7e9f1e9c0aaba7178cf3fa14fb27a22860a2b0c9629ef4b25e706
Binary file not shown.
Binary file not shown.
Binary file modified .yarn/install-state.gz
Binary file not shown.
188 changes: 169 additions & 19 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import anglicize from 'anglicize';
import _emojiRegex from 'emoji-regex/es2015/text.js';
import runes from 'runes';
import getPort from 'get-port';
import clone from 'rfdc';
import merge from 'deepmerge';
// import translitro from 'translitro';
// import Bleetify from 'bleetify';

Expand All @@ -34,8 +36,8 @@ if (!Object.prototype.hasOwnProperty.call(RegExp, 'escape')) {
if (!Object.prototype.hasOwnProperty.call(String, 'replaceAll')) {
String.prototype.replaceAll = function (find, replace) { // jshint ignore:line
// https:// developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll
// If you pass a RegExp to 'find', you _MUST_ include 'g' as a flag.
// TypeError: "replaceAll must be called with a global RegExp" not included, will silently cause significant errors. _MUST_ include 'g' as a flag for RegExp.
// If you pass a RegExp to 'find', you _MUST_ include 'g' as a property.
// TypeError: "replaceAll must be called with a global RegExp" not included, will silently cause significant errors. _MUST_ include 'g' as a property for RegExp.
// String parameters to 'find' do not require special handling.
// Does not conform to "special replacement patterns" when "Specifying a string as a parameter" for replace
// Does not conform to "Specifying a function as a parameter" for replace
Expand Down Expand Up @@ -292,6 +294,7 @@ const // there are more const function variables to follow,
console.dir({ text, });
return normalizeCharacters(unlink(text));
},
isObject = obj => typeof obj === 'object' && obj !== null,
cleanEmoji = (text) => {
if (typeof text !== 'undefined' && text !== null && text !== '') {
const emojiCount = isEmojiRidden(text);
Expand All @@ -300,11 +303,11 @@ const // there are more const function variables to follow,
return {
text: cleanedText.text,
alterations:
'\n[ Removed: ' +
'\nRemoved ' +
emojiCount +
' of ' +
runes(makeUnique(getEmoji(text).join(''))).length +
' Emoji, including ' +
' emoji, including ' +
makeUnique(
runes.substr(
makeUnique(getEmoji(text).join('')),
Expand Down Expand Up @@ -334,15 +337,15 @@ const // there are more const function variables to follow,
)
)
) +
' ]' +
'.' +
(cleanedText.count > 0 ?
'\n[ Collapsed: ' +
'\nCollapsed ' +
cleanedText.count +
' Exploded Word' +
'exploded word' +
(cleanedText.count === 1 ? '' : 's') +
' ]'
'.'
: '') +
'\n[ Removed: Uppercase, Fonts, Math, Diacritics ]',
'\nRemoved uppercase, fonts, math, diacritics.',
};
} else {
return {
Expand All @@ -351,19 +354,19 @@ const // there are more const function variables to follow,
).text.replaceAll(/\s\n\s/gu, ' \n'),
alterations:
(cleanedText.count > 0 ?
'\n[ Collapsed: ' +
'\nCollapsed ' +
cleanedText.count +
' Exploded Word' +
' exploded word' +
(cleanedText.count === 1 ? '' : 's') +
' ]'
'.'
: '') +
'\n[ Removed: Uppercase, Fonts, Math, Diacritics ]',
'\nRemoved Uppercase, Fonts, Math, Diacritics.',
};
}
} else {
return {
text: text,
alterations: '\n[ Error: Received empty text? ]',
alterations: '\n[ Error: Received empty text?.',
};
}
},
Expand Down Expand Up @@ -400,6 +403,124 @@ const // there are more const function variables to follow,
// rightTrimAllLines = text => text.split('\n').map(line => line.replaceAll(/\s+$/gu,'')).join('\n'),
// oneSpaceBeforeEachNewLine = text => rightTrimAllLines(text).replaceAll('\n', ' \n'),
fixAmp = (text) => text.replaceAll('&', '&'),
// cleaned_text = txtMap(
// url_expanded_text,
// {
// 'preprocess': {
//
// },
// 'number' : {
// 'true': {},
// 'false': {
// 'process': text => {
// cleanEmoji(
// cleanText(
// text
// )
// )
// }
// }
// }
// }
// ^^^ BUILD THIS ^^^
// txtMap( // why? i don't know
// url_expanded_text,
// [
// {
// 'emojiRidden': obj => isEmojiRidden(obj.text) === false ? false: true,
// },
// {
// 'type' : 'character',
// 'if' : {
// 'true' : 'emojiRidden',
// 'false' : 'isNumber',
// 'return': obj => removeEmoji(obj.return),
// },
// },
// ],
// )
// rfdc
// deepmerge
// txt-base
// // merge + clone is probably overkill
procBool = (obj) => {
},
procMap = (obj) => { // maybe don't clone at all and just manipulate the same obj over and over?
//maybe don't do this and find something better to do with your time
if (Array.isArray(obj)) {
return obj.map(procMap);
} else if (isObject(obj)){
if (Array.isArray(obj.map)) {
return obj; // reduce .map(procMap);
} else if (isObject(obj.map)){
let types = {
'if' : obj => {
if (isObject(obj.if)) {
const truePass = obj.if.true.reduce((accumulator, currentValue) => accumulator &&
procBool(merge(clone(obj), { 'parent': clone(obj) }, {'return':currentValue}))),
falsePass = true; // todo
if (truePass && falsePass) {
return procMap(merge.all([clone(obj), { 'parent': clone(obj) }, {'if': undefined, 'else': undefined}, obj.if, {'true': undefined, 'false': undefined, 'else': undefined }]));
} else if (isObject(obj.if.else) && obj.if.else) {
return procMap(merge.all([clone(obj), { 'parent': clone(obj) }, {'if': undefined, 'else': undefined}, obj.if.else]));
} else {
return procMap(merge.all([clone(obj), { 'parent': clone(obj) }, {'if': undefined, 'else': undefined}, obj.else]));
}
} else {
return obj;
}
},
'else': obj => self.if(obj),
'process': obj => {
for (i = 0; i < obj.keys.length; i++) {
if (types.includes(obj[obj.keys[i]])) {

} else {
if (typeof obj[obj.keys[i]] === 'function') {
obj[
} else {
}
}
}
}
};
types = merge.all([clone(types), clone(obj.types), clone(obj.map.types || {})]);
const type = typeof obj.type === 'string' ? types.keys.includes(obj.type) ? obj.type : 'process' : 'process';
return types[type](obj);
};
} else {
return obj
}
// if an array is received
// if there is a type:
// if there is a types value as a property
// if there is a body:
// default to set properties
// if a function is found in a property
} else {
return obj;
}
return obj;
},
txtMap = (text, map) => {
const obj = {
text,
map,
'runes': runes(text),
'types': {
'character': obj => {
let symbols = [];
for (i = 0; i < obj.return.length; i++) { // shallow or deep copy?
symbols.push(Symbol('character:' + i.toString() + ':' + Date.now().toISOString()));
obj.character[symbols[i]] = procMap(merge([clone(obj), { 'parent': clone(obj) }, {'return': obj.return[i], 'character': { i, 'text': obj.return[i]}}]))
}
return merge([clone(obj), { 'parent': clone(obj) }, { 'return': symbols.reduce((accumulator, currentValue) => accumulator + obj.character[currentValue].return)}]);
}
},
};
obj.return = obj.runes
return procMap(obj);
},
start = async () => {
try {
// user_SCREEN_NAME is replaced with the user's name.
Expand Down Expand Up @@ -689,17 +810,46 @@ const // there are more const function variables to follow,
media,
quoted_status_permalink_expanded
),
cleaned_text = cleanEmoji(
cleanText(
url_expanded_text
)
cleaned_text = txtMap( // why? i don't know
url_expanded_text, // could be array, could be object with properties like 'text'
[ // ordered, each process could have type: process, body:, but..
// todo: decide between property or just saying property leaning towards latter
{ // type: property, body: { 'emoji..
'emojiRidden': obj => isEmojiRidden(obj.text) === false ? false: true,
},
{
'type' : 'character', // split the return of whatever you receive by char
// creates 'character' properties like 'i', 'value'
// use: body: [] if more than one thing to apply
// body: [{ // highest priority last, default = index, priority only for application, not conditional evaluation
'if' : { // if both optional properties true/false == [values] 'then'
'true' : 'emojiRidden', // property: emojiRidden ?sugar overlaps w/plaintext?
'false' : 'isNumber', //listDefaults
'return': obj => removeEmoji(obj.return), //if function built for obj can just say return: 'functionName'
// function: if one needs to manipulate the full object
// 'or' : [{ 'true': 'emojiRidden' }, { 'true': 'isEmoji' }]
// 'else': { return: obj.return }
}, // array for multiple if thens
// 'else': if literally every if option doesn't happen
// }]
'return': obj.return, // happens last, use body: [{},{},...] for more complexity
},
],
// {
// 'type': 'process',
// 'body':
// 'begin': {}, // optional, runs first, once at all, carries down, .map
// 'process': {}// optional, runs second, per-object, if array runs each in order
// process.type: sync||async // todo: async/multiple at once, important, lol prolog
// 'end': {}, //optional, runs third, once at all, carries down, if array runs each in order
// },
),
straightened_lines = normalizeNewlines(
reduceEmptyLinesToSingle(
trimAllLines(
normalizeSpaces(
fixAmp(
cleaned_text.text
cleaned_text.return
)
)
)
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "twitter-reply-bot",
"type": "module",
"version": "0.6.10",
"version": "0.0.0",
"description": "base for twitter reply bot using autohook",
"main": "./lib/index.js",
"module": "lib/index.js",
Expand Down Expand Up @@ -123,10 +123,12 @@
"dependencies": {
"anglicize": "^1.0.0",
"bleetify": "^1.0.2",
"deepmerge": "^4.2.2",
"emoji-regex": "^9.0.0",
"fs": "0.0.2",
"get-port": "^5.1.1",
"replace-special-characters": "^1.0.2",
"rfdc": "^1.1.4",
"runes": "^0.4.3",
"timeout": "^0.2.1",
"translitro": "^0.2.3",
Expand Down
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,13 @@ __metadata:
languageName: node
linkType: hard

"deepmerge@npm:^4.2.2":
version: 4.2.2
resolution: "deepmerge@npm:4.2.2"
checksum: 85abf8e0045ee280996e7d2396979c877ef0741e413b716e42441110e0a83ac08098b2a49cea035510060bf667c0eae3189b2a52349f5fa4b000c211041637b1
languageName: node
linkType: hard

"defaults@npm:^1.0.3":
version: 1.0.3
resolution: "defaults@npm:1.0.3"
Expand Down Expand Up @@ -7036,6 +7043,13 @@ resolve@^1.10.0:
languageName: node
linkType: hard

"rfdc@npm:^1.1.4":
version: 1.1.4
resolution: "rfdc@npm:1.1.4"
checksum: 40a3a89d87a4398df94aa6210b1e51cab9351ddc6e486290ff0477e2b72e2c9e36b281ecebcb2655ad8c9ab71db3717d2e25e3f97fadd54cc02d1d9bd2ccf76e
languageName: node
linkType: hard

"rimraf@npm:^2.5.2, rimraf@npm:^2.5.4, rimraf@npm:^2.6.1, rimraf@npm:^2.6.2, rimraf@npm:^2.6.3, rimraf@npm:^2.7.1":
version: 2.7.1
resolution: "rimraf@npm:2.7.1"
Expand Down Expand Up @@ -8197,6 +8211,7 @@ resolve@^1.10.0:
bleetify: ^1.0.2
commitizen: 4.2.1
cz-conventional-changelog: 3.3.0
deepmerge: ^4.2.2
dotenv: 8.2.0
emoji-regex: ^9.0.0
fs: 0.0.2
Expand All @@ -8205,6 +8220,7 @@ resolve@^1.10.0:
json: 10.0.0
prettier: 2.1.2
replace-special-characters: ^1.0.2
rfdc: ^1.1.4
runes: ^0.4.3
semantic-release: 17.1.2
sleep-atomic: 1.0.0
Expand Down