<commit_before>/*
 * Copyright (C) 2016+     AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2
 * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
 */

/* ScriptData
Name: learn_commandscript
%Complete: 100
Comment: All learn related commands
Category: commandscripts
EndScriptData */

#include "Chat.h"
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "Language.h"
#include "SpellMgr.h"
#include "SpellInfo.h"
#include "Player.h"
#include "Pet.h"

class learn_commandscript : public CommandScript
{
public:
    learn_commandscript() : CommandScript("learn_commandscript") { }

    std::vector<ChatCommand> GetCommands() const override
    {
        static std::vector<ChatCommand> learnAllMyCommandTable =
        {
            { "class",          SEC_GAMEMASTER,  false, &HandleLearnAllMyClassCommand,       "" },
            { "pettalents",     SEC_GAMEMASTER,  false, &HandleLearnAllMyPetTalentsCommand,  "" },
            { "spells",         SEC_GAMEMASTER,  false, &HandleLearnAllMySpellsCommand,      "" },
            { "talents",        SEC_GAMEMASTER,  false, &HandleLearnAllMyTalentsCommand,     "" }
        };

        static std::vector<ChatCommand> learnAllCommandTable =
        {
            { "my",             SEC_GAMEMASTER,  false, nullptr,                                "",  learnAllMyCommandTable },
            { "gm",             SEC_GAMEMASTER,  false, &HandleLearnAllGMCommand,            "" },
            { "crafts",         SEC_GAMEMASTER,  false, &HandleLearnAllCraftsCommand,        "" },
            { "default",        SEC_GAMEMASTER,  false, &HandleLearnAllDefaultCommand,       "" },
            { "lang",           SEC_GAMEMASTER,  false, &HandleLearnAllLangCommand,          "" },
            { "recipes",        SEC_GAMEMASTER,  false, &HandleLearnAllRecipesCommand,       "" }
        };

        static std::vector<ChatCommand> learnCommandTable =
        {
            { "all",            SEC_GAMEMASTER,  false, nullptr,                                "",  learnAllCommandTable },
            { "",               SEC_GAMEMASTER,  false, &HandleLearnCommand,                 "" }
        };

        static std::vector<ChatCommand> commandTable =
        {
            { "learn",          SEC_GAMEMASTER,  false, nullptr,                                "", learnCommandTable },
            { "unlearn",        SEC_GAMEMASTER,  false, &HandleUnLearnCommand,               "" }
        };
        return commandTable;
    }

    static bool HandleLearnCommand(ChatHandler* handler, char const* args)
    {
        Player* targetPlayer = handler->getSelectedPlayer();

        if (!targetPlayer)
        {
            handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
            handler->SetSentErrorMessage(true);
            return false;
        }

        // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
        uint32 spell = handler->extractSpellIdFromLink((char*)args);
        if (!spell)
            return false;

        SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell);
        if (!spellInfo)
        {
            handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
            handler->SetSentErrorMessage(true);
            return false;
        }

        if (!SpellMgr::IsSpellValid(spellInfo))
        {
            handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell);
            handler->SetSentErrorMessage(true);
            return false;
        }

        SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spell);
        uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spell);
        if (handler->GetSession()->GetSecurity() < SEC_CONSOLE && (bounds.first != bounds.second || spellDifficultyId))
        {
            handler->PSendSysMessage("Spell %u cannot be learnt using a command!", spell);
            handler->SetSentErrorMessage(true);
            return false;<commit_msg>fix(Core/Commands): Learn spell for GM lvl 3 (#1651)<commit_after>/*
 * Copyright (C) 2016+     AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2
 * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
 */

/* ScriptData
Name: learn_commandscript
%Complete: 100
Comment: All learn related commands
Category: commandscripts
EndScriptData */

#include "Chat.h"
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "Language.h"
#include "SpellMgr.h"
#include "SpellInfo.h"
#include "Player.h"
#include "Pet.h"

class learn_commandscript : public CommandScript
{
public:
    learn_commandscript() : CommandScript("learn_commandscript") { }

    std::vector<ChatCommand> GetCommands() const override
    {
        static std::vector<ChatCommand> learnAllMyCommandTable =
        {
            { "class",          SEC_GAMEMASTER,  false, &HandleLearnAllMyClassCommand,       "" },
            { "pettalents",     SEC_GAMEMASTER,  false, &HandleLearnAllMyPetTalentsCommand,  "" },
            { "spells",         SEC_GAMEMASTER,  false, &HandleLearnAllMySpellsCommand,      "" },
            { "talents",        SEC_GAMEMASTER,  false, &HandleLearnAllMyTalentsCommand,     "" }
        };

        static std::vector<ChatCommand> learnAllCommandTable =
        {
            { "my",             SEC_GAMEMASTER,  false, nullptr,                                "",  learnAllMyCommandTable },
            { "gm",             SEC_GAMEMASTER,  false, &HandleLearnAllGMCommand,            "" },
            { "crafts",         SEC_GAMEMASTER,  false, &HandleLearnAllCraftsCommand,        "" },
            { "default",        SEC_GAMEMASTER,  false, &HandleLearnAllDefaultCommand,       "" },
            { "lang",           SEC_GAMEMASTER,  false, &HandleLearnAllLangCommand,          "" },
            { "recipes",        SEC_GAMEMASTER,  false, &HandleLearnAllRecipesCommand,       "" }
        };

        static std::vector<ChatCommand> learnCommandTable =
        {
            { "all",            SEC_GAMEMASTER,  false, nullptr,                                "",  learnAllCommandTable },
            { "",               SEC_GAMEMASTER,  false, &HandleLearnCommand,                 "" }
        };

        static std::vector<ChatCommand> commandTable =
        {
            { "learn",          SEC_GAMEMASTER,  false, nullptr,                                "", learnCommandTable },
            { "unlearn",        SEC_GAMEMASTER,  false, &HandleUnLearnCommand,               "" }
        };
        return commandTable;
    }

    static bool HandleLearnCommand(ChatHandler* handler, char const* args)
    {
        Player* targetPlayer = handler->getSelectedPlayer();

        if (!targetPlayer)
        {
            handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
            handler->SetSentErrorMessage(true);
            return false;
        }

        // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
        uint32 spell = handler->extractSpellIdFromLink((char*)args);
        if (!spell)
            return false;

        SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell);
        if (!spellInfo)
        {
            handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
            handler->SetSentErrorMessage(true);
            return false;
        }

        if (!SpellMgr::IsSpellValid(spellInfo))
        {
            handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell);
            handler->SetSentErrorMessage(true);
            return false;
        }

        SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spell);
        uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spell);
        if (handler->GetSession()->GetSecurity() < SEC_ADMINISTRATOR && (bounds.first != bounds.second || spellDifficultyId))
        {
            handler->PSendSysMessage("Spell %u cannot be learnt using a command!", spell);
            handler->SetSentErrorMessage(true);
            return false;
{'fraction_non_alphanumeric': 0.11181102362204724, 'fraction_numerical': 0.007631738340399758, 'mean_word_length': 2.2037252619324796, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5818535', 'n_tokens_mistral': 2447, 'n_tokens_neox': 2389, 'n_words': 424}