-
Notifications
You must be signed in to change notification settings - Fork 13
/
restrictions.lua
85 lines (76 loc) · 2.33 KB
/
restrictions.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
--[[
This file is part of HiT Hi FiT Hai's PtokaX scripts
Copyright: © 2014 HiT Hi FiT Hai group
Licence: GNU General Public Licence v3 https://www.gnu.org/licenses/gpl-3.0.html
--]]
function OnStartup()
package.path = Core.GetPtokaXPath().."scripts/?.lua;"..package.path
local tConfig = {
sBotName = SetMan.GetString( 21 ) or "PtokaX",
sRequirePath = "external.restrict.",
sHubAddress = SetMan.GetString( 2 ) or "localhost",
sProtocol = "http://",
}
tFlags, tList = {
bChat = true,
bShare = true,
}, {
"chat",
"share",
"nicks",
"search",
"passive",
}
tConfig.sHubFAQ = tConfig.sProtocol..tConfig.sHubAddress.."/faq/%s/%04d"
local function Error( sCode, iNum )
return tConfig.sHubFAQ:format( sCode:upper(), iNum )
end
for iIndex, sScript in ipairs( tList ) do
local r = require( tConfig.sRequirePath..sScript )
tList[sScript] = r( tConfig.sBotName, Error )
end
end
function ChatArrival( tUser, sMessage )
local sCmd, sData = sMessage:match "%b<> [-+/*?#](%a+) (%a+)|"
if ExecuteCommand( tUser, sCmd, sData ) then
return true
else
return tList.chat( tUser, sMessage, tFlags.bChat )
end
end
function UserConnected( tUser )
tList.nicks( tUser )
tList.passive( tUser )
end
function SearchArrival( tUser, sQuery )
return tList.passive( tUser ) or tList.share( tUser, sQuery, tFlags.bShare ) or tList.search( tUser, sQuery )
end
RegConnected, OpConnected = UserConnected, UserConnected
ConnectToMeArrival, MultiConnectToMeArrival, RevConnectToMeArrival = SearchArrival, SearchArrival, SearchArrival
ExecuteCommand = ( function()
local sReply = ( "<%s> { %%s } status updated to: %%s" ):format( SetMan.GetString(21) )
return function ( tUser, sCmd, sState )
if not ProfMan.GetProfilePermission( tUser.iProfile, 0 ) then return false end
if not ( sCmd and sState ) then return false end
local sCmd, sState, bState = sCmd:lower(), sState:lower()
if sCmd == "mainchat" then
if sState == "on" then
tFlags.bChat = false
elseif sState == "off" then
tFlags.bChat = true
end
bState = tFlags.bChat
elseif sCmd == "minshare" then
if sState == "on" then
tFlags.bShare = true
elseif sState == "off" then
tFlags.bShare = false
end
bState = tFlags.bShare
else
return false
end
Core.SendToUser( tUser, sReply:format(sCmd:upper(), tostring( bState )) )
return true
end
end )()