mirror of
https://github.com/Terncode/pixel.horse.git
synced 2026-12-03 05:10:04 +01:00
Filter party chat messages
This commit is contained in:
1 parent
1ad7cfae4d
commit
46c944b0ae
2 files changed
+18
-7
No files matched your search
+15
-4
@@ -147,7 +147,10 @@ export const createSay =
|
||||
}
|
||||
|
||||
if (isPartyChat(type)) {
|
||||
sayToParty(client, message, think ? MessageType.PartyThinking : MessageType.Party);
|
||||
const messageNoLinks = filterUrls(message);
|
||||
const messageCensored = filterBadWords(messageNoLinks);
|
||||
const partyType = think ? MessageType.PartyThinking : MessageType.Party;
|
||||
sayToParty(client, messageNoLinks, messageCensored, partyType, settings);
|
||||
}
|
||||
else {
|
||||
const friendWhisper = whisper && target !== undefined && isFriend(client, target);
|
||||
@@ -266,7 +269,9 @@ function sayWhisper(
|
||||
}
|
||||
}
|
||||
|
||||
function sayToParty(client: IClient, message: string, type: MessageType) {
|
||||
function sayToParty(
|
||||
client: IClient, message: string, censoredMessage: string, type: MessageType, settings: GameServerSettings
|
||||
) {
|
||||
if (!client.party) {
|
||||
saySystem(client, `you're not in a party`);
|
||||
}
|
||||
@@ -275,7 +280,13 @@ function sayToParty(client: IClient, message: string, type: MessageType) {
|
||||
}
|
||||
else {
|
||||
for (const c of client.party.clients) {
|
||||
sayTo(c, client.pony, message, type);
|
||||
if (c === client) {
|
||||
sayTo(c, client.pony, message, type);
|
||||
}
|
||||
else if (!isIgnored(c, client) && (c.isMod || !isHiddenBy(c, client))) {
|
||||
const filter = c.accountSettings.filterSwearWords || settings.filterSwears;
|
||||
sayTo(c, client.pony, filter ? censoredMessage : message, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -311,7 +322,7 @@ export function sayToOthers(
|
||||
sayWhisper(client, message, message, type, target, settings);
|
||||
}
|
||||
else if (isPartyMessage(type)) {
|
||||
sayToParty(client, message, type);
|
||||
sayToParty(client, message, message, type, settings);
|
||||
}
|
||||
else {
|
||||
sayToEveryone(client, message, message, type, settings);
|
||||
|
||||
@@ -815,7 +815,7 @@ describe('chat', () => {
|
||||
const client2 = mockClient();
|
||||
client.party = { clients: [client, client2] } as any;
|
||||
|
||||
sayToParty(client, 'test', MessageType.Party);
|
||||
sayToParty(client, 'test', 'test', MessageType.Party, {});
|
||||
|
||||
expect(client.saysQueue).eql([[client.pony.id, 'test', MessageType.Party]]);
|
||||
expect(client2.saysQueue).eql([[client.pony.id, 'test', MessageType.Party]]);
|
||||
@@ -827,7 +827,7 @@ describe('chat', () => {
|
||||
client.shadowed = true;
|
||||
client.party = { clients: [client, client2] } as any;
|
||||
|
||||
sayToParty(client, 'test', MessageType.Party);
|
||||
sayToParty(client, 'test', 'test', MessageType.Party, {});
|
||||
|
||||
expect(client.saysQueue).eql([[client.pony.id, 'test', MessageType.Party]]);
|
||||
expect(client2.saysQueue).eql([]);
|
||||
@@ -836,7 +836,7 @@ describe('chat', () => {
|
||||
it('sends error message to client if not in party', () => {
|
||||
const client = mockClient();
|
||||
|
||||
sayToParty(client, 'test', MessageType.Party);
|
||||
sayToParty(client, 'test', 'test', MessageType.Party, {});
|
||||
|
||||
expect(client.saysQueue).eql([[client.pony.id, `you're not in a party`, MessageType.System]]);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user