2020-11-03 02:08:57 +00:00
|
|
|
const osu = require("osu-packet"),
|
|
|
|
botCommandHandler = require("../BotCommandHandler.js");
|
2020-08-27 13:09:35 +01:00
|
|
|
|
2021-01-26 12:26:46 +00:00
|
|
|
module.exports = function(CurrentUser, CurrentPacket) {
|
2020-11-03 02:08:57 +00:00
|
|
|
let isSendingChannelLocked = false;
|
|
|
|
for (let i = 0; i < global.channels.length; i++) {
|
|
|
|
if (!CurrentPacket.data.target.includes("#")) break;
|
|
|
|
if (global.channels[i].channelName == CurrentPacket.data.target) {
|
|
|
|
isSendingChannelLocked = global.channels[i].locked;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSendingChannelLocked) {
|
|
|
|
if (CurrentPacket.data.message.includes("!")) {
|
|
|
|
botCommandHandler(CurrentUser, CurrentPacket.data.message, CurrentPacket.data.target);
|
|
|
|
} else {
|
|
|
|
const osuPacketWriter = new osu.Bancho.Writer;
|
|
|
|
osuPacketWriter.SendMessage({
|
|
|
|
sendingClient: global.users[0].username,
|
|
|
|
message: "The channel you are currently trying to send to is locked, please come back later!",
|
|
|
|
target: CurrentPacket.data.target,
|
|
|
|
senderId: global.users[0].id
|
|
|
|
});
|
|
|
|
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-27 13:09:35 +01:00
|
|
|
const osuPacketWriter = new osu.Bancho.Writer;
|
|
|
|
osuPacketWriter.SendMessage({
|
|
|
|
sendingClient: CurrentUser.username,
|
|
|
|
message: CurrentPacket.data.message,
|
|
|
|
target: CurrentPacket.data.target,
|
|
|
|
senderId: CurrentUser.id
|
|
|
|
});
|
|
|
|
|
2020-11-03 02:08:57 +00:00
|
|
|
if (CurrentPacket.data.target == "#multiplayer") {
|
2021-01-26 12:26:46 +00:00
|
|
|
global.StreamsHandler.sendToStream(CurrentUser.currentMatch.matchStreamName, osuPacketWriter.toBuffer, CurrentUser.id);
|
|
|
|
botCommandHandler(CurrentUser, CurrentPacket.data.message, CurrentUser.currentMatch.matchStreamName, true);
|
2020-11-03 02:08:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-27 13:09:35 +01:00
|
|
|
|
|
|
|
// Check the stream that we're sending to even exists
|
|
|
|
if (!global.StreamsHandler.doesStreamExist(CurrentPacket.data.target)) return;
|
|
|
|
|
|
|
|
// Write chat message to stream asociated with chat channel
|
2020-11-03 02:08:57 +00:00
|
|
|
global.StreamsHandler.sendToStream(CurrentPacket.data.target, osuPacketWriter.toBuffer, CurrentUser.id);
|
2021-01-26 12:26:46 +00:00
|
|
|
if (CurrentPacket.data.target == "#osu")
|
|
|
|
global.addChatMessage(`${CurrentUser.username}: ${CurrentPacket.data.message}`);
|
2020-11-03 02:08:57 +00:00
|
|
|
botCommandHandler(CurrentUser, CurrentPacket.data.message, CurrentPacket.data.target);
|
|
|
|
return;
|
2020-08-27 13:09:35 +01:00
|
|
|
}
|