Mercurial > wow > squawk
comparison Model.lua @ 19:431f2fce08f2
Added in link stripping
Coloured class names
Reply to specific squawk
Related squawks fixed
new arrow to indicate reply
limit to 140 characters
author | wobin |
---|---|
date | Tue, 12 May 2009 00:57:59 +1000 |
parents | a3328fffef5c |
children | 8df5d8ef2e27 |
comparison
equal
deleted
inserted
replaced
18:a3328fffef5c | 19:431f2fce08f2 |
---|---|
46 Model.Squawks = {} | 46 Model.Squawks = {} |
47 local Squawks = Model.Squawks | 47 local Squawks = Model.Squawks |
48 Squawks.Main = {} | 48 Squawks.Main = {} |
49 Squawks.Owners = {} | 49 Squawks.Owners = {} |
50 | 50 |
51 | |
52 local classcolours = { | |
53 ["DEATHKNIGHT"] = "C41F3B", | |
54 ["DRUID"] = "FF7D0A", | |
55 ["HUNTER"] = "ABD473", | |
56 ["MAGE"] = "69CCF0", | |
57 ["PALADIN"] = "F58CBA", | |
58 ["PRIEST"] = "FFFFFF", | |
59 ["ROGUE"] = "FFF569", | |
60 ["SHAMAN"] = "2459FF", | |
61 ["WARLOCK"] = "9482C9", | |
62 ["WARRIOR"] = "C79C6E", | |
63 } | |
64 | |
51 local function wrap(str, limit) | 65 local function wrap(str, limit) |
52 limit = limit or 72 | 66 limit = limit or 72 |
53 local here = 1 | 67 local here = 1 |
54 return str:gsub("(%s+)()(%S+)()", | 68 return str:gsub("|c%x-|H.-|h(.-)|h|r", "%1"):gsub("(%s+)()(%S+)()", |
55 function(sp, st, word, fi) | 69 function(sp, st, word, fi) |
56 if fi-here > limit then | 70 if fi-here > limit then |
57 here = st | 71 here = st |
58 return "\n"..word | 72 return "\n"..word |
59 end | 73 end |
60 end) | 74 end) |
61 end | 75 end |
62 | 76 |
63 function Squawks:new(Message, Owner) | 77 function Squawks:new(Message, Owner, Class, ReplyStamp) |
78 View:Print("New: "..ReplyStamp) | |
64 local o = {} | 79 local o = {} |
65 o.Owner = Owner or UnitName("player") | 80 o.Owner = Owner or UnitName("player") |
66 o.Message = wrap(Message) | 81 o.Message = wrap(Message) |
67 o.Time = time() | 82 o.Time = time() |
68 local reply, to = strsplit("@", ((strsplit(" ", Message)))) | 83 local reply, to = strsplit("@", ((strsplit(" ", Message)))) |
69 if reply == "" then | 84 if reply == "" then |
70 o.ReplyTo = to | 85 o.ReplyTo = to:match("%P+") -- Get everything except punctuation |
86 o.ReplyStamp = ReplyStamp | |
71 end | 87 end |
72 | 88 |
73 o.Related = {} | 89 o.Related = {} |
74 | 90 |
75 for word in string.gmatch(Message, "@(%a+)") do | 91 for word in string.gmatch(Message, "@(%S+)") do |
76 if word ~= o.ReplyTo or "" then | 92 if word ~= o.ReplyTo or "" then |
77 table.insert(o.Related, word) | 93 table.insert(o.Related, word) |
78 end | 94 end |
79 end | 95 end |
80 | 96 |
82 o.Related = nil | 98 o.Related = nil |
83 end | 99 end |
84 | 100 |
85 table.insert(self.Main, o) | 101 table.insert(self.Main, o) |
86 | 102 |
103 if not self.Squawkers[Owner] then | |
104 self.Squawkers[Owner] = {name = Owner, class=Class} | |
105 end | |
106 | |
87 if not self.Owners[Owner] then | 107 if not self.Owners[Owner] then |
88 self.Owners[Owner] = {} | 108 self.Owners[Owner] = {} |
89 end | 109 end |
110 | |
90 table.insert(self.Owners[Owner], o) | 111 table.insert(self.Owners[Owner], o) |
91 return o | 112 return o |
113 end | |
114 | |
115 function Squawks:OwnerString(squawk) | |
116 return "|cff"..classcolours[self.Squawkers[squawk.Owner].class or "WARRIOR"]..squawk.Owner.."|r" | |
92 end | 117 end |
93 | 118 |
94 function Squawks:Reload() | 119 function Squawks:Reload() |
95 for _,squawk in ipairs(Model.Squawks.Main) do | 120 for _,squawk in ipairs(Model.Squawks.Main) do |
96 if not self.Owners[squawk.Owner] then | 121 if not self.Owners[squawk.Owner] then |