added reply
This commit is contained in:
parent
f523e975d9
commit
b3fb42db81
1 changed files with 21 additions and 12 deletions
|
@ -14,11 +14,10 @@ int main(int argc, char **argv)
|
||||||
DokuWiki wiki(settings.wikiUrl, settings.wikiUser, settings.wikiPassword);
|
DokuWiki wiki(settings.wikiUrl, settings.wikiUser, settings.wikiPassword);
|
||||||
|
|
||||||
tgbot::LongPollBot bot(settings.telegramToken);
|
tgbot::LongPollBot bot(settings.telegramToken);
|
||||||
bot.callback([&wiki, &settings] (const tgbot::types::Message message,
|
bot.callback([&wiki, &settings](const tgbot::types::Message message,
|
||||||
const tgbot::methods::Api &api)
|
const tgbot::methods::Api &api)
|
||||||
{
|
{
|
||||||
if (message.text != nullptr
|
if (message.text != nullptr && message.from != nullptr
|
||||||
&& message.from != nullptr
|
|
||||||
&& message.from->username != nullptr)
|
&& message.from->username != nullptr)
|
||||||
{
|
{
|
||||||
if (settings.telegramUsers.find(*message.from->username)
|
if (settings.telegramUsers.find(*message.from->username)
|
||||||
|
@ -29,15 +28,26 @@ int main(int argc, char **argv)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::ostringstream logMessage;
|
std::ostringstream logMessage;
|
||||||
logMessage << message.from->firstName
|
logMessage << message.from->firstName << " (" << *message.from->username << ")"
|
||||||
<< " (" << *message.from->username << ")"
|
|
||||||
<< ": " << *message.text;
|
<< ": " << *message.text;
|
||||||
api.getLogger().info(logMessage.str());
|
api.getLogger().info(logMessage.str());
|
||||||
|
|
||||||
std::ostringstream wikiMessage;
|
std::ostringstream wikiMessage;
|
||||||
wikiMessage << "\n" << logMessage.str() << "\n";
|
wikiMessage << "\n" << logMessage.str() << "\n";
|
||||||
|
try
|
||||||
|
{
|
||||||
wiki.appendToPage("beezletest", wikiMessage.str());
|
wiki.appendToPage("beezletest", wikiMessage.str());
|
||||||
}
|
}
|
||||||
|
catch (std::runtime_error &e)
|
||||||
|
{
|
||||||
|
std::ostringstream reply;
|
||||||
|
reply << "Error writing to wiki: " << e.what();
|
||||||
|
api.getLogger().error(reply.str());
|
||||||
|
api.sendMessage(std::to_string(message.chat.id), reply.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
api.sendMessage(std::to_string(message.chat.id), "Stored to wiki");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
bot.start();
|
bot.start();
|
||||||
|
@ -51,4 +61,3 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue