Alex King 2a6cf8c8e7
[Strings] Add more number formatters (#2873)
* [Strings] Add more number formatters

# Notes
- Adds `Strings::ToUnsignedInt` for `uint32` support.
- Adds `Strings::ToBigInt` for `int64` support.
- Adds `Strings::ToUnsignedBigInt` for `uint64` support.
- Adds `Strings::ToFloat` for `float` support.
- Replaces all `std::stoi` references with `Strings::ToInt`.
- Replaces all `atoi` references with `Strings::ToInt`.
- Replaces all `std::stoul` references with `Strings::ToUnsignedInt`.
- Replaces all `atoul` references with `Strings::ToUnsignedInt`.
- Replaces all `std::stoll` references with `Strings::ToBigInt`.
- Replaces all `atoll` references with `Strings::ToBigInt`.
- Replaces all `std::stoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `atoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `std::stof` references with `Strings::ToFloat`.

* [Strings] Add more number formatters

- Adds `Strings::ToUnsignedInt` for `uint32` support.
- Adds `Strings::ToBigInt` for `int64` support.
- Adds `Strings::ToUnsignedBigInt` for `uint64` support.
- Adds `Strings::ToFloat` for `float` support.
- Replaces all `std::stoi` references with `Strings::ToInt`.
- Replaces all `atoi` references with `Strings::ToInt`.
- Replaces all `std::stoul` references with `Strings::ToUnsignedInt`.
- Replaces all `atoul` references with `Strings::ToUnsignedInt`.
- Replaces all `std::stoll` references with `Strings::ToBigInt`.
- Replaces all `atoll` references with `Strings::ToBigInt`.
- Replaces all `std::stoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `atoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `std::stof` references with `Strings::ToFloat`.

* Rebase cleanup

* Changes/benchmarks/tests

---------

Co-authored-by: Akkadius <akkadius1@gmail.com>
2023-03-04 17:01:19 -06:00

76 lines
1.3 KiB
C++
Executable File

#include "../client.h"
#include "../../common/repositories/account_repository.h"
void command_delacct(Client *c, const Seperator *sep)
{
auto arguments = sep->argnum;
if (!arguments) {
c->Message(Chat::White, "Format: #delacct [Account ID|Account Name]");
return;
}
uint32 account_id = 0;
std::string account_name;
if (sep->IsNumber(1)) {
account_id = Strings::ToUnsignedInt(sep->arg[1]);
auto a = AccountRepository::FindOne(content_db, account_id);
if (!a.id) {
c->Message(
Chat::White,
fmt::format(
"Account ID {} does not exist or is invalid.",
account_id
).c_str()
);
return;
}
account_name = a.name;
} else {
account_name = sep->arg[1];
auto a = AccountRepository::GetWhere(
content_db,
fmt::format(
"`name` = '{}'",
account_name
)
);
if (a.empty() || !a[0].id) {
c->Message(
Chat::White,
fmt::format(
"Account {} does not exist or is invalid.",
account_name
).c_str()
);
return;
}
account_id = a[0].id;
}
if (!AccountRepository::DeleteOne(content_db, account_id)) {
c->Message(
Chat::White,
fmt::format(
"Failed to delete account {} ({}).",
account_name,
account_id
).c_str()
);
return;
}
c->Message(
Chat::White,
fmt::format(
"Successfully deleted account {} ({}).",
account_name,
account_id
).c_str()
);
}