FontBot/src/bot.cpp

78 lines
10 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "bot.h"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
#include "replacefont.h"
#include "rulefont.h"
#include "turnfont.h"
#include "phonefont.h"
#include "vectorfont.h"
#include <bitset> // covnert chars to int
static const std::string fancyrepl[] {"𝓪","𝓫","𝓬","𝓭","𝓮","𝓯","𝓰","𝓱","𝓲","𝓳","𝓴","𝓵","𝓶","𝓷","𝓸","𝓹","𝓺","𝓻","𝓼","𝓽","𝓾","𝓿","𝔀","𝔁","𝔂","𝔃","𝓐","𝓑","𝓒","𝓓","𝓔","𝓕","𝓖","𝓗","𝓘","𝓙","𝓚","𝓛","𝓜","𝓝","𝓞","𝓟","𝓠","𝓡","𝓢","𝓣","𝓤","𝓥","𝓦","𝓧","𝓨","𝓩"};
static const std::string frakturrepl[] {"𝖆","𝖇","𝖈","𝖉","𝖊","𝖋","𝖌","𝖍","𝖎","𝖏","𝖐","𝖑","𝖒","𝖓","𝖔","𝖕","𝖖","𝖗","𝖘","𝖙","𝖚","𝖛","𝖜","𝖝","𝖞","𝖟","𝕬","𝕭","𝕮","𝕯","𝕰","𝕱","𝕲","𝕳","𝕴","𝕵","𝕶","𝕷","𝕸","𝕹","𝕺","𝕻","𝕼","𝕽","𝕾","𝕿","𝖀","𝖁","𝖂","𝖃","𝖄","𝖅"};
static const std::string doublerepl[] {"𝕒","𝕓","𝕔","𝕕","𝕖","𝕗","𝕘","𝕙","𝕚","𝕛","𝕜","𝕝","𝕞","𝕟","𝕠","𝕡","𝕢","𝕣","𝕤","𝕥","𝕦","𝕧","𝕨","𝕩","𝕪","𝕫","𝔸","𝔹","","𝔻","𝔼","𝔽","𝔾","","𝕀","𝕁","𝕂","𝕃","𝕄","","𝕆","","","","𝕊","𝕋","𝕌","𝕍","𝕎","𝕏","𝕐",""};
static const std::string cursedrepl[] {"ǻ̵͙͇̘͕͔̥̣̇̚", "b̶̛͕͔̦̏̈̏͆̚", "̴̛̻̯̬̟̺̂̀̔̈́́̅̐̽͑͜ç̴̢̮̯̭̘̗̘̄̉̕", "̴̺͎̩͎̣̯̯̮̭̾̐́̅͑͜d̶̢̝̠̳̤͚͙͖͔̬̿̔͗͌̓̈̈̿̽͋̓́̌̎̐͠ͅ", "̴̨̝̯͕̪͕̲̤̯͎̭̺̳̩̯̘̜̖͂̀̈́̑̓͊̐͛̈́͐̈́̆͋̔̀̓̚͠ȩ̷͈̟̠̣̗̣̭̖̟̀̈́̀͐͆͆̍̀̈́͋̈́͋̎̊̑̈͌͐̏̚", "̷̟͖̺̖̺͍̼͖̣̺͊̄̐f̶̟̪̤̰̘̈́͐̈́́͗̓̒̌̅́̈́͛̄̎̔͑̚̚͜͝͝", "̵̡̢̧͓̩̬̳̭̲͕͈̲̟͚̭̟̮̓͑̌g̷̹̝̘̥̉͐́̓̄̊̔̓̌̆̊͒͊̔̑͘͝͠ͅ", "̷͈͂̔̔̎̉͝h̸̢͓͇̯͚̼͓̋̆͑͜", "̵̧̛̻̼̳̪͉̰͕̝͎̼̈͆̉͛̑̋̒̈̚i̶̡͚̱̟̘̠͙̪̽̆̎̊̓̂̐̂́̌̃̈́̔͋͋͝", "̶͎̻͎͇͛̕ĵ̷̡̧̧̞̬̩̰̩̘͔͈̟̭̩̻̣̣̰̐͑̀̇̀̂͌̾̽̕͜ͅ", "̸͎̥̒͂̐̾͋̔͗́̊̒̽̈̑̌̅̿̀͘k̵̡͈̠̙̖̙̖͖̝̭̘̺̠̺͓̻͎̟̼̇͛", "̵̡̧̢̨̼̳̩̣͚̠̠͎̘̳̻̱̳̥̳̽͐̊͗̍͝ͅl̴̡̨̗͍͕̦̲̝͚̼͎̤̱͍̈̌̃̇͋̌̕͝͝͝", "̵̻̐̒̍͋͂̎̉̚͠͠m̴̤̪͍̲̤̪̺̟̦̠̗͎̎̑̂̅̄͋͛̒̿͛͘͝ͅ", "̶̡̡̝̥̱̬͓̜̖͙̥̰̣͉͇͒̔͜n̶̡̺͔̱̱̤̗̅͌̈́̈́̑̃͗̏̃̈̈́͆̈́̅̒͝", "̶̡̨̮̭̩̘̲͚͚̩̝̙̩̟̞͈͔̟͓̇̾͂̑̿̅̐͝ơ̵̛̜̯̜̾͑͐̍͌̓̅̚̕͠", "̴̪̪̍̅̈̉͂̆̕̕͠p̸̖͉̗̝͚̍̀̑̾̓̍̍̈̍̐̎͛͌̀̈́̓͝ͅ", "̴̨̧̠̹̩̘̦̹̱̌͛̋̕͝͠ͅq̷̡̛͔͙̼͕̲̥̲̪̭̻͈̦̻͈̳͒͂̈́̈́̓̈́͊̈͘̕͜͜ͅ", "̵̛̺̼̔̒̑̽̈̈́͋͒̀͊̀́͊ŗ̸̪̼̹͂̉̒̂̒͑͆̂̽̉̀̃", "̷̰̭̗̻̼̭̰̐̈́̔̑̂̈́̍̈́̌̚͜͠s̸̝̠̦̔̓͛̽̉̃͝͠", "̸͎̙̣͚̯̝̙̜̱̼͕̔̀t̷̹̯͗͂͑̇̉̎̒͌̒͑̋͆̽̀͘͝", "̶̧̪̼̘̙̣̹̩̣̲̥̘͎̣̄̊͠ų̶̭̟̫̩̦̞̱̥̟̗̬̥̦͛̄̈́̉̿̓̇̾͋͑̄́̈́̂͛̏̌͜͠͝ͅ", "̴̢̡̛̠̙̤̹͔̜͈͍̖͖̰̮̬̝̳̀̽̍̽̑̒͆̿̒͗͊͋͋̍̌ͅv̶̢̝̼̰̤͉̙̯͕̣̬͚̮̘̝̱͔̉̽̄̀̾̿̔͊̃͑̒̾̇̊̀͒͘͜͜͝͠͝ͅ", "̷̧̡̛͓̯̥̳͈̭̣̘̐̋́́̀̅̈́̈́̎̈́̿͛̒̒͘͝͝w̶̨͇̞̖̠̣̮̥̻̞̪͚͕͙͎͎̐̄̀͒̍́̽̔̑̌̄̽̐̑̈́̚͜͝", "̷͎̮͍͝x̷̥͕͙̳̦̬̗͉̝͉̺̞̏̌̂͊͊̈́̈̍͘͜", "̸͉̘̺͉̩̗̼̥̯̩̻̟̽̑́͂̎͐̔̂̄̉̐͛̅̍̽́̚͝y̸̨̤̺͎͓̰̠̲̺̰̟͕͉̝̣̻̬͍̼͛͐̑̎͒̀̔͆̀̀̓̽͊̌̒͘", "̶̨͖̘̭̮̤̫͎̹̫̺̗̿͊̅͒́̀̈́̾́̿̔̅̋̑̀͋́͑̚͝z̶͍̀̒̐͐̎͛̃̄́̈́̏̀́̎̎̃̄̕̕", "A̵̡͖͙̟̯̯̐͑̄̾͗̓͝", "̵̦̗̘̣̓̾̐̑̃͌̂͂̂̈̏̈́̍̈́̚͠͠ͅB̴̨̨̢̭̱̳̳͕͓̗̦͔̥͊̌̂̊͌̀̎̇̍́͒͊̑̂͜͠", "̴̘͇̩̮̺͒́̾̒́͗͒͋̎̔̅̀̀̆͜͝C̶͓̹̮̟͓͎̳͈̻̻̿̅̎̊̽̀͐̅͘͜͝͝͝͠", "̶̧̛̞͓̹̺͖̣̜̮̼̥̠̣̖͈͍̜̯͓̀͊̈͐͒ͅD̴̡̡̅͠", "̴̨͕̺̝̙̰̭̫̈̀͛͑͐͒̀̕Ȩ̴̢̛͔̦͇̬̱̰̙̮̬̗̥̦̄̿̒̎̉͋̃̓́̐̉́̍̿͘", "̸͈̻̮̟̅̔̇̈͐͛̍̐̄̒̓̌̑͑̔̎͘͜ͅF̵̛̞̬͎̳̖̥̈̓̓", "̷̡̜̼̝̩̣̙͙̫̜͕̬̻̈̇̄͗̓̇͘͜͜G̵̛̳͈̥̼̣̾͛̉̋͐̐̑̅̅͝", "̴̛̮̖̼̞͉̩̩͔̤̣̿́͗͋͋̚͜͜Ḥ̵̡̨̩͎̦̲̦̗̮̲̳͈̦̦̙͉̓̇̊́͊͗̚ͅ", "̴̠̠̝̲̹̮̖̳̹̫̘̇̀͝", "̶̨͓̥͉̝̘̝̮̼͙͍͒͆̆̉̓́̔̋̽̾̈̏̾̕I̸̢̢̙̲̲̣̩̻̣̓͌͂̏̂̅̈́̈́́̊̏̒̌͝͝ͅ", "̶̛̼̳̮̂͂̅͌̒̌͊̉͂͑̑́̇̃̕͝͝J̵̺̫̝͍̹̪͉̪̽͌̓̿͂̿͗̎̚̚͝", "̵̛̞͓̪̦̮͙̘͙͖̥̻͓̗̮̦̞̻͓̦̓̃̂͑̾͑̚Ǩ̵̡̡͍̪͔͉͔̠̻̗̝̹̥̤̺͎͋̀̀̓̐͑̽͐̒̍͘͜", "̵̞̹̳͉̮͖̫̪͂̾̓̑̀̄̐͊L̵̛͎̺̝͔̠͇͈͇̰͚͓̊͑̓̐̽͆̉͛̇̌͛̅͊͝͠͝͠", "̵̡̨̨͔̺̫̬̰̈́͊̿̃̚͠M̴̧͔̗̤̝̲̝̹̤͙̺̿̅̔͋̒̎̓̓̈́̇͑̈́̚̕͝͠", "̵̙̠͈͈̖͕̣͕̲̖̄̈́̀̽͂͋̑̃͋͜ͅŅ̷̢͈̜̦̑̓̓̓̒", "̵̨̛͉̭͓̟̼̹̥̖̥̖̼̥̠̩͉͓̟̔̃͐̇̉̅̂͒̍̏̃Ò̷̡̟̭͈̜̼̳̤̪͖̰͎̘̩̜̰̫̱̹͎̓", "̷̘͕͉̲̯̊̔̒̏͌̈͐̅̾͒͆̾̄́̂̑̚͝P̸̺̫̆̍͌̇͛̀̏", "̶̢͍̹͔̦̟̣͔̠͇̯͓̎̇̀͋̓̉̈́̓͘͜͜Q̷̨̧̛̛̻͕̬͖̘̳̤̎̎̀̑͑̃̔͒̇̈́̌́̀̂̋͘̕", "̷͖̥̺͙̯͉͋̐Ŕ̷̡̨̡̬̥̳͎̭̮̬̩̫̈͑̒̔̔́̌̍͌͋̽̈͌̚͜͝", "̸̛͉̰̫̈́̄͂̿̄̈́͆́̽͝͠S̷͔̱̝̘̭̘̮̮̦̣̟̼̊̀̏̄̆̏̾̋́̾͗̏͝ͅ", "̸̧̛͍̝̭̫̙̫͖͕͉͇͌̔̀̈̓̊̅̅̚T̵̛͍͉͉̥̞̞͚̮̺̜͓̲̥̽̈́͗̌͗͗͊̓̄̽͂͆̿́̉̚͜", "̶̯̣͉̦̰̗̝̩̭̜̘̦̫̖̟͈̜̥̃̿̀͊̔͜U̶̦͚͕̰̻̺̙̙͕̔̿͂̌̏̀͆̉", "̶̜̳̯̫̖̘̦̜̘̤̘͓͔͕̞̦͖̀̈̐͋̾̀̆̾̇̋̕͝͠V̷̡̻͎̞̼̤̫̫̲̳̜̪͙͓̰͇͌̀͋́͛͗̍̓͘͜", "̶̡̢̝̺͕͈̬͓̹͇̩̻̖͕̪̞̿̑̐̓̄̊̊̾͘W̶̜̰̗̬̄̂͗̀̅̔̊̍̆͗̓̑̐̕", "̴̡̡̛̘͓̱͕͚͚̲̱̺̰͈̫̹̒̐́͆̄̔͆̈́̀͂͘͘͠ͅX̷̰̿͒̎̎̍̀̚", "̶̞͖̜̘̬͉̗͚̝͔̤̲̣͗̑̈́͆̉̋̑̆̊́̓̀̄̊̈Y̶̢̢̝̻̞̖̤̰͇̐̆͋̅͆̍̀͜͜", "̴͎̼̠͕̬̰̯̲̬͔̖̦͖̜͕̙͋̏͂͜͠Z̷̢̡̛͖̩̟̬͔̝̫̭̼͐́̈́̉́̎̍͠"};
static const std::string monospacere[] {"𝚊", "𝚋", "𝚌", "𝚍", "𝚎", "𝚏", "𝚐", "𝚑", "𝚒", "𝚓", "𝚔", "𝚕", "𝚖", "𝚗", "𝚘", "𝚙", "𝚚", "𝚛", "𝚜", "𝚝", "𝚞", "𝚟", "𝚠", "𝚡", "𝚢", "𝚣", "𝙰", "𝙱", "𝙲", "𝙳", "𝙴", "𝙵", "𝙶", "𝙷", "𝙸", "𝙹", "𝙺", "𝙻", "𝙼", "𝙽", "𝙾", "𝙿", "𝚀", "𝚁", "𝚂", "𝚃", "𝚄", "𝚅", "𝚆", "𝚇", "𝚈", "𝚉"};
static const std::string circlesrepl[] {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
static const std::string boxrepl[] {"🄰", "🄱", "🄲", "🄳", "🄴", "🄵", "🄶", "🄷", "🄸", "🄹", "🄺", "🄻", "🄼", "🄽", "🄾", "🄿", "🅀", "🅁", "🅂", "🅃", "🅄", "🅅", "🅆", "🅇", "🅈", "🅉", "🄰", "🄱", "🄲", "🄳", "🄴", "🄵", "🄶", "🄷", "🄸", "🄹", "🄺", "🄻", "🄼", "🄽", "🄾", "🄿", "🅀", "🅁", "🅂", "🅃", "🅄", "🅅", "🅆", "🅇", "🅈", "🅉"};
static const std::string ncirclerepl[] {"🅐", "🅑", "🅒", "🅓", "🅔", "🅕", "🅖", "🅗", "🅘", "🅙", "🅚", "🅛", "🅜", "🅝", "🅞", "🅟", "🅠", "🅡", "🅢", "🅣", "🅤", "🅥", "🅦", "🅧", "🅨", "🅩", "🅐", "🅑", "🅒", "🅓", "🅔", "🅕", "🅖", "🅗", "🅘", "🅙", "🅚", "🅛", "🅜", "🅝", "🅞", "🅟", "🅠", "🅡", "🅢", "🅣", "🅤", "🅥", "🅦", "🅧", "🅨", "🅩"};
static const std::string nboxrepl[] {"🅰", "🅱", "🅲", "🅳", "🅴", "🅵", "🅶", "🅷", "🅸", "🅹", "🅺", "🅻", "🅼", "🅽", "🅾", "🅿", "🆀", "🆁", "🆂", "🆃", "🆄", "🆅", "🆆", "🆇", "🆈", "🆉", "🅰", "🅱", "🅲", "🅳", "🅴", "🅵", "🅶", "🅷", "🅸", "🅹", "🅺", "🅻", "🅼", "🅽", "🅾", "🅿", "🆀", "🆁", "🆂", "🆃", "🆄", "🆅", "🆆", "🆇", "🆈", "🆉"};
static const std::string widerepl[] {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
FontBot::FontBot() {
fonts.reserve(15);
fonts.push_back(new ReplaceFont("Fancy", fancyrepl));
fonts.push_back(new ReplaceFont("Fraktur", frakturrepl));
fonts.push_back(new ReplaceFont("Double", doublerepl));
fonts.push_back(new ReplaceFont("Cursed", cursedrepl));
fonts.push_back(new TurnFont());
fonts.push_back(new PhoneFont());
fonts.push_back(new ReplaceFont("monospace", monospacere));
fonts.push_back(new VectorFont());
fonts.push_back(new ReplaceFont("Circles", circlesrepl));
fonts.push_back(new ReplaceFont("Boxes", boxrepl));
fonts.push_back(new ReplaceFont("Negative Circles", ncirclerepl));
fonts.push_back(new ReplaceFont("Negative Boxes", nboxrepl));
fonts.push_back(new RuleFont("Binary", [](char c){ return std::bitset<8>((int) c).to_string() + " "; }));
fonts.push_back(new ReplaceFont("WIDE", widerepl));
}
FontBot::~FontBot() {
for(Font* f : fonts) {
delete f;
}
}
bool FontBot::handleInline(TelegramAPI::Manager* api, TelegramAPI::InlineQuery& q) {
if(q.query.empty()) return true;
// awnser
json arr = {};
uint8_t id = 1;
for(const Font* f : fonts) {
// skip font if it can not be applied
if(!f->canApply(q.query)) continue;
// apply font
std::string fontized;
json j;
f->applyFont(q.query, fontized);
j["type"] = "article";
j["id"] = id++;
j["title"] = f->getName();
j["description"] = fontized;
j["message_text"] = fontized;
arr.push_back(j);
}
// Log::info << arr;
api->answerInlineQuery(q.id, arr, 86400*7); //cache for a week
return true;
}