mirror of
https://github.com/fluxionary/minetest-book_runner.git
synced 2025-03-15 04:11:25 +00:00
create limit on the size of a book
This commit is contained in:
parent
e102f112d7
commit
ec73d73ec5
5 changed files with 39 additions and 10 deletions
|
@ -648,6 +648,7 @@ stds.minetest = {
|
|||
stds.book_runner = {
|
||||
globals = {
|
||||
"book_runner",
|
||||
minetest = {fields = {chat_send_player}},
|
||||
},
|
||||
read_globals = {
|
||||
"default",
|
||||
|
|
|
@ -10,6 +10,20 @@ repos:
|
|||
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: detect_debug
|
||||
name: detect debug
|
||||
language: pygrep
|
||||
entry: DEBUG
|
||||
pass_filenames: true
|
||||
exclude: .pre-commit-config.yaml
|
||||
fail_fast: true
|
||||
- id: stylua
|
||||
name: stylua
|
||||
language: system
|
||||
entry: stylua
|
||||
pass_filenames: true
|
||||
types: [ file, lua ]
|
||||
fail_fast: true
|
||||
- id: luacheck
|
||||
name: luacheck
|
||||
language: system
|
||||
|
@ -17,9 +31,4 @@ repos:
|
|||
pass_filenames: true
|
||||
types: [ file, lua ]
|
||||
args: [ -q ]
|
||||
- id: stylua
|
||||
name: stylua
|
||||
language: system
|
||||
entry: stylua
|
||||
pass_filenames: true
|
||||
types: [ file, lua ]
|
||||
fail_fast: true
|
||||
|
|
21
command.lua
21
command.lua
|
@ -1,9 +1,13 @@
|
|||
local f = string.format
|
||||
|
||||
local strip_colors = minetest.strip_colors
|
||||
|
||||
local strip_translation = futil.strip_translation
|
||||
|
||||
local S = default.get_translator
|
||||
|
||||
local max_book_length = book_runner.settings.max_book_length
|
||||
|
||||
minetest.register_chatcommand("run_in_book", {
|
||||
params = "<command> [<args>]",
|
||||
description = "run the command; put the output in the book's body",
|
||||
|
@ -38,11 +42,21 @@ minetest.register_chatcommand("run_in_book", {
|
|||
end
|
||||
|
||||
local orig_chat_send_player = minetest.chat_send_player
|
||||
local length = 0
|
||||
local skipped_lines = 0
|
||||
local too_long = false
|
||||
local received_messages = {}
|
||||
-- luacheck: push globals minetest.chat_send_player
|
||||
function minetest.chat_send_player(name2, message)
|
||||
if name == name2 then
|
||||
if too_long then
|
||||
skipped_lines = skipped_lines + 1
|
||||
elseif length + #message + 1 > max_book_length then
|
||||
too_long = true
|
||||
skipped_lines = skipped_lines + 1
|
||||
else
|
||||
table.insert(received_messages, strip_colors(strip_translation(message)))
|
||||
length = length + #message + 1
|
||||
end
|
||||
else
|
||||
orig_chat_send_player(name2, message)
|
||||
end
|
||||
|
@ -54,7 +68,10 @@ minetest.register_chatcommand("run_in_book", {
|
|||
end
|
||||
|
||||
minetest.chat_send_player = orig_chat_send_player
|
||||
-- luacheck: pop
|
||||
|
||||
if too_long then
|
||||
table.insert(received_messages, f("WARNING: too much output, %i lines omitted", skipped_lines))
|
||||
end
|
||||
|
||||
local text = table.concat(received_messages, "\n")
|
||||
local written_book = ItemStack("default:book_written")
|
||||
|
|
2
mod.conf
2
mod.conf
|
@ -5,6 +5,6 @@ website = https://content.minetest.net/packages/rheo/book_runner/
|
|||
author = fluxionary
|
||||
license = AGPL-3.0-or-later
|
||||
media_license = CC-BY-SA-4.0
|
||||
version = 2022-11-27
|
||||
version = 2023-05-12
|
||||
min_minetest_version = 5.6.1
|
||||
depends = default, fmod, futil
|
||||
|
|
2
settingtypes.txt
Normal file
2
settingtypes.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
# output will be truncated after this point, with a short message.
|
||||
book_runner:max_book_length (maximum length of the book) int 100000 0 640000
|
Loading…
Add table
Reference in a new issue