-
Notifications
You must be signed in to change notification settings - Fork 4
/
chat.lua
134 lines (113 loc) · 3.75 KB
/
chat.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
-- chat message interpretation
local _, addonData = ...
local L = LibStub("AceLocale-3.0"):GetLocale("SteaSummon")
local gossip = addonData.gossip
local debug = addonData.debug
local settings = addonData.settings
local summon = addonData.summon
local raid = addonData.raid
local chat = {
init = function(_)
debug:registerCategory("chat")
end,
callback = function (_, event, msg, servername, ...)
local me, _ = UnitName("player")
-- don't want randos adding themselves
local player, server = strsplit("-", servername)
if event == "CHAT_MSG_SAY" and player ~= me then
return
end
db("chat", "testing chat for keywords")
if player == me then
if msg and msg:find("!SS") == 1 then
local _, cmd, args = strsplit(" ", msg)
if cmd == nil then cmd = "list" end
if args == nil then args = "" end
cmd = string.lower(cmd)
db("chat","Received command : " .. cmd .. " " .. args)
if cmd == L["list"] then
local waitlist = summon:getWaiting()
cprint(L["Summon waiting list"])
count = 0
for _,waiting in pairs(waitlist) do
local pats = {["%%name"] = waiting[1], ["%%number"] = waiting[2]}
local s = L["%name waiting: %number seconds"]
s = tstring(s, pats)
cprint(s)
count = count + 1
end
local pats = {["%%count"] = count}
local s = L["%count waiting"]
s = tstring(s, pats)
cprint(s)
end
if cmd == L["debug"] then
if args == L["on"] then settings:debug(true)
elseif args == L["off"] then settings:debug(false)
else settings:debug(not settings:debug())
end
local offon = L["off"]
if settings:debug() then offon = L["on"] end
cprint("Debugging: ", offon)
end
if cmd == L["add"] then
-- add someone to list
if args ~= "" then
gossip:add(args, true )
end
end
end
end
if msg then
if string.sub(msg, 1,1) == "-" and settings:findSummonWord(string.sub(msg, 2)) then
name, server = strsplit("-", servername)
gossip:arrived(name, true)
elseif settings:findSummonWord(msg) then
-- someone wants a summon
name, server = strsplit("-", servername)
db("chat","adding ", name, "to summon list")
if IsInGroup(player) or (player == me and settings:debug()) then
gossip:add(player, event == "CHAT_MSG_WHISPER" )
end
elseif event == "CHAT_MSG_WHISPER" then
if raid:isInvTrigger(msg) then
raid:whisperedTrigger(player)
else
addonData.alt:whispered(player, msg)
end
end
end
end,
raid = function(self, msg, player)
if IsInRaid() then
self:sendChat(msg, "RAID", "RAID", player)
else
self:sendChat(msg, "PARTY", "PARTY", player)
end
end,
say = function(self, msg, player)
self:sendChat(msg, "SAY", "SAY", player)
end,
whisper = function(self, msg, player)
self:sendChat(msg, "WHISPER", player, player)
end,
sendChat = function(_, msg, channel, channel2, to)
db("chat", "sendChat ", msg, " ", channel, " ", to)
if msg ~= nil and msg ~= "" then
-- substitute variables in message
local trigphrase = SteaSummonSave.summonWords[1]
if trigphrase == nil then
trigphrase = ""
end
local patterns = {["%%p"] = to,
["%%l"] = GetMinimapZoneText(),
["%%z"] = GetZoneText(),
["%%t"] = trigphrase
}
msg = tstring(msg, patterns)
msg = "[SteaSummon] " .. msg
SendChatMessage(msg,channel,channel2,to)
end
end
}
addonData.chat = chat