Fixing a Bug that Crashes the ChatGPT/Grok Bots

in #steemyesterday

Previously, there was a bug - if you have emjois in the text, it will not be accepted thus causing bot to crash.

sqlState: 'HY000', 0|blockcha | sqlMessage: "Incorrect string value: '\\xF0\\x9F\\x8D\\x80\\xE2\\x99...' for column 'original_command' at row 1", 0|blockcha | sql: 'INSERT INTO blockchain (steemid, command, original_command, permlink, parent_author, parent_permlink, ok) VALUES (\'wakeupkitty\', \'!ask\', \'I find this a super cool entry! You forgot that red bot the greeter at the newcomers! All the AI generated text (posts + commemts)\\n\\nAnd the @justyy \\n!ask changed into: \\n\\n!ask Grok \\nand \\n!ask ChatGPT \\n\\nBoth don\\\'t give the same answer I tried it out. The layout differs too. \\n\\nWe also have the bitbots! \\nThe AI text checkers \\nPlagiarism checkers \\nThe smart keyboards \\nThe word and character counters \\nThe interest over your SP calculator \\nThe bingo card numbers generator\\nAnd many more we find so normal. \\n\\nA typo in @solperez her name is hereby corrected and @greatketty might find this interesting too. \\n\\nMOuSE squad time, you are hired. \\nI wonder if you had the right pucture after the first try. I noticed with the cats if I generate many with \\n\\n!bing \\n\\nIt seems to remember a certain style I looked at though that \\"memory\\" is wiped out as soon as I search for something else or don\\\'t use Bing for a longer time. \\n\\n!thumbup \\n\\nA great weekend \\n🍀♥️\', \'sxu5mm\', \'aneukpineung78\', \'artificial-intelligence-brief-history-its-existence-on-steem-and-case-example-image-creation-on-bing\', 0)'

Easy fix is to alter the tables to support by changing the schema:

ALTER TABLE blockchain MODIFY COLUMN original_command TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE blockchain CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

I've also made it safe by removing them:

const sanitizeText = (text) => {
  // Remove emojis and 4-byte UTF-8 characters
  return text.replace(/[\u{1F600}-\u{1F64F}]|[\u{1F300}-\u{1F5FF}]|[\u{1F680}-\u{1F6FF}]|[\u{1F1E0}-\u{1F1FF}]|[\u{2600}-\u{26FF}]|[\u{2700}-\u{27BF}]/gu, '');
};

image.png

Steem to the Moon🚀!