Speaking permission system with Adonis admin

I would like to get some assistance on making a PTS (permission to speak) system with Adonis. What I mean by this is that an admin can enable PTS with a command such as ;pts enable which then makes it so that if someone besides an admin talks they get banned. However, I also do want to make it so that whenever a nonadmin (when pts is enabled) they can type ;pts request, which then an admin could accept the PTS with ;pts grant USER TIMEINSECONDS.

All help will be appreciated.

1 Like

Have you had a go at this yourself? The documentation for Adonis plugins is well written and fairly easy to follow. There’s example plugins included with it, look for the plugins folder. This would be a server-sided plugin, so make sure you put yours in there. You’d need a player chatted signal, a flag to determine if PTS is enabled, a table of permitted users to compare against before banning and probably create a thread (using delay, spawn or coroutines) to remove the user from the table after the time supplied.

When you have a go at this, I’ll be happy to assist you with your code and any issues you have, as I’m sure others would too. Hopefully this helps to get you started!

2 Likes

Did you try writing some code before making this thread?
If not you should read the guidelines of this section before posting a thread.

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

As we’ve dicussed on Discord, here’s the final product:

server = nil
service = nil

return function()
	local Admin = server.Admin
	local Anti = server.Anti
	local Commands = server.Commands
	local Core = server.Core
	local Functions = server.Functions
	local HTTP = server.HTTP
	local Logs = server.Logs
	local Process = server.Process
	local Remote = server.Remote
	local Settings = server.Settings
	local Variables = server.Variables
	
	local PTSDefaultTime = 60
	local PTSEnabled = false
	local PTSBypass = {}
	local PTSBanned = {}
	local PTSRPrefix = Settings.Prefix
	local PTSRCommands = {"PTSR", "PTSRequest"}
	
	service.HookEvent("PlayerChatted", function(plr, msg)
		for _, cmd in pairs(PTSRCommands) do
			if string.lower(msg) == string.lower(PTSRPrefix)..string.lower(cmd) then
				return
			end
		end
		
		local plrLevel = Admin.GetLevel(plr)
		
		if PTSEnabled and not PTSBypass[plr.UserId] and plrLevel < 1 then
			Admin.AddBan(plr)
		end
	end)
	
	Commands.PTST = {
		Prefix = Settings.Prefix;
		Commands = {"PTST", "PTSToggle"};
		Args = {"enable/disable"};
		Description = "Toggle PTS";
		Hidden = false;
		Fun = false;
		AdminLevel = "Moderators";
		Function = function(plr, args)
			if not args[1] then
				error("Missing argument")
			end
			
			args[1] = string.lower(args[1])
			
			if string.find("enable", args[1]) == 1 then
				if not PTSEnabled then
					PTSEnabled = true
					PTSBypass = {}
					
					Functions.Hint("PTS has been enabled", service.Players:GetPlayers())
				else
					Functions.Hint("PTS is already enabled", {plr})
				end
			elseif string.find("disable", args[1]) == 1 then
				if PTSEnabled then
					PTSEnabled = false
					PTSBypass = {}
					
					Functions.Hint("PTS has been disabled", service.Players:GetPlayers())
				else
					Functions.Hint("PTS is already disabled", {plr})
				end
			end
		end
	}
	
	Commands.PTS = {
		Prefix = Settings.Prefix;
		Commands = {"PTS"};
		Args = {"grant/revoke", "player", "(time)"};
		Description = "Grant or revoke PTS";
		Hidden = false;
		Fun = false;
		AdminLevel = "Moderators";
		Function = function(plr, args)
			if not PTSEnabled then
				Functions.Hint("PTS is not enabled", {plr})
				return
			end
			
			if not args[1] then
				error("Missing argument")
			end
			
			args[1] = string.lower(args[1])
			
			if string.find("grant", args[1]) == 1 then
				local bypassTime = tonumber(args[3]) or PTSDefaultTime
				
				for _, tplr in pairs(Functions.GetPlayers(plr, args[2])) do
					local plrName = tplr.Name
					local userId = tplr.UserId
					local bypassSession = game:GetService("HttpService"):GenerateGUID(false)
					
					PTSBypass[userId] = bypassSession
					
					delay(bypassTime, function()
						if PTSBypass[userId] == bypassSession then
							PTSBypass[userId] = nil
							Functions.Hint(plrName.."'s PTS have expired", {plr})
						end
					end)
					
					Functions.Hint(plrName.." has been granted PTS for "..bypassTime.." seconds", {plr})
					Functions.Hint("You have been granted PTS for "..bypassTime.." seconds by "..plr.Name, {tplr})
				end
			elseif string.find("revoke", args[1]) == 1 then
				for _, tplr in pairs(Functions.GetPlayers(plr, args[2])) do
					if PTSBypass[tplr.UserId] then
						PTSBypass[tplr.UserId] = nil
						
						Functions.Hint(tplr.Name.." has been revoked PTS", {plr})
						Functions.Hint("Your PTS has been revoked by "..plr.Name, {tplr})
					end
				end
			end
		end
	}
	
	Commands.PTSR = {
		Prefix = PTSRPrefix;
		Commands = PTSRCommands;
		Args = {};
		Description = "Request PTS";
		Hidden = false;
		Fun = false;
		AdminLevel = "Players";
		Function = function(plr, args)
			if not PTSEnabled then
				Functions.Hint("PTS is not enabled", {plr})
				return
			end
			
			local plrLevel = Admin.GetLevel(plr)
			
			if not PTSBypass[plr.UserId] and plrLevel < 1 then
				for _, tplr in pairs(service.Players:GetPlayers()) do
					local targLevel = Admin.GetLevel(tplr)
					
					if targLevel >= 1 then
						Remote.MakeGui(tplr, "Notification", {
							Title = "PTS Request";
							Message = plr.Name.." has requested PTS. Click to accept request.";
							Time = 10;
							OnClick = Core.Bytecode("client.Remote.Send('ProcessCommand','"..Settings.Prefix.."PTS grant "..plr.Name.."')");
						})
					end
				end
			else
				Functions.Hint("You already have PTS", {plr})
			end
		end
	}
end

I’m glad I was able to help!

9 Likes