[Semi-Release] Warnings/Reports To Discord

This is a simple script. Not tested, should work though. I feel this is not really needed in #development:releases so I’ll put it here as a resource. It has no license, use as you wish :kissing_closed_eyes:

This was requested by @KianV in a PM

Source Code For it all

__resource.lua

------------------------------------------
--- Warnings To Discord, Made by FAXES ---
------------------------------------------

resource_manifest_version "44febabe-d386-4d18-afbe-5e627f4af937"

server_script "server.lua"

--[[
    ACE PERMISSIONS TO ADD TO SERVER.CFG

    add_ace WarnsReport faxes.warns.reports allow
    add_principal identifier.steam:HEX-ID-HERE WarnsReport
]]--

server.lua

------------------------------------------
--- Warnings To Discord, Made by FAXES ---
------------------------------------------

--- Config ---

webHookURL = "Add_Webhook_URL_Here" -- The Webhook link to post too.
enableReport = true -- Enable /report command
enableWarns = true -- Enable /warn command


--- Code ---

function DisplayHelp(text)
    SetTextComponentFormat("STRING")
    AddTextComponentString(text)
    DisplayHelpTextFromStringLabel(0, 0, 1, - 1)
end

if enableWarns then
    RegisterCommand("warn", function(source, args, rawCommand)
        local user = tonumber(args[1])
        local msg = table.concat(args, " ", 2)
        local username = GetPlayerName(user)
        if IsPlayerAceAllowed(source, "faxes.warns.reports") then
            sendTahTheFuckingDiscordChat(username, msg, "User was warned for:")
            DisplayHelp("~g~Warning Sent!")
        else
            DisplayHelp("~r~Invalid Permissions")
        end
    end)
end

if enableReport then
    RegisterCommand("report", function(source, args, rawCommand)
        local user = tonumber(args[1])
        local msg = table.concat(args, " ", 2)
        local username = GetPlayerName(user)
        sendTahTheFuckingDiscordChat(username, msg, "This user was reported for:")
        DisplayHelp("~g~Report Sent!")
    end)
end

function sendTahTheFuckingDiscordChat(name, message, type)
  	PerformHttpRequest(webHookURL, function(err, text, headers) end, 'POST', json.encode({username = name, content = type .. "\n" .. message}), { ['Content-Type'] = 'application/json' })
end

WarnPlayerToDiscord.rar (1.1 KB)

Like for nothing, I guess :heart:

8 Likes

Man … I don’t know how much I can thank you! you really are a hero

Haha np bro. :heart:

1 Like

I absolutely love the idea! I’m going to build on this as I really like the idea.

1 Like

Use it as ya want :stuck_out_tongue: No license :slight_smile:

I assume this allows other /report scripts to be used as an in-game report system but also reports the message to discord. Another great script FAXES!

Well you can push some of this code over to the other script.

Hello, it’s so great, but i get error like below:

I’ll pass over my associate @BigYoda as I’m going to sleep…

@FAXES thanks…

@Centuries Are you entering a correct id?

aaaa solved… ty man!

Hey, love your script’s but every time someone make a report or write /report without id the server gives errors. Is there a way for you to make it so when someone report without the id, a text will pop up to say to use id. And when someone dose a report It doesn’t make an error?
ERRORS:
Error when do /report (id) (reason):


Error when do /report (reason):

Through a quick peak - at least for /report id reason, it seems to be the display help function that is messing up the code. I will look into it.

1 Like

The webhook works fine for me, and sends the message fine - I took out the display help function and switched it to utilize the ChatMessage function so it would confirm the report has been sent. The error goes away.

Thx but now I got the problem with the help not showing

TriggerEvent('chat:addMessage', {
  color = { 255, 0, 0},
  multiline = true,
  args = {"Me", "The Player Has Been Reported"}
})

I believe this is the new - non-deprecated way to send a chat message, add this after the report is sent through the webhook

@faxes I made a cool little edit that utilizes embeds - they look so much nicer.

webhook = "" -- The Webhook link to post too.
local DISCORD_NAME = "Report Bot" -- Changes the name of the bot (default : Report Bot)
local DISCORD_IMAGE = "https://www.realbookies.com/wp-content/uploads/2019/03/reporting-analytics_60.png" -- Any Image URL works
enableReport = true -- Enable /report command

if enableReport then
    RegisterCommand("report", function(source, args, rawCommand)
        local user = tonumber(args[1])
        local msg = table.concat(args, " ", 2)
        local username = GetPlayerName(user)
        color = 65280
		sendMessage("The User ".. username .. " Was Reported For: ","**".. msg.."**", color)
    end)
end

function sendMessage(username, msg, color)
  local connect = {
        {
            ["color"] = color,
            ["title"] = "**".. username .."**",
            ["description"] = msg,
            ["footer"] = {
            ["text"] = "Made by ApolloCore",
            },
        }
    }
	-- debugging print(username)
	-- debugging print(msg)
	PerformHttpRequest(webhook, function(err, text, headers) end, 'POST', json.encode({username = DISCORD_NAME, embeds = connect, avatar_url = DISCORD_IMAGE}), { ['Content-Type'] = 'application/json' })
end

It only does reports and I didn’t add the chat message - however I definitely will!

1 Like

Dosen’t seem to work for me, when the help is deleted from server.cfg the script is still sending out errors

Are you sure you have restarted your server, also note i’m only doing a fix for the reporting system not the warning system. If it is a warning based error it most likely has something to do with the ace permissions.

Not using the warn system have it on false