-
Notifications
You must be signed in to change notification settings - Fork 5
/
serverscript.lua
105 lines (65 loc) · 1.83 KB
/
serverscript.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
-- credit: https://github.com/VioPaige
-- Services
local http = game:GetService("HttpService")
local rStorage = game:GetService("ReplicatedStorage")
-- Instances
-- Folders
local remoteFolder = rStorage:WaitForChild("Remotes")
-- Other
local getRemote = remoteFolder:WaitForChild("GetData")
local postRemote = remoteFolder:WaitForChild("PostData")
-- Variables
local api = "https://rocordbackend.herokuapp.com"
-- Functions
function getGuild()
local res = http:GetAsync(api ..'/get/guild')
res = http:JSONDecode(res)
return res
end
function getChannel(id)
local res = http:GetAsync(api ..'/get/channel/'.. id)
res = http:JSONDecode(res)
return res
end
function getMessages(channelid)
local res = http:GetAsync(api ..'/get/channelmessages/'.. channelid)
res = http:JSONDecode(res)
return res
end
function getAuthor(channelid, messageid)
local res = http:GetAsync(api ..'/get/messageauthor/'.. channelid ..'/'.. messageid)
res = http:JSONDecode(res)
return res
end
function postMessage(user, content, channelid)
local res = http:GetAsync(api ..'/post/message/'.. user ..'/'.. channelid ..'/'.. content)
--res = http:JSONDecode(res)
return res
end
function getRemote.OnServerInvoke(plr, reqtype, id, id2)
--print(plr, reqtype, id)
local result = nil
if reqtype == "guild" then
local res = getGuild()
result = res
elseif reqtype == "channel" then
local res = getChannel(id)
result = res
elseif reqtype == "messages" then
local res = getMessages(id)
for i, v in pairs(res) do
local author = getAuthor(v["channelId"], v["id"])
v["author"] = author
end
result = res
end
--print("success")
return result
end
function postRemote.OnServerInvoke(plr, message, channelid)
print(plr, message)
local result = nil
result = postMessage(plr.Name, message, channelid)
return result
end
-- Events