-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
278 lines (262 loc) · 11.1 KB
/
init.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
require("ts3init")
linkConvert = {
info = {
name = "Link Converter",
prefix = "LC",
folder = "linkConvert",
ext = "lua",
ver = "1.0",
author = "Bluscream",
},
setting = { -- Edit below this line! --
active = true, -- Enable the script.
debug = true, -- The script shows debug messages.
onConnect = false, -- Check the client version of every client each time we connect?
},
functions = {
protocols = true, -- Should protocols be reparsed?
lmgtfy = true, -- Should we allow google'ing etc?
lmgtfy_prefix = "!",
updateReminder = true, -- Should clients get a notification message when they use a outdated client?
offlineMSGReminder = true, -- Shoudl clients get a notification message when they have unread offline messages?
}, -- Edit above this line! --
protocols = { "steam://", "minecraft://", "repz://", "channelid://"},
var = {
ownVersion = "3.0.18.2", -- Change this to 0 to use your client's version.
ownBuild = 1445512488, -- Change this to 0 to use your client's build number.
requestedclientvars = false,
requestedclientvarsclid = 0,
},
notified = {
update = {},
offlinemsg = {},
},
-- commands = { "ip" = "http://whatismyipaddress.com/ip/%search%" }
}
local dbg_i = 0
function dbglog(msg)
if linkConvert.setting.debug then
dbg_i = dbg_i+1
ts3.printMessageToCurrentTab("["..dbg_i.."] > [B][U][COLOR=WHITE]"..msg.."[COLOR=WHITE][U][B]")
end
end
local function mysplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
function informedClients()
local str = "Outdated Clients: "
for i=1, #linkConvert.notified.update do
str = str..linkConvert.notified.update[i]..", "
end
ts3.printMessageToCurrentTab(str)
str = "Unread Offline Messages: "
for i=1, #linkConvert.notified.offlinemsg do
str = str..linkConvert.notified.offlinemsg[i]..", "
end
ts3.printMessageToCurrentTab(str)
str = nil;
end
local function reply(sCHID, msg, mode, target)
oldMSG = msg
if mode == 1 and target then
ts3.requestSendPrivateTextMsg(sCHID, msg, target)
elseif mode == 2 then
ts3.requestSendChannelTextMsg(sCHID, msg, ts3.getChannelOfClient(sCHID, ts3.getClientID(sCHID)))
elseif mode == 3 then
ts3.requestSendServerTextMsg(sCHID, msg)
else
ts3.printMessageToCurrentTab(msg)
end
end
local function lmgtfy(sCHID, message, targetMode, fromID)
if string.match( message, linkConvert.functions.lmgtfy_prefix ) then
for i=1, #linkConvert.commands do
local command = string.match( message, linkConvert.commands[i][1] )
local returner = string.match( message, linkConvert.commands[i][2] )
end
local sendMsg = string.gsub( message, "!whois", "" )
end
end
local function checkClientVersion(sCHID, clientID)
local clientVersion = ts3.getClientVariableAsString(sCHID, clientID, ts3defs.ClientProperties.CLIENT_VERSION)
if clientVersion then
clientVersion = string.gsub(clientVersion, "]", "")
clientVersion = mysplit(clientVersion, " [Build: ")
if tonumber(clientVersion[2]) < tonumber(linkConvert.var.ownBuild) then
local msg = "[b][url=https://r4p3.net/threads/lua-linkconvert-with-update-reminder-and-unread-messages-reminder.1500/]Teamspeak 3 Update reminder[/url] by [url=https://r4p3.net/members/bluscream.53/]Bluscream[/url][/b]"
msg = msg.."\n\nYou use a outdated Teamspeak 3 Client ([color=red]"..clientVersion[1].."[/color]). You should update your client with \"Help->Check for Update\" or directly on the [URL=http://www.teamspeak.com/downloads#client]Teamspeak website[/URL] to [color=green]"..linkConvert.var.ownVersion.."[/color]."
msg = msg.."\n\nDu nutzt einen veralteten Teamspeak 3 Client ([color=red]"..clientVersion[1].."[/color]). Du solltest ihn über \"Hilfe->Nach Aktualisierung suchen\" oder direkt über die [URL=http://www.teamspeak.com/downloads#client]Teamspeak Webseite[/URL] auf die Version [color=green]"..linkConvert.var.ownVersion.."[/color] updaten."
reply(sCHID, msg, 1, clientID)
local clientUID = ts3.getClientVariableAsString(sCHID, clientID, ts3defs.ClientProperties.CLIENT_UNIQUE_IDENTIFIER)
table.insert(linkConvert.notified.update, clientUID)
end
end
end
local function checkClientOfflineMSGs(sCHID, clientID)
local unreadMSGs = ts3.getClientVariableAsInt(sCHID, clientID, ts3defs.ClientProperties.CLIENT_UNREAD_MESSAGES)
if unreadMSGs then
if unreadMSGs > 0 then
local msg = "[b][url=https://r4p3.net/threads/lua-linkconvert-with-update-reminder-and-unread-messages-reminder.1500/]Teamspeak 3 Offline Message reminder[/url] by [url=https://r4p3.net/members/bluscream.53/]Bluscream[/url][/b]"
msg = msg.."\n\nYou have [color=red]"..unreadMSGs.."[/color] unread offline messages. Use \"Tools->Offline Messages\" or [CTRL]+[O] to read them."
msg = msg.."\n\nDu hast [color=red]"..unreadMSGs.."[/color] ungelesene offline Nachrichten. Nutze \"Extras->Offline Nachrichten\" oder [STRG]+[O] um sie zu lesen."
reply(sCHID, msg, 1, clientID)
local clientUID = ts3.getClientVariableAsString(sCHID, clientID, ts3defs.ClientProperties.CLIENT_UNIQUE_IDENTIFIER)
table.insert(linkConvert.notified.offlinemsg, clientUID)
end
end
end
local function checkAllClients(sCHID)
-- Get Self ID
local myClientID, error = ts3.getClientID(serverConnectionHandlerID)
if error ~= ts3errors.ERROR_ok then
print("Error getting own client ID: " .. error)
return
end
if myClientID == 0 then
ts3.printMessageToCurrentTab("Not connected")
return
end
local clients, error = ts3.getClientList(serverConnectionHandlerID)
if error == ts3errors.ERROR_not_connected then
ts3.printMessageToCurrentTab("Not connected")
return
elseif error ~= ts3errors.ERROR_ok then
print("Error getting client list: " .. error)
return
end
for i=1, #clients do
if clients[i] ~= myClientID then
checkClient(sCHID, clients[i])
end
end
end
local function checkClient(sCHID, clientID)
if linkConvert.functions.updateReminder then
local clientUID = ts3.getClientVariableAsString(sCHID, clientID, ts3defs.ClientProperties.CLIENT_UNIQUE_IDENTIFIER)
for i=1, #linkConvert.notified.update do
if clientUID == linkConvert.notified.update[i] then
dbglog("Ignoring Client "..clientUID.." cause he already got informed about his outdated version.")
return
end
end
linkConvert.var.requestedclientvarsclid = clientID
linkConvert.var.requestedclientvars = true
ts3.requestClientVariables(sCHID, clientID)
end
if linkConvert.functions.offlineMSGReminder then
local clientUID = ts3.getClientVariableAsString(sCHID, clientID, ts3defs.ClientProperties.CLIENT_UNIQUE_IDENTIFIER)
for i=1, #linkConvert.notified.offlinemsg do
if clientUID == linkConvert.notified.offlinemsg[i] then
dbglog("Ignoring Client "..clientUID.." cause he already got informed about his offline messages.")
return
end
end
checkClientOfflineMSGs(sCHID, clientID)
end
end
local function getOwnVersion(sCHID)
if linkConvert.functions.updateReminder then
if linkConvert.var.ownBuild == 0 then
local ownBuild = ts3.getClientLibVersionNumber()
ownBuild = mysplit(ownBuild, ".")
linkConvert.var.ownBuild = ownBuild[1]
end
if linkConvert.var.ownVersion == 0 then
local ownVersion = ts3.getClientLibVersion()
ownVersion = string.gsub(ownVersion, "]", "")
ownVersion = mysplit(ownVersion, " [Build: ")
linkConvert.var.ownVersion = ownVersion[1]
end
end
end
local function onTextMessageEvent(sCHID, targetMode, toID, fromID, fromName, fromUniqueIdentifier, message, ffIgnored)
if not oldMSG then oldMSG = "" end
if linkConvert.setting.active and oldMSG ~= message then
str = nil
-- TeamViewer Session
local str = string.match(message, 's%d%d%-%d%d%d%-%d%d%d') or string.match(message, '%d%d%d% %d%d%d% %d%d%d')
if str then
reply(sCHID, "Join TeamViewer session via [url=tvjoinv8://go.teamviewer.com?mid="..str:gsub("%-", "").."]Client[/url] or [url=http://get.teamviewer.com/v11/"..str:gsub("%-", "").."]Web[/url]", targetMode, fromID)
end
str = nil
-- TeamViewer Meeting
local str = string.match(message, 'm%d%d%-%d%d%d%-%d%d%d')
if str then
str = str:gsub("%-", "");str = str:gsub("%s", "");
reply(sCHID, "Join TeamViewer meeting via [url=tvjoinv8://go.teamviewer.com?mid="..str.."]Client[/url] or [url=https://go.teamviewer.com/v11/flash.aspx?tid="..str.."&lng=de]Web[/url]", targetMode, fromID)
end
str = nil
-- IPs
local s = string.match(message, '%d+%.%d+%.%d+%.%d+%:%d+'); local s2 = string.match(message, '%d+%.%d+%.%d+%.%d+')
if s then str = s elseif s2 then str = s2 end
s = nil; s2 = nil;
if str then
reply(sCHID,"[url=http://"..str.."]Web[/url] | [url=ts3server://"..str.."]TS³ Server[/url] |[url=minecraft://"..str.."]MC Server[/url]", 0, fromID)
end
str = nil
-- if linkConvert.function.protocols then
for i, protocol in ipairs(linkConvert.protocols) do
if string.match(message, protocol.."[^%s]*") and ts3.getClientID(sCHID) ~= fromID then
reply(sCHID,"[url]"..string.match(message, protocol.."[^%s]*").."[/url]", targetMode, fromID)
end
end
-- end
-- if linkConvert.function.lmgtfy then -- LMGTFY
-- lmgtfy(sCHID, message, targetMode, fromID)
-- end
end
local afkMSG = "Du bist nun seit 15 abwesend. Wenn du 20 Minuten abwesend bist wirst du zu \"Bot - AFK\" verschoben!"
if message == afkMSG and ts3.getClientID(sCHID) ~= fromID then
ts3.requestSendPrivateTextMsg(sCHID, "AntiAFK", fromID)
end
end
local function onConnectStatusChangeEvent(serverConnectionHandlerID, status, errorNumber)
if linkConvert.setting.active and linkConvert.setting.onConnect then
if status == ts3defs.ConnectStatus.STATUS_CONNECTION_ESTABLISHED then
if linkConvert.functions.updateReminder or linkConvert.functions.offlineMSGReminder then
getOwnVersion(sCHID)
if linkConvert.setting.onConnect then
checkAllClients(sCHID)
end
end
end
end
end
local function onClientMoveEvent(sCHID, clientID, oldChannelID, newChannelID, visibility, moveMessage)
if clientID ~= ts3.getClientID(sCHID) then
if oldChannelID == "0" or oldChannelID == 0 then
if linkConvert.functions.updateReminder or linkConvert.functions.offlineMSGReminder then
checkClient(sCHID, clientID)
end
end
end
end
local function onUpdateClientEvent(sCHID, clientID, invokerID, invokerName, invokerUniqueIdentifier)
if linkConvert.functions.updateReminder then
if linkConvert.var.requestedclientvars and linkConvert.var.requestedclientvarsclid == clientID then
local platform = ts3.getClientVariableAsString(sCHID,clientID,ts3defs.ClientProperties.CLIENT_PLATFORM)
if platform == "Windows" or platform == "Linux" or platform == "OS X" then
checkClientVersion(sCHID, clientID)
end
linkConvert.var.requestedclientvars = false
requestedclientvarsclid = nil
end
end
end
getOwnVersion(sCHID)
local events = {
onTextMessageEvent = onTextMessageEvent,
onConnectStatusChangeEvent = onConnectStatusChangeEvent,
onClientMoveEvent = onClientMoveEvent,
onUpdateClientEvent = onUpdateClientEvent
}
ts3.printMessageToCurrentTab(linkConvert.info.name.." loaded.")
ts3RegisterModule(linkConvert.info.folder, events)