Mercurial > wow > squawk
comparison Squawk.lua @ 0:2c267c596711
First import
Skeleton functionality, working on internals before anything
| author | wobin |
|---|---|
| date | Thu, 16 Apr 2009 17:26:19 +1000 |
| parents | |
| children | 188273d0efad |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:2c267c596711 |
|---|---|
| 1 -- A Twitter client of sorts for World of Warcraft | |
| 2 -- Author: Wobin | |
| 3 -- Email: wobster@gmail.com | |
| 4 -- | |
| 5 Squawk = LibStub("AceAddon-3.0"):NewAddon("Squawk", "AceDB-3.0") | |
| 6 | |
| 7 Squawk.Model = {} | |
| 8 Squawk.View = {} | |
| 9 Squawk.Controller = {} | |
| 10 | |
| 11 local Model = Squawk.Model | |
| 12 local View = Squawk.View | |
| 13 local Controller = Squawk.Controller | |
| 14 | |
| 15 Model.UserSettings = {} | |
| 16 local Settings = Model.UserSettings | |
| 17 | |
| 18 local defaults = { | |
| 19 profile = { | |
| 20 Squawks = {}, | |
| 21 Follower = {}, | |
| 22 Following = {}, | |
| 23 Blocked = {}, | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 function Squawk:OnInitialize() | |
| 28 Model.db = LibStub("AceDB-3.0"):New("SquawkDB", defaults) | |
| 29 Settings.Follower = Model.db.profile.Follower | |
| 30 Settings.Following = Model.db.profile.Following | |
| 31 Settings.Blocked = Model.db.profile.Blocked | |
| 32 Settings.Private = Model.db.profile.Private | |
| 33 | |
| 34 LibStub("AceComm-3.0"):Embed(Controller) | |
| 35 Controller:RegisterComm("Squawk", ReceiveMessage) | |
| 36 end | |
| 37 | |
| 38 -- Model -- | |
| 39 --[[ | |
| 40 --Each Squawk will have the following information: | |
| 41 -- * Owner (Name) | |
| 42 -- * Time (Epoch) | |
| 43 -- * Message (140 characters) | |
| 44 -- * ReplyTo (Name) | |
| 45 -- * Related (Names) | |
| 46 -- | |
| 47 -- Each User will have the following lists: | |
| 48 -- * Follower | |
| 49 -- * Following | |
| 50 -- * Blocked | |
| 51 -- * Privacy State | |
| 52 --]] | |
| 53 Model.Squawk = {} | |
| 54 local Squawk = Model.Squawk | |
| 55 | |
| 56 function Squawk:new(Message, Owner) | |
| 57 local o = {} | |
| 58 o.Owner = Owner or UnitName("player") | |
| 59 o.Message = Message | |
| 60 o.Time = os.time() | |
| 61 local reply, to = strsplit("@", ((strsplit(" ", Message)))) | |
| 62 if reply == "" then | |
| 63 o.ReplyTo = to | |
| 64 end | |
| 65 | |
| 66 o.Related = {} | |
| 67 | |
| 68 for word in string.gmatch(Message, "@(%a+)") do | |
| 69 if word ~= o.ReplyTo or "" then | |
| 70 table.insert(o.Related, word) | |
| 71 end | |
| 72 end | |
| 73 | |
| 74 return o | |
| 75 end | |
| 76 | |
| 77 function Squawk:Sort(Squawks) | |
| 78 return table.sort(Squawks, function(a,b) return a.Time < b.Time end) | |
| 79 end | |
| 80 | |
| 81 function Settings:IsPrivate() | |
| 82 return Settings.Private | |
| 83 end | |
| 84 | |
| 85 function Settings:AddFollower(Name) | |
| 86 table.insert(Settings.Follower, Name) | |
| 87 end | |
| 88 | |
| 89 function Settings:AddFollowing(Name) | |
| 90 table.insert(Settings.Following, Name) | |
| 91 end | |
| 92 | |
| 93 function Settings:AddBlock(Name) | |
| 94 table.insert(Settings.Blocked, Name) | |
| 95 end | |
| 96 | |
| 97 function Settings:RemoveFollower(Name) | |
| 98 for i,v in ipairs(Settings.Follower) do | |
| 99 if v == Name then | |
| 100 table.remove(Settings.Follower, i) | |
| 101 return | |
| 102 end | |
| 103 end | |
| 104 end | |
| 105 | |
| 106 function Settings:RemoveFollowing(Name) | |
| 107 for i,v in ipairs(Settings.Following) do | |
| 108 if v == Name then | |
| 109 table.remove(Settings.Following, i) | |
| 110 return | |
| 111 end | |
| 112 end | |
| 113 end | |
| 114 | |
| 115 function Settings:RemoveBlock(Name) | |
| 116 for i,v in ipairs(Settings.Blocked) do | |
| 117 if v == Name then | |
| 118 table.remove(Settings.Blocked, i) | |
| 119 return | |
| 120 end | |
| 121 end | |
| 122 end | |
| 123 | |
| 124 --Controller-- | |
| 125 | |
| 126 function Controller:TheyWantToFollowMe(Name) | |
| 127 if Settings:IsPrivate() then | |
| 128 self:PutForwardFollowRequest(Name) | |
| 129 self:SendMessageToTarget(Name, "#Pending|"..UnitName("player")) | |
| 130 else | |
| 131 Settings:AddFollower(Name) | |
| 132 View:NotifyOfNewFollower(Name) | |
| 133 self:SendMessageToTarget(Name, "#Follow|"..UnitName("player")) | |
| 134 end | |
| 135 end | |
| 136 | |
| 137 function Controller:IWantToFollowThem(Name) | |
| 138 | |
| 139 end | |
| 140 | |
| 141 function Controller:IAmNowFollowingThem(Name) | |
| 142 Settings:AddFollowing(Name) | |
| 143 View:NotifyOfNewFollowing(Name) | |
| 144 end | |
| 145 | |
| 146 function Controller:AddANewSquawk(Name, Message) | |
| 147 table.insert(Model.db.Squawks, Squawk:new(Message, Name)) | |
| 148 View:UpdateSquawkList() | |
| 149 end | |
| 150 | |
| 151 function Controller:SendMessageToTarget(Name, Message) | |
| 152 self:SendCommMessage("Squawk", Message, "WHISPER", Name, "BULK") | |
| 153 end | |
| 154 | |
| 155 function Controller:SendMessageToGuild(Message) | |
| 156 self:SendCommMessage("Squawk", Message, "GUILD") | |
| 157 end | |
| 158 | |
| 159 local Parse = { | |
| 160 ["#Pending"] = View:NotifyOfPending, | |
| 161 ["#Follow"] = Controller:IAmNowFollowingThem, | |
| 162 ["#Squawk"] = Controller:AddANewSquawk | |
| 163 } | |
| 164 | |
| 165 function Controller:ReceiveMessage(Prefix, Message, Distribution, Sender) | |
| 166 local command, name, info = strsplit("|",Message) | |
| 167 Parse[command](name, info) | |
| 168 end | |
| 169 -- View -- | |
| 170 | |
| 171 function View:UpdateSquawkList() | |
| 172 end | |
| 173 | |
| 174 function View:NotifyOfPending() | |
| 175 end | |
| 176 | |
| 177 function View:NotifyOfNewFollowing(Name) | |
| 178 end | |
| 179 | |
| 180 function View:NotifyOfNewFollower(Name) | |
| 181 end |
