PageRenderTime 53ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/TellTarget.lua

http://prat.googlecode.com/
Lua | 196 lines | 86 code | 36 blank | 74 comment | 10 complexity | e1de2394d6526f23c4a730f9510395fc MD5 | raw file
Possible License(s): GPL-3.0
  1. ---------------------------------------------------------------------------------
  2. --
  3. -- Prat - A framework for World of Warcraft chat mods
  4. --
  5. -- Copyright (C) 2006-2007 Prat Development Team
  6. --
  7. -- This program is free software; you can redistribute it and/or
  8. -- modify it under the terms of the GNU General Public License
  9. -- as published by the Free Software Foundation; either version 2
  10. -- of the License, or (at your option) any later version.
  11. --
  12. -- This program is distributed in the hope that it will be useful,
  13. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. -- GNU General Public License for more details.
  16. --
  17. -- You should have received a copy of the GNU General Public License
  18. -- along with this program; if not, write to:
  19. --
  20. -- Free Software Foundation, Inc.,
  21. -- 51 Franklin Street, Fifth Floor,
  22. -- Boston, MA 02110-1301, USA.
  23. --
  24. --
  25. -------------------------------------------------------------------------------
  26. --[[
  27. Name: module
  28. Revision: $Revision: 80703 $
  29. Author(s): Curney (asml8ed@gmail.com)
  30. Krtek (krtek4@gmail.com)
  31. Inspired by: idChat2_TellTarget by Industrial
  32. ChatFrameExtender by Satrina
  33. Website: http://www.wowace.com/files/index.php?path=Prat/
  34. Documentation: http://www.wowace.com/wiki/Prat/Integrated_Modules#TellTarget
  35. SVN: http://svn.wowace.com/wowace/trunk/Prat/
  36. Description: Module for Prat that adds a slash command (/tt) to send a message to your target (default=on).
  37. Dependencies: Prat
  38. ]]
  39. Prat:AddModuleToLoad(function()
  40. local PRAT_MODULE = Prat:RequestModuleName("TellTarget")
  41. if PRAT_MODULE == nil then
  42. return
  43. end
  44. local L = Prat:GetLocalizer({})
  45. --@debug@
  46. L:AddLocale("enUS", {
  47. ["TellTarget"] = true,
  48. ["Adds telltarget slash command (/tt)."] = true,
  49. ["Target does not exist."] = true,
  50. ["Target is not a player."] = true,
  51. ["No target selected."] = true,
  52. ["NoTarget"] = true,
  53. ["/tt"] = true,
  54. })
  55. --@end-debug@
  56. -- These Localizations are auto-generated. To help with localization
  57. -- please go to http://www.wowace.com/projects/prat-3-0/localization/
  58. --[===[@non-debug@
  59. L:AddLocale("enUS",
  60. --@localization(locale="enUS", format="lua_table", same-key-is-true=true, namespace="TellTarget")@
  61. )
  62. L:AddLocale("frFR",
  63. --@localization(locale="frFR", format="lua_table", same-key-is-true=true, namespace="TellTarget")@
  64. )
  65. L:AddLocale("deDE",
  66. --@localization(locale="deDE", format="lua_table", same-key-is-true=true, namespace="TellTarget")@
  67. )
  68. L:AddLocale("koKR",
  69. --@localization(locale="koKR", format="lua_table", same-key-is-true=true, namespace="TellTarget")@
  70. )
  71. L:AddLocale("esMX",
  72. --@localization(locale="esMX", format="lua_table", same-key-is-true=true, namespace="TellTarget")@
  73. )
  74. L:AddLocale("ruRU",
  75. --@localization(locale="ruRU", format="lua_table", same-key-is-true=true, namespace="TellTarget")@
  76. )
  77. L:AddLocale("zhCN",
  78. --@localization(locale="zhCN", format="lua_table", same-key-is-true=true, namespace="TellTarget")@
  79. )
  80. L:AddLocale("esES",
  81. --@localization(locale="esES", format="lua_table", same-key-is-true=true, namespace="TellTarget")@
  82. )
  83. L:AddLocale("zhTW",
  84. --@localization(locale="zhTW", format="lua_table", same-key-is-true=true, namespace="TellTarget")@
  85. )
  86. --@end-non-debug@]===]
  87. ----[[
  88. -- Chinese Local : CWDG Translation Team ???? (Thomas Mo)
  89. -- CWDG site: http://Cwowaddon.com
  90. -- $Rev: 80703 $
  91. --]]
  92. --
  93. --
  94. --
  95. --
  96. --
  97. --
  98. -- create prat module
  99. local module = Prat:NewModule(PRAT_MODULE, "AceHook-3.0")
  100. Prat:SetModuleDefaults(module.name, {
  101. profile = {
  102. on = true,
  103. }
  104. } )
  105. Prat:SetModuleOptions(module.name, {
  106. name = L["TellTarget"],
  107. desc = L["Adds telltarget slash command (/tt)."],
  108. type = "group",
  109. args = {
  110. info = {
  111. name = L["Adds telltarget slash command (/tt)."],
  112. type = "description",
  113. }
  114. }
  115. }
  116. )
  117. --[[------------------------------------------------
  118. Module Event Functions
  119. ------------------------------------------------]]--
  120. function module:OnModuleEnable()
  121. self:HookScript(ChatFrameEditBox, "OnTextChanged")
  122. end
  123. function module:OnModuleDisable()
  124. self:UnhookAll()
  125. end
  126. --[[------------------------------------------------
  127. Core Functions
  128. ------------------------------------------------]]--
  129. function module:OnTextChanged(editBox, ...)
  130. local command, msg = editBox:GetText():match("^(/%S+)%s(.*)$")
  131. if command == "/tt" or command == L["/tt"] then
  132. self:SendTellToTarget(editBox.chatFrame, msg)
  133. end
  134. self.hooks[editBox].OnTextChanged(editBox, ...)
  135. end
  136. function module:SendTellToTarget(frame, text)
  137. if frame == nil then frame = DEFAULT_CHAT_FRAME end
  138. local unitname, realm, fullname
  139. if UnitIsPlayer("target") then
  140. unitname, realm = UnitName("target")
  141. if unitname then
  142. if realm and not UnitIsSameServer("player", "target") then
  143. fullname = unitname.."-"..realm
  144. else
  145. fullname = unitname
  146. end
  147. end
  148. end
  149. ChatFrame_SendTell((fullname and fullname:gsub(" ", "") or L["NoTarget"]), frame)
  150. ChatFrameEditBox:SetText(text)
  151. end
  152. local function TellTarget(msg)
  153. module:SendTellToTarget(SELECTED_CHAT_FRAME, msg)
  154. end
  155. -- TODO: set slash command
  156. --SlashCmdList["module"] = TellTarget
  157. --SLASH_module1 = "/tt"
  158. --SLASH_module2 = L["/tt"]
  159. return
  160. end ) -- Prat:AddModuleToLoad