From 628e064056a02cbc3fb3b758df51559d62c37a10 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sat, 26 Feb 2022 15:40:11 -0500 Subject: Factor out commandAvailable --- command.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/command.c b/command.c index a127af3..511bc62 100644 --- a/command.c +++ b/command.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 C. McEnroe +/* Copyright (C) 2020 June McEnroe * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -639,6 +639,12 @@ size_t commandWillSplit(uint id, const char *input) { return 0; } +static bool commandAvailable(const struct Handler *handler) { + if (handler->flags & Restrict && self.restricted) return false; + if (handler->flags & Kiosk && self.kiosk) return false; + return true; +} + void command(uint id, char *input) { if (id == Debug && input[0] != '/' && !self.restricted) { commandQuote(id, input); @@ -667,10 +673,7 @@ void command(uint id, char *input) { uiFormat(id, Warm, NULL, "No such command %s", cmd); return; } - if ( - (self.restricted && handler->flags & Restrict) || - (self.kiosk && handler->flags & Kiosk) - ) { + if (!commandAvailable(handler)) { uiFormat(id, Warm, NULL, "Command %s is unavailable", cmd); return; } -- cgit 1.4.1