Mercurial > wow > squawk
comparison Squawk.lua @ 14:18c33a32ba31
Now supresses 'X Player is not online' messages when broadcasting to followers
Tooltip limited to 10 most recent
| author | wobin |
|---|---|
| date | Fri, 24 Apr 2009 15:19:43 +1000 |
| parents | 0ca5ec0b7502 |
| children | 9e61a930b822 |
comparison
equal
deleted
inserted
replaced
| 13:0ca5ec0b7502 | 14:18c33a32ba31 |
|---|---|
| 35 Settings.Requested = Model.db.profile.Requested | 35 Settings.Requested = Model.db.profile.Requested |
| 36 Settings.Blocked = Model.db.profile.Blocked | 36 Settings.Blocked = Model.db.profile.Blocked |
| 37 Settings.Private = Model.db.profile.Private | 37 Settings.Private = Model.db.profile.Private |
| 38 | 38 |
| 39 LibStub("AceComm-3.0"):Embed(Controller) | 39 LibStub("AceComm-3.0"):Embed(Controller) |
| 40 LibStub("AceTimer-3.0"):Embed(Controller) | |
| 40 Controller:RegisterComm("Squawk", Controller.ReceiveMessage) | 41 Controller:RegisterComm("Squawk", Controller.ReceiveMessage) |
| 41 | |
| 42 LibStub("AceConsole-3.0"):Embed(View) | 42 LibStub("AceConsole-3.0"):Embed(View) |
| 43 | |
| 43 end | 44 end |
| 44 | 45 |
| 45 -- Model -- | 46 -- Model -- |
| 46 --[[ | 47 --[[ |
| 47 --Each Squawk will have the following information: | 48 --Each Squawk will have the following information: |
| 114 | 115 |
| 115 return o | 116 return o |
| 116 end | 117 end |
| 117 | 118 |
| 118 function Squawk:Sort(Squawks) | 119 function Squawk:Sort(Squawks) |
| 119 return table.sort(Squawks, function(a,b) return a.Time < b.Time end) | 120 table.sort(Squawks, function(a,b) return a.Time > b.Time end) |
| 121 return Squawks | |
| 120 end | 122 end |
| 121 | 123 |
| 122 function Squawk:GetOwn(Squawks) | 124 function Squawk:GetOwn(Squawks) |
| 123 local mine = {} | 125 local mine = {} |
| 124 for _, squawk in ipairs(Squawks) do | 126 for _, squawk in ipairs(Squawks) do |
| 125 if squawk.Owner == UnitName("player") then | 127 if squawk.Owner == UnitName("player") then |
| 126 table.insert(mine, squawk) | 128 table.insert(mine, squawk) |
| 127 end | 129 end |
| 128 end | 130 end |
| 129 return self:Sort(mine) | 131 return self:Sort(mine) |
| 132 end | |
| 133 | |
| 134 function Squawk:GetLast10(Squawks) | |
| 135 local mine = {} | |
| 136 local limit = #Squawks < 10 and #Squawks or 10 | |
| 137 | |
| 138 Squawks = Squawk:Sort(Squawks) | |
| 139 | |
| 140 for i=1,limit do | |
| 141 table.insert(mine, Squawks[i]) | |
| 142 end | |
| 143 return mine | |
| 130 end | 144 end |
| 131 | 145 |
| 132 function Settings:IsPrivate() | 146 function Settings:IsPrivate() |
| 133 return Settings.Private | 147 return Settings.Private |
| 134 end | 148 end |
| 246 table.insert(Model.Squawks, Squawk:new(Message, Name)) | 260 table.insert(Model.Squawks, Squawk:new(Message, Name)) |
| 247 View:UpdateSquawkList() | 261 View:UpdateSquawkList() |
| 248 end | 262 end |
| 249 end | 263 end |
| 250 | 264 |
| 265 local trigger | |
| 266 local function RepressFailure(frame, event, ...) | |
| 267 if arg1:match(string.gsub(ERR_CHAT_PLAYER_NOT_FOUND_S, "%%s", "(.*)")) then | |
| 268 if trigger then Controller:CancelTimer(trigger, true) end | |
| 269 trigger = Controller:ScheduleTimer( | |
| 270 function() | |
| 271 ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", RepressFailure) | |
| 272 end, 3) -- Give it three seconds and then remove the filter. | |
| 273 return true | |
| 274 else | |
| 275 return false, unpack(...) | |
| 276 end | |
| 277 end | |
| 278 | |
| 251 function Controller:SendNewSquawk(Message) | 279 function Controller:SendNewSquawk(Message) |
| 252 if not Settings:IsPrivate() then | 280 if not Settings:IsPrivate() then |
| 253 self:SendMessageToGuild("#Squawk|"..UnitName("player").."|"..Message) | 281 self:SendMessageToGuild("#Squawk|"..UnitName("player").."|"..Message) |
| 254 end | 282 end |
| 255 | 283 |
| 256 self:AddANewSquawk(UnitName("player"), Message) | 284 self:AddANewSquawk(UnitName("player"), Message) |
| 257 | |
| 258 for name, _ in pairs(Settings.Following) do | 285 for name, _ in pairs(Settings.Following) do |
| 259 self:SendMessageToTarget(name, "#Squawk|"..UnitName("player").."|"..Message) | 286 self:SendMessageToTarget(name, "#Squawk|"..UnitName("player").."|"..Message) |
| 260 end | 287 end |
| 261 end | 288 end |
| 262 | 289 |
| 272 Settings:AddFollower(Name) | 299 Settings:AddFollower(Name) |
| 273 View:NotifyOfNewFollower(Name) | 300 View:NotifyOfNewFollower(Name) |
| 274 self:SendMessageToTarget(Name, "#Follow|"..UnitName("player")) | 301 self:SendMessageToTarget(Name, "#Follow|"..UnitName("player")) |
| 275 end | 302 end |
| 276 | 303 |
| 304 | |
| 305 | |
| 277 function Controller:SendMessageToTarget(Name, Message) | 306 function Controller:SendMessageToTarget(Name, Message) |
| 307 ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", RepressFailure) | |
| 278 self:SendCommMessage("Squawk", Message, "WHISPER", Name) | 308 self:SendCommMessage("Squawk", Message, "WHISPER", Name) |
| 279 end | 309 end |
| 280 | 310 |
| 281 function Controller:SendMessageToGuild(Message) | 311 function Controller:SendMessageToGuild(Message) |
| 282 self:SendCommMessage("Squawk", Message, "GUILD") | 312 self:SendCommMessage("Squawk", Message, "GUILD") |
| 293 function Controller:ReceiveMessage(Message, Distribution, Sender) | 323 function Controller:ReceiveMessage(Message, Distribution, Sender) |
| 294 local command, name, info = strsplit("|",Message) | 324 local command, name, info = strsplit("|",Message) |
| 295 View:Print(Distribution..":"..Message) | 325 View:Print(Distribution..":"..Message) |
| 296 Parse[command](Controller, name, info, Distribution) | 326 Parse[command](Controller, name, info, Distribution) |
| 297 end | 327 end |
| 328 | |
| 298 -- View -- | 329 -- View -- |
| 299 | 330 |
| 300 function View:UpdateSquawkList() | 331 function View:UpdateSquawkList() |
| 301 self:Print("Updated Squawk List") | 332 self:Print("Updated Squawk List") |
| 302 self:ShowMeMySquawks() | 333 self:ShowMeMySquawks() |
| 385 | 416 |
| 386 function LDBFeed:OnEnter() | 417 function LDBFeed:OnEnter() |
| 387 local tooltip = QTip:Acquire("Squawk",4, "LEFT", "LEFT", "LEFT", "RIGHT") | 418 local tooltip = QTip:Acquire("Squawk",4, "LEFT", "LEFT", "LEFT", "RIGHT") |
| 388 self.tooltip = tooltip | 419 self.tooltip = tooltip |
| 389 tooltip:AddHeader('Squawk') | 420 tooltip:AddHeader('Squawk') |
| 390 for i,squawk in ipairs(Model.Squawks) do | 421 for i,squawk in ipairs(Squawk:GetLast10(Model.Squawks)) do |
| 391 if #squawk.Message > 79 then | 422 if #squawk.Message > 79 then |
| 392 local head = true | 423 local head = true |
| 393 local message = {strsplit("\n",squawk.Message)} | 424 local message = {strsplit("\n",squawk.Message)} |
| 394 for _,line in ipairs(message) do | 425 for _,line in ipairs(message) do |
| 395 if head then | 426 if head then |
