Page 1 of 1

Help obtaining BP string data when mentioned in chat

Posted: Fri Oct 02, 2020 3:43 am
by superstalkerX
Hello, I have a discord bot that syncs up the discord chat and factorio chat. One of my goal features is that when a user puts a blueprint in the chat, I wish for my bot to grab the corresponding string from the factorio server and render it into an image. The image can be rendered using the famous factorio BlueprintBot.

I cannot find a way for my bot to obtain the BP string with the factorio API, maybe I overlooked something?

checking the factorio server logs, all that is mentioned is:

Code: Select all

2020-10-01 11:01:16 [CHAT] SuperstalkerX: [special-item=internal_1]
This [special-item=internal_1] does not tell me anything other than that it is possibly located in the server files somewhere.

Please help me in finding a way to obtain the BP string in some fashion, either though the factorio API or through disecting the server files.

When you tell me how this can be done. please be sure that what you are talking about is tested as i am a complete novis when it comes to LUA and its API. I do not wish to waste hours debugging something that would never work because of my ignorance. thank your for your understanding. :D

thank you!

Re: Help obtaining BP string data when mentioned in chat

Posted: Fri Oct 02, 2020 4:18 am
by DaveMcW
Put this script in control.lua. It listens for blueprints and dumps them to a custom file.

Code: Select all

script.on_event(defines.events.on_console_chat, function(event) 
  if string.find(event.message, "%[special%-item=internal") then
    local player = game.players[event.player_index]
    local item = player.cursor_stack
    if item and item.valid_for_read and item.is_blueprint then
      local output = player.name .. ": " .. item.export_stack() .. "\n"
      game.write_file("blueprints.log", output, true)
    end
  end
end)

Re: Help obtaining BP string data when mentioned in chat

Posted: Fri Oct 02, 2020 6:12 am
by superstalkerX
DaveMcW wrote: Fri Oct 02, 2020 4:18 am Put this script in control.lua. It listens for blueprints and dumps them to a custom file.

Code: Select all

script.on_event(defines.events.on_console_chat, function(event) 
  if string.find(event.message, "%[special%-item=internal") then
    local player = game.players[event.player_index]
    local item = player.cursor_stack
    if item and item.valid_for_read and item.is_blueprint then
      local output = player.name .. ": " .. item.export_stack() .. "\n"
      game.write_file("blueprints.log", output, true)
    end
  end
end)
Doesn't this rely on the player posting the message while the BP is on their curser?

Code: Select all

local item = player.cursor_stack
Don't get me wrong, this is leagues better than what I had before (nothing) and I massively appreciate your help in this.

Re: Help obtaining BP string data when mentioned in chat

Posted: Fri Oct 02, 2020 11:36 am
by Choumiko
superstalkerX wrote: Fri Oct 02, 2020 6:12 am Doesn't this rely on the player posting the message while the BP is on their curser?
Yes it does, and i don't think there is a way around it only working when the blueprint still is on the cursor. I haven't checked, but i suspect the rich text tag [special-item] is handled internally and not accessible through the api.

Re: Help obtaining BP string data when mentioned in chat

Posted: Fri Oct 02, 2020 12:39 pm
by eradicator
If the cursor isn't enough you could try watching on_player_cursor_stack_changed and keeping a list of recent blueprints. Or hope that some kind of other even is raised for the original shift+lmb. If there's no official support it doesn't really get less hacky... :/. But none of that'll work if players start c/p'ing their own chat messages etc.

Re: Help obtaining BP string data when mentioned in chat

Posted: Sun Oct 04, 2020 10:12 pm
by superstalkerX
Thanks, guys! I may make a request for devs to make this available in the API