Core/Commands: Add .guild list GM command to list all guilds (#30930)

This commit is contained in:
Alex Dcnh
2025-08-25 22:55:27 +01:00
committed by GitHub
parent 2e26b18851
commit 0ed0e66ee0
4 changed files with 60 additions and 2 deletions

View File

@@ -0,0 +1,16 @@
--
DELETE FROM `command` WHERE `name`='guild list';
INSERT INTO `command` (`name`, `help`) VALUES
('guild list','Syntax: .guild list. Lists every guild: ID | Name | Leader | Creation date | Members | Bank gold');
-- Strings for .guild list output
DELETE FROM `trinity_string` WHERE `entry` BETWEEN 1219 AND 1222;
INSERT INTO `trinity_string` (`entry`,`content_default`) VALUES
-- Title
(1219,'%s=== Guild list ===%s'),
-- Header (6 string args for labels)
(1220,'%s ID | Name | Leader | Creation date | Members | Bank gold%s'),
-- Row (id, name, gm, created, members, bankGold)
(1221,'%6u | %-24.24s | %-16.16s | %-19s | %7u | %10u'),
-- Total
(1222,'%sTotal guilds: %u%s');

View File

@@ -34,6 +34,8 @@ private:
~GuildMgr();
public:
typedef std::unordered_map<ObjectGuid::LowType, Trinity::unique_trackable_ptr<Guild>> GuildContainer;
GuildMgr(GuildMgr const&) = delete;
GuildMgr(GuildMgr&&) = delete;
GuildMgr& operator=(GuildMgr const&) = delete;
@@ -47,6 +49,8 @@ public:
Guild* GetGuildByName(std::string_view guildName) const;
std::string GetGuildNameById(ObjectGuid::LowType guildId) const;
GuildContainer const& GetGuildStore() const { return GuildStore; }
void LoadGuildRewards();
void LoadGuilds();
@@ -64,7 +68,6 @@ public:
void ResetTimes(bool week);
protected:
typedef std::unordered_map<ObjectGuid::LowType, Trinity::unique_trackable_ptr<Guild>> GuildContainer;
ObjectGuid::LowType NextGuildId;
GuildContainer GuildStore;
std::vector<GuildReward> GuildRewards;

View File

@@ -995,7 +995,13 @@ enum TrinityStrings
LANG_ACCOUNT_BNET_UNLINKED = 1216,
LANG_ACCOUNT_BNET_NOT_LINKED = 1217,
LANG_DISALLOW_TICKETS_CONFIG = 1218,
// 1219-1499 - free
// Guild list (.guild list)
LANG_GUILD_LIST_TITLE = 1219,
LANG_GUILD_LIST_HEADER = 1220,
LANG_GUILD_LIST_ROW = 1221,
LANG_GUILD_LIST_TOTAL = 1222,
// 1223-1499 - free
// Command argument parsers
LANG_CMDPARSER_EITHER = 1500,

View File

@@ -33,6 +33,7 @@ EndScriptData */
#include "ObjectMgr.h"
#include "Player.h"
#include "RBAC.h"
#include "Util.h"
#include <iomanip>
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU
@@ -56,6 +57,7 @@ public:
{ "rank", rbac::RBAC_PERM_COMMAND_GUILD_RANK, true, &HandleGuildRankCommand, "" },
{ "rename", rbac::RBAC_PERM_COMMAND_GUILD_RENAME, true, &HandleGuildRenameCommand, "" },
{ "info", rbac::RBAC_PERM_COMMAND_GUILD_INFO, true, &HandleGuildInfoCommand, "" },
{ "list", rbac::RBAC_PERM_COMMAND_GUILD_INFO, true, &HandleGuildListCommand, "" },
};
static std::vector<ChatCommand> commandTable =
{
@@ -299,6 +301,37 @@ public:
handler->PSendSysMessage(LANG_GUILD_INFO_EXTRA_INFO, guild->GetInfo().c_str()); // Extra Information
return true;
}
static bool HandleGuildListCommand(ChatHandler* handler)
{
std::string_view titleAndSummaryColor = handler->IsConsole() ? ""sv : "|cff00ff00"sv;
std::string_view tableHeaderColor = handler->IsConsole() ? ""sv : "|cff00ffff"sv;
std::string_view resetColor = handler->IsConsole() ? ""sv : "|r"sv;
handler->PSendSysMessage(LANG_GUILD_LIST_TITLE, titleAndSummaryColor, resetColor);
handler->PSendSysMessage(LANG_GUILD_LIST_HEADER, tableHeaderColor, resetColor);
GuildMgr::GuildContainer const& guildStore = sGuildMgr->GetGuildStore();
for (auto const& [id, g] : guildStore)
{
std::string gmName;
if (!sCharacterCache->GetCharacterNameByGuid(g->GetLeaderGUID(), gmName))
gmName = "---";
handler->PSendSysMessage(LANG_GUILD_LIST_ROW,
id,
g->GetName().c_str(),
gmName.c_str(),
TimeToTimestampStr(g->GetCreatedDate()).c_str(),
g->GetMembersCount(),
g->GetBankMoney() / GOLD
);
}
handler->PSendSysMessage(LANG_GUILD_LIST_TOTAL, titleAndSummaryColor, guildStore.size(), resetColor);
return true;
}
};
void AddSC_guild_commandscript()