ProAdmin - Easy Custom Commands and Chat

ProAdmin - Modular Custom Admin System

Hello! I have developed a custom admin system in your games. I developed this in ~1.5 hours. Basically you can create your own commands really easily, and also add your own admins and get player chatting events easier. This runs on the Server, so please create the object on the server.

This module allows you to:

  • Create your own commands, with custom arguments and names.
  • Add or remove admins.
  • Use “Sudo” to run commands like that player was running it themselves
  • Contains a Util function for getting players easily.

Grab the module here, and be sure to read below on how to set it up and use it:
ProAdmin V.10


Setup:

  1. Place the module in ServerScriptService.
  2. Require the module and call it’s functions.

Functions:

ProAdmin.New()

Creates a new ProAdmin system in your game.

Arguments:

  1. prefix : string - The prefix used when you call the command, like !teleport.
  2. admins : {number} - A list of UserIDs that will be admins.

Example:
ProAdmin.New("!", {"12345", "67890"})

ProAdmin:AddCommand()

Creates a new command.

Arguments:

  1. name : string - The name of the command to be typed in.
  2. commandFunction - The function called when the command is ran.
  3. adminOnly : boolean - If only admins can run this.
  4. override : boolean - ONLY use if you are ok with two commands with the same name being generated, recommended OFF.

Returns:
bool - If the command was created successfully.

Example:
ProAdmin:AddCommand("teleport", teleportFunction, true,)

ProAdmin:IsUserAdmin()

Returns if a player is an admin or not.

Arguments:

  1. player : Player - The player object to check for.

Returns:
bool - If the user is an admin or not.

Example:
local isAdmin = ProAdmin:IsUserAdmin(player)

ProAdmin:RemoveAdmin()

Removes a player from the admin list.

Arguments:

  1. userID : number - The userID of the player to remove.

Returns:
bool - User was successfully removed.

Example:
ProAdmin:RemoveAdmin(12345)

ProAdmin:AddAdmin()

Adds a player to the admin list.

Arguments:

  1. userID : number - The userID of the player to add.

Example:
ProAdmin:AddAdmin(12345)

ProAdmin:RunCommand()

Runs a command.

Arguments:

  1. name : string - The name of the command to run.
  2. args : {} - The arguments to send.
  3. player : Player - The player to run it as.

Example:
ProAdmin:RunCommand("teleport", {player, target}, player)

ProAdmin:PlayerFromName() *STATIC, USE FROM MODULE NOT INSTANCE*

Gets a player from their name.

Arguments:

  1. name : string - The name of the player to find.

Returns:
player : player - The player object.

Example:
local player = ProAdmin:PlayerFromName("LuckyEcho")

Example

local ServerScriptService = game:GetService("ServerScriptService")
local Libaries = ServerScriptService.Libs
local ProAdminModule = require(Libaries.ProAdmin)

-- Create an AdminModule with the prefix "!", and also make UserID 1536233 an admin.
local AdminModule = ProAdminModule.New("!", {1536233})

-- Add another admin with UserID 488202227 
AdminModule:AddAdmin(488202227)

-- Add a new command that prints out what a player says, does not require admin.
AdminModule:AddCommand("say", function(player, args)
	print(player.Name.. " says "..args[1])
end, false)

-- Listen for chats
AdminModule.OnPlayerChat:Connect(function(player, message)
	print(player.Name.. " said "..message)
end)

-- Easily get the player from their name
AdminModule:PlayerFromName("Lxc")

IMPORTANT

  • This is made for server side.
  • Make sure that you turn on AdminsOnly property for the commands you want to be only run by admins.
--[[
--!strict
--!native
 
    __                    __               ______           __         
   / /   __  __  _____   / /__   __  __   / ____/  _____   / /_   ____ 
  / /   / / / / / ___/  / //_/  / / / /  / __/    / ___/  / __ \ / __ \
 / /___/ /_/ / / /__   / ,<    / /_/ /  / /___   / /__   / / / // /_/ /
/_____/\__,_/  \___/  /_/|_|   \__, /  /_____/   \___/  /_/ /_/ \____/ 
                              /____/                                   
 
 
_____________________________________________________________________________________________________________________________________________________________________
 
    Example:
    
        local ServerScriptService = game:GetService("ServerScriptService")
		local Libaries = ServerScriptService.Libs
		local ProAdminModule = require(Libaries.ProAdmin)

		-- Create an AdminModule with the prefix "!", and also make UserID 1536233 an admin.
		local AdminModule = ProAdminModule.New("!", {1536233})

		-- Add another admin with UserID 488202227 
		AdminModule:AddAdmin(488202227)

		-- Add a new command that prints out what a player says, does not require admin.
		AdminModule:AddCommand("say", function(player, args)
			print(player.Name.. " says "..args[1])
		end, false)

		-- Listen for chats
		AdminModule.OnPlayerChat:Connect(function(player, message)
			print(player.Name.. " said "..message)
		end)
		
		-- Easily get the player from their name, autocompletes too!
		AdminModule:PlayerFromName("luckyEc")
 
 
    
    Thanks for using this module, I hope you enjoy using it. The documentation is below if you ever need to refer to it, and I would definitely
    recommend referring to it.
    
    @LuckyEcho
    1/29/2024 
    
_____________________________________________________________________________________________________________________________________________________________________
 
 
    [ ProAdmin Documentation ]
    
        * local Module = require(ProAdmin)
        
        
        
        [ FUNCTIONS ]
 
 	   * ProAdmin.New()
		    Description
		        Creates a new ProAdmin system in your game.
		    Parameters
		        1. prefix : string - The prefix used when you call the command, like !teleport.
		        2. admins : {number} - A list of UserIDs that will be admins.

 
 
       * ProAdmin:AddCommand()
		    Description
		        Creates a new command.
		    Parameters
		        1. name : string - The name of the command to be typed in.
		        2. commandFunction - The function called when the command is ran.
		        3. adminOnly : boolean - If only admins can run this.
		        4. override : boolean - ONLY use if you are ok with two commands with the same name being generated, recommended OFF.
		    Returns
		        bool - If the command was created successfully.

		* ProAdmin:IsUserAdmin()
		    Description
		        Returns if a player is an admin or not.
		    Parameters
		        1. player : Player - The player object to check for.
		    Returns
		        bool - If the user is an admin or not.

		* ProAdmin:RemoveAdmin()
		    Description
		        Removes a player from the admin list.
		    Parameters
		        1. userID : number - The userID of the player to remove.
		    Returns
		        bool - User was successfully removed.

		* ProAdmin:AddAdmin()
		    Description
		        Adds a player to the admin list.
		    Parameters
		        1. userID : number - The userID of the player to add.

		* ProAdmin:RunCommand()
		    Description
		        Runs a command.
		    Parameters
		        1. name : string - The name of the command to run.
		        2. args : {} - The arguments to send.
		        3. player : Player - The player to run it as.
		
		* ProAdmin:PlayerFromName()
		    Description
		        Get a player from their name.
		    Parameters
		        1. name : string - The name of the player to find.
		    Returns
		    	1. player : player - The player object.
		
        [ EVENTS ]
            
            
            
        * ProAdminInstance.OnPlayerChat:Connect(player, message, isAdmin)
               Description
                    -- Called when a player chats.
               Parameters
                    1. The player who chatted
                    2. The message they said.
                    3. If they are an admin or not.
         
                    
        [ Properties ]
        
        
        
        *  BoardInstance.Admins : {} / Table
                Description
                    -- All admins in the board in the form {UserID, UserID, ...}
              
        *  BoardInstance.Prefix : {} / Table
                Description
                    -- The prefix used in the system.
        
]]

-- [ SERVICES ]
local Players = game:GetService("Players")

-- [ LOGIC ]
local Signal = require(script:FindFirstChild("Signal"))

-- [ DATA ]
local ProAdmin = {}
ProAdmin.__index = ProAdmin

-- [ MODULE FUNCTIONS ]

-- Called when a player chats.
function ProAdmin:_OnPlayerChat(message : string, player : Player)
	if not player or not message then return end
	message = string.lower(message)
	
	-- Fire to users.
	local isAdmin = self:IsUserAdmin(player)
	self.OnPlayerChat:Fire(player, message, isAdmin)
	
	-- Split message.
	local splittedMessage = string.split(message, " ")

	-- Loop through commands fire right one.
	for _, command : {} in pairs(self.Commands) do	
		if self.Prefix.. string.lower(command.Name) == splittedMessage[1] then
			if command.AdminOnly and isAdmin or not command.AdminOnly then
				if command.Function then
					-- Fire and run command.
					task.spawn(command.Function, player, splittedMessage)
				end
			end
		end
	end
end

-- Called when a player is added to the game.
function ProAdmin:_OnPlayerAdded(player : Player)
	player.Chatted:Connect(function(message : string)
		self:_OnPlayerChat(message, player)
	end)
end

-- [ FUNCTIONS ]

-- Creates a new ProAdmin system in your game.
function ProAdmin.New(prefix : string, admins : {string})
	local self = {
		Prefix = prefix or "!",
		Admins = admins or {},
		Commands = {
			{
				["Name"] = "Teleport",
				["Function"] = function(player : Player, args)
					print("hey there! ")
					print(player, args)
				end,
				["AdminOnly"] = true,
			}	
		},
		_OnPlayerChat = ProAdmin:_OnPlayerChat(),
		OnPlayerChat = Signal.new(),
	}
	setmetatable(self, ProAdmin)
	
	-- Add current and future players.
	for _, player : Player in pairs(Players:GetPlayers()) do
		self:_OnPlayerAdded(player)
	end
	Players.PlayerAdded:Connect(function(player)
		self:_OnPlayerAdded(player)
	end)
	
	return self
end

-- Runs a command
-- @param {} - The arguments to send.
-- @param player - The player to run it as.
function ProAdmin:RunCommand(name : string, args : {}, player : Player)
	if not name or not args then warn("ProAdmin(): RunCommand nil parameter") return end
	for _, command in pairs(self.Commands) do
		if string.lower(command.Name) == string.lower(name) then
			if command.Function then
				task.spawn(command.Function, player, args)
			end
		end
	end
end


-- Adds a player to the admin list.
-- @param number - The userID of the player to add.
function ProAdmin:AddAdmin(userID : number)
	if not userID then warn("ProAdmin(): AddAdmin nil parameter") return end
	for _, admin in pairs(self.Admins) do
		if admin == userID then
			return
		end
	end
	table.insert(self.Admins, userID)
end

-- Adds a player to the admin list.
-- @param number - The userID of the player to add.
-- @return bool - User was sucessfully removed.
function ProAdmin:RemoveAdmin(userID : number)
	if not userID then warn("ProAdmin(): RemoveAdmin nil parameter") return false end
	for _, admin in pairs(self.Admins) do
		if admin == userID then
			table.remove(self.Admins, _)
			return true
		end
	end
	return false
end

-- Returns if a player is an admin or not.
-- @param player - The player object to check for.
-- @return bool - If the user is an admin or not.
function ProAdmin:IsUserAdmin(player : Player)
	if not player then warn("ProAdmin(): IsUserAdmin nil parameter") return end
	for _, admin in pairs(self.Admins) do
		if admin == player.UserId then
			return true
		end
	end
	return false
end

-- Returns if a player is an admin or not.
-- @param name - The player name to check for.
-- @return player - The user closet to the name.
function ProAdmin:PlayerFromName(name : string)
	if not name then warn("ProAdmin(): PlayerFromName nil parameter") return end
	name = string.lower(name)
	
	-- Check through all players
	for _, player : Player in pairs(Players:GetPlayers()) do
		local displayName = string.lower(player.DisplayName)
		local username = string.lower(player.Name)
		
		if string.find(displayName, name, 1, true) or string.find(username, name, 1, true) then
			return player
		end
	end
	return nil
end

-- Creates a new command.
-- @param name - The name of the command to be typed in.
-- @param commandFunction - The function called when the command is ran.
-- @param adminOnly - If only admins can run this.
-- @param override - ONLY use if you are ok with two commands with the same name being generated, recommended OFF.
-- @return bool - If the command was created successfully.
function ProAdmin:AddCommand(name : string, commandFunction, adminOnly : boolean, override : boolean)
	-- Error checking
	if not name or not commandFunction or adminOnly == nil then
		error("ProAdmin(): On AddCommand, no parameters can be nil!")
	end
	if override == nil then
		override = false
	end
	
	-- Check if command exists
	if not override then
		for _, command in pairs(self.Commands) do
			if string.lower(command.Name) == string.lower(name) then
				warn("ProAdmin(): "..name.. " is already being used as a command name! Set the override boolean to true in the parameters if you are ok with this.")
				return false
			end
		end
	end
	
	-- Insert into commands
	table.insert(self.Commands, {
		["Name"] = string.lower(name),
		["Function"] = commandFunction,
		["AdminOnly"] = adminOnly,
	})
	
	return true
end


-- [ RETURNING ]
return ProAdmin


Thank you for making to the end, if you have any problems just reply, or feedback!
PS: If you’re making a command that one of the arguments is a TARGET, like teleport, or bring all, then just use the PlayerFromName function, as it has autocomplete and makes getting the player so easy.

1 Like