diff 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
line wrap: on
line diff
--- a/Model.lua	Thu May 07 02:52:23 2009 +1000
+++ b/Model.lua	Tue May 12 00:57:59 2009 +1000
@@ -48,10 +48,24 @@
 Squawks.Main = {}
 Squawks.Owners = {}
 
+
+local classcolours = {
+["DEATHKNIGHT"] = "C41F3B",
+["DRUID"] = "FF7D0A",
+["HUNTER"] = "ABD473",
+["MAGE"] = "69CCF0",
+["PALADIN"] = "F58CBA",
+["PRIEST"] = "FFFFFF",
+["ROGUE"] = "FFF569",
+["SHAMAN"] = "2459FF",
+["WARLOCK"] = "9482C9",
+["WARRIOR"] = "C79C6E",
+}
+	
 local function wrap(str, limit)
   limit = limit or 72
-  local here = 1
-  return str:gsub("(%s+)()(%S+)()",
+	local here = 1
+  return str:gsub("|c%x-|H.-|h(.-)|h|r", "%1"):gsub("(%s+)()(%S+)()",
                           function(sp, st, word, fi)
                             if fi-here > limit then
                               here = st 
@@ -60,19 +74,21 @@
                           end)
 end
 
-function Squawks:new(Message, Owner)
+function Squawks:new(Message, Owner, Class, ReplyStamp)
+	View:Print("New: "..ReplyStamp)
 	local o = {}
 	o.Owner = Owner or UnitName("player")
 	o.Message = wrap(Message)
 	o.Time = time()
 	local reply, to = strsplit("@", ((strsplit(" ", Message))))
 	if reply == "" then
-		o.ReplyTo = to
+		o.ReplyTo = to:match("%P+") -- Get everything except punctuation
+		o.ReplyStamp = ReplyStamp
 	end
 
 	o.Related = {}
 
-	for word in string.gmatch(Message, "@(%a+)") do
+	for word in string.gmatch(Message, "@(%S+)") do
 		if word ~= o.ReplyTo or "" then
 			table.insert(o.Related, word)
 		end
@@ -84,13 +100,22 @@
 
 	table.insert(self.Main, o)
 	
+	if not self.Squawkers[Owner] then
+		self.Squawkers[Owner] = {name = Owner, class=Class}
+	end
+
 	if not self.Owners[Owner] then
 		self.Owners[Owner] = {}
 	end
+
 	table.insert(self.Owners[Owner], o)
 	return o
 end
 
+function Squawks:OwnerString(squawk)
+	return "|cff"..classcolours[self.Squawkers[squawk.Owner].class or "WARRIOR"]..squawk.Owner.."|r"
+end
+
 function Squawks:Reload()
 	for _,squawk in ipairs(Model.Squawks.Main) do
 		if not self.Owners[squawk.Owner] then