WoWInterface SVN MacroTalk

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /trunk
    from Rev 1 to Rev 2
    Reverse comparison

Rev 1 → Rev 2

MacroTalk/MacroTalkCommands.lua New file
0,0 → 1,62
--[[ /group ]]
local L = MacroTalk_Locals
local print = CogsUtils:GetPrint("MacroTalk: ")
 
SLASH_GROUP_CHAT1 = L["/group"]
SLASH_GROUP_CHAT2 = L["/gr"]
SlashCmdList["GROUP_CHAT"] = function(text)
local channel =
MacroTalk_InBattleground() and "BATTLEGROUND" or
GetNumRaidMembers() > 0 and "RAID" or
GetNumPartyMembers() > 0 and "PARTY"
 
if channel then
SendChatMessage(text, channel, DEFAULT_CHAT_FRAME.editBox.language)
else
print(ERR_NOT_IN_GROUP)
end
end
 
 
 
 
--[[ /tellunit ]]
SLASH_TELL_UNIT1 = L["/tellunit"]
SLASH_TELL_UNIT2 = L["/whisperunit"]
SLASH_TELL_UNIT3 = L["/tu"]
SLASH_TELL_UNIT4 = L["/wu"]
SlashCmdList["TELL_UNIT"] = function(text)
local unit, message = strsplit(" ", text, 2)
local name, realm = UnitName(unit:trim())
if realm and realm ~= "" then
name = name.."-"..realm
end
 
if name then
SendChatMessage(message, "WHISPER", nil, name)
end
end
 
 
 
 
--[[ /opt ]]
SLASH_OPTION_SLASH1 = L["/opt"]
SlashCmdList["OPTION_SLASH"] = function(message)
message = SecureCmdOptionParse(message)
if message then
MacroTalk_DoCommand(message)
end
end
 
 
 
 
--[[ /rnd ]]
SLASH_RANDOM_SLASH1 = L["/rndcmd"]
SlashCmdList["RANDOM_SLASH"] = function(message)
message = SecureCmdOptionParse(message)
if message then
MacroTalk_DoCommand(GetRandomArgument(strsplit("\\", message)):trim())
end
end
MacroTalk/Localization.enUS.lua New file
0,0 → 1,14
MacroTalk_Locals = {
["/group"] = "/group",
["/gr"] = "/gr",
["/tellunit"] = "/tellunit",
["/whisperunit"] = "/whisperunit",
["/tu"] = "/tu",
["/wu"] = "/wu",
["/opt"] = "/opt",
["/rnd"] = "/rnd",
["/rndcmd"] = "/rndcmd",
["<no %s>"] = "<no %s>",
["gender"] = "gender",
["You cannot use %s with /opt or /rnd."] = "You cannot use %s with /opt or /rnd.",
}
MacroTalk/MacroTalk.toc New file
0,0 → 1,13
## Interface: 20100
## Title: MacroTalk
## Notes: Adds helpful chat features for macros
## Author: Cogwheel
 
CogsUtils\CogsUtils.lua
 
Localization.enUS.lua
 
MacroTalk.lua
MacroTalkCommands.lua
MacroTalkChatOptions.lua
MacroTalkSubstitutions.lua
Property changes : Added: svn:executable +
MacroTalk/Localization.xxXX.lua New file
0,0 → 1,17
-- Please e-mail localization files to mcogwheel@gmail.com.
 
if GetLocale() == "xxXX" then
local L = MacroTalk_Locals
 
--L["/group"] = "xxx"
--L["/gr"] = "xxx"
--L["/tellunit"] = "xxx"
--L["/whisperunit"] = "xxx"
--L["/tu"] = "xxx"
--L["/wu"] = "xxx"
--L["/opt"] = "xxx"
--L["/rnd"] = "xxx"
--L["<no %s>"] = "xxx"
--L["gender"] = "xxx"
--L["You cannot use %s with /opt or /rnd."] = "xxx"
end
MacroTalk/MacroTalkChatOptions.lua New file
0,0 → 1,55
--[[ Option chat commands ]]
local L = MacroTalk_Locals
 
local function CreateCmdListEntry(category, command, num)
if not num then
num = command
command = _G[category..1]
end
 
for i = 1, num do
local subcommand = (_G[category..i] or command):sub(2)
_G["SLASH_OPTION_"..category..i] = L["/opt"]..subcommand
_G["SLASH_RANDOM_"..category..i] = L["/rnd"]..subcommand
end
 
SlashCmdList["OPTION_"..category] = function(message)
message = SecureCmdOptionParse(message)
if message then
MacroTalk_DoCommand(command.." "..message)
end
end
 
SlashCmdList["RANDOM_"..category] = function(message)
message = SecureCmdOptionParse(message)
if message then
MacroTalk_DoCommand(command.." "..GetRandomArgument(
strsplit("\\", message)):trim())
end
end
end
 
local baseCommands = {
["SLASH_BATTLEGROUND"] = 4,
["SLASH_CHANNEL"] = 4,
["SLASH_EMOTE"] = 8,
["SLASH_GUILD"] = 8,
["SLASH_OFFICER"] = 4,
["SLASH_PARTY"] = 4,
["SLASH_RAID"] = 6,
["SLASH_RAID_WARNING"] = 2,
["SLASH_REPLY"] = 4,
["SLASH_SAY"] = 4,
["SLASH_WHISPER"] = 10,
["SLASH_YELL"] = 8,
["SLASH_GROUP_CHAT"] = 2,
["SLASH_TELL_UNIT"] = 4,
}
 
for k, v in pairs(baseCommands) do
CreateCmdListEntry(k, v)
end
 
for i = 1, 10 do
CreateCmdListEntry("CHANNEL"..i.."_", "/"..i, 1)
end
MacroTalk/readme.txt New file
0,0 → 1,210
MacroTalk - v1.8
By Cogwheel
 
MacroTalk provides extended chat command support especially useful for macros.
For comments, bug reports, etc., please visit http://cogwheel.wowinterface.com.
 
Table of Contents
 
Disabling modules
Slash commands
/tellunit
/group
/opt
/rndcmd
Conditional chat commands
Random chat commands
Text substitutions
Straight substitutions
Unit information
 
Disabling modules:
If you would prefer only to have certain functionality from MacroTalk (for
instance, if you have another addon that provides similar functionality),
you can disable various modules by renaming or deleting the corresponding
.lua files. You can safely remove MacroTalkChatOptions, MacroTalkCommands,
and MacroTalkSubstitutions which correspond to Conditional/Random chat
commands, Slash commands, and Text substitutions, respectively.
 
Slash commands:
/tellunit (/tu, /whisperunit, /wu) <unit> <message>
Sends a whisper to the specified unit. See
http://www.wowwiki.com/API_TYPE_UnitId for a list of units
 
Example:
/cast Innervate
/tellunit target Incoming innervate
 
/group (/gr) <message>
Picks battleground, raid, or party chat depending on which type of group
you are in.
 
/opt [options] <slash command>; [options] <slash command>; ...
Picks from multiple slash commands given the options. You can only use
slash commands that don't trigger secure functions. Chat commands,
emotes, scripts, etc. are OK. /cast, /use, etc. are off limits.
 
Note: the sub-commands cannot use macro options since the semicolons
would cause ambiguity.
 
Example:
/opt [button:2] /bye; /wave
 
/rndcmd [options] <command 1>\<command 2>; [options] <command 3>\<command 4>...
Picks a random slash command out of the group chosen based on the
given options. Each group is a list of slash commands separated by the
backslash (\) character (this is in contrast to commas used for the
built-in random commands--commas are just too common in chat messages).
 
Note: like the /opt command, the sub-commands cannot use macro options
and you can't use any secure commands.
 
Example:
/rndcmd [swimming] /y Help! I'm Drowning! \ /s The water's great!;
/s Time for a swim... \ /dance
 
Conditional chat commands:
All chat commands (/say, /tell, /guild, etc.) can now accept macro options.
To use this functionality, simply start the command with /opt. Note:
[target=] has no effect on the output of the chat commands; it only affects
the other conditionals in the clause.
 
Example:
/optsay [swimming] gurgle; [mounted] The cavalry has arrived!
 
Example:
/cast [target=focus] Polymorph
/optgroup [target=focus, exists] Sheeping %f
 
Random chat commands:
Similar to the macro options, you can now add /rnd to the beginning of any
chat command to pick a random saying. The /rnd___ commands also take options
to pick a different list of sayings. The lists themselves are separated by
the backslash symbol (\).
 
Example:
/rndyell ZOMG! \ WTF?! \ You there! Check out that noise!
 
Example:
/rndsay [outdoors] Ahhh, the Great Outdoors! \ What a lovely day!;
I wish I could go outside right now \ Must... Leave... Building...
 
Text substitutions:
MacroTalk offers a variety of substitutions in addition to %t of the default
UI. Substitutions are prioritized by the length of the code; longer codes
are processed first. This means that %tl will be processed before %t. The
codes are case-insensitive so %Tl is equivalent to %tL.
 
Straight substitutions:
%n - Your name
%z - Your current zone
%sz - Your current sub-zone
%loc - Your map coordinates
 
Unit information:
%t - Name of your target (built in, but listed for consistency)
%f - Name of your focus
%m - Name of mouseover unit
%p - Name of your pet
%tt - Name of your target's target
 
You can suffix those with one of the following to return other pieces of
data about the unit:
 
l - Level
c - Class
g - Gender
gb - Gender (blank if no gender)
r - Race
rb - Race (blank if no race)
h - Health (XX/XX) - Acts like hp for players not in your party/raid/bg
hp - Health percentage (XX%)
ma - Mana - Not just 'm' because it conflicts with mouseover
mab - Mana (blank if no mana)
mp - Mana percentage
mpb - Mana percentage (blank if no mana)
ic - Raid icon
icb - Raid icon (blank if no icon)
 
Example:
/p Sheeping %f (level %fl %fg %fr %fc)
/cast [target=focus] Polymorph
 
Sample result: Sheeping Cogwheel (level 64 male Gnome Warrior)
 
You can also use the suffixes without a unit code to return information
about yourself.
 
Example:
/s I'm a level %l, %g, %r %c.
 
Sample result: I'm a level 68, male, gnome warrior.
 
Changes:
 
v1.8
- The ic and icb suffixes now insert the appropriate codes to send texture links
instead of just the name of the icons.
 
v1.7.2
- Fixed a bug where a hyphen (-) was incorrectly appended to the /tellunit
target in certain situations
 
v1.7.2
- %gb correctly eliminates the "no gender" message
- % without a code no longer substitutes as the player's name
 
v1.7.1
- Fixed suffixes to work without a unit
- Fixed error when using /gr outside of a group
 
v1.7
- /rnd___ commands should actually work now
- Changed /rnd to /rndcmd because of a conflict with the built-in /rnd command
- Added architecture for straight text substitutions (no interface yet--see
MacroTalkSubstitutions.lua for more information)
 
v1.6
- Added raid icon and "blank" suffixes
 
v1.5.1
- Fixed a bug that was preventing all SendChatMessage calls
 
v1.5
- The race suffix will use UnitRace for players and UnitCreatureType for NPCs
- Added %tt, %loc
- Added health and mana suffixes
 
v1.4
- /opt & /rnd will now print an error message if you attempt to use a secure
command
- Added %n, %z, %sz
- Added ability to use suffixes alone to get info about the player
- Changed unit prefixes to suffixes - INCOMPATIBLE WITH PREVIOUS VERSION
- Substitutions are no longer case-sensitive
- Restructured substitutions and localizations to be more generic
 
v1.3
- Added /rnd and /rnd___ commands
- Fixed a bug where the /opt prefix was only being applied to the first command
of a given type (e.g. only /opts would work but not /optsay)
 
v1.2
- Added generic /opt command
 
v1.1
- Improved localizability of substitutions
 
v1.0
- Name substitutions have been simplified a bit to match the functionality of %t
- Added pet unit substitution
- Added info type prefixes: level, class, gender, race
 
v0.9
- Added /opt___ commands
- Fixed a bug where %m behaved like %f
- No longer uses Satellite
- Added localization lua for future localization
 
v0.5
- Initial release
MacroTalk/MacroTalk.lua New file
0,0 → 1,26
--[[ Shared functions used by multiple modules ]]
local print = CogsUtils:GetPrint("MacroTalk: ")
 
function MacroTalk_InBattleground()
for i = 1, MAX_BATTLEFIELD_QUEUES do
status = GetBattlefieldStatus(i)
if status == "active" then
return true
end
end
return false
end
 
function MacroTalk_DoCommand(text)
local command = text:match("^(/%S+)")
 
if command and IsSecureCmd(command) then
print(L["You cannot use %s with /opt or /rnd."]:format(command))
return
end
 
local origText = ChatFrameEditBox:GetText()
ChatFrameEditBox:SetText(text)
ChatEdit_SendText(ChatFrameEditBox)
ChatFrameEditBox:SetText(origText)
end
MacroTalk/MacroTalkSubstitutions.lua New file
0,0 → 1,176
--[[ Text substitutions ]]
local L = MacroTalk_Locals
 
local subsBase = {
["%%[Nn]"] = function() return UnitName("player") end,
["%%[Zz]"] = GetRealZoneText,
["%%[Ss][Zz]"] = GetSubZoneText,
["%%[Ll][Oo][Cc]"] = function()
local x, y = GetPlayerMapPosition("player")
return ("%.0f, %.0f"):format(x * 100, y * 100)
end,
 
--[[
Until an interface is in place, you can add straight text substitutions
to this table. See the example below. Remove the -- from the front to use
it. Note also that it's case sensitive unless you write both upper- and
lower-case letters inside brackets like the substitutions above.]]
 
--["%%tsinfo"] = "TeamSpeak info: Server: host.domain.com, Password: 12345",
}
 
local sexes = {
L["<no %s>"]:format(L["gender"]),
MALE:lower(),
FEMALE:lower()
}
 
local unitInfoUnits = {
[""] = "player",
["[Tt]"] = "target",
["[Ff]"] = "focus",
["[Mm]"] = "mouseover",
["[Pp]"] = "pet",
["[Tt][Tt]"] = "targettarget",
}
 
local function ActualValue(unit)
return UnitInParty(unit) or UnitInRaid(unit) or
(MacroTalk_InBattleground() and
UnitFactionGroup(unit) == UnitFactionGroup("player"))
end
 
local unitInfoSuffixes = {
[""] = UnitName,
 
["[Ll]"] = function(unit)
local level = UnitLevel(unit)
return level > 0 and level or level < 0 and "??"
end,
 
["[Cc]"] = UnitClass,
 
["[Gg]"] = function(unit)
return sexes[UnitSex(unit)]
end,
 
["[Gg][Bb]"] = function(unit)
local sex = UnitSex(unit)
return sex > 1 and sexes[UnitSex(unit)] or ""
end,
 
["[Rr]"] = function(unit)
local race
if UnitIsPlayer(unit) then
race = UnitRace(unit)
else
race = UnitCreatureType(unit)
end
return race or L["<no %s>"]:format(RACE:lower())
end,
 
["[Rr][Bb]"] = function(unit)
local race
if UnitIsPlayer(unit) then
race = UnitRace(unit)
else
race = UnitCreatureType(unit)
end
return race or ""
end,
 
["[Hh]"] = function(unit)
if ActualValue(unit) then
return UnitHealth(unit).."/"..UnitHealthMax(unit)
else
return ("%.0f%%%%"):format(UnitHealth(unit))
end
end,
 
["[Hh][Pp]"] = function(unit)
return ("%.0f%%%%"):format(UnitHealth(unit)/UnitHealthMax(unit)*100)
end,
 
["[Mm][Aa]"] = function(unit)
local max = UnitManaMax(unit)
if max > 0 then
return UnitMana(unit).."/"..UnitManaMax(unit)
else
return L["<no %s>"]:format(MANA:lower())
end
end,
 
["[Mm][Aa][Bb]"] = function(unit)
local max = UnitManaMax(unit)
if max > 0 then
return UnitMana(unit).."/"..UnitManaMax(unit)
else
return ""
end
end,
 
["[Mm][Pp]"] = function(unit)
local max = UnitManaMax(unit)
if max > 0 then
return ("%.0f%%%%"):format(max > 0 and UnitMana(unit)/max*100 or 0)
else
return L["<no %s>"]:format(MANA:lower())
end
end,
 
["[Mm][Pp][Bb]"] = function(unit)
local max = UnitManaMax(unit)
if max > 0 then
return ("%.0f%%%%"):format(max > 0 and UnitMana(unit)/max*100 or 0)
else
return ""
end
end,
 
["[Ii][Cc]"] = function(unit)
local index = GetRaidTargetIndex(unit)
return index and "{"..(_G["RAID_TARGET_"..index]):lower().."}" or
L["<no %s>"]:format(EMBLEM_SYMBOL:lower())
end,
 
["[Ii][Cc][Bb]"] = function(unit)
local index = GetRaidTargetIndex(unit)
return index and "{"..(_G["RAID_TARGET_"..index]):lower().."}" or ""
end,
}
 
for initial, unit in pairs(unitInfoUnits) do
local noUnit = L["<no %s>"]:format(unit)
for suffix, func in pairs(unitInfoSuffixes) do
if initial ~= "" or suffix ~= "" then
local code = "%%"..initial..suffix
if subsBase[code] then
error(L["MacroTalk: Conflicting substitutions: "..code])
end
subsBase[code] = function()
return UnitExists(unit) and func(unit) or noUnit
end
end
end
end
 
local substitutions = {}
local i = 1
for k, v in pairs(subsBase) do
substitutions[i] = { code = k, func = v }
i = i + 1
end
 
sort(substitutions, function(subs1, subs2)
return subs2.code:len() < subs1.code:len()
end)
 
local OrigSendChatMessage = SendChatMessage
function SendChatMessage(text, ...)
for _, substitution in ipairs(substitutions) do
local func = substitution.func
text = text:gsub(substitution.code,
type(func) == "function" and func() or func)
end
return OrigSendChatMessage(text, ...)
end