initial
This commit is contained in:
commit
7b3b3d4999
|
@ -0,0 +1,20 @@
|
||||||
|
*.bin
|
||||||
|
*.out
|
||||||
|
build/
|
||||||
|
*.exe
|
||||||
|
.gdb_history
|
||||||
|
|
||||||
|
*.so
|
||||||
|
*.bmp
|
||||||
|
*.d
|
||||||
|
log.txt
|
||||||
|
|
||||||
|
test
|
||||||
|
.vscode/settings.json
|
||||||
|
|
||||||
|
fontbot
|
||||||
|
fontbot_strip
|
||||||
|
|
||||||
|
config.json
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
[submodule "thirdparty/TAPI"]
|
||||||
|
path = thirdparty/TAPI
|
||||||
|
url = ssh://gitea@git.okaestne.de:2233/okaestne/TAPI.git
|
||||||
|
branch = wip
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Linux",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/src/",
|
||||||
|
"${workspaceFolder}/thirdparty/TAPI/include/",
|
||||||
|
"${workspaceFolder}/thirdparty/TAPI/Log/",
|
||||||
|
],
|
||||||
|
"defines": [],
|
||||||
|
"compilerPath": "/usr/bin/g++",
|
||||||
|
"cStandard": "c11",
|
||||||
|
"cppStandard": "c++17",
|
||||||
|
"intelliSenseMode": "gcc-x64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "test Debuggen (gdb)",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/test",
|
||||||
|
"args": [],
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"environment": [],
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Automatische Strukturierung und Einrückung für \"gdb\" aktivieren",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"preLaunchTask": "make test",
|
||||||
|
"miDebuggerPath": "/usr/bin/gdb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Debuggen (gdb)",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/fontbot",
|
||||||
|
"args": [],
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"environment": [],
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Automatische Strukturierung und Einrückung für \"gdb\" aktivieren",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"preLaunchTask": "make all",
|
||||||
|
"miDebuggerPath": "/usr/bin/gdb"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "make all",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "make -j all",
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
|
"problemMatcher": [
|
||||||
|
"$gcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "make clean",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "make clean",
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "make test",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "make -j test",
|
||||||
|
"problemMatcher": ["$gcc"],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
# Author Yannis Gerlach
|
||||||
|
# Hochschule Osnabrück
|
||||||
|
# 13.11.2020
|
||||||
|
|
||||||
|
# `make clean all` nicht mit -j verwenden! -> race condition im make file
|
||||||
|
# statdessen: `make clean; make all -j` verwenden
|
||||||
|
|
||||||
|
NAME = fontbot
|
||||||
|
NAMETEST = test
|
||||||
|
CFLAGS = -std=c++17 -O2 -g -pipe -Wall -Wextra -Wno-unused-parameter -Wpedantic -rdynamic #-march=native -Wall
|
||||||
|
CXX = g++
|
||||||
|
SRCF = src/
|
||||||
|
BUILDDIR = build/
|
||||||
|
TESTF = tests/
|
||||||
|
DEPF = $(BUILDDIR)deps/
|
||||||
|
INCF = ./src/
|
||||||
|
INCFS = $(shell find $(INCF) -type d)
|
||||||
|
|
||||||
|
TP = ./thirdparty/
|
||||||
|
TAPIF = $(TP)TAPI/
|
||||||
|
TAPIA = $(TAPIF)libTAPI.a
|
||||||
|
|
||||||
|
LOGF = $(TAPIF)Log/
|
||||||
|
LOGO = $(LOGF)Log.o
|
||||||
|
|
||||||
|
INCLUDES = -I$(LOGF) -I$(TAPIF)include/ $(addprefix -I, $(INCFS))
|
||||||
|
LDFLAGS = -lcurl
|
||||||
|
|
||||||
|
SRCFILES = $(shell find $(SRCF) -name "*.cpp")
|
||||||
|
OBJFILES = $(patsubst $(SRCF)%, $(BUILDDIR)%, $(patsubst %.cpp, %.o, $(SRCFILES))) $(LOGO)
|
||||||
|
DEPFILES = $(wildcard $(DEPF)*.d)
|
||||||
|
|
||||||
|
SOURCEDIRS = $(shell find $(SRCF) -type d -printf "%p/\n")
|
||||||
|
BUILDDIRS = $(patsubst $(SRCF)%, $(BUILDDIR)%, $(SOURCEDIRS))
|
||||||
|
|
||||||
|
OBJFILESTEST = $(filter-out $(BUILDDIR)main.o, $(OBJFILES))
|
||||||
|
|
||||||
|
INCLUDES += $(addprefix -I, $(SOURCEDIRS))
|
||||||
|
|
||||||
|
all: $(NAME) runtest
|
||||||
|
|
||||||
|
$(NAME): $(BUILDDIRS) $(DEPF) $(OBJFILES) $(TAPIA)
|
||||||
|
@echo "Linking $@"
|
||||||
|
@$(CXX) $(CFLAGS) -o $@ $(filter %.o, $^) $(filter %.a, $^) $(LDFLAGS)
|
||||||
|
|
||||||
|
$(BUILDDIR)%.o: $(SRCF)%.cpp
|
||||||
|
@echo "Compiling: $@"
|
||||||
|
@$(CXX) $(CFLAGS) $(INCLUDES) $< -MM -MT $@ > $(DEPF)$(subst /,_,$*).d
|
||||||
|
@$(CXX) -c -o $@ $(CFLAGS) $(INCLUDES) $<
|
||||||
|
|
||||||
|
$(NAME)_strip: $(NAME)
|
||||||
|
@echo "Strip $<"
|
||||||
|
@strip -o $@ $<
|
||||||
|
|
||||||
|
%/:
|
||||||
|
mkdir -p $@
|
||||||
|
|
||||||
|
clean-depends:
|
||||||
|
$(RM) -r $(DEPF)
|
||||||
|
|
||||||
|
$(LOGO):
|
||||||
|
$(MAKE) -C $(LOGF) all
|
||||||
|
|
||||||
|
$(TAPIA):
|
||||||
|
$(MAKE) -C $(TAPIF) libTAPI.a
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) -r $(NAME) $(BUILDDIR) $(NAMETEST) $(NAME)_strip
|
||||||
|
$(MAKE) -C $(LOGF) $@
|
||||||
|
$(MAKE) -C $(TAPIF) $@
|
||||||
|
|
||||||
|
$(NAMETEST): $(BUILDDIRS) $(DEPF) $(TESTF)*.cpp $(OBJFILESTEST) $(TAPIA)
|
||||||
|
@echo "Compiling tests"
|
||||||
|
@$(CXX) -o $@ $(filter %.o, $^) $(filter %.a, $^) $(filter %.cpp, $^) $(CFLAGS) -I$(SRCF) $(INCLUDES) $(LDFLAGS)
|
||||||
|
|
||||||
|
runtest: $(NAMETEST)
|
||||||
|
@echo "Running tests"
|
||||||
|
./$<
|
||||||
|
|
||||||
|
.PHONY: clean all $(NAMETEST) clean-depends runtest
|
||||||
|
|
||||||
|
include $(DEPFILES)
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"telegram": {
|
||||||
|
"apikey": "123:abc"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
#include "bot.h"
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
#include "replacefont.h"
|
||||||
|
|
||||||
|
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̷̢̡̛͖̩̟̬͔̝̫̭̼͐́̈́̉́̎̍͠"};
|
||||||
|
|
||||||
|
FontBot::FontBot() {
|
||||||
|
fonts.reserve(4);
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
FontBot::~FontBot() {
|
||||||
|
for(Font* f : fonts) {
|
||||||
|
delete f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FontBot::handleInline(TelegramAPI::Manager* api, TelegramAPI::InlineQuery& q) {
|
||||||
|
json arr = {};
|
||||||
|
|
||||||
|
uint8_t id = 1;
|
||||||
|
for(const Font* f : fonts) {
|
||||||
|
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;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <TAPIManager.h>
|
||||||
|
|
||||||
|
#include "font.h"
|
||||||
|
|
||||||
|
class FontBot {
|
||||||
|
public:
|
||||||
|
FontBot();
|
||||||
|
~FontBot();
|
||||||
|
|
||||||
|
bool handleInline(TelegramAPI::Manager* api, TelegramAPI::InlineQuery& q);
|
||||||
|
private:
|
||||||
|
std::vector<Font*> fonts;
|
||||||
|
};
|
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Font {
|
||||||
|
public:
|
||||||
|
virtual ~Font() {}
|
||||||
|
virtual void applyFont(const std::string& in, std::string& out) const = 0;
|
||||||
|
virtual const std::string& getName() const = 0;
|
||||||
|
};
|
|
@ -0,0 +1,64 @@
|
||||||
|
|
||||||
|
#include <Log.h>
|
||||||
|
#include <TAPIInlineQuery.h>
|
||||||
|
#include <TAPIMarkup.h>
|
||||||
|
#include <TAPIManager.h>
|
||||||
|
#include <functional> //std bind
|
||||||
|
#include <signal.h> // signal
|
||||||
|
#include <fstream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
#include "bot.h"
|
||||||
|
|
||||||
|
static bool run = true;
|
||||||
|
|
||||||
|
void sig_handler(int sig_num) {
|
||||||
|
Log::info << "signalHandler triggered";
|
||||||
|
run = false;
|
||||||
|
(void) sig_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CommandStart : public TelegramAPI::Command {
|
||||||
|
public:
|
||||||
|
CommandStart() : TelegramAPI::Command("/start") {}
|
||||||
|
virtual bool process(TelegramAPI::Manager* m, const TelegramAPI::Message& msg) {
|
||||||
|
TelegramAPI::InlineKeyboard kb;
|
||||||
|
kb.addButton(TelegramAPI::InlineButton::createSwitchInlineQuery("Open in Chat"), 0);
|
||||||
|
return m->sendMessage(msg.chat.id, "This bot is inline only.", kb);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, const char** argv) {
|
||||||
|
Log::init();
|
||||||
|
Log::setConsoleLogLevel(Log::Level::TRACE);
|
||||||
|
Log::addLogfile("log.txt", Log::Level::WARN);
|
||||||
|
#if __unix__
|
||||||
|
Log::setColoredOutput(true);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Log::info << "Hello, World!";
|
||||||
|
|
||||||
|
//read config
|
||||||
|
std::ifstream configfile("config.json");
|
||||||
|
json j;
|
||||||
|
configfile >> j;
|
||||||
|
|
||||||
|
FontBot bot;
|
||||||
|
TelegramAPI::Manager tapi(j["telegram"]["apikey"]);
|
||||||
|
|
||||||
|
std::unique_ptr<TelegramAPI::Command> cmd(new CommandStart());
|
||||||
|
tapi.registerCommand(std::move(cmd));
|
||||||
|
|
||||||
|
namespace pl = std::placeholders;
|
||||||
|
tapi.setInlineQueryHandler(std::bind(&FontBot::handleInline, &bot, pl::_1, pl::_2));
|
||||||
|
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
while(run) {
|
||||||
|
tapi.getUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::stop();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
#include "replacefont.h"
|
||||||
|
|
||||||
|
ReplaceFont::ReplaceFont(const std::string& name, const std::string* repl) : name(name), repl(repl) {}
|
||||||
|
|
||||||
|
void ReplaceFont::applyFont(const std::string& in, std::string& out) const {
|
||||||
|
out.reserve(in.size()*2);
|
||||||
|
|
||||||
|
for(size_t pos_in = 0; pos_in < in.size(); ++pos_in) {
|
||||||
|
char c = in[pos_in];
|
||||||
|
if(c >= 'a' && c <= 'z') {
|
||||||
|
out += repl[c - 'a'];
|
||||||
|
} else if(c >= 'A' && c <= 'Z') {
|
||||||
|
out += repl[c - 'A' + 26];
|
||||||
|
} else {
|
||||||
|
out += c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& ReplaceFont::getName() const {
|
||||||
|
return name;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "font.h"
|
||||||
|
|
||||||
|
class ReplaceFont : public Font {
|
||||||
|
public:
|
||||||
|
ReplaceFont(const std::string& name, const std::string* repl);
|
||||||
|
|
||||||
|
virtual void applyFont(const std::string& in, std::string& out) const override;
|
||||||
|
virtual const std::string& getName() const override;
|
||||||
|
private:
|
||||||
|
const std::string name;
|
||||||
|
const std::string* repl; //pointer (array)
|
||||||
|
};
|
|
@ -0,0 +1,26 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
//tests
|
||||||
|
|
||||||
|
test_t tests[] = {NULL};
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
|
test_t* current = tests;
|
||||||
|
int failcount = 0;
|
||||||
|
int testcount = 0;
|
||||||
|
for(; *current; current++) {
|
||||||
|
testcount++;
|
||||||
|
printf("\033[1mRunning test number: %d ", testcount);
|
||||||
|
if((*current)()) {
|
||||||
|
printf("\033[1;92msucceeded\033[0;1m!\n");
|
||||||
|
} else {
|
||||||
|
printf("\033[1;91mfailed\033[0;1m\n");
|
||||||
|
failcount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\033[1;93m%d\033[0;1m/%d failed\n", failcount, testcount);
|
||||||
|
return failcount > 0;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
#define TESTFAILED 0
|
||||||
|
#define TESTGOOD 1
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#define TESTDATA "./tests/data/"
|
||||||
|
|
||||||
|
#define ASSERT(BED, ERR) if(!(BED)) { std::cout << __FILE__ << ":" << __LINE__ << " " << ERR << std::endl; return TESTFAILED; }
|
||||||
|
// #define ASSERT(BED) ASSERT(BED, "")
|
||||||
|
|
||||||
|
typedef int (*test_t)();
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit cccdf36c23903dd1ad3f8a57149257ce589e4aee
|
Loading…
Reference in New Issue