on_pre_console_chat (or on_cancel_console_chat)

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Angamara
Inserter
Inserter
Posts: 39
Joined: Mon Oct 30, 2017 3:52 pm
Contact:

on_pre_console_chat (or on_cancel_console_chat)

Post by Angamara »

hello,


Could we have something like this:

game.on_console_chat (player_index, command, parameters)

Called when someone talks in-game either a player or through the server interface.

Contains
player_index :: uint (optional): The player if any.
message_index :: uint: The message index.
message :: string: The chat message.
game.on_pre_console_chat (player_index, command, parameters)

Called before a message is sent in-game

Contains
player_index :: uint (optional): The player if any.
message_index :: uint: The message index.
message :: string: The chat message.
game.console_chat (player_index, message_index, message, cancel)

Cancels or modifies an in-game message before sending.

Parameters
player_index :: uint (optional): The player if any.
message_index :: uint: The message index.
message :: string (optional): The chat message.
cancel :: boolean (optional): cancel sending if true
game.map_settings.use_pre_console_chat = true

Makes sending in-game message only possible with game.console_chat

(As we process the message and we do not know how long it takes between the beginning of the execution of the function and the end of the execution, it is necessary to prevent the sending of the original message. Either with a map option, or with a boolean configurable in LUA when on_init.)


Example of use :

Code: Select all

script.on_event(defines.events.on_on_pre_console_chat, function(e)
	new_message = chat_filter(e.message)
	if new_message == "" then
		game.console_chat (e.player_index, e.message_index, false, true)
	else
		game.console_chat (e.player_index, e.message_index, new_message, false)
	end
end)
(*chat_filter is a personal function)

Example 1 :
Before sendind :
Bob475: I do not care about your life asshole
In-game chat :
Bob475: I do not care about your life ****"
Example 2 :
Before sendind :
Bob475: Fuck you
In-game chat :
(Nothing appears the message is canceled)

Example 3 :
(*With other personnal function)
Before sendind :
Teo102: note.test
In-game chat :
Teo102: This is a pre-recorded message named test
And we can find other use cases.
Last edited by Angamara on Mon Nov 13, 2017 6:51 pm, edited 1 time in total.
Angamara
Inserter
Inserter
Posts: 39
Joined: Mon Oct 30, 2017 3:52 pm
Contact:

Re: on_pre_console_chat

Post by Angamara »

After a few tests it seems that the command / mute sends the message only to the person concerned.

But on_console_chat captures his message anyway.

The solution already in place would mutate all people and return the message afterwards. But the message / mute should not be sent.

So I looked at LuaPermissionGroups. (defines.input_action.write_to_console)

There the message is not sent but is not captured by on_console_chat


The much simpler solution that I propose in the previous message would be to have:
on_cancel_console_chat

Called when someone talks in-game without PermissionGroups

Contains
player_index :: uint (optional): The player if any.
message :: string: The chat message.

and to do :

Code: Select all

game.permissions.groups[1].set_allows_action(defines.input_action.write_to_console, false)

script.on_event(defines.events.on_cancel_console_chat, function(e)
   new_message = chat_filter(e.message)
   game.print(e.player_index .. ": " .. new_message)
end)
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: on_pre_console_chat (or on_cancel_console_chat)

Post by eradicator »

If you're already forbidding everyone to normally talk you might as well implement a custom chat command, like "/say Hi idiots!" which can then be processed like any custom command without adding additional API hooks. You could even add local chat that can only be read by players physically near the person whos talking. Though personally... if anyone on my server showed consitently bad verbal behavior i'd rather ban them than enforce a filter on everybody.

Code: Select all

commands.add_command('say','Say something.', function(event)
  local message = event.parameter
  --filter stuff
  game.print(message)
  end)
LuaCommandProcessor
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14250
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: on_pre_console_chat (or on_cancel_console_chat)

Post by Rseding91 »

Just a small note: when you disable someones ability to do something through permissions their actions don't even leave their computer - they're blocked before they ever start.
If you want to get ahold of me I'm almost always on Discord.
Angamara
Inserter
Inserter
Posts: 39
Joined: Mon Oct 30, 2017 3:52 pm
Contact:

Re: on_pre_console_chat (or on_cancel_console_chat)

Post by Angamara »

The goal is to use the original chat but to process the messages.

The keyboard input management will be available in 0.16 to "copy" the chat feature. (for script scenarios)

If a gui.bottom appears in 0.16 and if you can completely disable the chat

So yes I would be able to duplicate the chat with channel management

The primary demand of this post is to have the posibility to manage a little more, the chat.
Angamara
Inserter
Inserter
Posts: 39
Joined: Mon Oct 30, 2017 3:52 pm
Contact:

Re: on_pre_console_chat (or on_cancel_console_chat)

Post by Angamara »

Since there is no sub-forum "Not Implemented mod requests"

I still do not know if no answer means:

1- A problem of understanding because of the language barrier.
2- A refusal to implement the idea because you do not see the interest.
3 - A refusal to implement the idea because it is not possible to implement it.
4 - You do not have time to answer.
5 - You do not know how to implement it
6 - Other.

In the meantime I found how to prevent a message from reaching the other players.
Given that the functionally original chat is not to send the message to players who are not part of my game.force.

I solved my concerns by creating a game.force for each player and manually sending the message to others.

Yes I know that a maximum of 64 forces is allowed. Just game.merge_force when a player disconnects and have a slot limit on the server.

This is not an optimal solution, but it works the time to have better.

For each of the following points can you tell if it's a possible thing or not?

Remove unnecessary notions [Possible, Impossible, No interest]
1. Stop sending a command in the console after sending. (Other than disabling the command) [Possible, Impossible, No interest]
2. Stop sending text to the console after sending. [Possible, Impossible, No interest]
3. Set a color to the message with game.print and player.print (The color exists in the chat but I did not find how to access it.) [Possible, Impossible, No interest]
4. Add gui.bottom To display GuiElement at the bottom of the screen. [Possible, Impossible, No interest]
5. Get the height and width of a player's game window [Possible, Impossible, No interest]
6. Detect the resizing of a player's game window [Possible, Impossible, No interest]
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: on_pre_console_chat (or on_cancel_console_chat)

Post by eradicator »

Angamara wrote:I still do not know if no answer means:

1- A problem of understanding because of the language barrier.
2- A refusal to implement the idea because you do not see the interest.
3 - A refusal to implement the idea because it is not possible to implement it.
4 - You do not have time to answer.
5 - You do not know how to implement it
6 - Other.
Welcome to modding :P, now you know how everybody else feels. (It's not 1 in this case though.)

Also forces have seperate technology, force bonuses etcpp, and i'm not sure how most other mods handle frequent force changes of existing players. Also if you "use up" all 64 forces, then other mods that need them won't be able to create any more.
You're basically introducing a huge heap of possible bugs and player confusion instead of just blocking normal chat and using /say :P

EDIT:
Angamara wrote:
1. Stop sending a command in the console after sending. (Other than disabling the command) [Possible, Impossible, No interest]
2. Stop sending text to the console after sending. [Possible, Impossible, No interest]
3. Set a color to the message with game.print and player.print (The color exists in the chat but I did not find how to access it.) [Possible, Impossible, No interest]
4. Add gui.bottom To display GuiElement at the bottom of the screen. [Possible, Impossible, No interest]
5. Get the height and width of a player's game window [Possible, Impossible, No interest]
6. Detect the resizing of a player's game window [Possible, Impossible, No interest]
All of those are currently impossible for mods. 3 is player.color, 5 and 6 will NEVER happen because they break determinism.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Angamara
Inserter
Inserter
Posts: 39
Joined: Mon Oct 30, 2017 3:52 pm
Contact:

Re: on_pre_console_chat (or on_cancel_console_chat)

Post by Angamara »

eradicator wrote: Also forces have seperate technology, force bonuses etcpp, and i'm not sure how most other mods handle frequent force changes of existing players. Also if you "use up" all 64 forces, then other mods that need them won't be able to create any more.
You're basically introducing a huge heap of possible bugs and player confusion instead of just blocking normal chat and using /say :P

This problem does not concern me, I do not develop a mod, not the way you think.

I use the scenario method, it does not involve installing mod and reloading different mods between two games.

So the 61 "forces" available are only for what the whole of my script does.

Thank you for letting the Factorio developers answer the questions about any features they might consider

I know what is currently permissible or not, that's why I'm asking for it.
And this problem of "determinism", nothing in the world of computer development prevents the sending and sharing of data.

If you want a data, you put in place solutions to send this information.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14250
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: on_pre_console_chat (or on_cancel_console_chat)

Post by Rseding91 »

1. Stop sending a command in the console after sending. (Other than disabling the command) [Possible, Impossible, No interest]
2. Stop sending text to the console after sending. [Possible, Impossible, No interest]
3. Set a color to the message with game.print and player.print (The color exists in the chat but I did not find how to access it.) [Already in 0.16, Possible, Impossible, No interest]
4. Add gui.bottom To display GuiElement at the bottom of the screen. [Possible, Impossible, No interest]
5. Get the height and width of a player's game window [Possible, Impossible, No interest]
6. Detect the resizing of a player's game window [Possible, Impossible, No interest]

Mostly I want to make sure it's a worth-while addition to the game that will actually be useful.
If you want to get ahold of me I'm almost always on Discord.
Angamara
Inserter
Inserter
Posts: 39
Joined: Mon Oct 30, 2017 3:52 pm
Contact:

Re: on_pre_console_chat (or on_cancel_console_chat)

Post by Angamara »

Rseding91 wrote:1. Stop sending a command in the console after sending. (Other than disabling the command) [Possible, Impossible, No interest]
2. Stop sending text to the console after sending. [Possible, Impossible, No interest]
3. Set a color to the message with game.print and player.print (The color exists in the chat but I did not find how to access it.) [Already in 0.16, Possible, Impossible, No interest]
4. Add gui.bottom To display GuiElement at the bottom of the screen. [Possible, Impossible, No interest]
5. Get the height and width of a player's game window [Possible, Impossible, No interest]
6. Detect the resizing of a player's game window [Possible, Impossible, No interest]

Mostly I want to make sure it's a worth-while addition to the game that will actually be useful.
Any chat management tool is always useful.

1. This one I do not have an example, but if the 2 is present, as much added this one, it is better to have it than to ask it later.
2. Channel management, filter, pre-recorded message.

4. Add icon and other button at the bottom of the screen, (near the chat bar for example) As it is not possible to know the height of the player's screen.
5. Would there be a solution to prevent the height of a GUIElemenet is greater than the window of the player?
Angamara
Inserter
Inserter
Posts: 39
Joined: Mon Oct 30, 2017 3:52 pm
Contact:

Re: on_pre_console_chat (or on_cancel_console_chat)

Post by Angamara »

Among the 3 possible additions, have you decided to include some?
User avatar
PennyJim
Long Handed Inserter
Long Handed Inserter
Posts: 67
Joined: Wed Jan 18, 2023 3:49 am
Contact:

Re: on_pre_console_chat (or on_cancel_console_chat)

Post by PennyJim »

Bumping this request for possibility to modify sent messages.

I'm trying to implement a slightly improved chatting experience, but because my workaround requires clearing chat and re-printing the modified messages, it ruins a couple QOL features they've added (primarily individual message fade out).

All I'm (currently) doing is adding a little color formatting and the ability to use :shortcodes: (like on discord).
Because of the fact that I can't modify messages, I've been forced to try and re-implement how every system message is sent so my solution doesn't make it ephemeral and clear it as soon as another message is sent. That leaves out messages other mods send, and the best I can do with that is provide an interface

While ephemeral message are okay for the most part, it also leaves them out of any formatting change I may want to implement (like a custom set 'warning' color for failed commands). As well as a fast moving chat will suppress them.
KeepResearchinSpoons
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Tue Dec 01, 2020 6:57 pm
Contact:

Re: on_pre_console_chat (or on_cancel_console_chat)

Post by KeepResearchinSpoons »

PennyJim wrote: Sun Jan 28, 2024 12:32 am Bumping this request for possibility to modify sent messages.
probably won't save you a day...
but there has been a working workaround... a while.
TL;DR: chatting player under "/mute" still raise chat/command lua events but muffles the following act-upon much in the preventDefault() sense.
(( the usual case of forums living in their own world is nothing I could really do anything about, sorry ))

elaborate: mute is made crappy ux wise; (player does not even know they are muted/ignored)
yet the IA is still sent with muted (unlike perms route that prevents the ia from even reaching the map-state)
the muted player's message/whispers are not printed by the engine to *other* players, but you can do so yourself (even asterisking anything and everything or asking a server to async-check it for a few ticks if you do so prefer)

you would probably find out the other shortcomings from that "crafty-hacker" way; I live it to you to find which other commands do not respect the muted status (maybe some of yours that were hand-made arent aware as well), but that is purely academic.
fun quest aside, you can even use a separate "rcon" thread to pushback the glorified messages back into the game (about 10-50 lines of python, I guess).

there is still a ton of "unholy" stuff like chat-history, meta-spam (like tech done, game-(un)paused etc. You can find a few public mods that implement "scrollable chat widget" on the portal or search some internet to find 4 more. One of these 4 has an integration with some external advanced profanity filter tooling, which might come handy for you. I wish you best of luck and best regards if so.


as a side not, some good time ago I've implemented a client-side only mod that does just that (replaces "macro" to stuff like lenny-face or multi-line ascii art); and I am aware there are at least a few other successful attempts like that. ((could even try asking particular devs if stuck, I think))
And if you ever seen a rainbowish text string (aka each letter wrapped in color tag) in some MP lobbies (or old chat-logs) ((the one comfy's motd is made after, hehe)) that was also me; hue shift ftw; even though simply by doing [ctrl-a] [ctrl-c] [-glob-shortcut-] [ctrl-v] [enter] in chat without "addons" or other stuff at that time. Probably have "taught" at least 8 ppl how to do the same trick back in the day...
well, enough old stories, for todayish that is.
Might say that little fun crusade allowed to MTL the chat two-ways among other devious things, hehehe. But who knows, maybe the dedicated chat overlay in a separate half-alpha window was not the real purpose of a richtexting expedition? Nobody knows, Neither do I.

Last advice, do not use `command` and process raw-events if you want a better control over commands and some "fixed" inputs for param values :>
have fun and may the luck of gears (spinning happily in fish-oil) be with you
cliff_build
Inserter
Inserter
Posts: 20
Joined: Thu Dec 03, 2020 4:52 pm
Contact:

Re: on_pre_console_chat (or on_cancel_console_chat)

Post by cliff_build »

I want to +1 the general request of "allow mods to control/augment/filter chat messages" - I don't care too much about what the implementation is.

In Biter Battles, we have three relevant forces, "north", "south", and "spectator". It is very helpful if we can augment messages to indicate who can see them. We already have "/north-chat", "/south-chat" and "/spectator-chat" commands, but it is annoying to use them every time, and many new players do not know/understand who can see their chats when they just send them normally (especially because the rules for spectators are confusing, depending on whether it is a "tournament mode" game or not).

So, I'd love if it was possible for a scenario/mod to have more control over what was printed, and what color things were printed as, when people send chat messages.

It could be as simple as "game.do_not_broadcast_chat_messages_by_default = true" and then it would be "on_console_chat" event's job to actually broadcast things.
Post Reply

Return to “Modding interface requests”