-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.lua
145 lines (114 loc) · 4.28 KB
/
main.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
135
136
137
138
139
140
141
142
143
144
145
--[[
Discord Notifier for AzerothCore & ElunaEngine
Created by: 0xCiBeR(https://github.com/0xCiBeR)
]]--
--[[
Config Flags Section -> EDIT TO YOUR LIKING!!
]]--
Config = {}
Config.hooks = {}
Config.eventOn = {}
-- By default, users are notified if any of the events are sent to Discord. Do you really want to disable this?
Config.privacyWarning = true
-- This is the global Discord Webhook to use if other specific Webhooks are not defined. IMPORTANT: Must always be defined since its used as fallback
Config.hooks.globalWebook = "https://discord.com/api/webhooks/............."
-- Webhook to send OnChat events
Config.hooks.PLAYER_EVENT_ON_CHAT = nil
-- Webhook to send OnWhisperChat events
Config.hooks.PLAYER_EVENT_ON_WHISPER = nil
-- Webhook to send OnGroupChat events
Config.hooks.PLAYER_EVENT_ON_GROUP_CHAT = nil
-- Webhook to send OnGuildChat events
Config.hooks.PLAYER_EVENT_ON_GUILD_CHAT = nil
-- Feature Flag for enabiling each event
Config.eventOn.PLAYER_EVENT_ON_CHAT = true
Config.eventOn.PLAYER_EVENT_ON_WHISPER = true
Config.eventOn.PLAYER_EVENT_ON_GROUP_CHAT = true
Config.eventOn.PLAYER_EVENT_ON_GUILD_CHAT = true
--[[
Event Mappings Section -- DO NOT TOUCH!!
]]--
local PLAYER_EVENT_ON_CHAT = 18
local PLAYER_EVENT_ON_WHISPER = 19
local PLAYER_EVENT_ON_GROUP_CHAT = 20
local PLAYER_EVENT_ON_GUILD_CHAT = 21
-- Misc
local PLAYER_EVENT_ON_LOGIN = 3
--[[
Utility Function Section -- DO NOT TOUCH!!
]]--
local function sendToDiscord(event, msg)
if msg and event then
local webhook = Config.hooks[event] or Config.hooks.globalWebook
HttpRequest("POST", webhook, '{"content": "'..msg..'"}', "application/json",
function(status, body, headers)
if status ~= 200 then
print("DiscordNotifier[Lua] Error when sending webhook to discord. Response body is: "..body)
end
end)
end
end
--[[
Events Section -- DO NOT TOUCH!!
]]--
-- OnChat
local function OnChat(event, player, msg, Type, lang)
if Config.eventOn.PLAYER_EVENT_ON_CHAT then
local name = player:GetName()
local guid = player:GetGUIDLow()
sendToDiscord("PLAYER_EVENT_ON_CHAT", '__CHAT__ -> **|'..guid..'| '..name..'**: '..msg)
end
end
-- OnWhisperChat
local function OnWhisperChat(event, player, msg, Type, lang, receiver)
if Config.eventOn.PLAYER_EVENT_ON_WHISPER then
local sName = player:GetName()
local sGuid = player:GetGUIDLow()
local rName = receiver:GetName()
local rGuid = receiver:GetGUIDLow()
sendToDiscord("PLAYER_EVENT_ON_WHISPER", '__WHISPER__ -> **|'..sGuid..'| '..sName..' -> |'..rGuid..'| '..rName..'**: '..msg)
end
end
-- OnGroupChat
local function OnGroupChat(event, player, msg, Type, lang, group)
local name = player:GetName()
local guid = player:GetGUIDLow()
local leaderGuid = group:GetLeaderGUID()
local leader = GetPlayerByGUID(leaderGuid)
local lName = leader:GetName()
local lGuidLow = leader:GetGUIDLow()
sendToDiscord("PLAYER_EVENT_ON_GROUP_CHAT", '__GROUP CHAT__ -> **|'..guid..'| '..name..'**: '..msg..' **[LEADER -> '..lName..'('..lGuidLow..')]**')
end
-- OnGuildChat
local function OnGuildChat(event, player, msg, Type, lang, guild)
local name = player:GetName()
local guid = player:GetGUIDLow()
local gName = guild:GetName()
local gId = guild:GetId()
sendToDiscord("PLAYER_EVENT_ON_GUILD_CHAT", '__GUILD__ -> **[ |'..gId..'| -> '..gName..'] |'..guid..'| '..name..'**: '..msg)
end
--[[
Register Events Section -- DO NOT TOUCH!!
]]--
-- OnChat
RegisterPlayerEvent(PLAYER_EVENT_ON_CHAT, OnChat)
-- OnWhisperChat
RegisterPlayerEvent(PLAYER_EVENT_ON_WHISPER, OnWhisperChat)
-- OnGroupChat
RegisterPlayerEvent(PLAYER_EVENT_ON_GROUP_CHAT, OnGroupChat)
-- OnGuildChat
RegisterPlayerEvent(PLAYER_EVENT_ON_GUILD_CHAT, OnGuildChat)
--[[
MISC -- DO NOT TOUCH!!
]]--
local function privacyAlert(event, player)
if Config.privacyWarning then
for i, v in pairs(Config.eventOn) do
if v == true then
player:SendBroadcastMessage("|cff00ff00[PRIVACY NOTICE] |cffff0000THIS SERVER IS CURRENTLY MONITORING AND FORWARDING TEXT MESSAGES SENT WITHIN THE SERVER TO DISCORD.")
break
end
end
end
end
RegisterPlayerEvent(PLAYER_EVENT_ON_LOGIN, privacyAlert)