Help obtaining BP string data when mentioned in chat

Place to get help with not working mods / modding interface.
superstalkerX
Inserter
Inserter
Posts: 20
Joined: Mon Mar 04, 2019 7:53 pm
Contact:

Help obtaining BP string data when mentioned in chat

Post 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!
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3716
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Help obtaining BP string data when mentioned in chat

Post 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)
superstalkerX
Inserter
Inserter
Posts: 20
Joined: Mon Mar 04, 2019 7:53 pm
Contact:

Re: Help obtaining BP string data when mentioned in chat

Post 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.
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Help obtaining BP string data when mentioned in chat

Post 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.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Help obtaining BP string data when mentioned in chat

Post 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.
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.
superstalkerX
Inserter
Inserter
Posts: 20
Joined: Mon Mar 04, 2019 7:53 pm
Contact:

Re: Help obtaining BP string data when mentioned in chat

Post by superstalkerX »

Thanks, guys! I may make a request for devs to make this available in the API
Post Reply

Return to “Modding help”