Fix inconsistent config set behavior, add checks for input, ensure newlines exist on cechos
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Charles Click 2024-06-17 13:14:00 -04:00
parent ee3bbdb2f8
commit 89848ef20b
Signed by: roryejinn
GPG Key ID: EDECB89DEDB998C0
9 changed files with 57 additions and 47 deletions

View File

@ -1,11 +1,11 @@
if not Bashmatic.death.event then if not Bashmatic.death.event then
cecho("<firebrick>Bashmatic: You must configure the death trigger first. Please see bm help for more info.") cecho("\n<firebrick>Bashmatic: You must configure the death trigger first. Please see bm help for more info.")
else else
if Bashmatic.enemies.group then if Bashmatic.enemies.group then
-- grouping enemies by area -- grouping enemies by area
local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil
if area == nil then if area == nil then
cecho("<firebrick>Bashmatic: We tried to add that enemy but got a bad area.\nGot: " .. area .. "<reset>") cecho("\n<firebrick>Bashmatic: We tried to add that enemy but got a bad area.\nGot: " .. area .. "<reset>")
else else
inlineAddTarget(matches[2], area) inlineAddTarget(matches[2], area)
end end

View File

@ -5,16 +5,16 @@ bmDisable()
if Bashmatic.enemies.group then if Bashmatic.enemies.group then
local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil
if area == nil then if area == nil then
cecho("<firebrick>Bashmatic: Attempted to clear area targets but got a bad area.\nGot: " .. area .. "<reset>") cecho("\n<firebrick>Bashmatic: Attempted to clear area targets but got a bad area.\nGot: " .. area .. "<reset>")
return return
end end
if not table.contains(Bashmatic.enemies.targets, area) then if not table.contains(Bashmatic.enemies.targets, area) then
cecho("<firebrick>Bashmatic: You don't have any enemies for the area " .. area .. "<reset>") cecho("\n<firebrick>Bashmatic: You don't have any enemies for the area " .. area .. "<reset>")
return return
end end
Bashmatic.enemies.targets.area = nil Bashmatic.enemies.targets.area = nil
cecho("<DarkSlateBlue>Bashmatic: Cleared target list for area " .. area .. "<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Cleared target list for area " .. area .. "<reset>")
else else
Bashmatic.enemies.targets = {} Bashmatic.enemies.targets = {}
cecho("<DarkSlateBlue>Bashmatic: Cleared target list.<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Cleared target list.<reset>")
end end

View File

@ -7,52 +7,62 @@ if which == "phrase" then
end end
Bashmatic.death.phrase = matches[3] Bashmatic.death.phrase = matches[3]
Bashmatic.death.event = tempRegexTrigger(".*" .. Bashmatic.death.phrase .. ".*",handleMobDeath) Bashmatic.death.event = tempRegexTrigger(".*" .. Bashmatic.death.phrase .. ".*",handleMobDeath)
cecho("<DarkSlateBlue>Bashmatic: Reset the death event trigger phrase to " .. matches[3] .. ".<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Reset the death event trigger phrase to " .. matches[3] .. ".<reset>")
elseif which == "start" then elseif which == "start" then
-- starting battle command -- starting battle command
Bashmatic.commands.start = matches[3] Bashmatic.commands.start = matches[3]
cecho("<DarkSlateBlue>Bashmatic: Set battle start command to " .. matches[3] .. " target.<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Set battle start command to " .. matches[3] .. " target.<reset>")
elseif which == "before" then elseif which == "before" then
-- before battle command -- before battle command
Bashmatic.commands.before = matches[3] Bashmatic.commands.before = matches[3]
cecho("<DarkSlateBlue>Bashmatic: Will send " .. matches[3] .. " before battle start.<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Will send " .. matches[3] .. " before battle start.<reset>")
elseif which == "during" then elseif which == "during" then
-- during battle command -- during battle command
Bashmatic.comands.during = matches[3] Bashmatic.comands.during = matches[3]
cecho("<DarkSlateBlue>Bashmatic: Will send " .. matches[3] .. " during battle every " .. Bashmatic.commands.duringTime .. " seconds.<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Will send " .. matches[3] .. " during battle every " .. Bashmatic.commands.duringTime .. " seconds.<reset>")
elseif which == "duringTime" then elseif which == "duringTime" then
-- during battle command time frame -- during battle command time frame
Bashmatic.commands.duringTime = tonumber(mathces[3]) Bashmatic.commands.duringTime = tonumber(mathces[3])
cecho("<DarkSlateBlue>Bashmatic: Will send " .. Bashmatic.commands.during .. " during battle every " .. tonumber(matches[3]) .. " seconds.<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Will send " .. Bashmatic.commands.during .. " during battle every " .. tonumber(matches[3]) .. " seconds.<reset>")
elseif which == "after" then elseif which == "after" then
-- after battle command -- after battle command
Bashmatic.commands.after = matches[3] Bashmatic.commands.after = matches[3]
cecho("<DarkSlateBlue>Bashmatic: Will send " .. matches[3] .. " after combat.<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Will send " .. matches[3] .. " after combat.<reset>")
elseif which == "lowercase" then elseif which == "lowercase" then
-- Converting target to lowercase in battle start command -- Converting target to lowercase in battle start command
Bashmatic.enemies.lowercase = not Bashmatic.enemies.lowercase if not table.contains({"yes", "no"}, matches[3]:lower()) then
cecho("\n<firebrick>Bashmatic: You need to set lowercase target conversion to yes or no.")
return
end
if matches[3]:lower() == "yes" then Bashmatic.enemies.lowercase = true end
if matches[3]:lower() == "no" then Bashmatic.enemies.lowercase = false end
if Bashmatic.enemies.lowercase then if Bashmatic.enemies.lowercase then
cecho("<DarkSlateBlue>Bashmatic: Will now convert targets to lowercase in starting command.") cecho("\n<DarkSlateBlue>Bashmatic: Will now convert targets to lowercase in starting command.")
else else
cecho("<DarkSlateBlue>Bashmatic: Will no longer convert targets to lowercase in starting command.") cecho("\n<DarkSlateBlue>Bashmatic: Will no longer convert targets to lowercase in starting command.")
end end
elseif which == "group" then elseif which == "group" then
-- group by area -- group by area
if #getRooms() == 0 then if #getRooms() == 0 then
Bashmatic.enemies.group = false Bashmatic.enemies.group = false
cecho("<firebrick>Bashmatic: No map detected. Did you make one? You need at least one room to use this feature.<reset>") cecho("\n<firebrick>Bashmatic: No map detected. Did you make one? You need at least one room to use this feature.<reset>")
else else
Bashmatic.enemies.group = not Bashmatic.enemies.group if not table.contains({"yes", "no"}, matches[3]:lower()) then
cecho("\n<firebrick>Bashmatic: You need to set enemy grouping by area to either yes or no.<reset>")
return
end
if matches[3]:lower() == "yes" then Bashmatic.enemies.group = true end
if matches[3]:lower() == "no" then Bashmatic.enemies.group = false end
if Bashmatic.enemies.group then if Bashmatic.enemies.group then
-- we've just turned on enemy grouping -- we've just turned on enemy grouping
Bashmatic.enemies.targets = {} Bashmatic.enemies.targets = {}
cecho("<DarkSlateBlue>Bashmatic: Now grouping enemies by areas. Cleared previous enemies.<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Now grouping enemies by areas. Cleared previous enemies.<reset>")
else else
-- we've just turned off enemy grouping -- we've just turned off enemy grouping
squashTargetGroups() squashTargetGroups()
cecho("<DarkSlateBlue>Bashmatic: No longer grouping enemies by areas. Squashed previous enemies into one large table.\nYou can bm clear to erase them.<reset>") cecho("\n<DarkSlateBlue>Bashmatic: No longer grouping enemies by areas. Squashed previous enemies into one large table.\nYou can bm clear to erase them.<reset>")
end end
end end
else else
cecho("<firebrick>Bashmatic: Unrecognized option " .. matches[3] .. ". See bm help for a list of options.") cecho("\n<firebrick>Bashmatic: Unrecognized option " .. matches[3] .. ". See bm help for a list of options.")
end end

View File

@ -3,26 +3,26 @@ local ourIndex = tonumber(matches[2])
if Bashmatic.enemies.group then if Bashmatic.enemies.group then
local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil
if area == nil then if area == nil then
cecho("<firebrick>Bashmatic: Attempted to clear area targets but got a bad area.\nGot: " .. area .. "<reset>") cecho("\n<firebrick>Bashmatic: Attempted to clear area targets but got a bad area.\nGot: " .. area .. "<reset>")
return return
end end
if not table.contains(Bashmatic.enemies.targets, area) then if not table.contains(Bashmatic.enemies.targets, area) then
cecho("<firebrick>Bashmatic: You don't have any enemies for the area " .. area .. "<reset>") cecho("\n<firebrick>Bashmatic: You don't have any enemies for the area " .. area .. "<reset>")
return return
end end
local size = table.size(Bashmatic.enemies.targets.area) local size = table.size(Bashmatic.enemies.targets.area)
if ourIndex > size then if ourIndex > size then
cecho("<firebrick>Bashmatic: Index out of range for this area. There are only " .. size .. " targets stored.<reset>") cecho("\n<firebrick>Bashmatic: Index out of range for this area. There are only " .. size .. " targets stored.<reset>")
return return
end end
table.remove(Bashmatic.enemies.targets.area, ourIndex) table.remove(Bashmatic.enemies.targets.area, ourIndex)
cecho("<DarkSlateBlue>Bashmatic: Removed target from the area list.<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Removed target from the area list.<reset>")
else else
local size = table.size(Bashmatic.enemies.targets) local size = table.size(Bashmatic.enemies.targets)
if ourIndex > size then if ourIndex > size then
cecho("<firebrick>Bashmatic: Index out of range. There are only " .. size .. " targets stored.<reset>") cecho("\n<firebrick>Bashmatic: Index out of range. There are only " .. size .. " targets stored.<reset>")
return return
end end
table.remove(Bashmatic.enemies.targets, ourIndex) table.remove(Bashmatic.enemies.targets, ourIndex)
cecho("<DarkSlateBlue>Bashmatic: Removed target from the list.<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Removed target from the list.<reset>")
end end

View File

@ -1,4 +1,4 @@
cecho([[<SteelBlue> cecho([[<DarkSlateBlue>
Bashmatic Help File Bashmatic Help File
Let's Bash some Mobs! Let's Bash some Mobs!
@ -22,7 +22,7 @@ bmc during - commands to execute during combat.
bmc duringTime - time delay between during command execution. Default 2 seconds. Wants a number. bmc duringTime - time delay between during command execution. Default 2 seconds. Wants a number.
bmc after - commands to execute after the death trigger fires. bmc after - commands to execute after the death trigger fires.
bmc group - set to yes or no to toggle grouping enemies by mudlet mapper areas on or off bmc group - set to yes or no to toggle grouping enemies by mudlet mapper areas on or off
bmc lowercase - This will convert your target to lowercase before starting the fight (So Kill Rat becomes Kill rat) bmc lowercase - set to yes or no to toggle converting your target to lowercase before starting the fight (So Kill Rat becomes Kill rat)
Aliases Available Aliases Available
----------------- -----------------

View File

@ -2,16 +2,16 @@ if Bashmatic.enemies.group then
-- grouped by areas -- grouped by areas
local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil
if area == nil then if area == nil then
cecho("<firebrick>Bashmatic: We got an invalid area.\nWe Got: " .. area .. "<reset>") cecho("\n<firebrick>Bashmatic: We got an invalid area.\nWe Got: " .. area .. "<reset>")
return return
end end
if not table.contains(Bashmatic.enemies.targets, area) then if not table.contains(Bashmatic.enemies.targets, area) then
cecho("<firebrick>Bashmatic: No enemies added from the area " .. area .. "<reset>") cecho("\n<firebrick>Bashmatic: No enemies added from the area " .. area .. "<reset>")
return return
end end
local size = table.size(Bashmatic.enemies.targets.area) local size = table.size(Bashmatic.enemies.targets.area)
if size == 0 then if size == 0 then
cecho("<firebrick>Bashmatic: No enemies added from the area " .. area .. "<reset>") cecho("\n<firebrick>Bashmatic: No enemies added from the area " .. area .. "<reset>")
return return
end end
if size <= 15 then if size <= 15 then
@ -26,7 +26,7 @@ else
-- not grouped by area -- not grouped by area
local size = table.size(Bashmatic.enemies.targets) local size = table.size(Bashmatic.enemies.targets)
if size == 0 then if size == 0 then
cecho("<firebrick>Bashmatic: No enemies added.<reset>") cecho("\n<firebrick>Bashmatic: No enemies added.<reset>")
return return
end end
if size <= 15 then if size <= 15 then

View File

@ -2,16 +2,16 @@ if Bashmatic.enemies.group then
-- grouped by areas -- grouped by areas
local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil
if area == nil then if area == nil then
cecho("<firebrick>Bashmatic: We got an invalid area.\nWe Got: " .. area .. "<reset>") cecho("\n<firebrick>Bashmatic: We got an invalid area.\nWe Got: " .. area .. "<reset>")
return return
end end
if not table.contains(Bashmatic.enemies.targets, area) then if not table.contains(Bashmatic.enemies.targets, area) then
cecho("<firebrick>Bashmatic: No enemies added from the area " .. area .. "<reset>") cecho("\n<firebrick>Bashmatic: No enemies added from the area " .. area .. "<reset>")
return return
end end
local size = table.size(Bashmatic.enemies.targets.area) local size = table.size(Bashmatic.enemies.targets.area)
if size == 0 then if size == 0 then
cecho("<firebrick>Bashmatic: No enemies added from the area " .. area .. "<reset>") cecho("\n<firebrick>Bashmatic: No enemies added from the area " .. area .. "<reset>")
return return
end end
if size <= 15 then if size <= 15 then
@ -21,7 +21,7 @@ if Bashmatic.enemies.group then
-- paginator -- paginator
local pages = math.floor(size/15)+1 local pages = math.floor(size/15)+1
if tonumber(matches[2]) > pages then if tonumber(matches[2]) > pages then
cecho("<firebrick>Bashmatic: There aren't that many pages. There are only " .. pages .. " pages.<reset>") cecho("\n<firebrick>Bashmatic: There aren't that many pages. There are only " .. pages .. " pages.<reset>")
return return
end end
local startIndex = ((tonumber(matches[2]) - 1)*15)+1 local startIndex = ((tonumber(matches[2]) - 1)*15)+1
@ -33,7 +33,7 @@ else
-- not grouped by area -- not grouped by area
local size = table.size(Bashmatic.enemies.targets) local size = table.size(Bashmatic.enemies.targets)
if size == 0 then if size == 0 then
cecho("<firebrick>Bashmatic: No enemies added.<reset>") cecho("\n<firebrick>Bashmatic: No enemies added.<reset>")
return return
end end
if size <= 15 then if size <= 15 then
@ -43,7 +43,7 @@ else
-- paginator -- paginator
local pages = math.floor(size/15)+1 local pages = math.floor(size/15)+1
if tonumber(matches[2]) > pages then if tonumber(matches[2]) > pages then
cecho("<firebrick>Bashmatic: There aren't that many pages. There are only " .. pages .. " pages.<reset>") cecho("\n<firebrick>Bashmatic: There aren't that many pages. There are only " .. pages .. " pages.<reset>")
return return
end end
local startIndex = ((tonumber(matches[2]) - 1)*15)+1 local startIndex = ((tonumber(matches[2]) - 1)*15)+1

View File

@ -3,5 +3,5 @@ Bashmatic.enabled = not Bashmatic.enabled
if Bashmatic.enabled and table.size(Bashmatic.hunting.events) == 0 and table.size(Bashmatic.enemies.targets) > 0 then if Bashmatic.enabled and table.size(Bashmatic.hunting.events) == 0 and table.size(Bashmatic.enemies.targets) > 0 then
-- we just turned ourself on, we have targets, and no triggers are running -- we just turned ourself on, we have targets, and no triggers are running
recreateTriggers() recreateTriggers()
cecho("<DarkSlateBlue>Bashmatic: Bashmatic turned on. Let's go bash some mobs.<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Bashmatic turned on. Let's go bash some mobs.<reset>")
end end

View File

@ -52,7 +52,7 @@ function handleLoadEvent()
Bashmatic.death.event = tempRegexTrigger(".*" .. Bashmatic.death.phrase .. ".*",handleMobDeath) Bashmatic.death.event = tempRegexTrigger(".*" .. Bashmatic.death.phrase .. ".*",handleMobDeath)
end end
cecho("<DarkSlateBlue>Bashmatic: Loaded settings. Let's bash some mobs.") cecho("\n<DarkSlateBlue>Bashmatic: Loaded settings. Let's bash some mobs.")
end end
registerAnonymousEventHandler("sysLoadEvent", handleLoadEvent) registerAnonymousEventHandler("sysLoadEvent", handleLoadEvent)
@ -110,14 +110,14 @@ end
function inlineAddTarget(target, area) function inlineAddTarget(target, area)
if area == nil then if area == nil then
cecho("<DarkSlateBlue>Bashmatic: Added " .. target .. " to hunting targets.<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Added " .. target .. " to hunting targets.<reset>")
if not table.contains(Bashmatic.enemies.targets, target) then if not table.contains(Bashmatic.enemies.targets, target) then
table.insert(Bashmatic.enemies.targets, target) table.insert(Bashmatic.enemies.targets, target)
end end
end end
if area ~= nil then if area ~= nil then
cecho("<DarkSlateBlue>Bashmatic: Added " .. target .. " to hunting targets in " .. area .. ".<reset>") cecho("\n<DarkSlateBlue>Bashmatic: Added " .. target .. " to hunting targets in " .. area .. ".<reset>")
if table.contains(Bashmatic.enemies.targets, area) then if table.contains(Bashmatic.enemies.targets, area) then
table.insert(Bashmatic.enemies.targets.area, target) table.insert(Bashmatic.enemies.targets.area, target)
else else
@ -136,11 +136,11 @@ function recreateTriggers()
-- Grouping enemies by areas -- Grouping enemies by areas
local thisArea = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil local thisArea = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil
if thisArea == nil then if thisArea == nil then
cecho("<firebrick>Bashmatic: We attempted to locate your area but failed.\nGot: " .. thisArea .. "<reset>") cecho("\n<firebrick>Bashmatic: We attempted to locate your area but failed.\nGot: " .. thisArea .. "<reset>")
return return
end end
if not table.contains(Bashmatic.enemies.targets, thisArea) then if not table.contains(Bashmatic.enemies.targets, thisArea) then
cecho("<firebrick>Bashmatic: You haven't added any enemies for the area " .. thisArea .. "<reset>") cecho("\n<firebrick>Bashmatic: You haven't added any enemies for the area " .. thisArea .. "<reset>")
return return
end end
for _, keyword in ipairs(Bashmatic.enemies.targets.thisArea) do for _, keyword in ipairs(Bashmatic.enemies.targets.thisArea) do
@ -189,7 +189,7 @@ function displayTargetList(start, endi, page, pages)
end end
cecho(thisTable:assemble()) cecho(thisTable:assemble())
if page ~= nil then if page ~= nil then
cecho("<DarkSlateBlue>Displaying " .. start .. " to " .. endi .. " (Page " .. page .. " of " .. pages .. ")<reset>") cecho("\n<DarkSlateBlue>Displaying " .. start .. " to " .. endi .. " (Page " .. page .. " of " .. pages .. ")<reset>")
end end
end end
@ -217,9 +217,9 @@ function displayAreaTargetList(area, start, endi, page, pages)
Bashmatic.enemies.targets.area[i] Bashmatic.enemies.targets.area[i]
}) })
end end
cecho("<MediumPurple>Target Listing for area " .. area .. "<reset>") cecho("\n<MediumPurple>Target Listing for area " .. area .. "<reset>")
if page ~= nil then if page ~= nil then
cecho("<DarkSlateBlue>Displaying " .. start .. " to " .. endi .. " (Page " .. page .. " of " .. pages .. ")<reset>") cecho("\n<DarkSlateBlue>Displaying " .. start .. " to " .. endi .. " (Page " .. page .. " of " .. pages .. ")<reset>")
end end
end end