summaryrefslogtreecommitdiff
path: root/modules/database/db_atheme.cpp
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2024-03-11 13:53:05 +0000
committerSadie Powell <sadie@witchery.services>2024-03-11 19:17:29 +0000
commit29e7674e56bf2b829bba22def2760d034a76e788 (patch)
treef40049ba995b03dd7c510d88f9f19db2d2e65a2e /modules/database/db_atheme.cpp
parente2df7d4d01f8fdb41c49ce8efc462cab005e7d5c (diff)
Replace convertTo/stringify with non-throwing alternatives.
Having these throw is terrible for ergonomics and there are loads of places where the exception was either silently ignored or not handled at all. Having a function which returns an optional and another that returns a default works a lot better imo.
Diffstat (limited to 'modules/database/db_atheme.cpp')
-rw-r--r--modules/database/db_atheme.cpp27
1 files changed, 9 insertions, 18 deletions
diff --git a/modules/database/db_atheme.cpp b/modules/database/db_atheme.cpp
index 3e613562b..3f62c29ca 100644
--- a/modules/database/db_atheme.cpp
+++ b/modules/database/db_atheme.cpp
@@ -56,16 +56,7 @@ public:
template<typename Numeric>
std::enable_if_t<std::is_arithmetic_v<Numeric>, Numeric> GetNum()
{
- try
- {
- auto token = Get();
- std::stringstream stream(token.str());
- Numeric ntoken = 0;
- stream >> ntoken;
- return ntoken;
- }
- catch (const ConvertException &) { }
- return 0;
+ return Anope::Convert<Numeric>(Get(), 0);
}
// Retrieves the entire row.
@@ -869,7 +860,7 @@ private:
else if (key == "private:close:reason")
data->suspend_reason = value;
else if (key == "private:close:timestamp")
- data->suspend_ts = convertTo<time_t>(value);
+ data->suspend_ts = Anope::Convert<time_t>(value, 0);
else if (key == "private:entrymsg")
{
auto *eml = ci->Require<EntryMessageList>("entrymsg");
@@ -891,19 +882,19 @@ private:
else if (key == "private:klinechan:reason")
data->suspend_reason = value;
else if (key == "private:klinechan:timestamp")
- data->suspend_ts = convertTo<time_t>(value);
+ data->suspend_ts = Anope::Convert<time_t>(value, 0);
else if (key == "private:mark:reason")
data->info_message = value;
else if (key == "private:mark:setter")
data->info_adder = value;
else if (key == "private:mark:timestamp")
- data->info_ts = convertTo<time_t>(value);
+ data->info_ts = Anope::Convert<time_t>(value, 0);
else if (key == "private:topic:setter")
ci->last_topic_setter = value;
else if (key == "private:topic:text")
ci->last_topic = value;
else if (key == "private:topic:ts")
- ci->last_topic_time = convertTo<time_t>(value);
+ ci->last_topic_time = Anope::Convert<time_t>(value, 0);
else
Log(this) << "Unknown channel metadata " << key << " = " << value;
@@ -953,7 +944,7 @@ private:
auto kill = Config->GetModule("nickserv")->Get<time_t>("kill", "60s");
auto killquick = Config->GetModule("nickserv")->Get<time_t>("killquick", "20s");
- auto secs = convertTo<unsigned>(value);
+ auto secs = Anope::Convert<time_t>(value, kill);
if (secs >= kill)
nc->Extend<bool>("KILLPROTECT");
else if (secs >= killquick)
@@ -966,7 +957,7 @@ private:
else if (key == "private:freeze:reason")
data->suspend_reason = value;
else if (key == "private:freeze:timestamp")
- data->suspend_ts = convertTo<time_t>(value);
+ data->suspend_ts = Anope::Convert<time_t>(value, 0);
else if (key == "private:host:actual")
data->last_real_mask = value;
else if (key == "private:host:vhost")
@@ -978,13 +969,13 @@ private:
else if (key == "private:mark:setter")
data->info_adder = value;
else if (key == "private:mark:timestamp")
- data->info_ts = convertTo<time_t>(value);
+ data->info_ts = Anope::Convert<time_t>(value, 0);
else if (key == "private:usercloak")
data->vhost = value;
else if (key == "private:usercloak-assigner")
data->vhost_creator = value;
else if (key == "private:usercloak-timestamp")
- data->vhost_ts = convertTo<time_t>(value);
+ data->vhost_ts = Anope::Convert<time_t>(value, 0);
else if (key.compare(0, 18, "private:usercloak:", 18) == 0)
data->vhost_nick[key.substr(18)] = value;
else