Initial commit
This commit is contained in:
559
scripting/sourcemod-discord-master/include/csgocolors.inc
Normal file
559
scripting/sourcemod-discord-master/include/csgocolors.inc
Normal file
@@ -0,0 +1,559 @@
|
||||
/**************************************************************************
|
||||
* *
|
||||
* Colored Chat Functions *
|
||||
* Author: exvel, Editor: Popoklopsi, Powerlord, Bara *
|
||||
* Version: 1.1.3 *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#if defined _colors_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _colors_included
|
||||
|
||||
#define MAX_MESSAGE_LENGTH 250
|
||||
#define MAX_COLORS 16
|
||||
|
||||
#define SERVER_INDEX 0
|
||||
#define NO_INDEX -1
|
||||
#define NO_PLAYER -2
|
||||
|
||||
enum Colors
|
||||
{
|
||||
Color_Default = 0,
|
||||
Color_Darkred,
|
||||
Color_Pink,
|
||||
Color_Green,
|
||||
Color_Lightgreen,
|
||||
Color_Lime,
|
||||
Color_Red,
|
||||
Color_Grey,
|
||||
Color_Olive,
|
||||
Color_A,
|
||||
Color_Lightblue,
|
||||
Color_Blue,
|
||||
Color_D,
|
||||
Color_Purple,
|
||||
Color_Darkrange,
|
||||
Color_Orange
|
||||
}
|
||||
|
||||
/* Colors' properties */
|
||||
new String:CTag[][] = {"{normal}", "{darkred}", "{pink}", "{green}", "{lightgreen}", "{lime}", "{red}", "{grey}", "{olive}", "{a}", "{lightblue}", "{blue}", "{d}", "{purple}", "{darkorange}", "{orange}"};
|
||||
new String:CTagCode[][] = {"\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0A", "\x0B", "\x0C", "\x0D", "\x0E", "\x0F", "\x10"};
|
||||
new bool:CTagReqSayText2[] = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
|
||||
new bool:CEventIsHooked = false;
|
||||
new bool:CSkipList[MAXPLAYERS+1] = {false,...};
|
||||
|
||||
/* Game default profile */
|
||||
new bool:CProfile_Colors[] = {true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false};
|
||||
new CProfile_TeamIndex[] = {NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX, NO_INDEX};
|
||||
new bool:CProfile_SayText2 = false;
|
||||
|
||||
/**
|
||||
* Prints a message to a specific client in the chat area.
|
||||
* Supports color tags.
|
||||
*
|
||||
* @param client Client index.
|
||||
* @param szMessage Message (formatting rules).
|
||||
* @return No return
|
||||
*
|
||||
* On error/Errors: If the client is not connected an error will be thrown.
|
||||
*/
|
||||
stock CPrintToChat(client, const String:szMessage[], any:...)
|
||||
{
|
||||
if (client <= 0 || client > MaxClients)
|
||||
ThrowError("Invalid client index %d", client);
|
||||
|
||||
if (!IsClientInGame(client))
|
||||
ThrowError("Client %d is not in game", client);
|
||||
|
||||
decl String:szBuffer[MAX_MESSAGE_LENGTH];
|
||||
decl String:szCMessage[MAX_MESSAGE_LENGTH];
|
||||
|
||||
SetGlobalTransTarget(client);
|
||||
|
||||
Format(szBuffer, sizeof(szBuffer), "\x01%s", szMessage);
|
||||
VFormat(szCMessage, sizeof(szCMessage), szBuffer, 3);
|
||||
|
||||
new index = CFormat(szCMessage, sizeof(szCMessage));
|
||||
|
||||
if (index == NO_INDEX)
|
||||
PrintToChat(client, "%s", szCMessage);
|
||||
else
|
||||
CSayText2(client, index, szCMessage);
|
||||
}
|
||||
|
||||
stock CReplyToCommand(client, const String:szMessage[], any:...)
|
||||
{
|
||||
|
||||
decl String:szCMessage[MAX_MESSAGE_LENGTH];
|
||||
VFormat(szCMessage, sizeof(szCMessage), szMessage, 3);
|
||||
|
||||
if (client == 0)
|
||||
{
|
||||
CRemoveTags(szCMessage, sizeof(szCMessage));
|
||||
PrintToServer("%s", szCMessage);
|
||||
}
|
||||
else if (GetCmdReplySource() == SM_REPLY_TO_CONSOLE)
|
||||
{
|
||||
CRemoveTags(szCMessage, sizeof(szCMessage));
|
||||
PrintToConsole(client, "%s", szCMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
CPrintToChat(client, "%s", szCMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints a message to all clients in the chat area.
|
||||
* Supports color tags.
|
||||
*
|
||||
* @param client Client index.
|
||||
* @param szMessage Message (formatting rules)
|
||||
* @return No return
|
||||
*/
|
||||
stock CPrintToChatAll(const String:szMessage[], any:...)
|
||||
{
|
||||
decl String:szBuffer[MAX_MESSAGE_LENGTH];
|
||||
|
||||
for (new i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if (IsClientInGame(i) && !IsFakeClient(i) && !CSkipList[i])
|
||||
{
|
||||
SetGlobalTransTarget(i);
|
||||
VFormat(szBuffer, sizeof(szBuffer), szMessage, 2);
|
||||
|
||||
CPrintToChat(i, "%s", szBuffer);
|
||||
}
|
||||
|
||||
CSkipList[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message to a specific client in the chat area.
|
||||
* Supports color tags and teamcolor tag.
|
||||
*
|
||||
* @param client Client index.
|
||||
* @param author Author index whose color will be used for teamcolor tag.
|
||||
* @param szMessage Message (formatting rules).
|
||||
* @return No return
|
||||
*
|
||||
* On error/Errors: If the client or author are not connected an error will be thrown.
|
||||
*/
|
||||
stock CPrintToChatEx(client, author, const String:szMessage[], any:...)
|
||||
{
|
||||
if (client <= 0 || client > MaxClients)
|
||||
ThrowError("Invalid client index %d", client);
|
||||
|
||||
if (!IsClientInGame(client))
|
||||
ThrowError("Client %d is not in game", client);
|
||||
|
||||
if (author < 0 || author > MaxClients)
|
||||
ThrowError("Invalid client index %d", author);
|
||||
|
||||
decl String:szBuffer[MAX_MESSAGE_LENGTH];
|
||||
decl String:szCMessage[MAX_MESSAGE_LENGTH];
|
||||
|
||||
SetGlobalTransTarget(client);
|
||||
|
||||
Format(szBuffer, sizeof(szBuffer), "\x01%s", szMessage);
|
||||
VFormat(szCMessage, sizeof(szCMessage), szBuffer, 4);
|
||||
|
||||
new index = CFormat(szCMessage, sizeof(szCMessage), author);
|
||||
|
||||
if (index == NO_INDEX)
|
||||
PrintToChat(client, "%s", szCMessage);
|
||||
else
|
||||
CSayText2(client, author, szCMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message to all clients in the chat area.
|
||||
* Supports color tags and teamcolor tag.
|
||||
*
|
||||
* @param author Author index whos color will be used for teamcolor tag.
|
||||
* @param szMessage Message (formatting rules).
|
||||
* @return No return
|
||||
*
|
||||
* On error/Errors: If the author is not connected an error will be thrown.
|
||||
*/
|
||||
stock CPrintToChatAllEx(author, const String:szMessage[], any:...)
|
||||
{
|
||||
if (author < 0 || author > MaxClients)
|
||||
ThrowError("Invalid client index %d", author);
|
||||
|
||||
if (!IsClientInGame(author))
|
||||
ThrowError("Client %d is not in game", author);
|
||||
|
||||
decl String:szBuffer[MAX_MESSAGE_LENGTH];
|
||||
|
||||
for (new i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if (IsClientInGame(i) && !IsFakeClient(i) && !CSkipList[i])
|
||||
{
|
||||
SetGlobalTransTarget(i);
|
||||
VFormat(szBuffer, sizeof(szBuffer), szMessage, 3);
|
||||
|
||||
CPrintToChatEx(i, author, "%s", szBuffer);
|
||||
}
|
||||
|
||||
CSkipList[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes color tags from the string.
|
||||
*
|
||||
* @param szMessage String.
|
||||
* @return No return
|
||||
*/
|
||||
stock CRemoveTags(String:szMessage[], maxlength)
|
||||
{
|
||||
for (new i = 0; i < MAX_COLORS; i++)
|
||||
ReplaceString(szMessage, maxlength, CTag[i], "", false);
|
||||
|
||||
ReplaceString(szMessage, maxlength, "{teamcolor}", "", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a color is allowed or not
|
||||
*
|
||||
* @param tag Color Tag.
|
||||
* @return True when color is supported, otherwise false
|
||||
*/
|
||||
stock CColorAllowed(Colors:color)
|
||||
{
|
||||
if (!CEventIsHooked)
|
||||
{
|
||||
CSetupProfile();
|
||||
|
||||
CEventIsHooked = true;
|
||||
}
|
||||
|
||||
return CProfile_Colors[color];
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the color with another color
|
||||
* Handle with care!
|
||||
*
|
||||
* @param color color to replace.
|
||||
* @param newColor color to replace with.
|
||||
* @noreturn
|
||||
*/
|
||||
stock CReplaceColor(Colors:color, Colors:newColor)
|
||||
{
|
||||
if (!CEventIsHooked)
|
||||
{
|
||||
CSetupProfile();
|
||||
|
||||
CEventIsHooked = true;
|
||||
}
|
||||
|
||||
CProfile_Colors[color] = CProfile_Colors[newColor];
|
||||
CProfile_TeamIndex[color] = CProfile_TeamIndex[newColor];
|
||||
|
||||
CTagReqSayText2[color] = CTagReqSayText2[newColor];
|
||||
Format(CTagCode[color], sizeof(CTagCode[]), CTagCode[newColor])
|
||||
}
|
||||
|
||||
/**
|
||||
* This function should only be used right in front of
|
||||
* CPrintToChatAll or CPrintToChatAllEx and it tells
|
||||
* to those funcions to skip specified client when printing
|
||||
* message to all clients. After message is printed client will
|
||||
* no more be skipped.
|
||||
*
|
||||
* @param client Client index
|
||||
* @return No return
|
||||
*/
|
||||
stock CSkipNextClient(client)
|
||||
{
|
||||
if (client <= 0 || client > MaxClients)
|
||||
ThrowError("Invalid client index %d", client);
|
||||
|
||||
CSkipList[client] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces color tags in a string with color codes
|
||||
*
|
||||
* @param szMessage String.
|
||||
* @param maxlength Maximum length of the string buffer.
|
||||
* @return Client index that can be used for SayText2 author index
|
||||
*
|
||||
* On error/Errors: If there is more then one team color is used an error will be thrown.
|
||||
*/
|
||||
stock CFormat(String:szMessage[], maxlength, author=NO_INDEX)
|
||||
{
|
||||
decl String:szGameName[30];
|
||||
|
||||
GetGameFolderName(szGameName, sizeof(szGameName));
|
||||
|
||||
/* Hook event for auto profile setup on map start */
|
||||
if (!CEventIsHooked)
|
||||
{
|
||||
CSetupProfile();
|
||||
HookEvent("server_spawn", CEvent_MapStart, EventHookMode_PostNoCopy);
|
||||
|
||||
CEventIsHooked = true;
|
||||
}
|
||||
|
||||
new iRandomPlayer = NO_INDEX;
|
||||
|
||||
// On CS:GO set invisible precolor
|
||||
if (StrEqual(szGameName, "csgo", false))
|
||||
Format(szMessage, maxlength, " \x01\x0B\x01%s", szMessage);
|
||||
|
||||
/* If author was specified replace {teamcolor} tag */
|
||||
if (author != NO_INDEX)
|
||||
{
|
||||
if (CProfile_SayText2)
|
||||
{
|
||||
ReplaceString(szMessage, maxlength, "{teamcolor}", "\x03", false);
|
||||
|
||||
iRandomPlayer = author;
|
||||
}
|
||||
/* If saytext2 is not supported by game replace {teamcolor} with green tag */
|
||||
else
|
||||
ReplaceString(szMessage, maxlength, "{teamcolor}", CTagCode[Color_Green], false);
|
||||
}
|
||||
else
|
||||
ReplaceString(szMessage, maxlength, "{teamcolor}", "", false);
|
||||
|
||||
/* For other color tags we need a loop */
|
||||
for (new i = 0; i < MAX_COLORS; i++)
|
||||
{
|
||||
/* If tag not found - skip */
|
||||
if (StrContains(szMessage, CTag[i], false) == -1)
|
||||
continue;
|
||||
|
||||
/* If tag is not supported by game replace it with green tag */
|
||||
else if (!CProfile_Colors[i])
|
||||
ReplaceString(szMessage, maxlength, CTag[i], CTagCode[Color_Green], false);
|
||||
|
||||
/* If tag doesn't need saytext2 simply replace */
|
||||
else if (!CTagReqSayText2[i])
|
||||
ReplaceString(szMessage, maxlength, CTag[i], CTagCode[i], false);
|
||||
|
||||
/* Tag needs saytext2 */
|
||||
else
|
||||
{
|
||||
/* If saytext2 is not supported by game replace tag with green tag */
|
||||
if (!CProfile_SayText2)
|
||||
ReplaceString(szMessage, maxlength, CTag[i], CTagCode[Color_Green], false);
|
||||
|
||||
/* Game supports saytext2 */
|
||||
else
|
||||
{
|
||||
/* If random player for tag wasn't specified replace tag and find player */
|
||||
if (iRandomPlayer == NO_INDEX)
|
||||
{
|
||||
/* Searching for valid client for tag */
|
||||
iRandomPlayer = CFindRandomPlayerByTeam(CProfile_TeamIndex[i]);
|
||||
|
||||
/* If player not found replace tag with green color tag */
|
||||
if (iRandomPlayer == NO_PLAYER)
|
||||
ReplaceString(szMessage, maxlength, CTag[i], CTagCode[Color_Green], false);
|
||||
|
||||
/* If player was found simply replace */
|
||||
else
|
||||
ReplaceString(szMessage, maxlength, CTag[i], CTagCode[i], false);
|
||||
|
||||
}
|
||||
/* If found another team color tag throw error */
|
||||
else
|
||||
{
|
||||
//ReplaceString(szMessage, maxlength, CTag[i], "");
|
||||
ThrowError("Using two team colors in one message is not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return iRandomPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Founds a random player with specified team
|
||||
*
|
||||
* @param color_team Client team.
|
||||
* @return Client index or NO_PLAYER if no player found
|
||||
*/
|
||||
stock CFindRandomPlayerByTeam(color_team)
|
||||
{
|
||||
if (color_team == SERVER_INDEX)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
for (new i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if (IsClientInGame(i) && GetClientTeam(i) == color_team)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return NO_PLAYER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a SayText2 usermessage to a client
|
||||
*
|
||||
* @param szMessage Client index
|
||||
* @param maxlength Author index
|
||||
* @param szMessage Message
|
||||
* @return No return.
|
||||
*/
|
||||
stock CSayText2(client, author, const String:szMessage[])
|
||||
{
|
||||
new Handle:hBuffer = StartMessageOne("SayText2", client, USERMSG_RELIABLE|USERMSG_BLOCKHOOKS);
|
||||
|
||||
if(GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf)
|
||||
{
|
||||
PbSetInt(hBuffer, "ent_idx", author);
|
||||
PbSetBool(hBuffer, "chat", true);
|
||||
PbSetString(hBuffer, "msg_name", szMessage);
|
||||
PbAddString(hBuffer, "params", "");
|
||||
PbAddString(hBuffer, "params", "");
|
||||
PbAddString(hBuffer, "params", "");
|
||||
PbAddString(hBuffer, "params", "");
|
||||
}
|
||||
else
|
||||
{
|
||||
BfWriteByte(hBuffer, author);
|
||||
BfWriteByte(hBuffer, true);
|
||||
BfWriteString(hBuffer, szMessage);
|
||||
}
|
||||
|
||||
EndMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates game color profile
|
||||
* This function must be edited if you want to add more games support
|
||||
*
|
||||
* @return No return.
|
||||
*/
|
||||
stock CSetupProfile()
|
||||
{
|
||||
decl String:szGameName[30];
|
||||
GetGameFolderName(szGameName, sizeof(szGameName));
|
||||
|
||||
if (StrEqual(szGameName, "cstrike", false))
|
||||
{
|
||||
CProfile_Colors[Color_Lightgreen] = true;
|
||||
CProfile_Colors[Color_Red] = true;
|
||||
CProfile_Colors[Color_Blue] = true;
|
||||
CProfile_Colors[Color_Olive] = true;
|
||||
CProfile_TeamIndex[Color_Lightgreen] = SERVER_INDEX;
|
||||
CProfile_TeamIndex[Color_Red] = 2;
|
||||
CProfile_TeamIndex[Color_Blue] = 3;
|
||||
CProfile_SayText2 = true;
|
||||
}
|
||||
else if (StrEqual(szGameName, "csgo", false))
|
||||
{
|
||||
CProfile_Colors[Color_Default] = true;
|
||||
CProfile_Colors[Color_Darkred] = true;
|
||||
CProfile_Colors[Color_Pink] = true;
|
||||
CProfile_Colors[Color_Green] = true;
|
||||
CProfile_Colors[Color_Lightgreen] = true;
|
||||
CProfile_Colors[Color_Lime] = true;
|
||||
CProfile_Colors[Color_Red] = true;
|
||||
CProfile_Colors[Color_Grey] = true;
|
||||
CProfile_Colors[Color_Olive] = true;
|
||||
CProfile_Colors[Color_A] = true;
|
||||
CProfile_Colors[Color_Lightblue] = true;
|
||||
CProfile_Colors[Color_Blue] = true;
|
||||
CProfile_Colors[Color_D] = true;
|
||||
CProfile_Colors[Color_Purple] = true;
|
||||
CProfile_Colors[Color_Darkrange] = true;
|
||||
CProfile_Colors[Color_Orange] = true;
|
||||
CProfile_Colors[Color_Red] = true;
|
||||
CProfile_Colors[Color_Blue] = true;
|
||||
CProfile_Colors[Color_Olive] = true;
|
||||
CProfile_Colors[Color_Darkred] = true;
|
||||
CProfile_Colors[Color_Lime] = true;
|
||||
CProfile_Colors[Color_Purple] = true;
|
||||
CProfile_Colors[Color_Grey] = true;
|
||||
CProfile_Colors[Color_Orange] = true;
|
||||
CProfile_TeamIndex[Color_Red] = 2;
|
||||
CProfile_TeamIndex[Color_Blue] = 3;
|
||||
CProfile_SayText2 = true;
|
||||
}
|
||||
else if (StrEqual(szGameName, "tf", false))
|
||||
{
|
||||
CProfile_Colors[Color_Lightgreen] = true;
|
||||
CProfile_Colors[Color_Red] = true;
|
||||
CProfile_Colors[Color_Blue] = true;
|
||||
CProfile_Colors[Color_Olive] = true;
|
||||
CProfile_TeamIndex[Color_Lightgreen] = SERVER_INDEX;
|
||||
CProfile_TeamIndex[Color_Red] = 2;
|
||||
CProfile_TeamIndex[Color_Blue] = 3;
|
||||
CProfile_SayText2 = true;
|
||||
}
|
||||
else if (StrEqual(szGameName, "left4dead", false) || StrEqual(szGameName, "left4dead2", false))
|
||||
{
|
||||
CProfile_Colors[Color_Lightgreen] = true;
|
||||
CProfile_Colors[Color_Red] = true;
|
||||
CProfile_Colors[Color_Blue] = true;
|
||||
CProfile_Colors[Color_Olive] = true;
|
||||
CProfile_TeamIndex[Color_Lightgreen] = SERVER_INDEX;
|
||||
CProfile_TeamIndex[Color_Red] = 3;
|
||||
CProfile_TeamIndex[Color_Blue] = 2;
|
||||
CProfile_SayText2 = true;
|
||||
}
|
||||
else if (StrEqual(szGameName, "hl2mp", false))
|
||||
{
|
||||
/* hl2mp profile is based on mp_teamplay convar */
|
||||
if (GetConVarBool(FindConVar("mp_teamplay")))
|
||||
{
|
||||
CProfile_Colors[Color_Red] = true;
|
||||
CProfile_Colors[Color_Blue] = true;
|
||||
CProfile_Colors[Color_Olive] = true;
|
||||
CProfile_TeamIndex[Color_Red] = 3;
|
||||
CProfile_TeamIndex[Color_Blue] = 2;
|
||||
CProfile_SayText2 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CProfile_SayText2 = false;
|
||||
CProfile_Colors[Color_Olive] = true;
|
||||
}
|
||||
}
|
||||
else if (StrEqual(szGameName, "dod", false))
|
||||
{
|
||||
CProfile_Colors[Color_Olive] = true;
|
||||
CProfile_SayText2 = false;
|
||||
}
|
||||
/* Profile for other games */
|
||||
else
|
||||
{
|
||||
if (GetUserMessageId("SayText2") == INVALID_MESSAGE_ID)
|
||||
{
|
||||
CProfile_SayText2 = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
CProfile_Colors[Color_Red] = true;
|
||||
CProfile_Colors[Color_Blue] = true;
|
||||
CProfile_TeamIndex[Color_Red] = 2;
|
||||
CProfile_TeamIndex[Color_Blue] = 3;
|
||||
CProfile_SayText2 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Action:CEvent_MapStart(Handle:event, const String:name[], bool:dontBroadcast)
|
||||
{
|
||||
CSetupProfile();
|
||||
|
||||
for (new i = 1; i <= MaxClients; i++)
|
||||
CSkipList[i] = false;
|
||||
}
|
||||
|
141
scripting/sourcemod-discord-master/include/discord.inc
Normal file
141
scripting/sourcemod-discord-master/include/discord.inc
Normal file
@@ -0,0 +1,141 @@
|
||||
#if defined _discord_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _discord_included
|
||||
|
||||
#include <smjansson>
|
||||
#include <discord/stocks>
|
||||
|
||||
typedef DiscordGuildsRetrieve = function void (DiscordBot bot, char[] id, char[] name, char[] icon, bool owner, int permissions, any data);
|
||||
|
||||
typedef DiscordGuildsRetrievedAll = function void (DiscordBot bot, ArrayList id, ArrayList name, ArrayList icon, ArrayList owner, ArrayList permissions, any data);
|
||||
|
||||
//Channel are Handles that are closed immediately after forwards called. To keep, clone. Or store id if thats what you want
|
||||
typedef DiscordGuildChannelsRetrieve = function void (DiscordBot bot, char[] guild, DiscordChannel Channel, any data);
|
||||
|
||||
typedef DiscordGuildChannelsRetrieveAll = function void (DiscordBot bot, char[] guild, ArrayList Channels, any data);
|
||||
|
||||
typedef DiscordGuildGetRoles = function void (DiscordBot bot, char[] guild, RoleList Roles, any data);
|
||||
|
||||
/**
|
||||
* Called when message is received
|
||||
* bot/channel/message are all destroyed after callback is sent.
|
||||
* You can clone it if need to keep.
|
||||
*/
|
||||
typeset OnChannelMessage {
|
||||
function void(DiscordBot bot, DiscordChannel channel, DiscordMessage message);
|
||||
};
|
||||
|
||||
typedef OnGetReactions = function void (DiscordBot bot, ArrayList Users, char[] channelID, const char[] messageID, const char[] emoji, any data);
|
||||
|
||||
typedef OnMessageSent = function void(DiscordBot bot, char[] channel, DiscordMessage message, any data);
|
||||
|
||||
typedef OnMessageDeleted = function void(DiscordBot bot, any data);
|
||||
|
||||
//hMemberList is JSON array containing guild members
|
||||
typedef OnGetMembers = function void(DiscordBot bot, char[] guild, Handle hMemberList);
|
||||
|
||||
methodmap Role < Handle {
|
||||
public void GetID(char[] buffer, int maxlength) {
|
||||
JsonObjectGetString(this, "id", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void GetName(char[] buffer, int maxlength) {
|
||||
JsonObjectGetString(this, "name", buffer, maxlength);
|
||||
}
|
||||
|
||||
public int GetColor() {
|
||||
return JsonObjectGetInt(this, "color");
|
||||
}
|
||||
|
||||
public int GetPosition() {
|
||||
return JsonObjectGetInt(this, "position");
|
||||
}
|
||||
|
||||
public int GetPermissions() {
|
||||
return JsonObjectGetInt(this, "permissions");
|
||||
}
|
||||
|
||||
public bool Hoist() {
|
||||
return JsonObjectGetBool(this, "hoist");
|
||||
}
|
||||
|
||||
public bool Managed() {
|
||||
return JsonObjectGetBool(this, "managed");
|
||||
}
|
||||
|
||||
public bool Mentionable() {
|
||||
return JsonObjectGetBool(this, "mentionable");
|
||||
}
|
||||
};
|
||||
|
||||
methodmap RoleList < Handle {
|
||||
property int Size {
|
||||
public get() {
|
||||
return json_array_size(this);
|
||||
}
|
||||
}
|
||||
public Role GetRole(int i) {
|
||||
return view_as<Role>(
|
||||
json_array_get(this, i)
|
||||
);
|
||||
}
|
||||
public Role Get(int i) {
|
||||
return this.GetRole(i);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
{
|
||||
"id": "80351110224678912",
|
||||
"username": "Nelly",
|
||||
"discriminator": "1337",
|
||||
"avatar": "8342729096ea3675442027381ff50dfe",
|
||||
"verified": true,
|
||||
"email": "nelly@discordapp.com"
|
||||
}
|
||||
*/
|
||||
//It's a JSON Handle with the above info TODO stop using natives!
|
||||
methodmap DiscordUser < Handle {
|
||||
public native void GetID(char[] buffer, int maxlength);
|
||||
|
||||
public native void GetUsername(char[] buffer, int maxlength);
|
||||
|
||||
public native void GetDiscriminator(char[] buffer, int maxlength);
|
||||
public int GetDiscriminatorInt() {
|
||||
char buffer[16];
|
||||
this.GetDiscriminator(buffer, sizeof(buffer));
|
||||
return StringToInt(buffer);
|
||||
}
|
||||
|
||||
public native void GetAvatar(char[] buffer, int maxlength);
|
||||
|
||||
public native bool IsVerified();
|
||||
|
||||
public native void GetEmail(char[] buffer, int maxlength);
|
||||
|
||||
public native bool IsBot();
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
{"timestamp": "2017-01-15T20:26:35.353000+00:00", "mention_everyone": false, "id": "270287641155469313", "pinned": false, "edited_timestamp": null, "author": {"username": "DK-Bot", "discriminator": "6274", "bot": true, "id": "186256454863290369", "avatar": null}, "mention_roles": [], "content": "ab", "channel_id": "229677130483499008", "mentions": [], "type": 0}
|
||||
*/
|
||||
methodmap DiscordMessage < Handle {
|
||||
public native void GetID(char[] buffer, int maxlength);
|
||||
|
||||
public native bool IsPinned();
|
||||
|
||||
public native DiscordUser GetAuthor();
|
||||
|
||||
public native void GetContent(char[] buffer, int maxlength);
|
||||
|
||||
public native void GetChannelID(char[] buffer, int maxlength);
|
||||
};
|
||||
|
||||
#include <discord/channel>
|
||||
#include <discord/message_embed>
|
||||
#include <discord/webhook>
|
||||
#include <discord/bot>
|
||||
#include <discord/GuildMember>
|
@@ -0,0 +1,29 @@
|
||||
methodmap DiscordGuildUser < Handle {
|
||||
//Returns User Object
|
||||
public DiscordUser GetUser() {
|
||||
return view_as<DiscordUser>(json_object_get(this, "user"));
|
||||
}
|
||||
|
||||
//Returns player's nick
|
||||
public void GetNickname(char[] buffer, int maxlength) {
|
||||
JsonObjectGetString(this, "nick", buffer, maxlength);
|
||||
}
|
||||
|
||||
//Returns JSON array list of roles. You can manually loop through them for now.
|
||||
public Handle GetRoles() {
|
||||
return json_object_get(this, "roles");
|
||||
}
|
||||
|
||||
//Returns the date the user joined the guild in format: "2015-04-26T06:26:56.936000+00:00"
|
||||
public void GetJoinedAt(char[] buffer, int maxlength) {
|
||||
JsonObjectGetString(this, "joined_at", buffer, maxlength);
|
||||
}
|
||||
|
||||
public bool IsDeaf() {
|
||||
return JsonObjectGetBool(this, "deaf");
|
||||
}
|
||||
|
||||
public bool IsMute() {
|
||||
return JsonObjectGetBool(this, "mute");
|
||||
}
|
||||
};
|
231
scripting/sourcemod-discord-master/include/discord/bot.inc
Normal file
231
scripting/sourcemod-discord-master/include/discord/bot.inc
Normal file
@@ -0,0 +1,231 @@
|
||||
methodmap DiscordBot < StringMap {
|
||||
public DiscordBot(const char[] token) {
|
||||
Handle json = json_object();
|
||||
json_object_set_new(json, "token", json_string(token));
|
||||
|
||||
return view_as<DiscordBot>(json);
|
||||
}
|
||||
|
||||
public void StopListening() {
|
||||
json_object_del(this, "listeningChannels");
|
||||
}
|
||||
|
||||
property float MessageCheckInterval {
|
||||
public get() {
|
||||
return JsonObjectGetFloat(this, "messageInterval", 3.0);
|
||||
}
|
||||
public set(float value) {
|
||||
json_object_set_new(this, "messageInterval", json_real(value));
|
||||
}
|
||||
}
|
||||
|
||||
public native void StartTimer(DiscordChannel Channel, OnChannelMessage fCallback);
|
||||
|
||||
/**
|
||||
* Retrieves a list of Channels the bot is listening to for messages
|
||||
*/
|
||||
public Handle GetListeningChannels() {
|
||||
return json_object_get(this, "listeningChannels");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the bot is listening to channel for messages
|
||||
* @param DiscordChannel Channel
|
||||
*/
|
||||
public bool IsListeningToChannel(DiscordChannel Channel) {
|
||||
char id[32];
|
||||
Channel.GetID(id, sizeof(id));
|
||||
|
||||
Handle hChannels = this.GetListeningChannels();
|
||||
if(hChannels == null) return false;
|
||||
|
||||
for(int i = 0; i < json_array_size(hChannels); i++) {
|
||||
DiscordChannel tempChannel = view_as<DiscordChannel>(json_array_get(hChannels, i));
|
||||
static char tempID[32];
|
||||
tempChannel.GetID(tempID, sizeof(tempID));
|
||||
if(StrEqual(id, tempID, false)) {
|
||||
delete tempChannel;
|
||||
delete hChannels;
|
||||
return true;
|
||||
}
|
||||
delete tempChannel;
|
||||
}
|
||||
delete hChannels;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the bot is listening to channel for messages
|
||||
* @param DiscordChannel Channel
|
||||
*/
|
||||
public bool IsListeningToChannelID(const char[] id) {
|
||||
Handle hChannels = this.GetListeningChannels();
|
||||
if(hChannels == null) return false;
|
||||
|
||||
for(int i = 0; i < json_array_size(hChannels); i++) {
|
||||
DiscordChannel tempChannel = view_as<DiscordChannel>(json_array_get(hChannels, i));
|
||||
static char tempID[32];
|
||||
tempChannel.GetID(tempID, sizeof(tempID));
|
||||
if(StrEqual(id, tempID, false)) {
|
||||
delete tempChannel;
|
||||
delete hChannels;
|
||||
return true;
|
||||
}
|
||||
delete tempChannel;
|
||||
}
|
||||
delete hChannels;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the bot from listening to that channel for messages
|
||||
* @param DiscordChannel Channel
|
||||
*/
|
||||
public void StopListeningToChannel(DiscordChannel Channel) {
|
||||
char id[32];
|
||||
Channel.GetID(id, sizeof(id));
|
||||
|
||||
Handle channels = this.GetListeningChannels();
|
||||
if(channels == null) return;
|
||||
|
||||
for(int i = 0; i < json_array_size(channels); i++) {
|
||||
DiscordChannel tempChannel = view_as<DiscordChannel>(json_array_get(channels, i));
|
||||
static char tempID[32];
|
||||
tempChannel.GetID(tempID, sizeof(tempID));
|
||||
if(StrEqual(id, tempID, false)) {
|
||||
json_array_remove(channels, i);
|
||||
i--;
|
||||
delete tempChannel;
|
||||
}
|
||||
}
|
||||
delete channels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the bot from listening to that channel id for messages
|
||||
* @param DiscordChannel Channel
|
||||
*/
|
||||
public void StopListeningToChannelID(const char[] id) {
|
||||
Handle channels = this.GetListeningChannels();
|
||||
if(channels == null) return;
|
||||
|
||||
for(int i = 0; i < json_array_size(channels); i++) {
|
||||
DiscordChannel tempChannel = view_as<DiscordChannel>(json_array_get(channels, i));
|
||||
static char tempID[32];
|
||||
tempChannel.GetID(tempID, sizeof(tempID));
|
||||
if(StrEqual(id, tempID, false)) {
|
||||
json_array_remove(channels, i);
|
||||
i--;
|
||||
delete tempChannel;
|
||||
}
|
||||
}
|
||||
delete channels;
|
||||
}
|
||||
|
||||
public DiscordChannel GetListeningChannelByID(const char[] id) {
|
||||
Handle channels = this.GetListeningChannels();
|
||||
if(channels == null) return null;
|
||||
|
||||
for(int i = 0; i < json_array_size(channels); i++) {
|
||||
DiscordChannel tempChannel = view_as<DiscordChannel>(json_array_get(channels, i));
|
||||
static char tempID[32];
|
||||
tempChannel.GetID(tempID, sizeof(tempID));
|
||||
if(StrEqual(id, tempID, false)) {
|
||||
delete channels;
|
||||
return tempChannel;
|
||||
}
|
||||
}
|
||||
delete channels;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start listening to the channel for messages.
|
||||
* The Channel handle is duplicated. Feel free to close yours.
|
||||
* @param DiscordChannel Channel
|
||||
*/
|
||||
public void StartListeningToChannel(DiscordChannel Channel, OnChannelMessage fCallback) {
|
||||
if(this.IsListeningToChannel(Channel)) return;
|
||||
|
||||
Handle channels = this.GetListeningChannels();
|
||||
|
||||
if(channels == null) {
|
||||
channels = json_array();
|
||||
json_object_set(this, "listeningChannels", channels);
|
||||
}
|
||||
|
||||
json_array_append(channels, Channel);
|
||||
|
||||
//Handle fForward = CreateForward(ET_Ignore, Param_Cell, Param_Cell, Param_String, Param_String, Param_String, Param_String, Param_String, Param_Cell);
|
||||
//AddToForward(fForward, GetMyHandle(), callback);
|
||||
|
||||
this.StartTimer(Channel, fCallback);
|
||||
}
|
||||
|
||||
|
||||
public native void AddReactionID(const char[] channel, const char[] messageid, const char[] emoji);
|
||||
|
||||
public void AddReaction(DiscordChannel channel, const char[] messageid, const char[] emoji) {
|
||||
char channelid[64];
|
||||
channel.GetID(channelid, sizeof(channelid));
|
||||
this.AddReactionID(channelid, messageid, emoji);
|
||||
}
|
||||
|
||||
public native void DeleteReactionID(const char[] channel, const char[] messageid, const char[] emoji, const char[] user);
|
||||
|
||||
public void DeleteReaction(DiscordChannel channel, const char[] messageid, const char[] emoji, const char[] user) {
|
||||
char chid[64];
|
||||
channel.GetID(chid, sizeof(chid));
|
||||
this.DeleteReactionID(chid, messageid, emoji, user);
|
||||
}
|
||||
|
||||
public void DeleteReactionSelf(DiscordChannel channel, const char[] messageid, const char[] emoji) {
|
||||
this.DeleteReaction(channel, messageid, emoji, "@me");
|
||||
}
|
||||
public void DeleteReactionAll(DiscordChannel channel, const char[] messageid, const char[] emoji) {
|
||||
this.DeleteReaction(channel, messageid, emoji, "@all");
|
||||
}
|
||||
|
||||
public void DeleteReactionSelfID(const char[] channel, const char[] messageid, const char[] emoji) {
|
||||
this.DeleteReactionID(channel, messageid, emoji, "@me");
|
||||
}
|
||||
public void DeleteReactionAllID(const char[] channel, const char[] messageid, const char[] emoji) {
|
||||
this.DeleteReactionID(channel, messageid, emoji, "@all");
|
||||
}
|
||||
|
||||
public native void GetReactionID(const char[] channel, const char[] messageid, const char[] emoji, OnGetReactions fCallback=INVALID_FUNCTION, any data=0);
|
||||
|
||||
public void GetReaction(DiscordChannel channel, const char[] messageid, const char[] emoji, OnGetReactions fCallback=INVALID_FUNCTION, any data=0) {
|
||||
char id[64];
|
||||
channel.GetID(id, sizeof(id));
|
||||
this.GetReactionID(id, messageid, emoji, fCallback, data);
|
||||
}
|
||||
|
||||
public native void GetToken(char[] token, int maxlength);
|
||||
|
||||
public native void SendMessage(DiscordChannel channel, char[] message, OnMessageSent fCallback=INVALID_FUNCTION, any data=0);
|
||||
|
||||
public native void SendMessageToChannelID(char[] channel, char[] message, OnMessageSent fCallback=INVALID_FUNCTION, any data=0);
|
||||
|
||||
public native void DeleteMessageID(char[] channel, char[] message, OnMessageDeleted fCallback=INVALID_FUNCTION, any data=0);
|
||||
public native void DeleteMessage(DiscordChannel channel, DiscordMessage message, OnMessageDeleted fCallback=INVALID_FUNCTION, any data=0);
|
||||
|
||||
|
||||
public native void GetGuilds(DiscordGuildsRetrieve fCallback = INVALID_FUNCTION, DiscordGuildsRetrievedAll fCallbackAll = INVALID_FUNCTION, any data=0);
|
||||
|
||||
public native void GetGuildChannels(char[] guild, DiscordGuildChannelsRetrieve fCallback = INVALID_FUNCTION, DiscordGuildChannelsRetrieveAll fCallbackAll = INVALID_FUNCTION, any data=0);
|
||||
|
||||
/**
|
||||
* ATM takes guild id, hopefully later on i will implement guild objects.
|
||||
* Limit is from 1-1000
|
||||
*/
|
||||
public native void GetGuildMembers(char[] guild, OnGetMembers fCallback, int limit=250, char[] afterUserID="");
|
||||
|
||||
/**
|
||||
* Same as above but displays ALL members, paginating automatically.
|
||||
* perPage is how many it should display per callback. 1-1000
|
||||
*/
|
||||
public native void GetGuildMembersAll(char[] guild, OnGetMembers fCallback, int perPage=250, char[] afterUserID="");
|
||||
|
||||
public native void GetGuildRoles(char[] guild, DiscordGuildGetRoles fCallback, any data);
|
||||
};
|
@@ -0,0 +1,77 @@
|
||||
enum
|
||||
{
|
||||
GUILD_TEXT = 0,
|
||||
DM,
|
||||
GUILD_VOICE,
|
||||
GROUP_DM,
|
||||
GUILD_CATEGORY
|
||||
};
|
||||
|
||||
methodmap DiscordChannel < StringMap {
|
||||
public DiscordChannel() {
|
||||
Handle hObj = json_object();
|
||||
return view_as<DiscordChannel>(hObj);
|
||||
}
|
||||
|
||||
public native void SendMessage(DiscordBot Bot, char[] message, OnMessageSent fCallback=INVALID_FUNCTION, any data=0);
|
||||
|
||||
public void GetGuildID(char[] buffer, int maxlength) {
|
||||
JsonObjectGetString(this, "guild_id", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void GetID(char[] buffer, int maxlength) {
|
||||
JsonObjectGetString(this, "id", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void GetName(char[] buffer, int maxlength) {
|
||||
JsonObjectGetString(this, "name", buffer, maxlength);
|
||||
}
|
||||
|
||||
property int Position {
|
||||
public get() {
|
||||
return JsonObjectGetInt(this, "position");
|
||||
}
|
||||
}
|
||||
|
||||
property bool IsPrivate {
|
||||
public get() {
|
||||
return JsonObjectGetBool(this, "is_private");
|
||||
}
|
||||
}
|
||||
|
||||
public void GetTopic(char[] buffer, int maxlength) {
|
||||
JsonObjectGetString(this, "topic", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void GetLastMessageID(char[] buffer, int maxlength) {
|
||||
JsonObjectGetString(this, "last_message_id", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetLastMessageID(const char[] id) {
|
||||
json_object_set_new(this, "last_message_id", json_string(id));
|
||||
}
|
||||
|
||||
property int Type {
|
||||
public get() {
|
||||
return JsonObjectGetInt(this, "type");
|
||||
}
|
||||
}
|
||||
|
||||
property int Bitrate {
|
||||
public get() {
|
||||
return JsonObjectGetInt(this, "bitrate");
|
||||
}
|
||||
}
|
||||
|
||||
property int UserLimit {
|
||||
public get() {
|
||||
return JsonObjectGetInt(this, "user_limit");
|
||||
}
|
||||
}
|
||||
|
||||
property bool IsText {
|
||||
public get() {
|
||||
return this.Type == GUILD_TEXT;
|
||||
}
|
||||
}
|
||||
};
|
@@ -0,0 +1,128 @@
|
||||
methodmap MessageEmbed < Handle {
|
||||
public MessageEmbed() {
|
||||
Handle hObj = json_object();
|
||||
return view_as<MessageEmbed>(hObj);
|
||||
}
|
||||
|
||||
public bool GetColor(char[] buffer, int maxlength) {
|
||||
return JsonObjectGetString(this, "color", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetColor(const char[] color) {
|
||||
json_object_set_new(this, "color", json_string(color));
|
||||
}
|
||||
|
||||
public bool GetTitle(char[] buffer, int maxlength) {
|
||||
return JsonObjectGetString(this, "title", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetTitle(const char[] title) {
|
||||
json_object_set_new(this, "title", json_string(title));
|
||||
}
|
||||
|
||||
public bool GetTitleLink(char[] buffer, int maxlength) {
|
||||
return JsonObjectGetString(this, "title_link", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetTitleLink(const char[] title_link) {
|
||||
json_object_set_new(this, "title_link", json_string(title_link));
|
||||
}
|
||||
|
||||
public bool GetImage(char[] buffer, int maxlength) {
|
||||
return JsonObjectGetString(this, "image_url", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetImage(const char[] image_url) {
|
||||
json_object_set_new(this, "image_url", json_string(image_url));
|
||||
}
|
||||
|
||||
public bool GetAuthor(char[] buffer, int maxlength) {
|
||||
return JsonObjectGetString(this, "author_name", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetAuthor(const char[] author_name) {
|
||||
json_object_set_new(this, "author_name", json_string(author_name));
|
||||
}
|
||||
|
||||
public bool GetAuthorLink(char[] buffer, int maxlength) {
|
||||
return JsonObjectGetString(this, "author_link", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetAuthorLink(const char[] author_link) {
|
||||
json_object_set_new(this, "author_link", json_string(author_link));
|
||||
}
|
||||
|
||||
public bool GetAuthorIcon(char[] buffer, int maxlength) {
|
||||
return JsonObjectGetString(this, "author_icon", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetAuthorIcon(const char[] author_icon) {
|
||||
json_object_set_new(this, "author_icon", json_string(author_icon));
|
||||
}
|
||||
|
||||
public bool GetThumb(char[] buffer, int maxlength) {
|
||||
return JsonObjectGetString(this, "thumb_url", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetThumb(const char[] thumb_url) {
|
||||
json_object_set_new(this, "thumb_url", json_string(thumb_url));
|
||||
}
|
||||
|
||||
public bool GetFooter(char[] buffer, int maxlength) {
|
||||
return JsonObjectGetString(this, "footer", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetFooter(const char[] footer) {
|
||||
json_object_set_new(this, "footer", json_string(footer));
|
||||
}
|
||||
|
||||
public bool GetFooterIcon(char[] buffer, int maxlength) {
|
||||
return JsonObjectGetString(this, "footer_icon", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetFooterIcon(const char[] footer_icon) {
|
||||
json_object_set_new(this, "footer_icon", json_string(footer_icon));
|
||||
}
|
||||
/**
|
||||
* Note: Setting Fields will delete the handle!
|
||||
*/
|
||||
property Handle Fields {
|
||||
public get() {
|
||||
return json_object_get(this, "fields");
|
||||
}
|
||||
|
||||
public set(Handle value) {
|
||||
json_object_set_new(this, "fields", value);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddField(const char[] name, const char[] value, bool inline) {
|
||||
Handle hObj = json_object();
|
||||
json_object_set_new(hObj, "name", json_string(name));
|
||||
json_object_set_new(hObj, "value", json_string(value));
|
||||
json_object_set_new(hObj, "inline", json_boolean(inline));
|
||||
Handle hArray = this.Fields;
|
||||
if(this.Fields == null) {
|
||||
hArray = json_array();
|
||||
}
|
||||
json_array_append_new(hArray, hObj);
|
||||
this.Fields = hArray;
|
||||
}
|
||||
|
||||
//Below don't support Slack Mode
|
||||
public bool GetDescription(char[] buffer, int maxlength) {
|
||||
return JsonObjectGetString(this, "description", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetDescription(const char[] description) {
|
||||
json_object_set_new(this, "description", json_string(description));
|
||||
}
|
||||
|
||||
public bool GetURL(char[] buffer, int maxlength) {
|
||||
return JsonObjectGetString(this, "url", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetURL(const char[] url) {
|
||||
json_object_set_new(this, "url", json_string(url));
|
||||
}
|
||||
};
|
@@ -0,0 +1,82 @@
|
||||
stock int JsonObjectGetInt(Handle hElement, char[] key) {
|
||||
Handle hObject = json_object_get(hElement, key);
|
||||
if(hObject == INVALID_HANDLE) return 0;
|
||||
|
||||
int value;
|
||||
if(json_is_integer(hObject)) {
|
||||
value = json_integer_value(hObject);
|
||||
}else if(json_is_string(hObject)) {
|
||||
char buffer[12];
|
||||
json_string_value(hObject, buffer, sizeof(buffer));
|
||||
value = StringToInt(buffer);
|
||||
}
|
||||
CloseHandle(hObject);
|
||||
return value;
|
||||
}
|
||||
|
||||
stock bool JsonObjectGetString(Handle hElement, char[] key, char[] buffer, maxlength) {
|
||||
Handle hObject = json_object_get(hElement, key);
|
||||
if(hObject == INVALID_HANDLE) return false;
|
||||
|
||||
if(json_is_integer(hObject)) {
|
||||
IntToString(json_integer_value(hObject), buffer, maxlength);
|
||||
}else if(json_is_string(hObject)) {
|
||||
json_string_value(hObject, buffer, maxlength);
|
||||
}else if(json_is_real(hObject)) {
|
||||
FloatToString(json_real_value(hObject), buffer, maxlength);
|
||||
}else if(json_is_true(hObject)) {
|
||||
FormatEx(buffer, maxlength, "true");
|
||||
}else if(json_is_false(hObject)) {
|
||||
FormatEx(buffer, maxlength, "false");
|
||||
}
|
||||
CloseHandle(hObject);
|
||||
return true;
|
||||
}
|
||||
|
||||
stock bool JsonObjectGetBool(Handle hElement, char[] key, bool defaultvalue=false) {
|
||||
Handle hObject = json_object_get(hElement, key);
|
||||
if(hObject == INVALID_HANDLE) return defaultvalue;
|
||||
|
||||
bool ObjectBool = defaultvalue;
|
||||
|
||||
if(json_is_integer(hObject)) {
|
||||
ObjectBool = view_as<bool>(json_integer_value(hObject));
|
||||
}else if(json_is_string(hObject)) {
|
||||
char buffer[11];
|
||||
json_string_value(hObject, buffer, sizeof(buffer));
|
||||
if(StrEqual(buffer, "true", false)) {
|
||||
ObjectBool = true;
|
||||
}else if(StrEqual(buffer, "false", false)) {
|
||||
ObjectBool = false;
|
||||
}else {
|
||||
int x = StringToInt(buffer);
|
||||
ObjectBool = view_as<bool>(x);
|
||||
}
|
||||
}else if(json_is_real(hObject)) {
|
||||
ObjectBool = view_as<bool>(RoundToFloor(json_real_value(hObject)));
|
||||
}else if(json_is_true(hObject)) {
|
||||
ObjectBool = true;
|
||||
}else if(json_is_false(hObject)) {
|
||||
ObjectBool = false;
|
||||
}
|
||||
CloseHandle(hObject);
|
||||
return ObjectBool;
|
||||
}
|
||||
|
||||
stock float JsonObjectGetFloat(Handle hJson, char[] key, float defaultValue=0.0) {
|
||||
Handle hObject = json_object_get(hJson, key);
|
||||
if(hObject == INVALID_HANDLE) return defaultValue;
|
||||
|
||||
float value = defaultValue;
|
||||
if(json_is_integer(hObject)) {
|
||||
value = float(json_integer_value(hObject));
|
||||
}else if(json_is_real(hObject)) {
|
||||
value = json_real_value(hObject);
|
||||
}else if(json_is_string(hObject)) {
|
||||
char buffer[12];
|
||||
json_string_value(hObject, buffer, sizeof(buffer));
|
||||
value = StringToFloat(buffer);
|
||||
}
|
||||
CloseHandle(hObject);
|
||||
return value;
|
||||
}
|
142
scripting/sourcemod-discord-master/include/discord/webhook.inc
Normal file
142
scripting/sourcemod-discord-master/include/discord/webhook.inc
Normal file
@@ -0,0 +1,142 @@
|
||||
methodmap DiscordWebHook < Handle {
|
||||
public DiscordWebHook(char[] url) {
|
||||
Handle mp = json_object();
|
||||
json_object_set_new(mp, "__url", json_string(url));
|
||||
Handle data = json_object();
|
||||
json_object_set_new(mp, "__data", data);
|
||||
|
||||
return view_as<DiscordWebHook>(mp);
|
||||
}
|
||||
|
||||
public void GetUrl(char[] buffer, int maxlength) {
|
||||
JsonObjectGetString(this, "__url", buffer, maxlength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets/Sets if the hook should be sent as Slack.
|
||||
* Note: color is different for slack than discord msg.
|
||||
*
|
||||
* @return True if Slack, otherwise false.
|
||||
*/
|
||||
property bool SlackMode {
|
||||
public get() {
|
||||
return JsonObjectGetBool(this, "__slack", false);
|
||||
}
|
||||
|
||||
public set(bool value) {
|
||||
json_object_set_new(this, "__slack", (value) ? json_true() : json_false());
|
||||
}
|
||||
}
|
||||
|
||||
property Handle Data {
|
||||
public get() {
|
||||
return json_object_get(this, "__data");
|
||||
}
|
||||
|
||||
public set(Handle value) {
|
||||
json_object_set_new(this, "__data", value);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateDataObject(char[] key, Handle hObject) {
|
||||
Handle data = this.Data;
|
||||
json_object_set_new(data, key, hObject);
|
||||
delete data;
|
||||
}
|
||||
|
||||
public bool GetDataBool(char[] key, bool defaultValue=false) {
|
||||
Handle data = this.Data;
|
||||
bool value = JsonObjectGetBool(data, key, defaultValue);
|
||||
delete data;
|
||||
return value;
|
||||
}
|
||||
|
||||
public bool GetDataString(char[] key, char[] buffer, int maxlength) {
|
||||
Handle data = this.Data;
|
||||
bool success = JsonObjectGetString(data, key, buffer, maxlength);
|
||||
delete data;
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: Deletes the MessageEmbed Object!
|
||||
*/
|
||||
public void Embed(MessageEmbed Object) {
|
||||
//this.UpdateDataObject("embeds", Object);
|
||||
Handle data = this.Data;
|
||||
Handle hArray = json_object_get(data, "embeds");
|
||||
|
||||
if(hArray == null) {
|
||||
hArray = json_array();
|
||||
json_object_set(data, "embeds", hArray);
|
||||
}
|
||||
|
||||
json_array_append_new(hArray, Object);
|
||||
delete hArray;
|
||||
delete data;
|
||||
|
||||
}
|
||||
|
||||
property bool tts {
|
||||
public get() {
|
||||
return this.GetDataBool("tts", false);
|
||||
}
|
||||
|
||||
public set(bool value) {
|
||||
this.UpdateDataObject("tts", json_boolean(value));
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetUsername(char[] buffer, int maxlength) {
|
||||
return this.GetDataString("username", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetUsername(const char[] name) {
|
||||
this.UpdateDataObject("username", json_string(name));
|
||||
}
|
||||
|
||||
public bool GetAvatar(char[] buffer, int maxlength) {
|
||||
return this.GetDataString("icon_url", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetAvatar(const char[] icon_url) {
|
||||
this.UpdateDataObject("icon_url", json_string(icon_url));
|
||||
}
|
||||
|
||||
public bool GetContent(char[] buffer, int maxlength) {
|
||||
return this.GetDataString("content", buffer, maxlength);
|
||||
}
|
||||
|
||||
public void SetContent(const char[] content) {
|
||||
this.UpdateDataObject("content", json_string(content));
|
||||
}
|
||||
|
||||
/*property Handle OnComplete {
|
||||
public get() {
|
||||
Handle fForward = null;
|
||||
if(!GetTrieValue(this, "callback", fForward)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fForward;
|
||||
}
|
||||
|
||||
public set(Handle value) {
|
||||
SetTrieValue(this, "callback", value);
|
||||
SetTrieValue(this, "plugin", GetMyHandle());
|
||||
}
|
||||
}
|
||||
|
||||
property Handle CallbackPlugin {
|
||||
public get() {
|
||||
Handle value = null;
|
||||
if(!GetTrieValue(this, "plugin", value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}*/
|
||||
|
||||
public native void Send();
|
||||
};
|
Reference in New Issue
Block a user