-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
176 lines (159 loc) · 4.43 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
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
local rblx = {}
local RBXScriptConnection = {}; do
RBXScriptConnection.__index = RBXScriptConnection
function RBXScriptConnection.new(func)
return setmetatable({
func = func,
Connected = true
}, RBXScriptConnection)
end
function RBXScriptConnection:Disconnect()
self.func = function() end
self.Connected = false
end
end
local RBXScriptSignal = {}; do
RBXScriptSignal.__index = RBXScriptSignal
local runService = game:GetService("RunService")
function RBXScriptSignal.new()
return setmetatable({
func = function() end,
eventIns = Instance.new("IntValue"),
connections = {},
once = {}
}, RBXScriptSignal)
end
function RBXScriptSignal:Fire(...)
for index, connection in pairs(self.connections) do
if connection.Connected then
task.spawn(connection.func, ...)
else
self.connections[index] = nil
end
end
for index, connection in pairs(self.once) do
if connection.Connected then
task.spawn(connection.func, ...)
end
end
self.once = {}
self.eventIns.Value += 1
end
function RBXScriptSignal:Connect(func)
self.connections[func] = RBXScriptConnection.new(func)
return self.connections[func]
end
function RBXScriptSignal:Wait()
self.eventIns.Changed:Wait()
end
function RBXScriptSignal:Once(func)
self.once[func] = RBXScriptConnection.new(func)
return self.once[func]
end
end
local message = {}; do
message.__index = message
function message.new(content: string, author: Player)
local self = setmetatable({}, message)
self.content = content
self.author = author
return self
end
end
local ctx = {}; do
function ctx.new(message, author)
return {
message = message,
author = author
}
end
end
local client = {}; do
client.services = {
players = game:GetService("Players");
replicatedstorage = game:GetService("ReplicatedStorage")
};
client.events = {
PlayerAdded = client.services.players.PlayerAdded,
PlayerRemoving = client.services.players.PlayerRemoving,
OnMessage = RBXScriptSignal.new()
};
client.commands = {}
client.__index = client
function client:Init()
if self.services.replicatedstorage:FindFirstChild("DefaultChatSystemChatEvents") then
print("Old Chat")
self.services.replicatedstorage.DefaultChatSystemChatEvents.OnMessageDoneFiltering.OnClientEvent:Connect(function(messageData)
print(typeof(messageData.FromSpeaker))
self.events.OnMessage:Fire(message.new(messageData.Message, game.Players[messageData.FromSpeaker]))
end)
else
print("New Chat")
local function onChat(author, msg)
self.events.OnMessage:Fire(message.new(msg, author))
end
for index, player in pairs(self.services.players:GetPlayers()) do
player.Chatted:Connect(function(msg)
onChat(player, msg)
end)
end
self.events.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
onChat(player, msg)
end)
end)
end
self.events.OnMessage:Connect(function(msg)
self:HandleMessage(msg)
end)
end
function client:HandleMessage(msg)
local player = msg.author
local message = msg.content
if string.sub(message, 1, #self.Prefix) == self.Prefix then
local spaceSplits = string.split(message, " ")
local commandName = string.sub(spaceSplits[1], #self.Prefix + 1, #spaceSplits[1])
local callback = self.Commands[commandName]
if callback then
local args = {}
if #spaceSplits > 1 then
for i = 2,#spaceSplits,1 do
local argument = spaceSplits[i]
args[#args + 1] = argument
end
end
local ctx = ctx.new(msg, player)
callback(ctx, unpack(args))
end
end
end
function client:OnEvent(eventName: string, callback)
if self.events[eventName] then
self.events[eventName]:Connect(callback)
else
error("No event named "..eventName)
end
end
function client:Send(message: string)
if not game.ReplicatedStorage:FindFirstChild("DefaultChatSystemChatEvents") then
game:GetService("TextChatService").TextChannels.RBXGeneral:SendAsync(message)
else
game.ReplicatedStorage.DefaultChatSystemChatEvents.SayMessageRequest:FireServer(message, "All")
end
end
function client:CreateCommand(commandName: string, callback)
self.Commands[commandName] = callback
end
function client.new(command_prefix: string)
local self = setmetatable({}, client)
self.Prefix = command_prefix
self.Commands = {}
self:Init()
return self
end
end
function rblx:CreateClient(command_prefix: string)
return client.new(command_prefix)
end
print("rblx.bo init.. v2")
return rblx