generated from your-land/yl_template
Delete announcement
This commit is contained in:
parent
59c25afe26
commit
137bcc0369
17
api.lua
17
api.lua
@ -11,3 +11,20 @@ function yl_announcements.get_announcement(a_id)
|
||||
end
|
||||
return yl_announcements.error
|
||||
end
|
||||
|
||||
function yl_announcements.delete(a_id)
|
||||
local announcements = yl_announcements.get_all_anncouncements()
|
||||
local data = {}
|
||||
local success = false
|
||||
for _, announcement in pairs(announcements) do
|
||||
if announcement.id ~= a_id then
|
||||
table.insert(data,announcement)
|
||||
else
|
||||
success = true
|
||||
end
|
||||
end
|
||||
if success ~= true then
|
||||
data = "Could not find announcement with id " .. a_id
|
||||
end
|
||||
return success, data
|
||||
end
|
||||
34
internal.lua
34
internal.lua
@ -1,17 +1,47 @@
|
||||
|
||||
-- Storage
|
||||
|
||||
function yl_announcements.load_announcements()
|
||||
yl_announcements.data = minetest.parse_json(yl_announcements.mod_storage:get_string("data")) or {}
|
||||
end
|
||||
|
||||
function yl_announcements.save_announcements()
|
||||
yl_announcements.mod_storage:set_string("data", minetest.write_json(yl_announcements.data))
|
||||
function yl_announcements.save_announcements(data)
|
||||
yl_announcements.mod_storage:set_string("data", minetest.write_json(data))
|
||||
end
|
||||
|
||||
-- Chatcommands
|
||||
|
||||
function yl_announcements.chatcommand_announcement_add(name, param)
|
||||
-- defense
|
||||
|
||||
end
|
||||
|
||||
function yl_announcements.chatcommand_announcement_delete(name, param)
|
||||
-- defense
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then
|
||||
return false, "Player not online"
|
||||
end
|
||||
if param == "" then
|
||||
return false, "Announcement ID missing"
|
||||
end
|
||||
local n_param = tonumber(param)
|
||||
if type(n_param) ~= "number" then
|
||||
return false, "Announcement ID not a number"
|
||||
end
|
||||
local announcement = yl_announcements.get_announcement(n_param)
|
||||
if announcement == yl_announcements.error then
|
||||
return false, "Cannot find announcement with given ID"
|
||||
end
|
||||
-- Delete the entry
|
||||
local success, data = yl_announcements.delete(n_param)
|
||||
-- Save
|
||||
if success == false then
|
||||
return false, data
|
||||
else
|
||||
yl_announcements.save_announcements(data)
|
||||
return true, "Deleted announcement ID " .. param
|
||||
end
|
||||
end
|
||||
|
||||
function yl_announcements.chatcommand_announcement_list_all(name, param)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user