Skip to content

Commit

Permalink
coffee: improve stats, also report on tea
Browse files Browse the repository at this point in the history
- show cups of tea
- tidy up code to allow skipping coffee
  • Loading branch information
adriaandegroot committed Jan 14, 2022
1 parent 63df787 commit 594a7fd
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/coffee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ namespace
}
namespace QuatBot
{
struct OptionalAnd {};
QStringList& operator << (QStringList& l, const OptionalAnd& a)
{
if (l.count() > 1)
{
l << "and";
}
return l;
}

class CoffeeStats
{
Expand Down Expand Up @@ -89,16 +98,24 @@ class Coffee::Private
{
for (const auto& u : m_stats)
{
QStringList info{QString("%1 has had %2 cups of coffee").arg(u.m_user).arg(u.m_coffee)};
QStringList info{u.m_user};
if (u.m_coffee > 0)
{
info << OptionalAnd{} << QString("has had %1 cups of coffee").arg(u.m_coffee);
}
if (u.m_tea > 0)
{
info << OptionalAnd{} << QString("has had %1 cups of tea").arg(u.m_tea);
}
if (u.m_cookie > 0)
{
info << QString("and has %1 cookies").arg(u.m_cookie);
info << OptionalAnd{} << QString("has %1 cookies").arg(u.m_cookie);
}
if (u.m_cookieEated > 0)
{
info << QString("and has eaten %1 cookies").arg(u.m_cookieEated);
info << OptionalAnd{} << QString("has eaten %1 cookies").arg(u.m_cookieEated);
}
info << "so far.";
info << ".";
bot->message(info);
}
}
Expand Down

0 comments on commit 594a7fd

Please sign in to comment.