You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.4 KiB
3.4 KiB
title: Another Ebooks Bot For Telegram
date: 01-08-20
Yes, I've written another markov chain bot. A markov chain was one of the first
things I attempted when I was trying to learn python years ago. I made another
one last year and have again used a markov chain project to help me learn a
language: C++.
code
This one is a bot for the messaging app Telegram. You can add it to a group and
it will listen to the conversation to build its markov chain databse[^2]. It will
reply periodically to a random message using its last word as the seed. It looks
like a reallly basic form of keyboard autocomplete.
It can also import plain-text files. This is useful if you want it to loosely
imitate the prose of a specific author.
But this one does support arbitrary order markov chains and uses an SQLite
database instead of json save-files like the last one. It is also structured to
(theoretically) allow you to swap the SQLite database for say... a posgtres
databse. Because performance is what C++ is about.
If it seems over-engineered it's because I tried to ram in as many c++
features as possible in order to help me learn the language.
My main method of learning has just been reading the
first third of A Tour of C++ by Bjarne Stroustrup, watching random C++
conference talks[^1], searching online, and referring to
cppreference.com. Its not the worst way of
learning a language, and I have to say I prefer textbooks to videos or tutorials
just thanks to the pacing, but I started to wish my University did an "Intro To
Software Engineering in C++" course, like they do for Java. Having a lecturer
guide you through the main bases of the language over 13 weeks is immensely
helpful.
Anyway, there is still some design and debugging work to do with this project.
The more significant problems are the structure of the SQL generation and binding
code, and the structure of the queries. The former because its a mess and hard
to maintain, and the latter because queries cannot be batched in transactions
I dont know of a way of doing it without just gitting gud at SQL. I also kind of
regret using this C++ sql library. It is very nice, but the plain C SQL
library also seems good enough, and would let me practice RAII.
Theres plenty of work I can do on it to make it a more useable meme robot, but I
don't know if I will. I've already had 1 year of having a robotic talking parrot
in our groupchat and I don't know if I should instantiate another.
This Program Is Bad, but it did teach me some valuable lessons like:
- How bad ld linker errors are
- How ugly C++ syntax is
- The sheer number of footguns present in the C++ language
- How to properly declare then define classes
- The hellscape that is build systems
- The hellscape that is libraries
- I didnt even use that many libraries really...
- How slow the c++ compiler (and linting tools) are compared to C.
- I wish I had time to learn Go.
In all seriousness though, C++ is a pretty scary language, but still a very
interesting one.
I really need to think of more creative projects though.
[^1]: I did solve one bug because I remembered it for a talk so it wasn't
just exam-study-procrastination when I watched them last semester.
[^2]: It does not store verbatim messages only word-pairs, word-triplets...
depending on the order of the markov chain; and how many times they occurred.