ModerationService - Simplyifying Moderation

ModerationService - Simplifying Moderation

Owned by Anonymous Systems


This project is fairly new, excpect bugs & more
“Simplifying Moderation”

Recent Updates

Version 1.0.0:

  • ModerationService Released
  • Ban, Kick, Warning Features Added
  • Check Ban, View Warnings, Unban Features Added
Features
  • Banning
  • Kicking
  • Adding Warnings
  • Viewing Warnings
  • Removing Bans
  • Ban Checking
  • Time Banning
Links

Offical Anonymous Systems Group
Github Link
ModerationService Module


Please only provide constructive criticism! This is a new service owned by Anonymous Systems. This is not a chat command or a user interface panel This module allows you to call: Ban(); Kick(); and other similar functions, allowing you to integrate it into your own chat commands and GUI Panels. This project is open-sourced, which means you can modify it in any way you see fit.

This uses MessagingService, which means you can kick and ban players across servers. Guess what? The module also allows you to ban players who are offline!


CREDITS


@CodedJer - Coding ModerationService
@InfiniteBlackPIX - Advice, Help with MessagingService
@screenswitch1 - Helping with a datastore problem (tysm)
@LightningLion58 - Helping with time ban
@Gooncreeper - Ideas


Contribution


How can you contribute? You can suggest more features, help improve the code, etc.

Please report any bugs, issues, typos you find and they will be fixed!


Polls


Will you be using ModerationService?
  • I will not be using ModerationService
  • I will be using ModerationService

0 voters

What do you think about ModerationService?
  • This module is very good
  • This module can be improved
  • This module sucks

0 voters

12 Likes

A feature you could add would be temp banning people (can already be made using ban & unban functions provided, but a tempban function would make it easier)

2 Likes

I have already planned that, glad to see other people want this added!

1 Like

Where’d you get this idea?

1 Like

Offline kicking? :thinking:

Would you kick them at the first time they join the game?

2 Likes

Oops, accidentaly said kicking, I’ll fix that.

I mean that’s an idea :eyes:

2 Likes

I was reading some posts on the dev forum of users wanting roblox to add a service called “BanService” with :Ban() and :Unban() methods, so I decided to make a resource called “BanService” But I wanted to add more such as warnings so I changed it to be “ModerationService”.

1 Like

this is better then my resource

But cant you just make a panel so you dont have to shut down the game?

1 Like

What do you mean by “shutdown the game”

1 Like

Shutdown the game to update the ban list.

1 Like

Hm? This doesnt shutdown the game to update the banlist? why’d you think that?

1 Like

Ohh…

im dumb enough to not realize that
But can you ban other mods?

1 Like

As this module is not integrated into any admin system, yes you can kick mods, if the developer is integrating this to an admin panel/chat commands they are the people responsible to integrate anti-mod kicking!

1 Like

Quick Update - Nothing Serious

  • Removed a testing print I forgot to remove
  • Added a version checker so you will always know if you are not updated!
1 Like

Can you add temp banning so you can specify a time for the player to be banned

2 Likes

This is planned for the next update!

1 Like

Important hotfix


Warning function had an issue where it would only keep the first warning and override the others with the new one, this has been fixed with this update.
THIS IS AN HOTFIX AND NOT A UPDATE
Thank you so much @screenswitch1

1 Like

This could really use profileservice (module)
As this module simply wraps up datastore call functions profileservice would allow for extremely safe and secure datastore saving and crap preventing those who shouldnt be there from well being there

(it also caches so you don’t end up queueing up like 30 calls if you try checking warnings that much for some reason)

3 Likes

This comment is going to be mostly code review
Im going to just throw out alot of stuff here
and not alot of explaining

Code Simplification

When erroring you don’t need to return the error | return error()
When checking if a variable exists you can use assert() Example:

--old method
if UserId == nil then return error("Parameter UserId is nil") end
--better method
assert(UserId, "Parameter UserId is nil")
--even better method (checks that it is a number)
assert(type(UserId) == "number", "Parameter UserId is invalid")

Now looking further on I’m not sure why you didn’t use self here:

local Warnings = service:viewWarnings(UserId)
--could be
local Warnings = self:viewWarnings(UserId)

I would strongly recommend using self here because you are defining your function with : instead of .

Instead of doing this to default

if Reason == nil then Reason = DefaultReasonBan end
--You can do
Reason = Reason or DefaultReasonBan

With checking if the player is still there before kicking

local Player = Players:GetPlayerByUserId(UserId)
if not Player then return end
Player:Kick(Reason)

--There are two alternatives; I reccomend the second
local Player = Players:GetPlayerByUserId(UserId)
if Player then
    Player:Kick(Reason)
end

--Second
local Player = Players:GetPlayerByUserId(UserId)
_ = Player and Player:Kick(Reason)

Explanation for the second here: (I made this : clout)

I am very disapointed in this pcall:

local Key = "-Ban"..UserId
local success, result = pcall(function()
	ModerationDatastore:SetAsync(Key,{Reason, Moderator})
end)
if not success then
	warn("[ModerationService] Failed to Set DataStore Value for "..UserId..".\nError:",result)
	return
end

You should really really really really really do it like this:

xpcall(ModerationDatastore.SetAsync, 
	function(...) 
		warn("[ModerationService] Failed to Set DataStore Value for ",UserId,".\n\tError:", ...
	end, ModerationDatastore, Key, {Reason, Moderator}
)

Time to throw more sources at you

https://create.roblox.com/docs/scripting/luau/functions#variadic-functions

I am going slightly insane looking at your code.
on :CheckBan
i uh
Did you know?
that
you can return multiple arguments:

--from
return {false,false}
--to:
return false, false

--thank you

Instead of concatinating stuff on warn functions like this:

warn("you did bad things" .. player.UserId)

You can do:

warn("you did good things", player.UserId)

its just so much cleaner

Did you know:
tables can have indexes;

local TheGreatestTableAlive = {}
TheGreatestTableAlive.Banned = false
TheGreatestTableAlive.BanReason = "you did something"

it will make your code much more readable, and give developers interacting with your api a good time.

Using this new knowledge:
Apply this to every part of the module; thank you.
After that; I’ll inspect further into the module.

If you need clarification on anything I have said so far, I will be happy to help because I wrote this is five seconds and then did not read it and then clicked the post button and then hoped you would read this and then hoped something spectaculous would happen.

ps. I like the module.

4 Likes

The old method is safer as using assert can lead to memory leaks and can slow down your process, here is a forum explaining this. So I would simply make your own assert function like this

local function Assert(condition, func)
   if not condition then
      error(func(), 2)
   end
   return condition
end
3 Likes