Implemented pagination for !showbans, !listlevels and !listaliases (issue #54)

This commit is contained in:
Timo Smit 2016-03-09 18:21:28 +01:00
parent f286ab78bc
commit 7445e7b173
6 changed files with 113 additions and 13 deletions

View file

@ -17,6 +17,7 @@
local util = require "luascripts.wolfadmin.util.util"
local settings = require "luascripts.wolfadmin.util.settings"
local pagination = require "luascripts.wolfadmin.util.pagination"
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands"
local stats = require "luascripts.wolfadmin.players.stats"
@ -57,7 +58,10 @@ function commandListAliases(clientId, cmdArguments)
end
local player = db.getplayer(stats.get(cmdClient, "playerGUID"))["id"]
local aliases = db.getaliases(player)
local count = db.getaliasescount(player)
local limit, offset = pagination.calculate(count, 30, tonumber(cmdArguments[2]))
local aliases = db.getaliases(player, limit, offset)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dAliases for ^7"..et.gentity_get(cmdClient, "pers.netname").."^d:\";")
for _, alias in pairs(aliases) do
@ -67,8 +71,9 @@ function commandListAliases(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^7"..spaces..alias["alias"].." ^7"..string.format("%8s", alias["used"]).." times\";")
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dlistaliases: ^9"..#aliases.." known aliases for ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9 (open console for the full list).\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9Showing results ^7"..(offset + 1).." ^9- ^7"..limit.." ^9of ^7"..count.."^9.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dlistaliases: ^9aliases for ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9were printed to the console.\";")
return true
end
commands.addadmin("listaliases", commandListAliases, "f", "display all known aliases for a player", "^9[^3name|slot#^9]", function() return (settings.get("db_type") == "cfg") end)
commands.addadmin("listaliases", commandListAliases, "f", "display all known aliases for a player", "^9[^3name|slot#^9] ^9(^hoffset^9)", function() return (settings.get("db_type") == "cfg") end)

View file

@ -17,6 +17,7 @@
local util = require "luascripts.wolfadmin.util.util"
local settings = require "luascripts.wolfadmin.util.settings"
local pagination = require "luascripts.wolfadmin.util.pagination"
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands"
local stats = require "luascripts.wolfadmin.players.stats"
@ -73,7 +74,10 @@ function commandListLevels(clientId, cmdArguments)
end
local player = db.getplayer(stats.get(cmdClient, "playerGUID"))["id"]
local levels = db.getlevels(player)
local count = db.getlevelscount(player)
local limit, offset = pagination.calculate(count, 30, tonumber(cmdArguments[2]))
local levels = db.getlevels(player, limit, offset)
if not (levels and #levels > 0) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistlevels: ^9there are no recorded levels for player ^7"..et.gentity_get(cmdClient, "pers.netname").."^9.\";")
@ -83,9 +87,10 @@ function commandListLevels(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^f"..string.format("%4s", level["id"]).." ^7"..string.format("%-20s", util.removeColors(db.getlastalias(level["admin_id"])["alias"])).." ^f"..os.date("%d/%m/%Y", level["datetime"]).." ^7"..level["level"].."\";")
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9Showing results ^7"..(offset + 1).." ^9- ^7"..limit.." ^9of ^7"..count.."^9.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dlistlevels: ^9recorded levels for ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9were printed to the console.\";")
end
return true
end
commands.addadmin("listlevels", commandListLevels, "s", "display all levels on the server")
commands.addadmin("listlevels", commandListLevels, "s", "display all levels on the server", (settings.get("db_type") == "cfg" and nil or "^9(^3name|slot#^9) ^9(^hoffset^9)"))

View file

@ -17,6 +17,7 @@
local util = require "luascripts.wolfadmin.util.util"
local settings = require "luascripts.wolfadmin.util.settings"
local pagination = require "luascripts.wolfadmin.util.pagination"
local db = require "luascripts.wolfadmin.db.db"
local commands = require "luascripts.wolfadmin.commands.commands"
@ -47,7 +48,9 @@ function commandShowWarns(clientId, cmdArguments)
return true
end
local playerWarns = warns.get(cmdClient)
local count = warns.getcount(cmdClient)
local limit, offset = pagination.calculate(count, 30, tonumber(cmdArguments[2]))
local playerWarns = warns.getlimit(cmdClient, limit, offset)
if not (playerWarns and #playerWarns > 0) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dshowwarns: ^9there are no warnings for player ^7"..et.gentity_get(cmdClient, "pers.netname").."^9.\";")
@ -57,9 +60,10 @@ function commandShowWarns(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^f"..string.format("%4s", warn["id"]).." ^7"..string.format("%-20s", util.removeColors(db.getlastalias(warn["admin_id"])["alias"])).." ^f"..os.date("%d/%m/%Y", warn["datetime"]).." ^7"..warn["reason"].."\";")
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9Showing results ^7"..(offset + 1).." ^9- ^7"..limit.." ^9of ^7"..count.."^9.\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dshowwarns: ^9warnings for ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9were printed to the console.\";")
end
return true
end
commands.addadmin("showwarns", commandShowWarns, "R", "display warnings for a specific player", "^9[^3name|slot#^9]", function() return (settings.get("g_warnHistory") == 0 or settings.get("db_type") == "cfg") end)
commands.addadmin("showwarns", commandShowWarns, "R", "display warnings for a specific player", "^9[^3name|slot#^9] ^9(^hoffset^9)", function() return (settings.get("g_warnHistory") == 0 or settings.get("db_type") == "cfg") end)