Firebot icon indicating copy to clipboard operation
Firebot copied to clipboard

[Bug] $readFile: Reading the last line of a text file does not work correctly

Open dontcallmechicken opened this issue 1 year ago • 5 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

  • Variable $readFile[path\to\file.txt, last] don't work. Nothing is output when reading the last line of a text file.
  • Variable $readFile[path\to\file.txt, random]. Only outputs the lines before the last one. If the last line appears to be output, nothing is displayed. Just like with the "last" option.

Expected Behavior

The "last" option should output the last line of the specified text file. The "random" option should also output the last line of the text file.

The variable $readFile[path\to\file.txt] outputs the entire text file completely and correctly. These options read the text file correctly: "first" and "specific line number".

The variable $fileLineCount[path/to/file.txt] shows the correct number of existing lines in the text file.

Steps To Reproduce

No response

Version

5.62.1

What operating system are you using Firebot on?

Linux Distro

Relevant log output

No meaningful log entries available.

Contact Details (Optional)

Discord: DCMC (dontcallmechicken.dcmc)

dontcallmechicken avatar Jun 28 '24 00:06 dontcallmechicken

is the file ending in a new line ?

CKY- avatar Jun 28 '24 14:06 CKY-

is the file ending in a new line ?

No, the end of the file, i.e. the last line, is also the last entry. Not an empty line. I have also tested it with other text files that have existed for a long time and have always worked. The error also occurs there.

The effects and commands that use this variable no longer work correctly.

dontcallmechicken avatar Jun 28 '24 14:06 dontcallmechicken

  • Variable $readFile[path\to\file.txt, last] don't work. Nothing is output when reading the last line of a text file.
  • Variable $readFile[path\to\file.txt, random]. Only outputs the lines before the last one. If the last line appears to be output, nothing is displayed. Just like with the "last" option.

im going to ping you in discord i cant replicate this. lets see if we can diagnose it a bit?

CKY- avatar Jun 28 '24 15:06 CKY-

im going to ping you in discord i cant replicate this. lets see if we can diagnose it a bit?

Okay. I'm excited! :)

dontcallmechicken avatar Jun 28 '24 15:06 dontcallmechicken

firebot appends a new line on all file writes firebot when firebot tries to read in the last line or a random line the appended NewLine returns a blank entry.

this is a 2 fold issue. with the file write and file read. thank you for the info in discord. the issue is under the same tittle

CKY- avatar Jun 28 '24 16:06 CKY-

Commit 895605a addressed this issue, and it's live in the nightly releases. Once the next release hits the proverbial store shelves with this change, the $readFile variable will have an additional option available to it for trimming out whitespace.

You'll be able to use it with:

  • $readFile[path\to\file.txt, first, true] to get the first non-blank line
  • $readFile[path\to\file.txt, last, true] to get the last non-blank line
  • $readFile[path\to\file.txt, random, true] to get a random non-blank line
  • $readFile[path\to\file.txt, 3, true] to get the third non-blank line

All other invocations, or anything utilizing false as the third parameter, will retain their current behavior for backwards compatibility reasons.

Note for a dev: add labels Dev Complete and Release Pending to this issue as desired.

phroggster avatar Jul 06 '24 11:07 phroggster