Skip to content

artemka-sh/samotlor-quest-tgbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QuizQuest Bot

A Telegram quest/quiz bot built entirely in modern C++17 with Qt & TgBot)

License: MIT C++17


✨ Features

Category Details
Gameplay Interactive question‑by‑question quest (supports MCQ & free‑form answers), instant validation, final summary
Persistence PostgreSQL storage of users & answers, auto‑migration on first launch
Config‑driven All wording/questions in a single questions.json; secrets in config.json
Keyboard UX Reply keyboard with answer options, hides automatically after click
Fault tolerance Long‑poll restart loop, graceful handling of unknown updates, reconnect back‑off
i18n‑ready UTF‑8 everywhere; questions file can be any language

🤔 Why another Telegram bot in C++?

  • Performance & footprint – native binary starts in ~10 ms and uses <20 MB RAM even on a 512 MB VPS.
  • One dependency graph – same tool‑chain we already use for the rest of the backend (C++, CMake, clang‑tidy).
  • Fun & curiosity – pushing C++ outside the usual server/embedded bubble.

If you just need a simple bot, Python is fine. This repo is for people who enjoy unusual tech choices.


🏗️ Tech stack

  • C++17 – core language, RAII design
  • Qt 5/6 (Core & SQL) – JSON parsing, PostgreSQL driver, cross‑platform utils
  • TgBot – Telegram Bot API for C++
  • PostgreSQL ≥ 14(tested) – persistent storage
  • CMake ≥ 3.20 – build system

📂 Project layout

├── CMakeLists.txt
├── src/
│   ├── botapplication.hpp / .cpp   # high‑level orchestrator
│   ├── telegram_messenger.*        # thin wrapper around TgBot::Bot
│   ├── database_manager.*          # Qt SQL helpers
│   ├── questions.*                 # loads questions.json
│   └── config.*                    # config data parser
├── res/
│   ├── config.json                 # secrets & DB creds 
│   └── questions.json              # game script
└── tests/

🚀 Quick start

1 · Clone & build

git clone https://github.com/artemka-sh/samotlor-quest-tgbot/ #you must recursive udate git submodules
cd samotlor-quest-tgbot
cmake ..
cmake --build .

2 · Create res/config.json

{
  "telegram_token": "123456:ABC‑DEF…",
  "db_address": "localhost",
  "db_port": "5432",
  "db_name": "questbot",
  "db_user": "questbot",
  "db_password": "secret",
  "lazy_time": 3600            #don't using
}

3 · Run migrations (auto)

First launch will create tables users and user_answers if they don’t exist.

4 · Start the bot

./build/samotlor-quest-tgbot       # logs to stdout

background working with log to file

 nohup ./samotlor-quest-tgbot >log4.txt 2>&1 &

The binary restarts itself with a built‑in endless loop that catches any exception and starts over.

🧩 Extending the quest

  1. Open res/questions.json.
  2. Append a new object: { "id": 42, "type": "text", "question": "What is the answer?", "allowCustomAnswer": true }
  3. Restart the bot – no recompilation required.

Details on the schema are in questions.hpp comments.


🙌 Contributing

PRs and issues are welcome!

📜 License

Distributed under the MIT License. See LICENSE for details.

How it's look like

exampleimage

About

Telegram quiz + quest, survey, bot written in modern C++17 (Qt + TgBot) with PostgreSQL persistence.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors