diff --git a/Discord/scripting/Discord.sp b/Discord/scripting/Discord.sp index 8aaf6567..424a6796 100644 --- a/Discord/scripting/Discord.sp +++ b/Discord/scripting/Discord.sp @@ -41,6 +41,8 @@ int g_iPlayersAtPOST = 0; int g_iRatelimitRemaining = 5; int g_iRatelimitReset; +float g_fReportCooldown[MAXPLAYERS + 1]; + public Plugin myinfo = { name = "Discord core", @@ -92,6 +94,8 @@ public void OnPluginStart() AddCommandListener(CommandListener_SmChat, "sm_chat"); + RegConsoleCmd("sm_report", Command_Report); + if (g_bLoadedLate) { for (int i = 1; i <= MaxClients; i++) @@ -118,6 +122,8 @@ public void OnPluginEnd() public void OnClientPutInServer(int client) { + g_fReportCooldown[client] = 0.0; + if (!g_bTimerDone) return; @@ -814,3 +820,79 @@ public int entWatch_OnClientUnbanned(int admin, int client) else Discord_POST(DISCORD_ENTWATCH_WEBHOOKURL, sMessage, true, sUsername, false, "", false); } + +public Action Command_Report(int client, int argc) +{ + if (BaseComm_IsClientGagged(client)) + return Plugin_Handled; + + if (argc < 2) + { + ReplyToCommand(client, "[SM] Usage: sm_report "); + return Plugin_Handled; + } + + if (g_fReportCooldown[client] > GetGameTime()) + { + ReplyToCommand(client, "[SM] Please wait another %d seconds before sending another report.", RoundToNearest(g_fReportCooldown[client] - GetGameTime())); + return Plugin_Handled; + } + + int iTarget; + char sTarget[32]; + + GetCmdArg(1, sTarget, sizeof(sTarget)); + + if ((iTarget = FindTarget(client, sTarget, true, false)) <= 0) + return Plugin_Handled; + + char sFormatted[4096]; + char sReportText[128]; + char sClientAuthID32[32]; + char sTargetAuthID32[32]; + char sCurrentMap[32]; + int iClientUID = GetClientUserId(client); + int iTargetUID = GetClientUserId(iTarget); + + GetCmdArgString(sReportText, sizeof(sReportText)); + Format(sReportText, sizeof(sReportText) - strlen(sTarget) + 1, sReportText[strlen(sTarget) + 1]); + + if (sReportText[0] == '"') + StripQuotes(sReportText); + + GetClientAuthId(client, AuthId_Steam3, sClientAuthID32, sizeof(sClientAuthID32)); + GetClientAuthId(iTarget, AuthId_Steam3, sTargetAuthID32, sizeof(sTargetAuthID32)); + + GetCurrentMap(sCurrentMap, sizeof(sCurrentMap)); + + Format(sFormatted, sizeof(sFormatted), + "@here\n```%s - Tick: %d``````Reporter: %N (#%d)\nTarget: %N (#%d)\nReason: %s\n```", + sCurrentMap, GetGameTickCount(), client, iClientUID, iTarget, iTargetUID, sReportText); + + char sUsername[MAX_NAME_LENGTH]; + GetClientName(client, sUsername, sizeof(sUsername)); + + if (g_sAvatarURL[client][0] != '\0') + Discord_POST(DISCORD_REPORT_WEBHOOKURL, sFormatted, true, sUsername, true, g_sAvatarURL[client], false); + else + Discord_POST(DISCORD_REPORT_WEBHOOKURL, sFormatted, true, sUsername, false, "", false); + + Format(sFormatted, sizeof(sFormatted), "#%d \"%N\" reported #%d \"%N\" for:\n\x04[Reports]\x01 %s", iClientUID, client, iTargetUID, iTarget, sReportText); + + for (int i = 1; i <= MaxClients; i++) + { + if (!IsClientInGame(i) || !IsClientAuthorized(i)) + continue; + + if (!CheckCommandAccess(i, "", ADMFLAG_GENERIC, true)) + continue; + + PrintToChat(i, "\x01\x04[Reports]\x01 %s", sFormatted); + } + + g_fReportCooldown[client] = GetGameTime() + 30.0; + + ReplyToCommand(client, "\x01\x04[Reports]\x01 Your report was successfully submitted!"); + + return Plugin_Handled; +}