vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 local locals = KC_ITEMS_LOCALS.modules.chatlink
2  
3 KC_ChatLink = KC_ItemsModule:new({
4 type = "chatlink",
5 name = locals.name,
6 desc = locals.description,
7 cmdOptions = locals.chat,
8 dependencies = {"common"},
9 optPath = {"chatlink", "options"}
10 })
11  
12 KC_Items:Register(KC_ChatLink)
13  
14 function KC_ChatLink:Enable()
15 self:Hook("ChatEdit_OnTextChanged", "OnTextChanged")
16 end
17  
18 function KC_ChatLink:OnTextChanged()
19 local text = this:GetText();
20 if (not(strfind(text, "^/script") or strfind(text, "^/dump"))) then
21 this:SetText(self:ParseChatMessage(text))
22 end
23 self.Hooks["ChatEdit_OnTextChanged"].orig(this)
24 end
25  
26 function KC_ChatLink:ParseChatMessage(text)
27 if (self:GetOpt(self.optPath, "safe")) then
28 return string.gsub(text, "($[|]?[h]?)%[(.-)%]([|]?[h]?)", self.LinkifyName)
29 else
30 return string.gsub(text, "([|]?[h]?)%[(.-)%]([|]?[h]?)", self.LinkifyName)
31 end
32 end
33  
34 function KC_ChatLink.LinkifyName(head, text, tail)
35 if (head ~= "|h" and tail ~= "|h") then -- only linkify things text that isn't linked already
36 local link = KC_ChatLink:GetLinkByName(text);
37 if (link) then return link; end
38 end
39 return head.."["..text.."]"..tail;
40 end
41  
42 function KC_ChatLink:GetLinkByName(text)
43 local _, _, name, property = strfind(text, "(.-)(%((.-)%))?")
44  
45 name = (name and property) and string.gsub(name, " +$", "") or text
46  
47 local links = self:GetLinkTable(name)
48 if (links and getn(links) > 0) then
49 if (getn(links) > 1) then
50 self:PrintList(links)
51 end
52 return self.common:GetTextLink(format("item:%s:0:0:0", links[1]))
53 else
54 self:Msg("No Matching Links")
55 return nil;
56 end
57  
58 end
59  
60 function KC_ChatLink:GetLinkTable(name)
61 matches={}
62 name = strlower(name)
63 for i=1,25000 do
64 local n = GetItemInfo(i)
65 if(n and string.find(strlower(n),name,nil,1)) then
66 table.insert(matches,i)
67 end
68 end
69  
70 return matches
71 end
72  
73 function KC_ChatLink:PrintList(list)
74 local text = format("|cff00CC00LinkList(%s):|cff0099CC", getn(list))
75 local sep = ""
76  
77 for i,k in pairs(list) do
78 local name = GetItemInfo(k)
79 text = format("%s%s %s ", text, sep, name)
80 sep = ","
81 if (i == 10) then
82 text = text .. "..."
83 break
84 end
85 end
86  
87 self:Msg(text)
88 end
89  
90 ---
91  
92 function KC_ChatLink:mode()
93 local status = self:TogOpt(self.optPath, "safe")
94 self:Result(locals.msg.mode, status, locals.map)
95 end