fix(Scripts/Commands): Use the argument parser to parse guild names (#17863)

This commit is contained in:
Andrew
2023-11-26 12:59:58 -03:00
committed by GitHub
parent e68bd9060a
commit 76a2bbfef0

View File

@@ -53,7 +53,7 @@ public:
return commandTable; return commandTable;
} }
static bool HandleGuildCreateCommand(ChatHandler* handler, Optional<PlayerIdentifier> target, std::string_view guildName) static bool HandleGuildCreateCommand(ChatHandler* handler, Optional<PlayerIdentifier> target, QuotedString guildName)
{ {
if (!target) if (!target)
{ {
@@ -67,8 +67,6 @@ public:
return false; return false;
} }
guildName = guild_commandscript::_RemoveQuotes(guildName);
if (guildName.empty()) if (guildName.empty())
{ {
return false; return false;
@@ -111,10 +109,8 @@ public:
return true; return true;
} }
static bool HandleGuildDeleteCommand(ChatHandler*, std::string_view guildName) static bool HandleGuildDeleteCommand(ChatHandler*, QuotedString guildName)
{ {
guildName = guild_commandscript::_RemoveQuotes(guildName);
if (guildName.empty()) if (guildName.empty())
{ {
return false; return false;
@@ -130,7 +126,7 @@ public:
return true; return true;
} }
static bool HandleGuildInviteCommand(ChatHandler* handler, Optional<PlayerIdentifier> target, std::string_view guildName) static bool HandleGuildInviteCommand(ChatHandler* handler, Optional<PlayerIdentifier> target, QuotedString guildName)
{ {
if (!target) if (!target)
{ {
@@ -142,8 +138,6 @@ public:
return false; return false;
} }
guildName = guild_commandscript::_RemoveQuotes(guildName);
if (guildName.empty()) if (guildName.empty())
{ {
return false; return false;
@@ -202,11 +196,8 @@ public:
return targetGuild->ChangeMemberRank(player->GetGUID(), rank); return targetGuild->ChangeMemberRank(player->GetGUID(), rank);
} }
static bool HandleGuildRenameCommand(ChatHandler* handler, std::string_view oldGuildStr, std::string_view newGuildStr) static bool HandleGuildRenameCommand(ChatHandler* handler, QuotedString oldGuildStr, QuotedString newGuildStr)
{ {
oldGuildStr = guild_commandscript::_RemoveQuotes(oldGuildStr);
newGuildStr = guild_commandscript::_RemoveQuotes(newGuildStr);
if (oldGuildStr.empty() || newGuildStr.empty()) if (oldGuildStr.empty() || newGuildStr.empty())
{ {
return false; return false;
@@ -238,7 +229,7 @@ public:
return true; return true;
} }
static bool HandleGuildInfoCommand(ChatHandler* handler, Optional<Variant<ObjectGuid::LowType, std::string_view>> const& guildIdentifier) static bool HandleGuildInfoCommand(ChatHandler* handler, Optional<Variant<ObjectGuid::LowType, QuotedString>> const& guildIdentifier)
{ {
Guild* guild = nullptr; Guild* guild = nullptr;
@@ -247,7 +238,7 @@ public:
if (ObjectGuid::LowType const* guid = std::get_if<ObjectGuid::LowType>(&*guildIdentifier)) if (ObjectGuid::LowType const* guid = std::get_if<ObjectGuid::LowType>(&*guildIdentifier))
guild = sGuildMgr->GetGuildById(*guid); guild = sGuildMgr->GetGuildById(*guid);
else else
guild = sGuildMgr->GetGuildByName(guildIdentifier->get<std::string_view>()); guild = sGuildMgr->GetGuildByName(guildIdentifier->get<QuotedString>());
} }
else if (Optional<PlayerIdentifier> target = PlayerIdentifier::FromTargetOrSelf(handler); target && target->IsConnected()) else if (Optional<PlayerIdentifier> target = PlayerIdentifier::FromTargetOrSelf(handler); target && target->IsConnected())
guild = target->GetConnectedPlayer()->GetGuild(); guild = target->GetConnectedPlayer()->GetGuild();
@@ -275,20 +266,6 @@ public:
handler->PSendSysMessage(LANG_GUILD_INFO_EXTRA_INFO, guild->GetInfo().c_str()); // Extra Information handler->PSendSysMessage(LANG_GUILD_INFO_EXTRA_INFO, guild->GetInfo().c_str()); // Extra Information
return true; return true;
} }
private:
static std::string_view _RemoveQuotes(std::string_view inputString)
{
if (inputString.starts_with('"') && inputString.ends_with('"'))
{
inputString.remove_prefix(1);
inputString.remove_suffix(1);
return inputString;
}
else
{
return "";
}
}
}; };
void AddSC_guild_commandscript() void AddSC_guild_commandscript()