Skip to content

Instantly share code, notes, and snippets.

@moonexpr
Last active May 20, 2017 00:45
Show Gist options
  • Save moonexpr/17ff6185c4325d4df5af642214025c72 to your computer and use it in GitHub Desktop.
Save moonexpr/17ff6185c4325d4df5af642214025c72 to your computer and use it in GitHub Desktop.
Use's discord relay to call administrators
local string = string
local net = net
local table = table
local SVDiscordRelay = SVDiscordRelay
calladmin = {}
local ERROR_LIB = 0x1
local ERROR_ENT = 0x2
local ERROR_CACHE = 0x3
local ERROR_PERM = 0x4
local ERROR_RATE = 0x5
local ISSUE_DONATION = 0x1
local ISSUE_GAMEPLAY = 0x2
calladmin.c = {
rate = 60 * 5
}
calladmin.l = {
net = "calladmin",
ulx.command,
ULib.ACCESS_ALL,
ULib.cmds.StringArg,
ULib.cmds.optional,
ULib.tsayError,
print,
string.format,
net.Receive,
net.Start,
net.Send,
player.GetAll,
game.GetIPAddress,
net.ReadTable,
}
calladmin.e = {
[ERROR_LIB] = "calladmin::ERROR_LIB: Missing SVDiscordRelay Library!",
[ERROR_ENT] = "calladmin::ERROR_ENT: You must have a valid player object to submit a report!",
[ERROR_CACHE] = "calladmin::ERROR_CACHE: Type a random message in chat to allow us to download your account properly!",
[ERROR_PERM] = "calladmin::ERROR_PERM: You do not have permission to submit forms according to your account.",
[ERROR_RATE] = "calladmin::ERROR_RATE: You cannot submit another form for a while.",
}
calladmin.o = {
[ISSUE_DONATION] = "-- DONATION ISSUE --",
[ISSUE_GAMEPLAY] = "-- GAMEPLAY ISSUE --"
}
if SERVER then
calladmin.le = {
util.AddNetworkString,
game.GetMap,
}
calladmin.le [1] (calladmin.l ["net"])
calladmin.rates = {}
function calladmin.throwError (pTarget, strMessage)
strNick = "Diablo Gaming"
strSteamID = "STEAM_0:0"
if pTarget and IsValid (pTarget) and pTarget:IsPlayer () then
strNick = pTarget:Nick ()
strSteamID = pTarget:SteamID ()
strMessage = strMessage:gsub ("{PLAYER}", strNick)
strMessage = strMessage:gsub ("{PLAYER_STEAMID}", strSteamID)
calladmin.l [5] (pTarget, strMessage, true)
else
strMessage = strMessage:gsub ("{PLAYER}", strNick)
strMessage = strMessage:gsub ("{PLAYER_STEAMID}", strSteamID)
end
calladmin.l [6] (calladmin.l [7] ("error from %s (%s): %s", strNick, strSteamID, strMessage))
end
function calladmin.stringBuilder (pComposer, tblPayload)
strSubject = tblPayload ["DComboBox#Reporting"]
strReport = tblPayload ["DTextEntry#ReportEntry"]
-- BASE_STRING = "<@&91661971606224896>\n**Reporter**:\t%s (%s) [%s]\n**Subject**:\t%s\n\n```%s```\n"
BASE_STRING = "<@here>\n**Reporter**:\t%s (%s) [%s]\n**Subject**:\t%s\n\n```%s```\n"
return calladmin.l [7] (BASE_STRING, pComposer:Nick (), pComposer:SteamID64 (), pComposer:GetUserGroup (), strSubject, strReport)
end
function calladmin.post (pComposer, tblPayload)
local tblWebAPI = SVDiscordRelay.CacheAPI [pComposer:SteamID ()]
SVDiscordRelay.SendToDiscordRawEmbed ("Diablo Gaming", false, calladmin.stringBuilder (pComposer, tblPayload), {
color = 0xFF0000,
author = {
name = name,
url = "http://steamcommunity.com/profiles/" .. pComposer:SteamID64 (),
icon_url = tblWebAPI ["avatarfull"]
},
fields = {
{
name = "Reporting:",
value = tblPayload ["DComboBox#Reporting"],
inline = false,
},
{
name = "Resolve Issue:",
value = calladmin.l [7] ("steam://connect/%s", calladmin.l [12] ()),
inline = false,
}
},
footer = {
text = "The current map is " .. calladmin.le [2] () .. " with " .. #calladmin.l [11] () .. " total players."
}
})
end
function calladmin.net (iLength, pSender)
local _space = " "
tblPayload = calladmin.l [13] ()
if not calladmin.rates [pSender:SteamID ()] or calladmin.rates [pSender:SteamID ()] + calladmin.c ["rate"] >= CurTime () then
calladmin.rates [pSender:SteamID ()] = CurTime ()
calladmin.post (pSender, tblPayload)
else
calladmin.throwError (pSender, calladmin.e [ERROR_RATE])
end
end
calladmin.l [8] (calladmin.l ["net"], calladmin.net)
else
calladmin.checkValidation = function ()
if not calladmin.DermElementTree ["DTextEntry#ReportEntry"]["panel"] then return end
if not calladmin.DermElementTree ["DComboBox#Reporting"]["panel"] then return end
if not calladmin.DermElementTree ["DButton#Submit"]["panel"] then return end
if (calladmin.DermElementTree ["DComboBox#Reporting"]["panel"]:GetSelected () and #calladmin.DermElementTree ["DTextEntry#ReportEntry"]["panel"]:GetText () >= 120) then
calladmin.DermElementTree ["DButton#Submit"]["panel"]:SetEnabled (true)
else
calladmin.DermElementTree ["DButton#Submit"]["panel"]:SetEnabled (false)
end
end
calladmin.submitForm = function ()
tblCollect = {}
calladmin.DermElementTree ["_order"] = nil
for strReference, tblData in pairs (calladmin.DermElementTree) do
if calladmin.DermElementTree [strReference]["spawn"]["_collect"] then
tblCollect [strReference] = calladmin.DermElementTree [strReference]["spawn"]["_collect"] (calladmin.DermElementTree [strReference]["panel"])
else
tblCollect [strReference] = "no data"
end
end
-- Close Main Frame
calladmin.frame:Close ()
-- Send it off to mothership!
calladmin.l [9] (calladmin.l ["net"])
net.WriteTable (tblCollect)
net.SendToServer ()
end
calladmin.DermElements = {
--{
-- _element = "DCategoryList",
-- _reference = "DCategoryList#Severity",
-- _call = function (self)
-- self:SetSize (w - 40, 20)
-- self:Add ("Immediately")
-- end,
--},
{
_element = "DLabel",
_reference = "DLabel#Reporting",
_pos = "left",
_call = function (self)
self:SetFont ("CloseCaption_Normal")
self:SetText ("What are you reporting?")
self:SizeToContents ()
end,
},
{
_element = "DComboBox",
_reference = "DComboBox#Reporting",
_call = function (self)
w, h = self:GetParent ():GetSize ()
self:SetValue ("Choose an inquiry...")
self:SetSize (w - 40, 20)
for i = 1, #calladmin.o do
m = self:AddChoice (calladmin.l [7] ("\t%s", calladmin.o [i]), "GENERAL")
end
tblPlayers = calladmin.l [11] ()
for i = 1, #tblPlayers do
pSelectable = tblPlayers [i]
self:AddChoice (calladmin.l [7] ("%s (%s) [%s]", pSelectable:Nick (), pSelectable:SteamID (), pSelectable:GetUserGroup ()), "PLAYER")
end
function self:OnSelect (iIndexSelect, strPrimarySelect, strSecondarySelect)
if strSecondarySelect != "PLAYER" then
chat.AddText (":information: Your report will be filed differently on our database.")
end
calladmin.checkValidation ()
end
end,
_collect = function (self)
str, _ = self:GetSelected ()
return str
end,
},
{
_element = "DLabel",
_reference = "DLabel#ReportDetails",
_pos = "left",
_call = function (self)
self:SetFont ("CloseCaption_Normal")
self:SetText ("What's your complaint?")
self:SizeToContents ()
end,
},
{
_element = "DLabel",
_reference = "DLabel#DestributedAI",
_hidden = true,
_call = function (self)
self:SetSize (0, 0)
self:SetColor (Color (0, 0, 0, 0))
end,
},
{
_element = "DTextEntry",
_reference = "DTextEntry#ReportEntry",
_call = function (self)
w, h = self:GetParent ():GetSize ()
self:SetSize (w - 40, 20)
self:SetMultiline (true)
self:SetUpdateOnType (true)
self.OnValueChange = function (self)
calladmin.DermElementTree ["DLabel#DestributedAI"]["panel"]:SetText (self:GetText ())
calladmin.DermElementTree ["DLabel#DestributedAI"]["panel"]:SizeToContents ()
iHackWidth, iHackHeight = calladmin.DermElementTree ["DLabel#DestributedAI"]["panel"]:GetSize ()
--self:SetSize (w - 40, (#self:GetText ():Explode ("\n") + 1) * 20)
self:SetSize (w - 40, math.Clamp ((iHackHeight * 2), 20, 75))
if #self:GetText () < 120 then
calladmin.DermElementTree ["DLabel#ReportEntryLength"]["panel"]:SetColor (Color (255, 200, 0))
calladmin.DermElementTree ["DLabel#ReportEntryLength"]["panel"]:SetText (("You need ≥ %i more characters."):format (120 - #self:GetText ()))
elseif #self:GetText () == 0 then
calladmin.DermElementTree ["DLabel#ReportEntryLength"]["panel"]:SetColor (Color (255, 0, 0))
calladmin.DermElementTree ["DLabel#ReportEntryLength"]["panel"]:SetText ("You need ≥ 120 characters.")
else
calladmin.DermElementTree ["DLabel#ReportEntryLength"]["panel"]:SetColor (Color (0, 200, 0))
calladmin.DermElementTree ["DLabel#ReportEntryLength"]["panel"]:SetText ("OK")
end
calladmin.DermElementTree ["DLabel#ReportEntryLength"]["panel"]:SizeToContentsX ()
iHeightAdj = 35
iFrameWidth, iFrameHeight = self:GetParent ():GetSize ()
for strRef, tblElement in pairs (calladmin.DermElementTree ["_order"]) do
Derma = tblElement ["panel"]
tblElement = tblElement ["spawn"]
if tblElement ["_hidden"] then
continue
end
iElementWidth, iElementHeight = Derma:GetSize ()
iElementPosX, iElementPosY = Derma:GetPos ()
-- Check to make sure that if we manually moved our element, we don't reset it.
if not tblElement ["_pos"] or tblElement ["_pos"] == "center" then
Derma:SetPos ((iFrameWidth - iElementWidth) / 2, iHeightAdj)
elseif tblElement ["_pos"] == "custom" then
-- Do Nothing
elseif tblElement ["_pos"] == "left" then
Derma:SetPos (20, iHeightAdj)
elseif tblElement ["_pos"] == "right" then
Derma:SetPos (iFrameWidth - iElementWidth - 20, iHeightAdj)
end
iHeightAdj = iHeightAdj + iElementHeight + 10
end
calladmin.checkValidation ()
end
end,
_collect = function (self)
return self:GetText ()
end
},
{
_element = "DLabel",
_reference = "DLabel#ReportEntryLength",
_pos = "right",
_call = function (self)
self:SetFont ("Trebuchet18")
self:SetColor (Color (255, 0, 0))
self:SetText ("You need ≥ 120 characters.")
self:SizeToContents ()
end,
},
{
_element = "DButton",
_reference = "DButton#Submit",
_call = function (self)
self:SetEnabled (false)
self:SetText ("Submit")
function self:DoClick ()
calladmin.submitForm ()
end
end,
},
}
calladmin.DermElementTree = { ["_order"] = {} }
function calladmin.initDerm ()
calladmin.frame = vgui.Create ("DFrame")
calladmin.frame:SetTitle ("Call a Staff Member")
calladmin.frame:SetSize (ScrW () / 3, ScrH () / 1.5)
calladmin.frame:SetDraggable (true)
function calladmin.frame:OnClose ()
calladmin.frame = nil
calladmin.DermElementTree = { ["_order"] = {} }
end
iFrameWidth, iFrameHeight = calladmin.frame:GetSize ()
calladmin.frame:SetPos ((ScrW () - iFrameWidth) / 2, (ScrH () - iFrameHeight) / 2)
iHeightAdj = 35
for i = 1, #calladmin.DermElements do
tblElement = calladmin.DermElements [i]
calladmin.DermElementTree [tblElement ["_reference"]] = {
["panel"] = vgui.Create (tblElement ["_element"], calladmin.frame),
["spawn"] = tblElement
}
table.insert (calladmin.DermElementTree ["_order"], calladmin.DermElementTree [tblElement ["_reference"]])
tblElement ["_call"] (calladmin.DermElementTree [tblElement ["_reference"]]["panel"])
if tblElement ["_hidden"] then
continue
end
iElementWidth, iElementHeight = calladmin.DermElementTree [tblElement ["_reference"]]["panel"]:GetSize ()
iElementPosX, iElementPosY = calladmin.DermElementTree [tblElement ["_reference"]]["panel"]:GetPos ()
-- Check to make sure that if we manually moved our element, we don't reset it.
if iElementPosX == 0 and iElementPosY == 0 then
if not tblElement ["_pos"] or tblElement ["_pos"] == "center" then
calladmin.DermElementTree [tblElement ["_reference"]]["panel"]:SetPos ((iFrameWidth - iElementWidth) / 2, iHeightAdj)
elseif tblElement ["_pos"] == "custom" then
-- Do Nothing
elseif tblElement ["_pos"] == "left" then
calladmin.DermElementTree [tblElement ["_reference"]]["panel"]:SetPos (20, iHeightAdj)
elseif tblElement ["_pos"] == "right" then
calladmin.DermElementTree [tblElement ["_reference"]]["panel"]:SetPos (iFrameWidth - iElementWidth - 20, iHeightAdj)
end
end
iHeightAdj = iHeightAdj + iElementHeight + 10
end
calladmin.frame:MakePopup ()
end
calladmin.l [8] (calladmin.l ["net"], function ()
calladmin.initDerm ()
end)
end
function calladmin.callback (pCaller)
if not SVDiscordRelay then
calladmin.throwError (pCaller, calladmin.e [ERROR_LIB])
elseif not pCaller or not IsValid (pCaller) or not pTarget:IsPlayer () then
print (pCaller)
calladmin.throwError (pCaller, calladmin.e [ERROR_ENT])
elseif not SVDiscordRelay.CacheAPI [pCaller:SteamID ()] then
calladmin.throwError (pCaller, calladmin.e [ERROR_CACHE])
elseif calladmin.rates [pSender:SteamID ()] and calladmin.rates [pSender:SteamID ()] + calladmin.c ["rate"] >= CurTime () then
calladmin.throwError (pCaller, calladmin.e [ERROR_RATE])
end
calladmin.l [9] (calladmin.l ["net"])
calladmin.l [10] (pCaller)
end
calladmin ["m_IObject"] = calladmin.l [1] ("Utility", "ulx calladmin", calladmin.callback, "!calladmin")
calladmin ["m_IObject"]:defaultAccess (calladmin.l [2])
calladmin ["m_IObject"]:help ("Submit a report to online admins")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment