auto join game

This commit is contained in:
mrbesen 2022-03-15 19:57:25 +01:00
parent 188db932fb
commit 8a69fdc81f
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
1 changed files with 10 additions and 5 deletions

View File

@ -2,6 +2,11 @@
#include <sstream>
static Game::UserInfo userToUserInfo(const TelegramAPI::User& u) {
// + (u.last_name.empty() ? "" : " " + u.last_name) // problems with spaces and unicode in last name
return {u.id, u.first_name, u.username};
}
Bot::Bot(TelegramAPI::Manager* tapi, Conf& conf) : tapi(tapi), conf(conf) {}
Bot::~Bot() {}
@ -15,6 +20,11 @@ bool Bot::handleStart(TelegramAPI::Manager* api, const TelegramAPI::Message& msg
// create a empty game
Game g;
// @GroupAnonymousBot
if(msg.from.id != 1087968824 && !msg.from.is_bot) {
g.addPlayer(userToUserInfo(msg.from));
}
std::vector<TelegramAPI::MessageEntity> entities;
const std::string text = gameToMessage(g, entities);
auto sendmsg = api->sendMessage(msg.chat.id, text, gameToKeyboard(g), entities);
@ -26,11 +36,6 @@ bool Bot::handleMessage(TelegramAPI::Manager* api, TelegramAPI::Message& msg) {
return true;
}
static Game::UserInfo userToUserInfo(const TelegramAPI::User& u) {
// + (u.last_name.empty() ? "" : " " + u.last_name) // problems with spaces and unicode in last name
return {u.id, u.first_name, u.username};
}
#define delret delete g; \
return true