48 std::function<void(
const std::string&)>
Send;
54 std::string
Text(std::string_view key,
Tokens tokens = {})
const;
68 void Say(std::string_view key,
Tokens tokens = {})
const;
71 void SayRaw(std::string_view line)
const;
106 std::function<Result<Reply>(
const Caller&, std::span<const BoundArg>)>
Invoke;
130 "A command handler takes (Caller, Args::...) and returns Result<Reply> or nothing. A generic lambda "
131 "cannot be one: its parameter list is the argument specification, so the types have to be "
136template <HasOneCallOperator F>
141template <
class R,
class... A>
149template <
class C,
class R,
class... A>
153template <
class C,
class R,
class... A>
157template <
class C,
class R,
class... A>
161template <
class C,
class R,
class... A>
165template <
class R,
class... A>
169template <
class R,
class... A>
201 _def.Name = std::string(name);
207 _def.Aliases.emplace_back(alias);
214 _def.Description = std::string(text);
221 _def.PermissionName = std::string(permission);
269 template <
class F,
class... A>
272 static_assert((
CommandArg<A> && ...),
"Every command handler parameter after Caller must be an Args:: type.");
273 static_assert(
OptionalsTrail<A...>(),
"Only trailing command arguments may be Args::Opt.");
274 static_assert(
RestIsLast<A...>(),
"Args::Rest must be the last command argument.");
276 std::function<Result<Reply>(
Caller, A...)> fn;
277 if constexpr (std::is_void_v<std::invoke_result_t<std::decay_t<F>&,
Caller, A...>>)
280 h(c, std::move(args)...);
286 fn = std::forward<F>(handler);
290 _def.Invoke = [fn = std::move(fn)](
const Caller& caller, std::span<const BoundArg> bound) {
291 return Unpack(fn, caller, bound, std::index_sequence_for<A...>{});
293 _install(std::move(_def));
297 template <
class... A, std::size_t... I>
299 std::span<const BoundArg> bound, std::index_sequence<I...>)
305 CommandDefinition _def;
std::function< void(CommandDefinition)> Installer
CommandBuilder & Alias(std::string_view alias)
CommandBuilder & UsageKey(std::string_view key)
CommandBuilder & Describe(std::string_view text)
CommandBuilder & PlayersAndServer()
CommandBuilder(Installer install, std::string_view name)
CommandBuilder & Permission(std::string_view permission)
CommandBuilder & PlayersOnly()
CommandBuilder & ServerOnly()
One connected player, owned by PlayerManager for the length of the connection.
Localization system. Loads one JSON file per language; nested objects flatten into dotted keys (categ...
consteval bool RestIsLast()
std::expected< T, Error > Result
std::map< std::string, std::string > Tokens
std::vector< ArgDesc > DescribeArgs()
consteval bool OptionalsTrail()
static T From(const BoundArg &bound)
Who invoked the command, and how to answer them.
void SayRaw(std::string_view line) const
Result< Reply > Ok(std::string_view key, Tokens tokens={}) const
std::function< void(const std::string &)> Send
VoltMod::Translations & Translations
std::string Text(std::string_view key, Tokens tokens={}) const
Result< Reply > Fail(std::string_view key, Tokens tokens={}) const
void Say(std::string_view key, Tokens tokens={}) const
One command as the builder assembled it.
std::string PermissionName
std::function< Result< Reply >(const Caller &, std::span< const BoundArg >)> Invoke
std::vector< std::string > Aliases
std::vector< ArgDesc > Args
CommandArgList< A... > List
The parameter list of a handler, after the leading Caller.
What a command handler answers with.