├── .gitignore ├── LICENSE ├── README.md ├── discord ├── Channel.sp ├── Guild.sp ├── ListenToChannel.sp ├── Message.sp ├── Reaction.sp ├── Shared.sp └── User.sp ├── discord_api.sp ├── example_bot.sp ├── example_bot_callbacks.sp ├── example_webhook.sp └── include ├── discord.inc └── discord ├── DiscordActivity.inc ├── DiscordAttachment.inc ├── DiscordBot.inc ├── DiscordChannel.inc ├── DiscordChannelMention.inc ├── DiscordConnection.inc ├── DiscordEmbed.inc ├── DiscordEmbedAuthor.inc ├── DiscordEmbedField.inc ├── DiscordEmbedFooter.inc ├── DiscordEmbedImage.inc ├── DiscordEmbedProvider.inc ├── DiscordEmbedThumbnail.inc ├── DiscordEmbedVideo.inc ├── DiscordEmoji.inc ├── DiscordException.inc ├── DiscordGatewayPayload.inc ├── DiscordGuild.inc ├── DiscordGuildUser.inc ├── DiscordIdentifyProperties.inc ├── DiscordMessage.inc ├── DiscordMessageReference.inc ├── DiscordObject.inc ├── DiscordPermission.inc ├── DiscordPresence.inc ├── DiscordReaction.inc ├── DiscordRequest.inc ├── DiscordRole.inc ├── DiscordTypeExtensions.inc ├── DiscordUser.inc ├── DiscordVoiceRegion.inc └── DiscordWebHook.inc /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # discord-api 2 | SourceMod Discord API with minimal dependency. 3 | 4 | ### Dependencies: 5 | * https://github.com/KillStr3aK/DateTime (compile) 6 | * https://github.com/clugg/sm-json (compile) 7 | * [SteamWorks](http://users.alliedmods.net/~kyles/builds/SteamWorks/) (compile | extension) 8 | 9 | ### Documentation: 10 | - If you only want to send webhooks in your plugin, you don't need to run the main plugin, just include discord 11 | - SOON.. 12 | -------------------------------------------------------------------------------- /discord/Channel.sp: -------------------------------------------------------------------------------- 1 | public int DiscordBot_ModifyChannel(Handle plugin, int params) 2 | { 3 | DiscordBot bot = GetNativeCell(1); 4 | DiscordChannel from = GetNativeCell(2); 5 | DiscordChannel to = GetNativeCell(3); 6 | OnDiscordChannelModified cb = view_as(GetNativeFunction(4)); 7 | 8 | DataPack pack = new DataPack(); 9 | pack.WriteCell(bot); 10 | pack.WriteCell(plugin); 11 | pack.WriteFunction(cb); 12 | pack.WriteCell(GetNativeCell(5)); 13 | pack.WriteCell(GetNativeCell(6)); 14 | 15 | char channelID[32]; 16 | from.GetID(channelID, sizeof(channelID)); 17 | ModifyChannel(bot, channelID, to, pack); 18 | } 19 | 20 | public int DiscordBot_ModifyChannelID(Handle plugin, int params) 21 | { 22 | DiscordBot bot = GetNativeCell(1); 23 | DiscordChannel to = GetNativeCell(3); 24 | 25 | char channelID[32]; 26 | GetNativeString(2, channelID, sizeof(channelID)); 27 | 28 | OnDiscordChannelModified cb = view_as(GetNativeFunction(4)); 29 | 30 | DataPack pack = new DataPack(); 31 | pack.WriteCell(bot); 32 | pack.WriteCell(plugin); 33 | pack.WriteFunction(cb); 34 | pack.WriteCell(GetNativeCell(5)); 35 | pack.WriteCell(GetNativeCell(6)); 36 | ModifyChannel(bot, channelID, to, pack); 37 | } 38 | 39 | public int DiscordBot_DeleteChannel(Handle plugin, int params) 40 | { 41 | DiscordBot bot = GetNativeCell(1); 42 | DiscordChannel channel = GetNativeCell(2); 43 | OnDiscordChannelModified cb = view_as(GetNativeFunction(3)); 44 | 45 | DataPack pack = new DataPack(); 46 | pack.WriteCell(bot); 47 | pack.WriteCell(plugin); 48 | pack.WriteFunction(cb); 49 | pack.WriteCell(GetNativeCell(4)); 50 | pack.WriteCell(GetNativeCell(5)); 51 | 52 | char channelID[32]; 53 | channel.GetID(channelID, sizeof(channelID)); 54 | DeleteChannel(bot, channelID, pack); 55 | } 56 | 57 | public int DiscordBot_DeleteChannelID(Handle plugin, int params) 58 | { 59 | DiscordBot bot = GetNativeCell(1); 60 | 61 | char channelID[32]; 62 | GetNativeString(2, channelID, sizeof(channelID)); 63 | 64 | OnDiscordChannelModified cb = view_as(GetNativeFunction(3)); 65 | 66 | DataPack pack = new DataPack(); 67 | pack.WriteCell(bot); 68 | pack.WriteCell(plugin); 69 | pack.WriteFunction(cb); 70 | pack.WriteCell(GetNativeCell(4)); 71 | pack.WriteCell(GetNativeCell(5)); 72 | DeleteChannel(bot, channelID, pack); 73 | } 74 | 75 | public int DiscordBot_CreateDM(Handle plugin, int params) 76 | { 77 | DiscordBot bot = GetNativeCell(1); 78 | DiscordUser user = GetNativeCell(2); 79 | 80 | char userid[64]; 81 | user.GetID(userid, sizeof(userid)); 82 | CreateDM(bot, userid); 83 | } 84 | 85 | public int DiscordBot_CreateDMID(Handle plugin, int params) 86 | { 87 | DiscordBot bot = GetNativeCell(1); 88 | 89 | char userid[64]; 90 | GetNativeString(2, userid, sizeof(userid)); 91 | CreateDM(bot, userid); 92 | } 93 | 94 | public int DiscordBot_GetChannel(Handle plugin, int params) 95 | { 96 | DiscordBot bot = GetNativeCell(1); 97 | 98 | char channelID[32]; 99 | GetNativeString(2, channelID, sizeof(channelID)); 100 | 101 | OnGetDiscordChannel cb = view_as(GetNativeFunction(3)); 102 | 103 | DataPack pack = new DataPack(); 104 | pack.WriteCell(bot); 105 | pack.WriteCell(plugin); 106 | pack.WriteFunction(cb); 107 | pack.WriteCell(GetNativeCell(4)); 108 | pack.WriteCell(GetNativeCell(5)); 109 | GetChannel(bot, channelID, pack); 110 | } 111 | 112 | public int DiscordBot_TriggerTypingIndicator(Handle plugin, int params) 113 | { 114 | DiscordBot bot = GetNativeCell(1); 115 | DiscordChannel channel = GetNativeCell(2); 116 | 117 | char channelID[32]; 118 | channel.GetID(channelID, sizeof(channelID)); 119 | TriggerTypingIndicator(bot, channelID); 120 | } 121 | 122 | public int DiscordBot_TriggerTypingIndicatorID(Handle plugin, int params) 123 | { 124 | DiscordBot bot = GetNativeCell(1); 125 | 126 | char channelID[32]; 127 | GetNativeString(2, channelID, sizeof(channelID)); 128 | TriggerTypingIndicator(bot, channelID); 129 | } 130 | 131 | static void ModifyChannel(DiscordBot bot, const char[] channelid, DiscordChannel to, DataPack pack) 132 | { 133 | char route[64]; 134 | Format(route, sizeof(route), "channels/%s", channelid); 135 | SendRequest(bot, route, to, k_EHTTPMethodPATCH, OnDiscordDataReceived, _, pack); 136 | } 137 | 138 | static void DeleteChannel(DiscordBot bot, const char[] channelid, DataPack pack) 139 | { 140 | char route[64]; 141 | Format(route, sizeof(route), "channels/%s", channelid); 142 | SendRequest(bot, route, _, k_EHTTPMethodDELETE, OnDiscordDataReceived, _, pack); 143 | } 144 | 145 | static void CreateDM(DiscordBot bot, const char[] userid) 146 | { 147 | char route[64]; 148 | Format(route, sizeof(route), "users/@me/channels"); 149 | 150 | JSON_Object obj = new JSON_Object(); 151 | obj.SetString("recipient_id", userid); 152 | SendRequest(bot, route, obj, k_EHTTPMethodPOST); 153 | } 154 | 155 | static void GetChannel(DiscordBot bot, const char[] channelid, DataPack pack) 156 | { 157 | char route[64]; 158 | Format(route, sizeof(route), "channels/%s", channelid); 159 | SendRequest(bot, route, _, k_EHTTPMethodGET, OnDiscordDataReceived, _, pack); 160 | } 161 | 162 | static void TriggerTypingIndicator(DiscordBot bot, const char[] channelid) 163 | { 164 | char route[64]; 165 | Format(route, sizeof(route), "channels/%s/typing", channelid); 166 | SendRequest(bot, route, _, k_EHTTPMethodPOST); 167 | } -------------------------------------------------------------------------------- /discord/Guild.sp: -------------------------------------------------------------------------------- 1 | public int DiscordBot_CreateGuild(Handle plugin, int params) 2 | { 3 | DiscordBot bot = GetNativeCell(1); 4 | DiscordGuild guild = GetNativeCell(2); 5 | OnDiscordGuildCreated cb = GetNativeCell(3); 6 | 7 | DataPack pack = new DataPack(); 8 | pack.WriteCell(bot); 9 | pack.WriteCell(plugin); 10 | pack.WriteFunction(cb); 11 | pack.WriteCell(GetNativeCell(4)); 12 | pack.WriteCell(GetNativeCell(5)); 13 | 14 | CreateGuild(bot, guild, pack); 15 | } 16 | 17 | public int DiscordBot_AddRole(Handle plugin, int params) 18 | { 19 | DiscordBot bot = GetNativeCell(1); 20 | DiscordGuild guild = GetNativeCell(2); 21 | DiscordUser user = GetNativeCell(3); 22 | DiscordRole role = GetNativeCell(4); 23 | 24 | char guildid[64]; 25 | guild.GetID(guildid, sizeof(guildid)); 26 | 27 | char userid[64]; 28 | user.GetID(userid, sizeof(userid)); 29 | 30 | char roleid[64]; 31 | role.GetID(roleid, sizeof(roleid)); 32 | AddRole(bot, guildid, userid, roleid); 33 | } 34 | 35 | public int DiscordBot_AddRoleID(Handle plugin, int params) 36 | { 37 | DiscordBot bot = GetNativeCell(1); 38 | 39 | char guildid[64]; 40 | GetNativeString(2, guildid, sizeof(guildid)); 41 | 42 | char userid[64]; 43 | GetNativeString(3, userid, sizeof(userid)); 44 | 45 | char roleid[64]; 46 | GetNativeString(4, roleid, sizeof(roleid)); 47 | AddRole(bot, guildid, userid, roleid); 48 | } 49 | 50 | public int DiscordBot_RemoveRole(Handle plugin, int params) 51 | { 52 | DiscordBot bot = GetNativeCell(1); 53 | DiscordGuild guild = GetNativeCell(2); 54 | DiscordUser user = GetNativeCell(3); 55 | DiscordRole role = GetNativeCell(4); 56 | 57 | char guildid[64]; 58 | guild.GetID(guildid, sizeof(guildid)); 59 | 60 | char userid[64]; 61 | user.GetID(userid, sizeof(userid)); 62 | 63 | char roleid[64]; 64 | role.GetID(roleid, sizeof(roleid)); 65 | RemoveRole(bot, guildid, userid, roleid); 66 | } 67 | 68 | public int DiscordBot_RemoveRoleID(Handle plugin, int params) 69 | { 70 | DiscordBot bot = GetNativeCell(1); 71 | 72 | char guildid[64]; 73 | GetNativeString(2, guildid, sizeof(guildid)); 74 | 75 | char userid[64]; 76 | GetNativeString(3, userid, sizeof(userid)); 77 | 78 | char roleid[64]; 79 | GetNativeString(4, roleid, sizeof(roleid)); 80 | RemoveRole(bot, guildid, userid, roleid); 81 | } 82 | 83 | public int DiscordBot_GetGuild(Handle plugin, int params) 84 | { 85 | DiscordBot bot = GetNativeCell(1); 86 | 87 | char guildid[64]; 88 | GetNativeString(2, guildid, sizeof(guildid)); 89 | 90 | bool with_counts = GetNativeCell(3); 91 | OnGetDiscordGuild cb = view_as(GetNativeFunction(4)); 92 | 93 | DataPack pack = new DataPack(); 94 | pack.WriteCell(bot); 95 | pack.WriteCell(plugin); 96 | pack.WriteFunction(cb); 97 | pack.WriteCell(GetNativeCell(5)); 98 | pack.WriteCell(GetNativeCell(6)); 99 | GetGuild(bot, guildid, with_counts, pack); 100 | } 101 | 102 | public int DiscordBot_GetGuildMember(Handle plugin, int params) 103 | { 104 | DiscordBot bot = GetNativeCell(1); 105 | DiscordGuild guild = GetNativeCell(2); 106 | DiscordUser user = GetNativeCell(3); 107 | OnGetDiscordGuildUser cb = view_as(GetNativeFunction(4)); 108 | 109 | char guildid[64]; 110 | guild.GetID(guildid, sizeof(guildid)); 111 | 112 | char userid[64]; 113 | user.GetID(userid, sizeof(userid)); 114 | 115 | DataPack pack = new DataPack(); 116 | pack.WriteCell(bot); 117 | pack.WriteCell(plugin); 118 | pack.WriteFunction(cb); 119 | pack.WriteCell(GetNativeCell(5)); 120 | pack.WriteCell(GetNativeCell(6)); 121 | GetGuildMember(bot, guildid, userid, pack); 122 | } 123 | 124 | public int DiscordBot_GetGuildMemberID(Handle plugin, int params) 125 | { 126 | DiscordBot bot = GetNativeCell(1); 127 | 128 | char guildid[64]; 129 | GetNativeString(2, guildid, sizeof(guildid)); 130 | 131 | char userid[64]; 132 | GetNativeString(3, userid, sizeof(userid)); 133 | 134 | OnGetDiscordGuildUser cb = view_as(GetNativeFunction(4)); 135 | 136 | DataPack pack = new DataPack(); 137 | pack.WriteCell(bot); 138 | pack.WriteCell(plugin); 139 | pack.WriteFunction(cb); 140 | pack.WriteCell(GetNativeCell(5)); 141 | pack.WriteCell(GetNativeCell(6)); 142 | GetGuildMember(bot, guildid, userid, pack); 143 | } 144 | 145 | public int DiscordBot_GetGuildScheduledEvent(Handle plugin, int params) 146 | { 147 | DiscordBot bot = GetNativeCell(1); 148 | DiscordGuild guild = GetNativeCell(2); 149 | 150 | char guildid[64]; 151 | guild.GetID(guildid, sizeof(guildid)); 152 | 153 | char eventid[64]; 154 | GetNativeString(3, eventid, sizeof(eventid)); 155 | 156 | OnGetDiscordGuildScheduledEvent cb = view_as(GetNativeFunction(4)); 157 | 158 | DataPack pack = new DataPack(); 159 | pack.WriteCell(bot); 160 | pack.WriteCell(plugin); 161 | pack.WriteFunction(cb); 162 | pack.WriteCell(GetNativeCell(5)); 163 | pack.WriteCell(GetNativeCell(6)); 164 | GetGuildScheduledEvent(bot, guildid, eventid, pack); 165 | } 166 | 167 | public int DiscordBot_DeleteGuildScheduledEvent(Handle plugin, int params) 168 | { 169 | DiscordBot bot = GetNativeCell(1); 170 | DiscordGuild guild = GetNativeCell(2); 171 | DiscordGuildScheduledEvent event = GetNativeCell(3); 172 | 173 | char guildid[64]; 174 | guild.GetID(guildid, sizeof(guildid)); 175 | 176 | char eventid[64]; 177 | event.GetID(eventid, sizeof(eventid)); 178 | 179 | DeleteGuildScheduledEvent(bot, guildid, eventid); 180 | } 181 | 182 | static void CreateGuild(DiscordBot bot, DiscordGuild guild, DataPack pack) 183 | { 184 | char route[128]; 185 | Format(route, sizeof(route), "guilds"); 186 | SendRequest(bot, route, guild, k_EHTTPMethodPOST, OnDiscordDataReceived, _, pack); 187 | } 188 | 189 | static void AddRole(DiscordBot bot, const char[] guildid, const char[] userid, const char[] roleid) 190 | { 191 | char route[128]; 192 | Format(route, sizeof(route), "guilds/%s/members/%s/roles/%s", guildid, userid, roleid); 193 | SendRequest(bot, route, _, k_EHTTPMethodPUT); 194 | } 195 | 196 | static void RemoveRole(DiscordBot bot, const char[] guildid, const char[] userid, const char[] roleid) 197 | { 198 | char route[128]; 199 | Format(route, sizeof(route), "guilds/%s/members/%s/roles/%s", guildid, userid, roleid); 200 | SendRequest(bot, route, _, k_EHTTPMethodDELETE); 201 | } 202 | 203 | static void GetGuild(DiscordBot bot, const char[] guildid, bool with_counts, DataPack pack) 204 | { 205 | char route[128]; 206 | Format(route, sizeof(route), "guilds/%s?with_counts=%s", guildid, with_counts ? "true" : "false"); 207 | SendRequest(bot, route, _, k_EHTTPMethodGET, OnDiscordDataReceived, _, pack); 208 | } 209 | 210 | static void GetGuildMember(DiscordBot bot, const char[] guildid, const char[] userid, DataPack pack) 211 | { 212 | char route[128]; 213 | Format(route, sizeof(route), "guilds/%s/members/%s", guildid, userid); 214 | SendRequest(bot, route, _, k_EHTTPMethodGET, OnDiscordDataReceived, _, pack); 215 | } 216 | 217 | static void GetGuildScheduledEvent(DiscordBot bot, const char[] guildid, const char[] eventid, DataPack pack) 218 | { 219 | char route[128]; 220 | Format(route, sizeof(route), "guilds/%s/scheduled-events/%s", guildid, eventid); 221 | SendRequest(bot, route, _, k_EHTTPMethodGET, OnDiscordDataReceived, _, pack); 222 | } 223 | 224 | static void DeleteGuildScheduledEvent(DiscordBot bot, const char[] guildid, const char[] eventid) 225 | { 226 | char route[128]; 227 | Format(route, sizeof(route), "guilds/%s/scheduled-events/%s", guildid, eventid); 228 | SendRequest(bot, route, _, k_EHTTPMethodDELETE); 229 | } -------------------------------------------------------------------------------- /discord/ListenToChannel.sp: -------------------------------------------------------------------------------- 1 | public int DiscordBot_StartTimer(Handle plugin, int params) 2 | { 3 | DiscordBot bot = GetNativeCell(1); 4 | DiscordChannel channel = GetNativeCell(2); 5 | OnDiscordChannelMessage cb = view_as(GetNativeFunction(3)); 6 | 7 | DataPack pack = new DataPack(); 8 | pack.WriteCell(bot); 9 | pack.WriteCell(plugin); 10 | pack.WriteFunction(cb); 11 | pack.WriteCell(channel); 12 | 13 | ListenGetMessages(bot, channel, pack); 14 | } 15 | 16 | static void ListenGetMessages(DiscordBot bot, DiscordChannel channel, DataPack pack) 17 | { 18 | char channelid[32]; 19 | channel.GetID(channelid, sizeof(channelid)); 20 | 21 | char lastmessageid[32]; 22 | channel.GetLastMessageID(lastmessageid, sizeof(lastmessageid)); 23 | 24 | char route[256]; 25 | Format(route, sizeof(route), "channels/%s/messages?limit=%i&after=%s", channelid, 100, lastmessageid); 26 | SendRequest(bot, route, _, k_EHTTPMethodGET, OnListenChannelDataReceived, _, pack); 27 | } 28 | 29 | public int OnListenChannelDataReceived(Handle request, bool failure, int offset, int statuscode, DataPack pack) 30 | { 31 | if(failure || (statuscode != 200 && statuscode != 204)) 32 | { 33 | if(statuscode == 400 || statuscode == 429 || statuscode == 500) 34 | { 35 | // bad format or rate limit or server error handling 36 | } 37 | 38 | new DiscordException("OnListenChannelDataReceived - Fail %i %i", failure, statuscode); 39 | delete pack; 40 | delete request; 41 | return; 42 | } 43 | 44 | SteamWorks_GetHTTPResponseBodyCallback(request, ReceivedData, pack); 45 | delete request; 46 | } 47 | 48 | static stock Action GetMessageTimer(Handle timer, DataPack pack) 49 | { 50 | pack.Reset(); 51 | DiscordBot bot = pack.ReadCell(); 52 | pack.ReadCell(); // read plugin handle to jump position.. 53 | pack.ReadFunction(); // read function callback to jump position.. 54 | DiscordChannel channel = pack.ReadCell(); 55 | 56 | ListenGetMessages(bot, channel, pack); 57 | } 58 | 59 | static int ReceivedData(const char[] data, DataPack pack) 60 | { 61 | pack.Reset(); 62 | DiscordBot bot = pack.ReadCell(); 63 | Handle plugin = pack.ReadCell(); 64 | Function callback = pack.ReadFunction(); 65 | DiscordChannel channel = pack.ReadCell(); 66 | 67 | if(!bot.IsListeningToChannel(channel) || callback == INVALID_FUNCTION) 68 | { 69 | delete pack; 70 | return; 71 | } 72 | 73 | char channelid[32]; 74 | DiscordMessageList messages = view_as(json_decode(data)); 75 | 76 | for(int i = messages.Length - 1; i >= 0; i--) 77 | { 78 | DiscordMessage message = view_as(messages.GetObject(i)); 79 | message.GetChannelID(channelid, sizeof(channelid)); 80 | 81 | if(!bot.IsListeningToChannelID(channelid)) 82 | { 83 | delete pack; 84 | return; 85 | } 86 | 87 | if(i == 0) 88 | { 89 | char messageid[64]; 90 | message.GetID(messageid, sizeof(messageid)); 91 | channel.SetLastMessageID(messageid); 92 | } 93 | 94 | Call_StartFunction(plugin, callback); 95 | Call_PushCell(bot); 96 | Call_PushCell(channel); 97 | Call_PushCell(message); 98 | Call_Finish(); 99 | } 100 | 101 | messages.Dispose(); 102 | CreateTimer(bot.MessageCheckInterval, GetMessageTimer, pack); 103 | } -------------------------------------------------------------------------------- /discord/Message.sp: -------------------------------------------------------------------------------- 1 | public int DiscordBot_SendMessageToChannel(Handle plugin, int params) 2 | { 3 | DiscordBot bot = GetNativeCell(1); 4 | DiscordChannel channel = GetNativeCell(2); 5 | DiscordMessage message = GetNativeCell(3); 6 | 7 | char szID[32]; 8 | channel.GetID(szID, sizeof(szID)); 9 | SendMessage(bot, szID, message); 10 | } 11 | 12 | public int DiscordBot_SendMessageToChannelID(Handle plugin, int params) 13 | { 14 | DiscordBot bot = GetNativeCell(1); 15 | char channel[32]; 16 | GetNativeString(2, channel, sizeof(channel)); 17 | DiscordMessage message = GetNativeCell(3); 18 | SendMessage(bot, channel, message); 19 | } 20 | 21 | public int DiscordBot_DeleteMessage(Handle plugin, int params) 22 | { 23 | DiscordBot bot = GetNativeCell(1); 24 | DiscordChannel channel = GetNativeCell(2); 25 | DiscordMessage message = GetNativeCell(3); 26 | 27 | char channelID[32]; 28 | channel.GetID(channelID, sizeof(channelID)); 29 | 30 | char messageID[32]; 31 | message.GetID(messageID, sizeof(messageID)); 32 | DeleteMessage(bot, channelID, messageID); 33 | } 34 | 35 | public int DiscordBot_DeleteMessageID(Handle plugin, int params) 36 | { 37 | DiscordBot bot = GetNativeCell(1); 38 | char channelID[32]; 39 | GetNativeString(2, channelID, sizeof(channelID)); 40 | 41 | char messageID[32]; 42 | GetNativeString(3, messageID, sizeof(messageID)); 43 | DeleteMessage(bot, channelID, messageID); 44 | } 45 | 46 | public int DiscordBot_DeleteMessagesBulk(Handle plugin, int params) 47 | { 48 | DiscordBot bot = GetNativeCell(1); 49 | char channelID[32]; 50 | GetNativeString(2, channelID, sizeof(channelID)); 51 | 52 | JSON_Array messages = GetNativeCell(3); 53 | 54 | char route[64]; 55 | Format(route, sizeof(route), "channels/%s/messages/bulk-delete", channelID); 56 | SendRequest(bot, route, messages, k_EHTTPMethodPOST); 57 | } 58 | 59 | public int DiscordBot_EditMessage(Handle plugin, int params) 60 | { 61 | DiscordBot bot = GetNativeCell(1); 62 | DiscordChannel channel = GetNativeCell(2); 63 | DiscordMessage from = GetNativeCell(3); 64 | DiscordMessage to = GetNativeCell(4); 65 | 66 | char channelID[32]; 67 | channel.GetID(channelID, sizeof(channelID)); 68 | 69 | char messageID[32]; 70 | from.GetID(messageID, sizeof(messageID)); 71 | EditMessage(bot, channelID, messageID, to); 72 | } 73 | 74 | public int DiscordBot_EditMessageID(Handle plugin, int params) 75 | { 76 | DiscordBot bot = GetNativeCell(1); 77 | DiscordMessage to = GetNativeCell(4); 78 | char channelID[32]; 79 | GetNativeString(2, channelID, sizeof(channelID)); 80 | 81 | char messageID[32]; 82 | GetNativeString(3, messageID, sizeof(messageID)); 83 | EditMessage(bot, channelID, messageID, to); 84 | } 85 | 86 | public int DiscordBot_PinMessage(Handle plugin, int params) 87 | { 88 | DiscordBot bot = GetNativeCell(1); 89 | DiscordChannel channel = GetNativeCell(2); 90 | DiscordMessage message = GetNativeCell(3); 91 | 92 | char channelID[32]; 93 | channel.GetID(channelID, sizeof(channelID)); 94 | 95 | char messageID[32]; 96 | message.GetID(messageID, sizeof(messageID)); 97 | PinMessage(bot, channelID, messageID); 98 | } 99 | 100 | public int DiscordBot_PinMessageID(Handle plugin, int params) 101 | { 102 | DiscordBot bot = GetNativeCell(1); 103 | 104 | char channelID[32]; 105 | GetNativeString(2, channelID, sizeof(channelID)); 106 | 107 | char messageID[32]; 108 | GetNativeString(3, messageID, sizeof(messageID)); 109 | PinMessage(bot, channelID, messageID); 110 | } 111 | 112 | public int DiscordBot_UnpinMessage(Handle plugin, int params) 113 | { 114 | DiscordBot bot = GetNativeCell(1); 115 | DiscordChannel channel = GetNativeCell(2); 116 | DiscordMessage message = GetNativeCell(3); 117 | 118 | char channelID[32]; 119 | channel.GetID(channelID, sizeof(channelID)); 120 | 121 | char messageID[32]; 122 | message.GetID(messageID, sizeof(messageID)); 123 | UnpinMessage(bot, channelID, messageID); 124 | } 125 | 126 | public int DiscordBot_UnpinMessageID(Handle plugin, int params) 127 | { 128 | DiscordBot bot = GetNativeCell(1); 129 | 130 | char channelID[32]; 131 | GetNativeString(2, channelID, sizeof(channelID)); 132 | 133 | char messageID[32]; 134 | GetNativeString(3, messageID, sizeof(messageID)); 135 | UnpinMessage(bot, channelID, messageID); 136 | } 137 | 138 | public int DiscordBot_GetChannelMessages(Handle plugin, int params) 139 | { 140 | DiscordBot bot = GetNativeCell(1); 141 | DiscordChannel channel = GetNativeCell(2); 142 | 143 | char around[32]; 144 | GetNativeString(3, around, sizeof(around)); 145 | 146 | char before[32]; 147 | GetNativeString(4, before, sizeof(before)); 148 | 149 | char after[32]; 150 | GetNativeString(5, after, sizeof(after)); 151 | 152 | int limit = GetNativeCell(6); 153 | 154 | OnGetDiscordChannelMessages cb = view_as(GetNativeFunction(7)); 155 | 156 | DataPack pack = new DataPack(); 157 | pack.WriteCell(bot); 158 | pack.WriteCell(plugin); 159 | pack.WriteFunction(cb); 160 | pack.WriteCell(GetNativeCell(8)); 161 | pack.WriteCell(GetNativeCell(9)); 162 | 163 | char channelID[32]; 164 | channel.GetID(channelID, sizeof(channelID)); 165 | GetChannelMessages(bot, channelID, around, before, after, limit, pack); 166 | } 167 | 168 | public int DiscordBot_GetChannelMessagesID(Handle plugin, int params) 169 | { 170 | DiscordBot bot = GetNativeCell(1); 171 | 172 | char channelID[32]; 173 | GetNativeString(2, channelID, sizeof(channelID)); 174 | 175 | char around[32]; 176 | GetNativeString(3, around, sizeof(around)); 177 | 178 | char before[32]; 179 | GetNativeString(4, before, sizeof(before)); 180 | 181 | char after[32]; 182 | GetNativeString(5, after, sizeof(after)); 183 | 184 | int limit = GetNativeCell(6); 185 | 186 | OnGetDiscordChannelMessages cb = view_as(GetNativeFunction(7)); 187 | 188 | DataPack pack = new DataPack(); 189 | pack.WriteCell(bot); 190 | pack.WriteCell(plugin); 191 | pack.WriteFunction(cb); 192 | pack.WriteCell(GetNativeCell(8)); 193 | pack.WriteCell(GetNativeCell(9)); 194 | GetChannelMessages(bot, channelID, around, before, after, limit, pack); 195 | } 196 | 197 | public int DiscordBot_GetChannelMessage(Handle plugin, int params) 198 | { 199 | DiscordBot bot = GetNativeCell(1); 200 | DiscordChannel channel = GetNativeCell(2); 201 | 202 | char messageID[32]; 203 | GetNativeString(3, messageID, sizeof(messageID)); 204 | 205 | OnGetDiscordChannelMessage cb = view_as(GetNativeFunction(4)); 206 | 207 | DataPack pack = new DataPack(); 208 | pack.WriteCell(bot); 209 | pack.WriteCell(plugin); 210 | pack.WriteFunction(cb); 211 | pack.WriteCell(GetNativeCell(5)); 212 | pack.WriteCell(GetNativeCell(6)); 213 | 214 | char channelID[32]; 215 | channel.GetID(channelID, sizeof(channelID)); 216 | GetChannelMessage(bot, channelID, messageID, pack); 217 | } 218 | 219 | public int DiscordBot_GetChannelMessageID(Handle plugin, int params) 220 | { 221 | DiscordBot bot = GetNativeCell(1); 222 | 223 | char channelID[32]; 224 | GetNativeString(2, channelID, sizeof(channelID)); 225 | 226 | char messageID[32]; 227 | GetNativeString(3, messageID, sizeof(messageID)); 228 | 229 | OnGetDiscordChannelMessage cb = view_as(GetNativeFunction(4)); 230 | 231 | DataPack pack = new DataPack(); 232 | pack.WriteCell(bot); 233 | pack.WriteCell(plugin); 234 | pack.WriteFunction(cb); 235 | pack.WriteCell(GetNativeCell(5)); 236 | pack.WriteCell(GetNativeCell(6)); 237 | GetChannelMessage(bot, channelID, messageID, pack); 238 | } 239 | 240 | public int DiscordBot_GetPinnedMessages(Handle plugin, int params) 241 | { 242 | DiscordBot bot = GetNativeCell(1); 243 | DiscordChannel channel = GetNativeCell(2); 244 | OnGetDiscordChannelPinnedMessages cb = view_as(GetNativeFunction(3)); 245 | 246 | DataPack pack = new DataPack(); 247 | pack.WriteCell(bot); 248 | pack.WriteCell(plugin); 249 | pack.WriteFunction(cb); 250 | pack.WriteCell(GetNativeCell(4)); 251 | pack.WriteCell(GetNativeCell(5)); 252 | 253 | char channelID[32]; 254 | channel.GetID(channelID, sizeof(channelID)); 255 | GetPinnedMessages(bot, channelID, pack); 256 | } 257 | 258 | public int DiscordBot_GetPinnedMessagesID(Handle plugin, int params) 259 | { 260 | DiscordBot bot = GetNativeCell(1); 261 | 262 | char channelID[32]; 263 | GetNativeString(2, channelID, sizeof(channelID)); 264 | 265 | OnGetDiscordChannelPinnedMessages cb = view_as(GetNativeFunction(3)); 266 | 267 | DataPack pack = new DataPack(); 268 | pack.WriteCell(bot); 269 | pack.WriteCell(plugin); 270 | pack.WriteFunction(cb); 271 | pack.WriteCell(GetNativeCell(4)); 272 | pack.WriteCell(GetNativeCell(5)); 273 | GetPinnedMessages(bot, channelID, pack); 274 | } 275 | 276 | public int DiscordBot_CrosspostMessage(Handle plugin, int params) 277 | { 278 | DiscordBot bot = GetNativeCell(1); 279 | DiscordChannel channel = GetNativeCell(2); 280 | DiscordMessage message = GetNativeCell(3); 281 | 282 | char channelID[32]; 283 | channel.GetID(channelID, sizeof(channelID)); 284 | 285 | char messageID[32]; 286 | message.GetID(messageID, sizeof(messageID)); 287 | 288 | CrosspostMessage(bot, channelID, messageID); 289 | } 290 | 291 | static void SendMessage(DiscordBot bot, const char[] channelid, DiscordMessage message) 292 | { 293 | char route[64]; 294 | Format(route, sizeof(route), "channels/%s/messages", channelid); 295 | SendRequest(bot, route, message, k_EHTTPMethodPOST); 296 | } 297 | 298 | static void DeleteMessage(DiscordBot bot, const char[] channelid, const char[] messageid) 299 | { 300 | char route[64]; 301 | Format(route, sizeof(route), "channels/%s/messages/%s", channelid, messageid); 302 | SendRequest(bot, route, _, k_EHTTPMethodDELETE); 303 | } 304 | 305 | static void EditMessage(DiscordBot bot, const char[] channelid, const char[] messageid, DiscordMessage message) 306 | { 307 | char route[64]; 308 | Format(route, sizeof(route), "channels/%s/messages/%s", channelid, messageid); 309 | SendRequest(bot, route, message, k_EHTTPMethodPATCH); 310 | } 311 | 312 | static void PinMessage(DiscordBot bot, const char[] channelid, const char[] messageid) 313 | { 314 | char route[64]; 315 | Format(route, sizeof(route), "channels/%s/pins/%s", channelid, messageid); 316 | SendRequest(bot, route, _, k_EHTTPMethodPUT); 317 | } 318 | 319 | static void UnpinMessage(DiscordBot bot, const char[] channelid, const char[] messageid) 320 | { 321 | char route[64]; 322 | Format(route, sizeof(route), "channels/%s/pins/%s", channelid, messageid); 323 | SendRequest(bot, route, _, k_EHTTPMethodDELETE); 324 | } 325 | 326 | static void GetChannelMessages(DiscordBot bot, const char[] channelid, const char[] around, const char[] before, const char[] after, int limit, DataPack pack) 327 | { 328 | char route[256]; 329 | Format(route, sizeof(route), "channels/%s/messages?around=%s&before=%s&after=%s&limit=%i", channelid, around, before, after, limit); 330 | SendRequest(bot, route, _, k_EHTTPMethodGET, OnDiscordDataReceived, _, pack); 331 | } 332 | 333 | static void GetChannelMessage(DiscordBot bot, const char[] channelid, const char[] messageid, DataPack pack) 334 | { 335 | char route[64]; 336 | Format(route, sizeof(route), "channels/%s/messages/%s", channelid, messageid); 337 | SendRequest(bot, route, _, k_EHTTPMethodGET, OnDiscordDataReceived, _, pack); 338 | } 339 | 340 | static void GetPinnedMessages(DiscordBot bot, const char[] channelid, DataPack pack) 341 | { 342 | char route[64]; 343 | Format(route, sizeof(route), "channels/%s/pins", channelid); 344 | SendRequest(bot, route, _, k_EHTTPMethodGET, OnDiscordDataReceived, _, pack); 345 | } 346 | 347 | static void CrosspostMessage(DiscordBot bot, const char[] channelid, const char[] messageid) 348 | { 349 | char route[128]; 350 | Format(route, sizeof(route), "channels/%s/messages/%s/crosspost", channelid, messageid); 351 | SendRequest(bot, route, _, k_EHTTPMethodPOST); 352 | } -------------------------------------------------------------------------------- /discord/Reaction.sp: -------------------------------------------------------------------------------- 1 | public int DiscordBot_CreateReaction(Handle plugin, int params) 2 | { 3 | DiscordBot bot = GetNativeCell(1); 4 | DiscordChannel channel = GetNativeCell(2); 5 | DiscordMessage message = GetNativeCell(3); 6 | DiscordEmoji emoji = GetNativeCell(4); 7 | 8 | char channelID[32]; 9 | channel.GetID(channelID, sizeof(channelID)); 10 | 11 | char messageID[32]; 12 | message.GetID(messageID, sizeof(messageID)); 13 | CreateReaction(bot, channelID, messageID, emoji); 14 | } 15 | 16 | public int DiscordBot_DeleteOwnReaction(Handle plugin, int params) 17 | { 18 | DiscordBot bot = GetNativeCell(1); 19 | DiscordChannel channel = GetNativeCell(2); 20 | DiscordMessage message = GetNativeCell(3); 21 | DiscordEmoji emoji = GetNativeCell(4); 22 | 23 | char channelID[32]; 24 | channel.GetID(channelID, sizeof(channelID)); 25 | 26 | char messageID[32]; 27 | message.GetID(messageID, sizeof(messageID)); 28 | DeleteReaction(bot, channelID, messageID, emoji, null); 29 | } 30 | 31 | public int DiscordBot_DeleteReaction(Handle plugin, int params) 32 | { 33 | DiscordBot bot = GetNativeCell(1); 34 | DiscordChannel channel = GetNativeCell(2); 35 | DiscordMessage message = GetNativeCell(3); 36 | DiscordEmoji emoji = GetNativeCell(4); 37 | DiscordUser user = GetNativeCell(5); 38 | 39 | char channelID[32]; 40 | channel.GetID(channelID, sizeof(channelID)); 41 | 42 | char messageID[32]; 43 | message.GetID(messageID, sizeof(messageID)); 44 | DeleteReaction(bot, channelID, messageID, emoji, user); 45 | } 46 | 47 | public int DiscordBot_CreateReactionID(Handle plugin, int params) 48 | { 49 | DiscordBot bot = GetNativeCell(1); 50 | char channelID[32]; 51 | GetNativeString(2, channelID, sizeof(channelID)); 52 | 53 | char messageID[32]; 54 | GetNativeString(3, messageID, sizeof(messageID)); 55 | 56 | DiscordEmoji emoji = GetNativeCell(4); 57 | CreateReaction(bot, channelID, messageID, emoji); 58 | } 59 | 60 | public int DiscordBot_DeleteOwnReactionID(Handle plugin, int params) 61 | { 62 | DiscordBot bot = GetNativeCell(1); 63 | char channelID[32]; 64 | GetNativeString(2, channelID, sizeof(channelID)); 65 | 66 | char messageID[32]; 67 | GetNativeString(3, messageID, sizeof(messageID)); 68 | 69 | DiscordEmoji emoji = GetNativeCell(4); 70 | DeleteReaction(bot, channelID, messageID, emoji, null); 71 | } 72 | 73 | public int DiscordBot_DeleteReactionID(Handle plugin, int params) 74 | { 75 | DiscordBot bot = GetNativeCell(1); 76 | char channelID[32]; 77 | GetNativeString(2, channelID, sizeof(channelID)); 78 | 79 | char messageID[32]; 80 | GetNativeString(3, messageID, sizeof(messageID)); 81 | 82 | DiscordEmoji emoji = GetNativeCell(4); 83 | DiscordUser user = GetNativeCell(5); 84 | DeleteReaction(bot, channelID, messageID, emoji, user); 85 | } 86 | 87 | public int DiscordBot_DeleteAllReactions(Handle plugin, int params) 88 | { 89 | DiscordBot bot = GetNativeCell(1); 90 | DiscordChannel channel = GetNativeCell(2); 91 | DiscordMessage message = GetNativeCell(3); 92 | 93 | char channelID[32]; 94 | channel.GetID(channelID, sizeof(channelID)); 95 | 96 | char messageID[32]; 97 | message.GetID(messageID, sizeof(messageID)); 98 | 99 | DeleteAllReactions(bot, channelID, messageID, null); 100 | } 101 | 102 | public int DiscordBot_DeleteAllReactionsID(Handle plugin, int params) 103 | { 104 | DiscordBot bot = GetNativeCell(1); 105 | 106 | char channelID[32]; 107 | GetNativeString(2, channelID, sizeof(channelID)); 108 | 109 | char messageID[32]; 110 | GetNativeString(3, messageID, sizeof(messageID)); 111 | 112 | DeleteAllReactions(bot, channelID, messageID, null); 113 | } 114 | 115 | public int DiscordBot_DeleteAllReactionsEmoji(Handle plugin, int params) 116 | { 117 | DiscordBot bot = GetNativeCell(1); 118 | DiscordChannel channel = GetNativeCell(2); 119 | DiscordMessage message = GetNativeCell(3); 120 | DiscordEmoji emoji = GetNativeCell(4); 121 | 122 | char channelID[32]; 123 | channel.GetID(channelID, sizeof(channelID)); 124 | 125 | char messageID[32]; 126 | message.GetID(messageID, sizeof(messageID)); 127 | 128 | DeleteAllReactions(bot, channelID, messageID, emoji); 129 | } 130 | 131 | public int DiscordBot_DeleteAllReactionsEmojiID(Handle plugin, int params) 132 | { 133 | DiscordBot bot = GetNativeCell(1); 134 | DiscordEmoji emoji = GetNativeCell(4); 135 | 136 | char channelID[32]; 137 | GetNativeString(2, channelID, sizeof(channelID)); 138 | 139 | char messageID[32]; 140 | GetNativeString(3, messageID, sizeof(messageID)); 141 | 142 | DeleteAllReactions(bot, channelID, messageID, emoji); 143 | } 144 | 145 | static void CreateReaction(DiscordBot bot, const char[] channelid, const char[] messageid, DiscordEmoji emoji) 146 | { 147 | char emojiName[48]; 148 | emoji.GetName(emojiName, sizeof(emojiName)); 149 | 150 | char route[128]; 151 | Format(route, sizeof(route), "channels/%s/messages/%s/reactions/%s/@me", channelid, messageid, emojiName); 152 | SendRequest(bot, route, _, k_EHTTPMethodPUT); 153 | } 154 | 155 | static void DeleteReaction(DiscordBot bot, const char[] channelid, const char[] messageid, DiscordEmoji emoji, DiscordUser user) 156 | { 157 | char emojiName[48]; 158 | emoji.GetName(emojiName, sizeof(emojiName)); 159 | 160 | char route[128]; 161 | if(user == null) //null => delete own reaction 162 | Format(route, sizeof(route), "channels/%s/messages/%s/reactions/%s/@me", channelid, messageid, emojiName); 163 | else { 164 | char userID[32]; 165 | user.GetID(userID, sizeof(userID)); 166 | Format(route, sizeof(route), "channels/%s/messages/%s/reactions/%s/%s", channelid, messageid, emojiName, userID); 167 | } 168 | 169 | SendRequest(bot, route, _, k_EHTTPMethodDELETE); 170 | } 171 | 172 | static void DeleteAllReactions(DiscordBot bot, const char[] channelid, const char[] messageid, DiscordEmoji emoji) 173 | { 174 | char route[128]; 175 | if(emoji == null) 176 | { 177 | Format(route, sizeof(route), "channels/%s/messages/%s/reactions", channelid, messageid); 178 | } else { 179 | char emojiName[48]; 180 | emoji.GetName(emojiName, sizeof(emojiName)); 181 | Format(route, sizeof(route), "channels/%s/messages/%s/reactions/%s", channelid, messageid, emojiName); 182 | } 183 | 184 | SendRequest(bot, route, _, k_EHTTPMethodDELETE); 185 | } -------------------------------------------------------------------------------- /discord/Shared.sp: -------------------------------------------------------------------------------- 1 | public int OnDiscordDataReceived(Handle request, bool failure, int offset, int statuscode, DataPack pack) 2 | { 3 | if(failure || (statuscode != 200 && statuscode != 204)) 4 | { 5 | if(statuscode == 400 || statuscode == 429 || statuscode == 500) 6 | { 7 | // bad format or rate limit or server error handling 8 | } 9 | 10 | new DiscordException("OnDiscordDataReceived - Fail %i %i", failure, statuscode); 11 | delete request; 12 | delete pack; 13 | return; 14 | } 15 | 16 | SteamWorks_GetHTTPResponseBodyCallback(request, ReceivedData, pack); 17 | delete request; 18 | } 19 | 20 | static int ReceivedData(const char[] data, DataPack pack) 21 | { 22 | pack.Reset(); 23 | DiscordBot bot = pack.ReadCell(); 24 | Handle plugin = pack.ReadCell(); 25 | Function callback = pack.ReadFunction(); 26 | any data1 = pack.ReadCell(); 27 | any data2 = pack.ReadCell(); 28 | delete pack; 29 | 30 | if(callback != INVALID_FUNCTION) 31 | { 32 | Call_StartFunction(plugin, callback); 33 | Call_PushCell(bot); 34 | Call_PushCell(json_decode(data)); 35 | Call_PushCell(data1); 36 | Call_PushCell(data2); 37 | Call_Finish(); 38 | } 39 | } -------------------------------------------------------------------------------- /discord/User.sp: -------------------------------------------------------------------------------- 1 | public int DiscordBot_ModifySelf(Handle plugin, int params) 2 | { 3 | DiscordBot bot = GetNativeCell(1); 4 | char username[32]; 5 | GetNativeString(2, username, sizeof(username)); 6 | 7 | char avatar[128]; 8 | GetNativeString(3, avatar, sizeof(avatar)); 9 | ModifySelf(bot, username, avatar); 10 | } 11 | 12 | static void ModifySelf(DiscordBot bot, const char[] username, const char[] avatar) 13 | { 14 | char route[64]; 15 | Format(route, sizeof(route), "users/@me"); 16 | 17 | JSON_Object obj = new JSON_Object(); 18 | obj.SetString("username", username); 19 | if(strlen(avatar) > 0) 20 | obj.SetString("avatar", avatar); 21 | 22 | SendRequest(bot, route, obj, k_EHTTPMethodPATCH); 23 | } -------------------------------------------------------------------------------- /discord_api.sp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #pragma tabsize 4; 5 | #pragma newdecls required; 6 | #pragma semicolon 1; 7 | 8 | #include "discord/Shared.sp" 9 | #include "discord/Message.sp" 10 | #include "discord/Reaction.sp" 11 | #include "discord/User.sp" 12 | #include "discord/ListenToChannel.sp" 13 | #include "discord/Channel.sp" 14 | #include "discord/Guild.sp" 15 | 16 | /* https://discord.com/developers/docs/reference#api-versioning-api-versions */ 17 | #define API_VERSION 10 18 | 19 | public Plugin myinfo = 20 | { 21 | name = "Discord API", 22 | author = "Nexd @ Eternar", 23 | description = "This library is limited to the basic REST API that Discord provides.", 24 | version = "1.0", 25 | url = "https://github.com/KillStr3aK | https://eternar.dev" 26 | }; 27 | 28 | public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) 29 | { 30 | CreateNative("DiscordBot.TriggerTypingIndicator", DiscordBot_TriggerTypingIndicator); 31 | CreateNative("DiscordBot.TriggerTypingIndicatorID", DiscordBot_TriggerTypingIndicatorID); 32 | 33 | CreateNative("DiscordBot.StartTimer", DiscordBot_StartTimer); 34 | 35 | CreateNative("DiscordBot.CreateGuild", DiscordBot_CreateGuild); 36 | CreateNative("DiscordBot.GetGuild", DiscordBot_GetGuild); 37 | CreateNative("DiscordBot.GetGuildMember", DiscordBot_GetGuildMember); 38 | CreateNative("DiscordBot.GetGuildMemberID", DiscordBot_GetGuildMemberID); 39 | 40 | CreateNative("DiscordBot.GetGuildScheduledEvent", DiscordBot_GetGuildScheduledEvent); 41 | CreateNative("DiscordBot.DeleteGuildScheduledEvent", DiscordBot_DeleteGuildScheduledEvent); 42 | 43 | CreateNative("DiscordBot.AddRole", DiscordBot_AddRole); 44 | CreateNative("DiscordBot.RemoveRole", DiscordBot_RemoveRole); 45 | 46 | CreateNative("DiscordBot.AddRoleID", DiscordBot_AddRoleID); 47 | CreateNative("DiscordBot.RemoveRoleID", DiscordBot_RemoveRoleID); 48 | 49 | CreateNative("DiscordBot.CreateDM", DiscordBot_CreateDM); 50 | CreateNative("DiscordBot.CreateDMID", DiscordBot_CreateDMID); 51 | 52 | CreateNative("DiscordBot.ModifySelf", DiscordBot_ModifySelf); 53 | 54 | CreateNative("DiscordBot.GetChannel", DiscordBot_GetChannel); 55 | CreateNative("DiscordBot.GetChannelMessages", DiscordBot_GetChannelMessages); 56 | CreateNative("DiscordBot.GetChannelMessagesID", DiscordBot_GetChannelMessagesID); 57 | CreateNative("DiscordBot.GetChannelMessage", DiscordBot_GetChannelMessage); 58 | CreateNative("DiscordBot.GetChannelMessageID", DiscordBot_GetChannelMessageID); 59 | 60 | CreateNative("DiscordBot.DeleteChannel", DiscordBot_DeleteChannel); 61 | CreateNative("DiscordBot.DeleteChannelID", DiscordBot_DeleteChannelID); 62 | 63 | CreateNative("DiscordBot.ModifyChannel", DiscordBot_ModifyChannel); 64 | CreateNative("DiscordBot.ModifyChannelID", DiscordBot_ModifyChannelID); 65 | 66 | CreateNative("DiscordBot.SendMessageToChannel", DiscordBot_SendMessageToChannel); 67 | CreateNative("DiscordBot.SendMessageToChannelID", DiscordBot_SendMessageToChannelID); 68 | 69 | CreateNative("DiscordBot.EditMessage", DiscordBot_EditMessage); 70 | CreateNative("DiscordBot.EditMessageID", DiscordBot_EditMessageID); 71 | 72 | CreateNative("DiscordBot.PinMessage", DiscordBot_PinMessage); 73 | CreateNative("DiscordBot.PinMessageID", DiscordBot_PinMessageID); 74 | 75 | CreateNative("DiscordBot.UnpinMessage", DiscordBot_UnpinMessage); 76 | CreateNative("DiscordBot.UnpinMessageID", DiscordBot_UnpinMessageID); 77 | 78 | CreateNative("DiscordBot.GetPinnedMessages", DiscordBot_GetPinnedMessages); 79 | CreateNative("DiscordBot.GetPinnedMessagesID", DiscordBot_GetPinnedMessagesID); 80 | 81 | CreateNative("DiscordBot.CrosspostMessage", DiscordBot_CrosspostMessage); 82 | 83 | CreateNative("DiscordBot.DeleteMessagesBulk", DiscordBot_DeleteMessagesBulk); 84 | CreateNative("DiscordBot.DeleteMessage", DiscordBot_DeleteMessage); 85 | CreateNative("DiscordBot.DeleteMessageID", DiscordBot_DeleteMessageID); 86 | 87 | CreateNative("DiscordBot.CreateReaction", DiscordBot_CreateReaction); 88 | CreateNative("DiscordBot.CreateReactionID", DiscordBot_CreateReactionID); 89 | 90 | CreateNative("DiscordBot.DeleteOwnReaction", DiscordBot_DeleteOwnReaction); 91 | CreateNative("DiscordBot.DeleteOwnReactionID", DiscordBot_DeleteOwnReactionID); 92 | 93 | CreateNative("DiscordBot.DeleteReaction", DiscordBot_DeleteReaction); 94 | CreateNative("DiscordBot.DeleteReactionID", DiscordBot_DeleteReactionID); 95 | 96 | CreateNative("DiscordBot.DeleteAllReactions", DiscordBot_DeleteAllReactions); 97 | CreateNative("DiscordBot.DeleteAllReactionsID", DiscordBot_DeleteAllReactionsID); 98 | 99 | CreateNative("DiscordBot.DeleteAllReactionsEmoji", DiscordBot_DeleteAllReactionsEmoji); 100 | CreateNative("DiscordBot.DeleteAllReactionsEmojiID", DiscordBot_DeleteAllReactionsEmojiID); 101 | RegPluginLibrary("Discord-API"); 102 | return APLRes_Success; 103 | } 104 | 105 | void SendRequest(DiscordBot bot, const char[] route, JSON_Object json = null, EHTTPMethod method = k_EHTTPMethodGET, SteamWorksHTTPDataReceived OnDataReceivedCb = INVALID_FUNCTION, SteamWorksHTTPRequestCompleted OnRequestCompletedCb = INVALID_FUNCTION, any data1 = 0, any data2 = 0) 106 | { 107 | if(OnRequestCompletedCb == INVALID_FUNCTION) 108 | { 109 | OnRequestCompletedCb = OnHTTPRequestComplete; // include/discord/DiscordRequest.inc#L8 110 | } 111 | 112 | if(OnDataReceivedCb == INVALID_FUNCTION) 113 | { 114 | OnDataReceivedCb = OnHTTPDataReceive; // include/discord/DiscordRequest.inc#L10 115 | } 116 | 117 | char szEndpoint[512]; 118 | Format(szEndpoint, sizeof(szEndpoint), "https://discord.com/api/v%i/%s", API_VERSION, route); 119 | 120 | DiscordRequest request = new DiscordRequest(szEndpoint, method); 121 | request.Timeout = 30; 122 | request.SetCallbacks(OnRequestCompletedCb, _, OnDataReceivedCb); 123 | request.SetBot(bot); 124 | request.SetJsonBody(json); 125 | request.SetContextValue(data1, data2); 126 | request.SetContentSize(); 127 | request.Send(); 128 | } -------------------------------------------------------------------------------- /example_bot.sp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #pragma tabsize 0; 5 | #pragma newdecls required; 6 | #pragma semicolon 1; 7 | 8 | public Plugin myinfo = 9 | { 10 | name = "Discord Bot Example", 11 | author = "Nexd", 12 | description = "Doing random things", 13 | version = "1.0", 14 | url = "https://github.com/KillStr3aK" 15 | }; 16 | 17 | #define BOT_TOKEN "" 18 | 19 | public void OnPluginStart() 20 | { 21 | DiscordBot bot = new DiscordBot(BOT_TOKEN); 22 | 23 | /* Send a random message with embed */ 24 | DiscordMessage message = new DiscordMessage("Aye!"); 25 | DiscordEmbed embed = new DiscordEmbed(); 26 | embed.WithDescription("Random Description"); 27 | embed.WithAuthor(new DiscordEmbedAuthor("Example Bot", "https://github.com/KillStr3aK")); 28 | embed.WithFooter(new DiscordEmbedFooter("NEXD @ Eternar")); 29 | message.Embed(embed); 30 | 31 | bot.SendMessageToChannelID("866539462401982514", message); 32 | /* -- */ 33 | 34 | /* Create reaction */ 35 | bot.CreateReactionID("866539462401982514", "869072008464441405", DiscordEmoji.FromName(":100:")); 36 | /* -- */ 37 | 38 | /* Delete animated custom reaction that was created by this bot */ 39 | bot.DeleteOwnReactionID("866539462401982514", "869072008464441405", DiscordEmoji.FromName("a:heartrainbow:842923225397985340")); 40 | /* -- */ 41 | 42 | /* Delete message */ 43 | bot.DeleteMessageID("866539462401982514", "869047387413413888"); 44 | /* -- */ 45 | 46 | bot.Dispose(); 47 | } 48 | -------------------------------------------------------------------------------- /example_bot_callbacks.sp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #pragma tabsize 0; 5 | #pragma newdecls required; 6 | #pragma semicolon 1; 7 | 8 | public Plugin myinfo = 9 | { 10 | name = "Discord Bot Example Callbacks", 11 | author = "Nexd", 12 | description = "Doing random things", 13 | version = "1.0", 14 | url = "https://github.com/KillStr3aK" 15 | }; 16 | 17 | #define BOT_TOKEN "" 18 | #define GUILD_ID "" 19 | #define USER_ID "" 20 | #define CHANNEL_ID "" 21 | 22 | DiscordBot discordBot = null; 23 | 24 | public void OnPluginStart() 25 | { 26 | discordBot = new DiscordBot(BOT_TOKEN); 27 | discordBot.GetGuild(GUILD_ID, true, OnGuildReceived); 28 | discordBot.GetChannel(CHANNEL_ID, OnChannelReceived); 29 | } 30 | 31 | public void OnChannelReceived(DiscordBot bot, DiscordChannel channel) 32 | { 33 | char szChannelName[32]; 34 | channel.GetName(szChannelName, sizeof(szChannelName)); 35 | PrintToServer("current channel name: %s", szChannelName); 36 | 37 | channel.SetName("random new name"); 38 | bot.ModifyChannel(channel, channel, INVALID_FUNCTION); 39 | 40 | bot.StartListeningToChannel(channel, OnMessageReceived); 41 | 42 | /* you shouldn't dispose the channel in this case because the bot is listening to it */ 43 | //channel.Dispose(); 44 | } 45 | 46 | /* Simple discord->ingame chat relay */ 47 | public void OnMessageReceived(DiscordBot bot, DiscordChannel channel, DiscordMessage message) 48 | { 49 | if(message.Author.IsBot) 50 | return; 51 | 52 | DiscordUser user = message.GetAuthor(); 53 | 54 | char szMessage[256]; 55 | message.GetContent(szMessage, sizeof(szMessage)); 56 | 57 | char szUsername[MAX_DISCORD_USERNAME_LENGTH]; 58 | user.GetUsername(szUsername, sizeof(szUsername)); 59 | 60 | char szDiscriminator[MAX_DISCORD_DISCRIMINATOR_LENGTH]; 61 | user.GetDiscriminator(szDiscriminator, sizeof(szDiscriminator)); 62 | 63 | PrintToChatAll("%s#%s: %s", szUsername, szDiscriminator, szMessage); 64 | } 65 | 66 | public void OnGuildReceived(DiscordBot bot, DiscordGuild guild) 67 | { 68 | if(guild != null) 69 | { 70 | char guildid[64]; 71 | guild.GetID(guildid, sizeof(guildid)); 72 | bot.GetGuildMemberID(guildid, USER_ID, OnGuildUserReceived); 73 | 74 | /* Release guild resource */ 75 | guild.Dispose(); 76 | } 77 | } 78 | 79 | public void OnGuildUserReceived(DiscordBot bot, DiscordGuildUser user) 80 | { 81 | char szUserNickname[MAX_DISCORD_NICKNAME_LENGTH]; 82 | user.GetNickname(szUserNickname, sizeof(szUserNickname)); 83 | PrintToServer("User nickname: %s", szUserNickname); 84 | 85 | /* Release user resource */ 86 | user.Dispose(); 87 | } 88 | 89 | public void OnPluginEnd() 90 | { 91 | /* totally pointless there but nvm */ 92 | discordBot.Dispose(); 93 | } -------------------------------------------------------------------------------- /example_webhook.sp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #pragma tabsize 0; 5 | #pragma newdecls required; 6 | #pragma semicolon 1; 7 | 8 | public Plugin myinfo = 9 | { 10 | name = "Discord WebHook Example", 11 | author = "Nexd", 12 | description = "", 13 | version = "1.0", 14 | url = "https://github.com/KillStr3aK" 15 | }; 16 | 17 | //webhook 18 | #define ENDPOINT "" 19 | #define CONTENT "" 20 | #define USERNAME "" 21 | #define AVATAR "" 22 | 23 | //embed 24 | #define COLOR "#5D00FF" 25 | #define TITLE "" 26 | #define WITH_TIMESTAMP 27 | 28 | //author 29 | #define AUTHOR_NAME "" 30 | #define AUTHOR_URL "" 31 | #define AUTHOR_ICON "" 32 | 33 | //footer 34 | #define FOOTER_TEXT "" 35 | #define FOOTER_ICON "" 36 | 37 | #define THUMBNAIL_LINK "" 38 | #define THUMBNAIL_HEIGHT 200 39 | #define THUMBNAIL_WIDTH 300 40 | 41 | #define IMAGE_LINK "" 42 | #define IMAGE_HEIGHT 200 43 | #define IMAGE_WIDTH 300 44 | 45 | public void OnPluginStart() 46 | { 47 | DiscordWebHook hook = new DiscordWebHook(ENDPOINT); 48 | hook.SetContent(CONTENT); 49 | hook.SetUsername(USERNAME); 50 | hook.SetAvatar(AVATAR); 51 | 52 | DiscordEmbed embed = new DiscordEmbed(); 53 | embed.SetColor(COLOR); 54 | embed.WithTitle(TITLE); 55 | embed.WithAuthor(new DiscordEmbedAuthor(AUTHOR_NAME, AUTHOR_URL, AUTHOR_ICON)); 56 | embed.WithFooter(new DiscordEmbedFooter(FOOTER_TEXT, FOOTER_ICON)); 57 | 58 | #if defined WITH_TIMESTAMP 59 | embed.WithTimestamp(new DateTime(DateTime_Now) - TimeSpan.FromHours(2)); //timezone things 60 | #endif 61 | 62 | embed.WithImage(new DiscordEmbedImage(IMAGE_LINK, IMAGE_HEIGHT, IMAGE_WIDTH)); 63 | embed.WithThumbnail(new DiscordEmbedThumbnail(THUMBNAIL_LINK, THUMBNAIL_HEIGHT, THUMBNAIL_WIDTH)); 64 | 65 | for(int i = 0; i < 25; i++) 66 | { 67 | bool inline = i % 2 == 0; // i % 2 is used to 'randomize' inline 68 | embed.AddField(new DiscordEmbedField("FIELD", "VALUE", inline)); 69 | } 70 | 71 | hook.Embed(embed); 72 | hook.Send(); 73 | hook.Dispose(); 74 | } 75 | -------------------------------------------------------------------------------- /include/discord.inc: -------------------------------------------------------------------------------- 1 | #if defined _discord_included_ 2 | #endinput 3 | #endif 4 | #define _discord_included_ 5 | 6 | #pragma dynamic 32768; 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include -------------------------------------------------------------------------------- /include/discord/DiscordActivity.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordActivity_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordActivity_included_ 5 | 6 | enum DiscordActivityType 7 | { 8 | Game = 0, 9 | Streaming, 10 | Listening, 11 | Watching, 12 | Custom, 13 | Competing 14 | } 15 | 16 | methodmap DiscordActivity < JSON_Object 17 | { 18 | public DiscordActivity(const char[] name, DiscordActivityType type, const char[] url = "") 19 | { 20 | JSON_Object obj = new JSON_Object(); 21 | obj.SetString("name", name); 22 | obj.SetString("url", url); 23 | obj.SetInt("type", view_as(type)); 24 | return view_as(obj); 25 | } 26 | 27 | /** 28 | * Release resources 29 | */ 30 | public void Dispose() 31 | { 32 | if(this == null) 33 | return; 34 | 35 | this.Cleanup(); 36 | delete this; 37 | } 38 | } -------------------------------------------------------------------------------- /include/discord/DiscordAttachment.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordAttachment_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordAttachment_included_ 5 | 6 | methodmap DiscordAttachment < DiscordObject 7 | { 8 | /** 9 | * height of file (if image) 10 | */ 11 | property int Height 12 | { 13 | public get() { return this.GetInt("height"); } 14 | } 15 | 16 | /** 17 | * width of file (if image) 18 | */ 19 | property int Width 20 | { 21 | public get() { return this.GetInt("width"); } 22 | } 23 | 24 | /** 25 | * size of file in bytes 26 | */ 27 | property int Size 28 | { 29 | public get() { return this.GetInt("size"); } 30 | } 31 | 32 | /** 33 | * whether this attachment is ephemeral 34 | * Ephemeral attachments will automatically be removed after a set period of time. 35 | * Ephemeral attachments on messages are guaranteed to be available as long as the message itself exists. 36 | */ 37 | property bool Ephemeral 38 | { 39 | public get() { return this.GetBool("ephemeral"); } 40 | } 41 | 42 | /** 43 | * source url of file 44 | */ 45 | public bool GetUrl(char[] output, int maxsize) 46 | { 47 | return this.GetString("url", output, maxsize); 48 | } 49 | 50 | /** 51 | * a proxied url of file 52 | */ 53 | public bool GetProxyUrl(char[] output, int maxsize) 54 | { 55 | return this.GetString("proxy_url", output, maxsize); 56 | } 57 | 58 | /** 59 | * name of file attached 60 | */ 61 | public bool GetFilename(char[] output, int maxsize) 62 | { 63 | return this.GetString("filename", output, maxsize); 64 | } 65 | 66 | /** 67 | * description for the file 68 | */ 69 | public bool GetDescription(char[] output, int maxsize) 70 | { 71 | return this.GetString("description", output, maxsize); 72 | } 73 | 74 | /** 75 | * the attachment's media type 76 | * ( https://en.wikipedia.org/wiki/Media_type ) 77 | */ 78 | public bool GetContentType(char[] output, int maxsize) 79 | { 80 | return this.GetString("content_type", output, maxsize); 81 | } 82 | } -------------------------------------------------------------------------------- /include/discord/DiscordBot.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordBot_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordBot_included_ 5 | 6 | #include 7 | #include 8 | 9 | enum DiscordGatewayIntents 10 | { 11 | /* 12 | - GUILD_CREATE 13 | - GUILD_UPDATE 14 | - GUILD_DELETE 15 | - GUILD_ROLE_CREATE 16 | - GUILD_ROLE_UPDATE 17 | - GUILD_ROLE_DELETE 18 | - CHANNEL_CREATE 19 | - CHANNEL_UPDATE 20 | - CHANNEL_DELETE 21 | - CHANNEL_PINS_UPDATE 22 | - THREAD_CREATE 23 | - THREAD_UPDATE 24 | - THREAD_DELETE 25 | - THREAD_LIST_SYNC 26 | - THREAD_MEMBER_UPDATE 27 | - THREAD_MEMBERS_UPDATE * 28 | - STAGE_INSTANCE_CREATE 29 | - STAGE_INSTANCE_UPDATE 30 | - STAGE_INSTANCE_DELETE 31 | */ 32 | GUILDS = (1 << 0), 33 | 34 | /* 35 | - GUILD_MEMBER_ADD 36 | - GUILD_MEMBER_UPDATE 37 | - GUILD_MEMBER_REMOVE 38 | - THREAD_MEMBERS_UPDATE * 39 | */ 40 | GUILD_MEMBERS = (1 << 1), 41 | 42 | /* 43 | - GUILD_BAN_ADD 44 | - GUILD_BAN_REMOVE 45 | */ 46 | GUILD_BANS = (1 << 2), 47 | 48 | /* 49 | - GUILD_EMOJIS_UPDATE 50 | */ 51 | GUILD_EMOJIS = (1 << 3), 52 | 53 | /* 54 | - GUILD_INTEGRATIONS_UPDATE 55 | - INTEGRATION_CREATE 56 | - INTEGRATION_UPDATE 57 | - INTEGRATION_DELETE 58 | */ 59 | GUILD_INTEGRATIONS = (1 << 4), 60 | 61 | /* 62 | - WEBHOOKS_UPDATE 63 | */ 64 | GUILD_WEBHOOKS = (1 << 5), 65 | 66 | /* 67 | - INVITE_CREATE 68 | - INVITE_DELETE 69 | */ 70 | GUILD_INVITES = (1 << 6), 71 | 72 | /* 73 | - VOICE_STATE_UPDATE 74 | */ 75 | GUILD_VOICE_STATES = (1 << 7), 76 | 77 | /* 78 | - PRESENCE_UPDATE 79 | */ 80 | GUILD_PRESENCES = (1 << 8), 81 | 82 | /* 83 | - MESSAGE_CREATE 84 | - MESSAGE_UPDATE 85 | - MESSAGE_DELETE 86 | - MESSAGE_DELETE_BULK 87 | */ 88 | GUILD_MESSAGES = (1 << 9), 89 | 90 | /* 91 | - MESSAGE_REACTION_ADD 92 | - MESSAGE_REACTION_REMOVE 93 | - MESSAGE_REACTION_REMOVE_ALL 94 | - MESSAGE_REACTION_REMOVE_EMOJI 95 | */ 96 | GUILD_MESSAGE_REACTIONS = (1 << 10), 97 | 98 | /* 99 | - TYPING_START 100 | */ 101 | GUILD_MESSAGE_TYPING = (1 << 11), 102 | 103 | /* 104 | - MESSAGE_CREATE 105 | - MESSAGE_UPDATE 106 | - MESSAGE_DELETE 107 | - CHANNEL_PINS_UPDATE 108 | */ 109 | DIRECT_MESSAGES = (1 << 12), 110 | 111 | /* 112 | - MESSAGE_REACTION_ADD 113 | - MESSAGE_REACTION_REMOVE 114 | - MESSAGE_REACTION_REMOVE_ALL 115 | - MESSAGE_REACTION_REMOVE_EMOJI 116 | */ 117 | DIRECT_MESSAGE_REACTIONS = (1 << 13), 118 | 119 | /* 120 | - TYPING_START 121 | */ 122 | DIRECT_MESSAGE_TYPING = (1 << 14), 123 | 124 | MESSAGE_CONTENT = (1 << 15), 125 | 126 | /* 127 | - GUILD_SCHEDULED_EVENT_CREATE 128 | - GUILD_SCHEDULED_EVENT_UPDATE 129 | - GUILD_SCHEDULED_EVENT_DELETE 130 | - GUILD_SCHEDULED_EVENT_USER_ADD 131 | - GUILD_SCHEDULED_EVENT_USER_REMOVE 132 | */ 133 | GUILD_SCHEDULED_EVENTS = (1 << 16) 134 | } 135 | 136 | methodmap DiscordBot < JSON_Object 137 | { 138 | /* Unused until there is no wss */ 139 | 140 | property bool Compress 141 | { 142 | public get() { return this.GetBool("compress"); } 143 | public set(bool value) { this.SetBool("compress", value); } 144 | } 145 | 146 | property int Threshold 147 | { 148 | public get() { return this.GetInt("large_threshold"); } 149 | } 150 | 151 | property DiscordGatewayIntents Intents 152 | { 153 | public get() { return view_as(this.GetInt("intents")); } 154 | public set(DiscordGatewayIntents value) { this.SetInt("intents", view_as(value)); } 155 | } 156 | 157 | /* - - */ 158 | 159 | property float MessageCheckInterval 160 | { 161 | public get() { return this.GetFloat("message_check_interval", 3.0); } 162 | public set(float value) { this.SetFloat("message_check_interval", value); } 163 | } 164 | 165 | public DiscordBot(const char[] token/*, DiscordPresence presence, DiscordGatewayPayload payload = null*/) 166 | { 167 | JSON_Object obj = new JSON_Object(); 168 | obj.SetString("token", token); 169 | //obj.SetObject("properties", payload); 170 | //obj.SetObject("presence", presence); 171 | return view_as(obj); 172 | } 173 | 174 | public DiscordChannelList GetListeningChannels() 175 | { 176 | return view_as(this.GetObject("listening_channels")); 177 | } 178 | 179 | /** 180 | * Checks if the bot is listening to channel for messages 181 | * @param channelid channel id. 182 | */ 183 | public bool IsListeningToChannelID(const char[] channelid) 184 | { 185 | DiscordChannelList channels = this.GetListeningChannels(); 186 | if(channels != null) 187 | { 188 | for(int i = 0; i < channels.Length; i++) 189 | { 190 | static char tempID[32]; 191 | channels.GetString(i, tempID, sizeof(tempID)); 192 | 193 | if(StrEqual(channelid, tempID, false)) 194 | { 195 | return true; 196 | } 197 | } 198 | } 199 | 200 | return false; 201 | } 202 | 203 | /** 204 | * Checks if the bot is listening to channel for messages 205 | * @param channel channel object. 206 | */ 207 | public bool IsListeningToChannel(DiscordChannel channel) 208 | { 209 | char channelid[32]; 210 | channel.GetID(channelid, sizeof(channelid)); 211 | return this.IsListeningToChannelID(channelid); 212 | } 213 | 214 | /** 215 | * Stops the bot from listening to that channel id for messages 216 | * @param channelid channel id. 217 | */ 218 | public void StopListeningToChannelID(const char[] channelid) 219 | { 220 | DiscordChannelList channels = this.GetListeningChannels(); 221 | if(channels != null) 222 | { 223 | for(int i = 0; i < channels.Length; i++) 224 | { 225 | static char tempID[32]; 226 | channels.GetString(i, tempID, sizeof(tempID)); 227 | 228 | if(StrEqual(channelid, tempID)) 229 | { 230 | channels.Remove(i); 231 | i--; 232 | } 233 | } 234 | } 235 | } 236 | 237 | public native void StartTimer(DiscordChannel channel, OnDiscordChannelMessage callback); 238 | 239 | /** 240 | * Stops the bot from listening to that channel id for messages 241 | * @param channel channel object. 242 | */ 243 | public void StopListeningToChannel(DiscordChannel channel) 244 | { 245 | char channelid[32]; 246 | channel.GetID(channelid, sizeof(channelid)); 247 | this.StopListeningToChannelID(channelid); 248 | } 249 | 250 | /** 251 | * Start listening to the channel for messages. 252 | * @param channel channel object. 253 | */ 254 | public void StartListeningToChannel(DiscordChannel channel, OnDiscordChannelMessage callback) 255 | { 256 | if(this.IsListeningToChannel(channel)) 257 | return; 258 | 259 | DiscordChannelList channels = this.GetListeningChannels(); 260 | if(channels == null) 261 | { 262 | channels = view_as(new JSON_Array()); 263 | this.SetObject("listening_channels", channels); 264 | } 265 | 266 | char channelid[32]; 267 | channel.GetID(channelid, sizeof(channelid)); 268 | channels.PushString(channelid); 269 | this.StartTimer(channel, callback); 270 | } 271 | 272 | /** 273 | * Get the bot token. 274 | * @param output output buffer. 275 | * @param maxsize maximum length. 276 | */ 277 | public bool GetToken(char[] output, int maxsize) 278 | { 279 | return this.GetString("token", output, maxsize); 280 | } 281 | 282 | /** 283 | * Release resources 284 | */ 285 | public void Dispose() 286 | { 287 | if(this == null) 288 | return; 289 | 290 | this.Cleanup(); 291 | delete this; 292 | } 293 | 294 | /** 295 | * Create a new guild. 296 | * Fires a Guild Create Gateway event. 297 | * This endpoint can be used only by bots in less than 10 guilds. 298 | * 299 | * @param guild guild object with these values: https://discord.com/developers/docs/resources/guild#create-guild-json-params 300 | * @param callback a DiscordGuild object on success. 301 | * @param data custom data passed through the request to use in the callback 302 | * @param data2 custom data passed through the request to use in the callback 303 | */ 304 | public native void CreateGuild(DiscordGuild guild, OnDiscordGuildCreated callback, any data = 0, any data2 = 0); 305 | 306 | /** 307 | * Returns the guild object for the given id. 308 | * If with_counts is set to true, this will also return approximate_member_count and approximate_presence_count for the guild. 309 | * 310 | * DiscordGuild handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 311 | * 312 | * @param guildid id of the guild you want to get. 313 | * @param with_counts when true, will return approximate member and presence counts for the guild 314 | * @param callback a DiscordGuild object on success. 315 | * @param data custom data passed through the request to use in the callback 316 | * @param data2 custom data passed through the request to use in the callback 317 | */ 318 | public native void GetGuild(const char[] guildid, bool with_counts, OnGetDiscordGuild callback, any data = 0, any data2 = 0); 319 | 320 | /** 321 | * Returns a guild member object for the specified user id. 322 | * 323 | * DiscordGuildUser handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 324 | * 325 | * @param guild DiscordGuild from where you want to get the user. 326 | * @param user DiscordUser that you want to get. (DiscordGuildUser object is different than a normal DiscordUser) 327 | * @param callback a DiscordGuildUser object on success. 328 | * @param data custom data passed through the request to use in the callback 329 | * @param data2 custom data passed through the request to use in the callback 330 | */ 331 | public native void GetGuildMember(DiscordGuild guild, DiscordUser user, OnGetDiscordGuildUser callback, any data = 0, any data2 = 0); 332 | 333 | /** 334 | * Returns a guild member object for the specified user id. 335 | * 336 | * DiscordGuildUser handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 337 | * 338 | * @param guildid guild ID from where you want to get the user. 339 | * @param userid user ID that you want to get. (DiscordGuildUser object is different than a normal DiscordUser) 340 | * @param callback a DiscordGuildUser object on success. 341 | * @param data custom data passed through the request to use in the callback 342 | * @param data2 custom data passed through the request to use in the callback 343 | */ 344 | public native void GetGuildMemberID(const char[] guildid, const char[] userid, OnGetDiscordGuildUser callback, any data = 0, any data2 = 0); 345 | 346 | /** 347 | * Get a guild scheduled event. 348 | * Returns a guild scheduled event object on success. 349 | * 350 | * @param guild guild that has the event scheduled. 351 | * @param eventid id of the event. 352 | * @param callback a guild scheduled event object on success. 353 | * @param data custom data passed through the request to use in the callback 354 | * @param data2 custom data passed through the request to use in the callback 355 | */ 356 | public native void GetGuildScheduledEvent(DiscordGuild guild, const char[] eventid, OnGetDiscordGuildScheduledEvent callback, any data = 0, any data2 = 0); 357 | 358 | /** 359 | * Delete a guild scheduled event. 360 | * Returns a 204 on success. 361 | * 362 | * @param guild guild that has the event scheduled. 363 | * @param event scheduled event. 364 | */ 365 | public native void DeleteGuildScheduledEvent(DiscordGuild guild, DiscordGuildScheduledEvent event); 366 | 367 | /** 368 | * Adds a role to a guild member. 369 | * Requires the MANAGE_ROLES permission. 370 | * Returns a 204 empty response on success. 371 | * Fires a Guild Member Update Gateway event. 372 | * 373 | * @param guild where you want to add the role to the user. 374 | * @param user target who get the role. 375 | * @param role that will be added to the user. 376 | */ 377 | public native void AddRole(DiscordGuild guild, DiscordUser user, DiscordRole role); 378 | 379 | /** 380 | * Adds a role to a guild member. 381 | * Requires the MANAGE_ROLES permission. 382 | * Returns a 204 empty response on success. 383 | * Fires a Guild Member Update Gateway event. 384 | * 385 | * @param guild ID where you want to add the role to the user. 386 | * @param user ID target who get the role. 387 | * @param role ID that will be added to the user. 388 | */ 389 | public native void AddRoleID(const char[] guildid, const char[] userid, const char[] roleid); 390 | 391 | /** 392 | * Removes a role from a guild member. 393 | * Requires the MANAGE_ROLES permission. 394 | * Returns a 204 empty response on success. 395 | * Fires a Guild Member Update Gateway event. 396 | * 397 | * @param guild where you want to remove the role from the user. 398 | * @param user target who lose the role. 399 | * @param role that will be removed from the user. 400 | */ 401 | public native void RemoveRole(DiscordGuild guild, DiscordUser user, DiscordRole role); 402 | 403 | /** 404 | * Removes a role from a guild member. 405 | * Requires the MANAGE_ROLES permission. 406 | * Returns a 204 empty response on success. 407 | * Fires a Guild Member Update Gateway event. 408 | * 409 | * @param guild ID where you want to remove the role from the user. 410 | * @param user ID target who lose the role. 411 | * @param role ID that will be removed from the user. 412 | */ 413 | public native void RemoveRoleID(const char[] guildid, const char[] userid, const char[] roleid); 414 | 415 | /** 416 | * Create a new DM channel with a user. 417 | * You should not use this endpoint to DM everyone in a server about something. 418 | * DMs should generally be initiated by a user action. 419 | * If you open a significant amount of DMs too quickly, your bot may be rate limited or blocked from opening new ones. 420 | * 421 | * @param user the recipient to open a DM channel with 422 | * @param callback a DM channel object. (TODO) 423 | */ 424 | public native void CreateDM(DiscordUser user); 425 | 426 | /** 427 | * Create a new DM channel with a user. 428 | * You should not use this endpoint to DM everyone in a server about something. 429 | * DMs should generally be initiated by a user action. 430 | * If you open a significant amount of DMs too quickly, your bot may be rate limited or blocked from opening new ones. 431 | * 432 | * @param userid the recipient user id to open a DM channel with 433 | * @param callback a DM channel object. (TODO) 434 | */ 435 | public native void CreateDMID(const char[] userid); 436 | 437 | /** Modify the requester's user account settings. 438 | * 439 | * @param username user's username, if changed may cause the user's discriminator to be randomized. 440 | * @param avatar if passed, modifies the user's avatar 441 | * @param callback a user object on success. (TODO) 442 | */ 443 | public native void ModifySelf(const char[] username, const char[] avatar = ""); 444 | 445 | /** 446 | * Get a channel by ID. 447 | * Returns a channel object. 448 | * If the channel is a thread, a thread member object is included in the returned result. 449 | * 450 | * @param channelid id of channel you want to get. 451 | * @param callback a channel object on success. 452 | * @param data custom data passed through the request to use in the callback 453 | * @param data2 custom data passed through the request to use in the callback 454 | */ 455 | public native void GetChannel(const char[] channelid, OnGetDiscordChannel callback, any data = 0, any data2 = 0); 456 | 457 | /** 458 | * Delete a channel, or close a private message. 459 | * Requires the MANAGE_CHANNELS permission for the guild, or MANAGE_THREADS if the channel is a thread. 460 | * 461 | * @param channel channel you want to delete. 462 | * @param callback a channel object on success. 463 | * @param data custom data passed through the request to use in the callback 464 | * @param data2 custom data passed through the request to use in the callback 465 | */ 466 | public native void DeleteChannel(DiscordChannel channel, OnDiscordChannelDeleted callback, any data = 0, any data2 = 0); 467 | 468 | /** 469 | * Delete a channel, or close a private message. 470 | * Requires the MANAGE_CHANNELS permission for the guild, or MANAGE_THREADS if the channel is a thread. 471 | * 472 | * @param channelid ID of the channel that you want to delete. 473 | * @param callback a channel object on success. 474 | * @param data custom data passed through the request to use in the callback 475 | * @param data2 custom data passed through the request to use in the callback 476 | */ 477 | public native void DeleteChannelID(const char[] channelid, OnDiscordChannelDeleted callback, any data = 0, any data2 = 0); 478 | 479 | /** 480 | * Update a channel's settings. 481 | * All JSON parameters are optional. 482 | * 483 | * @param from DiscordChannel the channel you want to modify. 484 | * @param to DiscordChannel object with the modifies you want to apply to the channel. 485 | * @param callback a channel on success, and a 400 BAD REQUEST on invalid parameters. 486 | * @param data custom data passed through the request to use in the callback 487 | * @param data2 custom data passed through the request to use in the callback 488 | */ 489 | public native void ModifyChannel(DiscordChannel from, DiscordChannel to, OnDiscordChannelModified callback, any data = 0, any data2 = 0); 490 | 491 | /** 492 | * Update a channel's settings. 493 | * All JSON parameters are optional. 494 | * 495 | * @param channelid id of the channel you want to modify. 496 | * @param to DiscordChannel object with the modifies you want to apply to the channel. 497 | * @param callback a channel on success, and a 400 BAD REQUEST on invalid parameters. 498 | * @param data custom data passed through the request to use in the callback 499 | * @param data2 custom data passed through the request to use in the callback 500 | */ 501 | public native void ModifyChannelID(const char[] channelid, DiscordChannel to, OnDiscordChannelModified callback, any data = 0, any data2 = 0); 502 | 503 | /** 504 | * Post a message to a guild text or DM channel. 505 | * Fires a Message Create Gateway event. 506 | * See https://discord.com/developers/docs/reference#message-formatting for more information on how to properly format messages. 507 | * Files must be attached using a multipart/form-data body as described in Uploading Files. (Not supported yet) 508 | * 509 | * @param channel DiscordChannel where you want to send the message. (Can be DM) 510 | * @param message DiscordMessage object that you want to send. 511 | * @param callback a message object. (TODO) 512 | */ 513 | public native void SendMessageToChannel(DiscordChannel channel, DiscordMessage message); 514 | 515 | /** 516 | * Post a message to a guild text or DM channel. 517 | * Fires a Message Create Gateway event. 518 | * See https://discord.com/developers/docs/reference#message-formatting for more information on how to properly format messages. 519 | * Files must be attached using a multipart/form-data body as described in Uploading Files. (Not supported yet) 520 | * 521 | * @param channelid id of the channel where you want to send the message. 522 | * @param message DiscordMessage object that you want to send. 523 | * @param callback a message object. (TODO) 524 | */ 525 | public native void SendMessageToChannelID(const char[] channelid, DiscordMessage message); 526 | 527 | /** 528 | * Edit a previously sent message. 529 | * The fields content, embeds, and flags can be edited by the original message author. 530 | * Other users can only edit flags and only if they have the MANAGE_MESSAGES permission in the corresponding channel. 531 | * When specifying flags, ensure to include all previously set flags/bits in addition to ones that you are modifying. 532 | * Only flags documented in the table below may be modified by users (unsupported flag changes are currently ignored without error). 533 | * When the content field is edited, the mentions array in the message object will be reconstructed from scratch based on the new content. 534 | * The allowed_mentions field of the edit request controls how this happens. 535 | * If there is no explicit allowed_mentions in the edit request, the content will be parsed with default allowances, that is, without regard to whether or not an allowed_mentions was present in the request that originally created the message. 536 | * Fires a Message Update Gateway event. 537 | * 538 | * @param channel DiscordChannel where the message is located. 539 | * @param from DiscordMessage that you want to edit. 540 | * @param to DiscordMessage with the modifies you want to apply to the message. 541 | * @param callback a message object. (TODO) 542 | */ 543 | public native void EditMessage(DiscordChannel channel, DiscordMessage from, DiscordMessage to); 544 | 545 | /** 546 | * Edit a previously sent message. The fields content, embeds, and flags can be edited by the original message author. 547 | * Other users can only edit flags and only if they have the MANAGE_MESSAGES permission in the corresponding channel. 548 | * When specifying flags, ensure to include all previously set flags/bits in addition to ones that you are modifying. 549 | * Only flags documented in the table below may be modified by users (unsupported flag changes are currently ignored without error). 550 | * When the content field is edited, the mentions array in the message object will be reconstructed from scratch based on the new content. 551 | * The allowed_mentions field of the edit request controls how this happens. 552 | * If there is no explicit allowed_mentions in the edit request, the content will be parsed with default allowances, that is, without regard to whether or not an allowed_mentions was present in the request that originally created the message. 553 | * Fires a Message Update Gateway event. 554 | * 555 | * @param channelid id of the channel where the message is located. 556 | * @param messageid id of the message that you want to edit. 557 | * @param to DiscordMessage with the modifies you want to apply to the message. 558 | * @param callback a message object. (TODO) 559 | */ 560 | public native void EditMessageID(const char[] channelid, const char[] messageid, DiscordMessage to); 561 | 562 | /** 563 | * Pin a message in a channel. 564 | * Requires the MANAGE_MESSAGES permission. 565 | * Returns a 204 empty response on success. 566 | * 567 | * @param channel channel where the message is located. 568 | * @param message message you want to pin. 569 | */ 570 | public native void PinMessage(DiscordChannel channel, DiscordMessage message); 571 | 572 | /** 573 | * Pin a message in a channel. 574 | * Requires the MANAGE_MESSAGES permission. 575 | * Returns a 204 empty response on success. 576 | * 577 | * @param channelid id of the channel where the message is located. 578 | * @param message id of the message you want to pin. 579 | */ 580 | public native void PinMessageID(const char[] channelid, const char[] messageid); 581 | 582 | /** 583 | * Unpin a message in a channel. 584 | * Requires the MANAGE_MESSAGES permission. 585 | * Returns a 204 empty response on success. 586 | * 587 | * @param channel channel where the message is located. 588 | * @param message message you want to unpin. 589 | */ 590 | public native void UnpinMessage(DiscordChannel channel, DiscordMessage message); 591 | 592 | /** 593 | * Unpin a message in a channel. 594 | * Requires the MANAGE_MESSAGES permission. 595 | * Returns a 204 empty response on success. 596 | * 597 | * @param channelid id of the channel where the message is located. 598 | * @param message id of the message you want to unpin. 599 | */ 600 | public native void UnpinMessageID(const char[] channelid, const char[] messageid); 601 | 602 | /** 603 | * Returns all pinned messages in the channel as an array of message objects. 604 | * 605 | * @param channel channel where the messages are located. 606 | * @param callback an array of message objects. 607 | * @param data custom data passed through the request to use in the callback 608 | * @param data2 custom data passed through the request to use in the callback 609 | */ 610 | public native void GetPinnedMessages(DiscordChannel channel, OnGetDiscordChannelPinnedMessages callback, any data = 0, any data2 = 0); 611 | 612 | /** 613 | * Returns all pinned messages in the channel as an array of message objects. 614 | * 615 | * @param channelid id of the channel where the messages are located. 616 | * @param callback an array of message objects. 617 | * @param data custom data passed through the request to use in the callback 618 | * @param data2 custom data passed through the request to use in the callback 619 | */ 620 | public native void GetPinnedMessagesID(const char[] channelid, OnGetDiscordChannelPinnedMessages callback, any data = 0, any data2 = 0); 621 | 622 | /** 623 | * Delete a message. 624 | * If operating on a guild channel and trying to delete a message that was not sent by the current user, this endpoint requires the MANAGE_MESSAGES permission. 625 | * 626 | * @param channel channel where the message is. 627 | * @param message message you want to delete. 628 | */ 629 | public native void DeleteMessage(DiscordChannel channel, DiscordMessage message); 630 | 631 | /** 632 | * Delete a message. 633 | * If operating on a guild channel and trying to delete a message that was not sent by the current user, this endpoint requires the MANAGE_MESSAGES permission. 634 | * 635 | * @param channelid channel id where the message is. 636 | * @param messageid message id you want to delete. 637 | */ 638 | public native void DeleteMessageID(const char[] channelid, const char[] messageid); 639 | 640 | /** 641 | * Delete multiple messages in a single request. 642 | * This endpoint can only be used on guild channels and requires the MANAGE_MESSAGES permission. 643 | * 644 | * @param channel channel where the message is. 645 | * @param messages an array of message ids to delete (2-100). 646 | */ 647 | public native void DeleteMessagesBulk(DiscordChannel channel, DiscordMessageList messages); 648 | 649 | /** 650 | * Returns the messages for a channel. 651 | * If operating on a guild channel, this endpoint requires the VIEW_CHANNEL permission to be present on the current user. 652 | * If the current user is missing the READ_MESSAGE_HISTORY permission in the channel then this will return no messages (since they cannot read the message history). 653 | * Returns an array of message objects on success. 654 | * 655 | * @param channel channel where the message(s) are located. 656 | * @param around Get messages around this message ID (absent by default) 657 | * @param before Get messages before this message ID (absent by default) 658 | * @param after Get messages after this message ID (absent by default) 659 | * @param limit Max number of messages to return (1-100) (50 by default) 660 | * @param callback array of message objects on success. 661 | * @param data custom data passed through the request to use in the callback 662 | * @param data2 custom data passed through the request to use in the callback 663 | */ 664 | public native void GetChannelMessages(DiscordChannel channel, const char[] around = "", const char[] before = "", const char[] after = "", int limit = 50, OnGetDiscordChannelMessages callback, any data = 0, any data2 = 0); 665 | 666 | /** 667 | * Returns the messages for a channel. 668 | * If operating on a guild channel, this endpoint requires the VIEW_CHANNEL permission to be present on the current user. 669 | * If the current user is missing the READ_MESSAGE_HISTORY permission in the channel then this will return no messages (since they cannot read the message history). 670 | * Returns an array of message objects on success. 671 | * 672 | * @param channelid id of the channel where the message(s) are located. 673 | * @param around Get messages around this message ID (absent by default) 674 | * @param before Get messages before this message ID (absent by default) 675 | * @param after Get messages after this message ID (absent by default) 676 | * @param limit Max number of messages to return (1-100) (50 by default) 677 | * @param callback array of message objects on success. 678 | * @param data custom data passed through the request to use in the callback 679 | * @param data2 custom data passed through the request to use in the callback 680 | */ 681 | public native void GetChannelMessagesID(const char[] channelid, const char[] around = "", const char[] before = "", const char[] after = "", int limit = 50, OnGetDiscordChannelMessages callback, any data = 0, any data2 = 0); 682 | 683 | /** 684 | * Returns a specific message in the channel. 685 | * If operating on a guild channel, this endpoint requires the READ_MESSAGE_HISTORY permission to be present on the current user. 686 | * Returns a message object on success. 687 | * 688 | * @param channel channel where the message is located. 689 | * @param messageid id of the message. 690 | * @param callback a message object on success. 691 | * @param data custom data passed through the request to use in the callback 692 | * @param data2 custom data passed through the request to use in the callback 693 | */ 694 | public native void GetChannelMessage(DiscordChannel channel, const char[] messageid, OnGetDiscordChannelMessage callback, any data = 0, any data2 = 0); 695 | 696 | /** 697 | * Returns a specific message in the channel. 698 | * If operating on a guild channel, this endpoint requires the READ_MESSAGE_HISTORY permission to be present on the current user. 699 | * Returns a message object on success. 700 | * 701 | * @param channelid id of the channel where the message is located. 702 | * @param messageid id of the message. 703 | * @param callback a message object on success. 704 | * @param data custom data passed through the request to use in the callback 705 | * @param data2 custom data passed through the request to use in the callback 706 | */ 707 | public native void GetChannelMessageID(const char[] channelid, const char[] messageid, OnGetDiscordChannelMessage callback, any data = 0, any data2 = 0); 708 | 709 | /** 710 | * Crosspost a message in a News Channel to following channels. 711 | * This endpoint requires the SEND_MESSAGES permission, if the current user sent the message, or additionally the MANAGE_MESSAGES permission, for all other messages, to be present for the current user. 712 | * Returns a message object. 713 | * 714 | * @param channel channel where the message is. 715 | * @param message message you want to crosspost. 716 | */ 717 | public native void CrosspostMessage(DiscordChannel channel, DiscordMessage message); 718 | 719 | /** 720 | * Create a reaction for the message. 721 | * This endpoint requires the 'READ_MESSAGE_HISTORY' permission to be present on the current user. 722 | * Additionally, if nobody else has reacted to the message using this emoji, this endpoint requires the 'ADD_REACTIONS' permission to be present on the current user. 723 | * 724 | * @param channel channel where the message is. 725 | * @param message message that you want to react to. 726 | * @param emoji reaction emoji. 727 | */ 728 | public native void CreateReaction(DiscordChannel channel, DiscordMessage message, DiscordEmoji emoji); 729 | 730 | /** 731 | * Create a reaction for the message. 732 | * This endpoint requires the 'READ_MESSAGE_HISTORY' permission to be present on the current user. 733 | * Additionally, if nobody else has reacted to the message using this emoji, this endpoint requires the 'ADD_REACTIONS' permission to be present on the current user. 734 | * 735 | * @param channelid channel id where the message is. 736 | * @param messageid message id that you want to react to. 737 | * @param emoji reaction emoji. 738 | */ 739 | public native void CreateReactionID(const char[] channelid, const char[] messageid, DiscordEmoji emoji); 740 | 741 | /** 742 | * Delete a reaction the current user has made for the message. 743 | * Returns a 204 empty response on success. 744 | * 745 | * @param channel channel where the message is. 746 | * @param message message that has the reaction. 747 | * @param emoji reaction emoji you want to delete. 748 | */ 749 | public native void DeleteOwnReaction(DiscordChannel channel, DiscordMessage message, DiscordEmoji emoji); 750 | 751 | /** 752 | * Delete a reaction the current user has made for the message. 753 | * Returns a 204 empty response on success. 754 | * 755 | * @param channelid id of the channel where the message is. 756 | * @param message id of the message that has the reaction. 757 | * @param emoji reaction emoji you want to delete. 758 | */ 759 | public native void DeleteOwnReactionID(const char[] channelid, const char[] messageid, DiscordEmoji emoji); 760 | 761 | /** 762 | * Deletes another user's reaction. 763 | * This endpoint requires the MANAGE_MESSAGES permission to be present on the current user. 764 | * Returns a 204 empty response on success. 765 | * 766 | * @param channel channel where the message is. 767 | * @param message message that has the reaction. 768 | * @param emoji reaction emoji you want to delete. 769 | * @param user user who used the reaction. 770 | */ 771 | public native void DeleteReaction(DiscordChannel channel, DiscordMessage message, DiscordEmoji emoji, DiscordUser user); 772 | 773 | /** 774 | * Deletes another user's reaction. 775 | * This endpoint requires the MANAGE_MESSAGES permission to be present on the current user. 776 | * Returns a 204 empty response on success. 777 | * 778 | * @param channelid id of the channel where the message is. 779 | * @param message id of the message that has the reaction. 780 | * @param emoji reaction emoji you want to delete. 781 | * @param user user who used the reaction. 782 | */ 783 | public native void DeleteReactionID(const char[] channelid, const char[] messageid, DiscordEmoji emoji, DiscordUser user); 784 | 785 | /** 786 | * Deletes all reactions on a message. 787 | * This endpoint requires the MANAGE_MESSAGES permission to be present on the current user. 788 | * Fires a Message Reaction Remove All Gateway event. 789 | * 790 | * @param channel channel where the message is. 791 | * @param message message that has the reaction. 792 | */ 793 | public native void DeleteAllReactions(DiscordChannel channel, DiscordMessage message); 794 | 795 | /** 796 | * Deletes all reactions on a message. 797 | * This endpoint requires the MANAGE_MESSAGES permission to be present on the current user. 798 | * Fires a Message Reaction Remove All Gateway event. 799 | * 800 | * @param channelid id of the channel where the message is. 801 | * @param message id of the message that has the reaction. 802 | */ 803 | public native void DeleteAllReactionsID(const char[] channelid, const char[] messageid); 804 | 805 | /** 806 | * Deletes all the reactions for a given emoji on a message. 807 | * This endpoint requires the MANAGE_MESSAGES permission to be present on the current user. 808 | * Fires a Message Reaction Remove Emoji Gateway event. 809 | * 810 | * @param channel channel where the message is. 811 | * @param message message that has the reaction. 812 | */ 813 | public native void DeleteAllReactionsEmoji(DiscordChannel channel, DiscordMessage message, DiscordEmoji emoji); 814 | 815 | /** 816 | * Deletes all the reactions for a given emoji on a message. 817 | * This endpoint requires the MANAGE_MESSAGES permission to be present on the current user. 818 | * Fires a Message Reaction Remove Emoji Gateway event. 819 | * 820 | * @param channelid id of the channel where the message is. 821 | * @param message id of the message that has the reaction. 822 | */ 823 | public native void DeleteAllReactionsEmojiID(const char[] channelid, const char[] messageid, DiscordEmoji emoji); 824 | 825 | /** 826 | * Post a typing indicator for the specified channel. 827 | * Generally bots should not implement this route. 828 | * However, if a bot is responding to a command and expects the computation to take a few seconds, this endpoint may be called to let the user know that the bot is processing their message. 829 | * Returns a 204 empty response on success. Fires a Typing Start Gateway event. 830 | * 831 | * @param channel channel where the typing should be triggered. 832 | */ 833 | public native void TriggerTypingIndicator(DiscordChannel channel); 834 | 835 | /** 836 | * Post a typing indicator for the specified channel. 837 | * Generally bots should not implement this route. 838 | * However, if a bot is responding to a command and expects the computation to take a few seconds, this endpoint may be called to let the user know that the bot is processing their message. 839 | * Returns a 204 empty response on success. Fires a Typing Start Gateway event. 840 | * 841 | * @param channelid id of the channel where the typing should be triggered. 842 | */ 843 | public native void TriggerTypingIndicatorID(const char[] channelid); 844 | } -------------------------------------------------------------------------------- /include/discord/DiscordChannel.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordChannel_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordChannel_included_ 5 | 6 | #include 7 | 8 | enum DiscordChannelType 9 | { 10 | GUILD_TEXT = 0, /* a text channel within a server */ 11 | DM, /* a direct message between users */ 12 | GUILD_VOICE, /* a voice channel within a server */ 13 | GROUP_DM, /* a direct message between multiple users */ 14 | GUILD_CATEGORY, /* an organizational category that contains up to 50 channels. for further info: https://support.discord.com/hc/en-us/articles/115001580171-Channel-Categories-101 */ 15 | GUILD_NEWS, /* a channel that users can follow and crosspost into their own server. for further info: https://support.discord.com/hc/en-us/articles/360032008192 */ 16 | GUILD_STORE, /* a channel in which game developers can sell their game on Discord. for further info: https://discord.com/developers/docs/game-and-server-management/special-channels */ 17 | GUILD_NEWS_THREAD = 10, /* a temporary sub-channel within a GUILD_NEWS channel */ 18 | GUILD_PUBLIC_THREAD, /* a temporary sub-channel within a GUILD_TEXT channel */ 19 | GUILD_PRIVATE_THREAD, /* a temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission */ 20 | GUILD_STAGE_VOICE, /* a voice channel for hosting events with an audience. for further info: https://support.discord.com/hc/en-us/articles/1500005513722 */ 21 | GUILD_DIRECTORY, /* the channel in a hub containing the listed servers */ 22 | GUILD_FORUM /* (still in development) a channel that can only contain threads, The GUILD_FORUM channel type is still in active development. Avoid implementing any features that are not documented here, since they are subject to change without notice! */ 23 | } 24 | 25 | enum DiscordChannelVideoQualityMode 26 | { 27 | AUTO = 1, /* Discord chooses the quality for optimal performance */ 28 | FULL /* 720p */ 29 | } 30 | 31 | enum DiscordChannelFlags 32 | { 33 | PINNED = (1 << 1) /* this thread is pinned to the top of its parent forum channel */ 34 | } 35 | 36 | /** 37 | * Called as callback when a new message received on a listened channel. 38 | * 39 | * @param bot same handle as the bot you have used to call the native. 40 | * @param channel DiscordChannel object received. 41 | * @param message DiscordMessage object received. 42 | * 43 | * @noreturn 44 | */ 45 | typedef OnDiscordChannelMessage = function void (DiscordBot bot, DiscordChannel channel, DiscordMessage message); 46 | 47 | /** DiscordBot.ModifyChannel | DiscordBot.ModifyChannelID 48 | * 49 | * Called as callback after a successful request. 50 | * 51 | */ 52 | typeset OnDiscordChannelModified 53 | { 54 | /** 55 | * 56 | * @param bot same handle as the bot you have used to call the native. 57 | * @param channel DiscordChannel object received. 58 | * DiscordChannel handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 59 | * 60 | * @noreturn 61 | */ 62 | function void (DiscordBot bot, DiscordChannel channel); 63 | 64 | /** 65 | * 66 | * @param bot same handle as the bot you have used to call the native. 67 | * @param channel DiscordChannel object received. 68 | * DiscordChannel handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 69 | * @param data custom data passed through the request to use in the callback 70 | * 71 | * @noreturn 72 | */ 73 | function void (DiscordBot bot, DiscordChannel channel, any data); 74 | 75 | /** 76 | * 77 | * @param bot same handle as the bot you have used to call the native. 78 | * @param channel DiscordChannel object received. 79 | * DiscordChannel handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 80 | * @param data custom data passed through the request to use in the callback 81 | * @param data2 custom data passed through the request to use in the callback 82 | * 83 | * @noreturn 84 | */ 85 | function void (DiscordBot bot, DiscordChannel channel, any data, any data2); 86 | } 87 | 88 | /** DiscordBot.DeleteChannel 89 | * 90 | * Called as callback after a successful request. 91 | * 92 | */ 93 | typeset OnDiscordChannelDeleted 94 | { 95 | /** 96 | * 97 | * @param bot same handle as the bot you have used to call the native. 98 | * @param channel DiscordChannel object received. 99 | * DiscordChannel handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 100 | * 101 | * @noreturn 102 | */ 103 | function void (DiscordBot bot, DiscordChannel channel); 104 | 105 | /** 106 | * 107 | * @param bot same handle as the bot you have used to call the native. 108 | * @param channel DiscordChannel object received. 109 | * DiscordChannel handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 110 | * @param data custom data passed through the request to use in the callback 111 | * 112 | * @noreturn 113 | */ 114 | function void (DiscordBot bot, DiscordChannel channel, any data); 115 | 116 | /** 117 | * 118 | * @param bot same handle as the bot you have used to call the native. 119 | * @param channel DiscordChannel object received. 120 | * DiscordChannel handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 121 | * @param data custom data passed through the request to use in the callback 122 | * @param data2 custom data passed through the request to use in the callback 123 | * 124 | * @noreturn 125 | */ 126 | function void (DiscordBot bot, DiscordChannel channel, any data, any data2); 127 | } 128 | 129 | /** DiscordBot.GetChannel 130 | * 131 | * Called as callback after a successful request. 132 | * 133 | */ 134 | typeset OnGetDiscordChannel 135 | { 136 | /** 137 | * 138 | * @param bot same handle as the bot you have used to call the native. 139 | * @param channel DiscordChannel object received. 140 | * DiscordChannel handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 141 | * 142 | * @noreturn 143 | */ 144 | function void (DiscordBot bot, DiscordChannel channel); 145 | 146 | /** 147 | * 148 | * @param bot same handle as the bot you have used to call the native. 149 | * @param channel DiscordChannel object received. 150 | * DiscordChannel handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 151 | * @param data custom data passed through the request to use in the callback 152 | * 153 | * @noreturn 154 | */ 155 | function void (DiscordBot bot, DiscordChannel channel, any data); 156 | 157 | /** 158 | * 159 | * @param bot same handle as the bot you have used to call the native. 160 | * @param channel DiscordChannel object received. 161 | * DiscordChannel handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 162 | * @param data custom data passed through the request to use in the callback 163 | * @param data2 custom data passed through the request to use in the callback 164 | * 165 | * @noreturn 166 | */ 167 | function void (DiscordBot bot, DiscordChannel channel, any data, any data2); 168 | } 169 | 170 | /** 171 | * The thread metadata object contains a number of thread-specific channel fields that are not needed by other channel types. 172 | */ 173 | methodmap ThreadMetaData < JSON_Object 174 | { 175 | /** 176 | * whether the thread is archived 177 | */ 178 | property bool Archived 179 | { 180 | public get() { return this.GetBool("archived"); } 181 | } 182 | 183 | /** 184 | * duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080 185 | */ 186 | property int AutoArchiveDuration 187 | { 188 | public get() { return this.GetInt("auto_archive_duration"); } 189 | } 190 | 191 | /** 192 | * whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it 193 | */ 194 | property bool Locked 195 | { 196 | public get() { return this.GetBool("locked"); } 197 | } 198 | 199 | /** 200 | * whether non-moderators can add other non-moderators to a thread; only available on private threads 201 | */ 202 | property bool Invitable 203 | { 204 | public get() { return this.GetBool("invitable"); } 205 | } 206 | 207 | /** 208 | * timestamp when the thread was created; only populated for threads created after 2022-01-09 209 | */ 210 | public bool GetCreateTimestampDateTime(DateTime& out) 211 | { 212 | char szDate[DATE_LENGTH]; 213 | this.GetString("create_timestamp", szDate, sizeof(szDate)); 214 | return DateTime.TryParse(szDate, out); 215 | } 216 | 217 | /** 218 | * timestamp when the thread was created; only populated for threads created after 2022-01-09 219 | */ 220 | public bool GetCreateTimestamp(char[] output, int maxsize) 221 | { 222 | return this.GetString("create_timestamp", output, maxsize); 223 | } 224 | 225 | /** 226 | * timestamp when the thread's archive status was last changed, used for calculating recent activity 227 | */ 228 | public bool GetArchiveTimestampDateTime(DateTime& out) 229 | { 230 | char szDate[DATE_LENGTH]; 231 | this.GetString("archive_timestamp", szDate, sizeof(szDate)); 232 | return DateTime.TryParse(szDate, out); 233 | } 234 | 235 | /** 236 | * timestamp when the thread's archive status was last changed, used for calculating recent activity 237 | */ 238 | public bool GetArchiveTimestamp(char[] output, int maxsize) 239 | { 240 | return this.GetString("archive_timestamp", output, maxsize); 241 | } 242 | 243 | /** 244 | * Release resources 245 | */ 246 | public void Dispose() 247 | { 248 | if(this == null) 249 | return; 250 | 251 | this.Cleanup(); 252 | delete this; 253 | } 254 | } 255 | 256 | /** 257 | * A thread member is used to indicate whether a user has joined a thread or not. 258 | */ 259 | methodmap ThreadMember < DiscordObject 260 | { 261 | /** 262 | * any user-thread settings, currently only used for notifications 263 | */ 264 | property int Flags 265 | { 266 | public get() { return this.GetInt("flags"); } 267 | } 268 | 269 | /** 270 | * the id of the user 271 | */ 272 | public bool GetUserID(char[] output, int maxsize) 273 | { 274 | return this.GetString("user_id", output, maxsize); 275 | } 276 | 277 | /** 278 | * the time the current user last joined the thread 279 | */ 280 | public bool GetJoinTimestampDateTime(DateTime& out) 281 | { 282 | char szDate[DATE_LENGTH]; 283 | this.GetString("join_timestamp", szDate, sizeof(szDate)); 284 | return DateTime.TryParse(szDate, out); 285 | } 286 | 287 | /** 288 | * the time the current user last joined the thread 289 | */ 290 | public bool GetJoinTimestamp(char[] output, int maxsize) 291 | { 292 | return this.GetString("join_timestamp", output, maxsize); 293 | } 294 | } 295 | 296 | /** 297 | * Represents a guild or DM channel within Discord. 298 | */ 299 | methodmap DiscordChannel < DiscordObject 300 | { 301 | /** 302 | * the type of channel 303 | */ 304 | property DiscordChannelType Type 305 | { 306 | public get() { return view_as(this.GetInt("type")); } 307 | 308 | public set(DiscordChannelType value) { this.SetInt("type", view_as(value)); } 309 | } 310 | 311 | /** 312 | * whether the channel is nsfw 313 | */ 314 | property bool IsNSFW 315 | { 316 | public get() { return this.GetBool("nsfw"); } 317 | 318 | public set(bool value) { this.SetBool("nsfw", value); } 319 | } 320 | 321 | /** 322 | * the bitrate (in bits) of the voice channel 323 | */ 324 | property int Bitrate 325 | { 326 | public get() { return this.GetInt("bitrate"); } 327 | 328 | public set(int value) { this.SetInt("bitrate", value); } 329 | } 330 | 331 | /** 332 | * the user limit of the voice channel 333 | */ 334 | property int UserLimit 335 | { 336 | public get() { return this.GetInt("user_limit"); } 337 | 338 | public set(int value) { this.SetInt("user_limit", value); } 339 | } 340 | 341 | /** 342 | * whether the channel is text 343 | */ 344 | property bool IsText 345 | { 346 | public get() { return this.Type == GUILD_TEXT; } 347 | } 348 | 349 | /** 350 | * whether the channel is private DM 351 | */ 352 | property bool IsPrivate 353 | { 354 | public get() { return this.Type == DM; } 355 | } 356 | 357 | /** 358 | * the camera video quality mode of the voice channel, 1 (AUTO) when not present 359 | */ 360 | property DiscordChannelVideoQualityMode VideoQualityMode 361 | { 362 | public get() { return view_as(this.GetInt("video_quality_mode")); } 363 | } 364 | 365 | /** 366 | * an approximate count of users in a thread, stops counting at 50 367 | */ 368 | property int MemberCount 369 | { 370 | public get() { return this.GetInt("member_count"); } 371 | } 372 | 373 | /** 374 | * an approximate count of messages in a thread, stops counting at 50 375 | */ 376 | property int MessageCount 377 | { 378 | public get() { return this.GetInt("message_count"); } 379 | } 380 | 381 | /** 382 | * sorting position of the channel 383 | */ 384 | property int Position 385 | { 386 | public get() { return this.GetInt("position"); } 387 | 388 | public set(int value) { this.SetInt("position", value); } 389 | } 390 | 391 | /** 392 | * explicit permission overwrites for members and roles 393 | */ 394 | property JSON_Array PermissionOverwrites 395 | { 396 | public get() { return view_as(this.GetObject("permission_overwrites")); } 397 | 398 | public set(JSON_Array value) { this.SetObject("permission_overwrites", value); } 399 | } 400 | 401 | /** 402 | * amount of seconds a user has to wait before sending another message (0-21600); 403 | * bots, as well as users with the permission manage_messages or manage_channel, are unaffected 404 | * also applies to thread creation. Users can send one message and create one thread during each RateLimitPerUser interval. 405 | */ 406 | property int RateLimitPerUser 407 | { 408 | public get() { return this.GetInt("rate_limit_per_user"); } 409 | 410 | public set(int value) { this.SetInt("rate_limit_per_user", value); } 411 | } 412 | 413 | /** 414 | * the recipients of the DM 415 | */ 416 | property JSON_Array Recipients 417 | { 418 | public get() { return view_as(this.GetObject("recipients")); } 419 | } 420 | 421 | /** 422 | * thread-specific fields not needed by other channels 423 | */ 424 | property ThreadMetaData ThreadMetaData 425 | { 426 | public get() { return view_as(this.GetObject("thread_metadata")); } 427 | } 428 | 429 | /** 430 | * thread member object for the current user, if they have joined the thread, only included on certain API endpoints 431 | */ 432 | property ThreadMember ThreadMember 433 | { 434 | public get() { return view_as(this.GetObject("member")); } 435 | } 436 | 437 | /** 438 | * default duration that the clients (not the API) will use for newly created threads, in minutes, to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080 439 | */ 440 | property int DefaultAutoArchiveDuration 441 | { 442 | public get() { return this.GetInt("default_auto_archive_duration"); } 443 | } 444 | 445 | /** 446 | * DiscordChannelFlags combined as a bitfield 447 | */ 448 | property int Flags 449 | { 450 | public get() { return this.GetInt("flags"); } 451 | 452 | public set(int value) { this.SetInt("flags", value); } 453 | } 454 | 455 | /** 456 | * icon hash of the group DM 457 | */ 458 | public bool GetIcon(char[] output, int maxsize) 459 | { 460 | return this.GetString("icon", output, maxsize); 461 | } 462 | 463 | /** 464 | * icon hash of the group DM 465 | */ 466 | public void SetIcon(const char[] input) 467 | { 468 | this.SetString("icon", input); 469 | } 470 | 471 | /** 472 | * the name of the channel (1-100 characters) 473 | */ 474 | public bool GetName(char[] output, int maxsize) 475 | { 476 | return this.GetString("name", output, maxsize); 477 | } 478 | 479 | /** 480 | * the name of the channel (1-100 characters) 481 | */ 482 | public void SetName(const char[] input) 483 | { 484 | this.SetString("name", input); 485 | } 486 | 487 | /** 488 | * the channel topic (0-1024 characters) 489 | */ 490 | public bool GetTopic(char[] output, int maxsize) 491 | { 492 | return this.GetString("topic", output, maxsize); 493 | } 494 | 495 | /** 496 | * the channel topic (0-1024 characters) 497 | */ 498 | public void SetTopic(const char[] input) 499 | { 500 | this.SetString("topic", input); 501 | } 502 | 503 | /** 504 | * voice region id for the voice channel, automatic when set to null 505 | */ 506 | public bool GetRtcRegion(char[] output, int maxsize) 507 | { 508 | return this.GetString("rtc_region", output, maxsize); 509 | } 510 | 511 | /** 512 | * the id of the guild (may be missing for some channel objects received over gateway guild dispatches) 513 | */ 514 | public bool GetGuildID(char[] output, int maxsize) 515 | { 516 | return this.GetString("guild_id", output, maxsize); 517 | } 518 | 519 | /** 520 | * the id of the last message sent in this channel (or thread for GUILD_FORUM channels) (may not point to an existing or valid message or thread) 521 | */ 522 | public bool GetLastMessageID(char[] output, int maxsize) 523 | { 524 | return this.GetString("last_message_id", output, maxsize); 525 | } 526 | 527 | /** 528 | * the id of the last message sent in this channel (or thread for GUILD_FORUM channels) (may not point to an existing or valid message or thread) 529 | */ 530 | public void SetLastMessageID(const char[] output) 531 | { 532 | this.SetString("last_message_id", output); 533 | } 534 | 535 | /** 536 | * id of the creator of the group DM or thread 537 | */ 538 | public bool GetOwnerID(char[] output, int maxsize) 539 | { 540 | return this.GetString("owner_id", output, maxsize); 541 | } 542 | 543 | /** 544 | * application id of the group DM creator if it is bot-created 545 | */ 546 | public bool GetApplicationID(char[] output, int maxsize) 547 | { 548 | return this.GetString("application_id", output, maxsize); 549 | } 550 | 551 | /** 552 | * for guild channels: id of the parent category for a channel (each parent category can contain up to 50 channels) 553 | * for threads: id of the text channel this thread was created 554 | */ 555 | public bool GetParentID(char[] output, int maxsize) 556 | { 557 | return this.GetString("parent_id", output, maxsize); 558 | } 559 | 560 | /** 561 | * when the last pinned message was pinned. This may be null in events such as GUILD_CREATE when a message is not pinned. 562 | */ 563 | public bool GetLastPinTimestampDateTime(DateTime& out) 564 | { 565 | char szDate[DATE_LENGTH]; 566 | this.GetString("last_pin_timestamp", szDate, sizeof(szDate)); 567 | return DateTime.TryParse(szDate, out); 568 | } 569 | 570 | /** 571 | * when the last pinned message was pinned. This may be null in events such as GUILD_CREATE when a message is not pinned. 572 | */ 573 | public bool GetLastPinTimestamp(char[] output, int maxsize) 574 | { 575 | return this.GetString("last_pin_timestamp", output, maxsize); 576 | } 577 | 578 | /** 579 | * computed permissions for the invoking user in the channel, including overwrites, only included when part of the resolved data received on a slash command interaction 580 | */ 581 | public bool GetPermissions(char[] output, int maxsize) 582 | { 583 | return this.GetString("permissions", output, maxsize); 584 | } 585 | 586 | /** 587 | * computed permissions for the invoking user in the channel, including overwrites, only included when part of the resolved data received on a slash command interaction 588 | */ 589 | public void SetPermissions(const char[] input) 590 | { 591 | this.SetString("permissions", input); 592 | } 593 | } -------------------------------------------------------------------------------- /include/discord/DiscordChannelMention.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordChannelMention_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordChannelMention_included_ 5 | 6 | methodmap DiscordChannelMention < DiscordObject 7 | { 8 | property DiscordChannelType Type 9 | { 10 | public get() { return view_as(this.GetInt("type")); } 11 | } 12 | 13 | public bool GetGuildID(char[] output, int maxsize) 14 | { 15 | return this.GetString("guild_id", output, maxsize); 16 | } 17 | 18 | public bool GetName(char[] output, int maxsize) 19 | { 20 | return this.GetString("name", output, maxsize); 21 | } 22 | } -------------------------------------------------------------------------------- /include/discord/DiscordConnection.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordConnection_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordConnection_included_ 5 | 6 | enum DiscordConnectionVisibility 7 | { 8 | Visibility_NONE = 0, 9 | Visibility_EVERTYONE = 1 10 | } 11 | 12 | methodmap DiscordConnection < DiscordObject 13 | { 14 | property bool Revoked 15 | { 16 | public get() { return this.GetBool("revoked"); } 17 | } 18 | 19 | property bool Verified 20 | { 21 | public get() { return this.GetBool("verified"); } 22 | } 23 | 24 | property bool FriendSync 25 | { 26 | public get() { return this.GetBool("friend_sync"); } 27 | } 28 | 29 | property bool ShowActivity 30 | { 31 | public get() { return this.GetBool("show_activity"); } 32 | } 33 | 34 | property DiscordConnectionVisibility Visibility 35 | { 36 | public get() { return view_as(this.GetInt("visibility")); } 37 | } 38 | 39 | public bool GetName(char[] output, int maxsize) 40 | { 41 | return this.GetString("name", output, maxsize); 42 | } 43 | 44 | public bool GetType(char[] output, int maxsize) 45 | { 46 | return this.GetString("type", output, maxsize); 47 | } 48 | 49 | public JSON_Array GetIntegrations() 50 | { 51 | return view_as(this.GetObject("integrations")); 52 | } 53 | } -------------------------------------------------------------------------------- /include/discord/DiscordEmbed.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordEmbed_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordEmbed_included_ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define MAX_EMBED_DESCRIPTION_LENGTH 4096 // https://discord.com/developers/docs/resources/channel#embed-limits-limits 15 | #define MAX_EMBED_FIELDS 25 16 | 17 | methodmap DiscordEmbed < JSON_Object 18 | { 19 | public DiscordEmbed(DiscordEmbed embed = view_as(null)) 20 | { 21 | if(embed == null) 22 | embed = view_as(new JSON_Object()); 23 | 24 | return embed; 25 | } 26 | 27 | /** 28 | * title of embed 29 | */ 30 | public void WithTitle(const char[] title) 31 | { 32 | this.SetString("title", title); 33 | } 34 | 35 | /** 36 | * title of embed 37 | */ 38 | public bool GetTitle(char[] output, int maxsize) 39 | { 40 | return this.GetString("title", output, maxsize); 41 | } 42 | 43 | /** 44 | * description of embed 45 | */ 46 | public void WithDescription(const char[] description) 47 | { 48 | this.SetString("description", description); 49 | } 50 | 51 | /** 52 | * description of embed 53 | */ 54 | public bool GetDescription(char[] output, int maxsize) 55 | { 56 | return this.GetString("description", output, maxsize); 57 | } 58 | 59 | /** 60 | * url of embed 61 | */ 62 | public void WithUrl(const char[] url) 63 | { 64 | this.SetString("url", url); 65 | } 66 | 67 | /** 68 | * url of embed 69 | */ 70 | public bool GetUrl(char[] output, int maxsize) 71 | { 72 | return this.GetString("url", output, maxsize); 73 | } 74 | 75 | /** 76 | * timestamp of embed content 77 | */ 78 | public void WithTimestamp(DateTime dateTime) 79 | { 80 | char szDate[DATE_LENGTH]; 81 | dateTime.ToString(szDate, sizeof(szDate), "%Y-%m-%d %H:%M:%S%z"); 82 | this.SetString("timestamp", szDate); 83 | } 84 | 85 | /** 86 | * timestamp of embed content 87 | */ 88 | public bool GetTimestamp(DateTime& out) 89 | { 90 | char szDate[DATE_LENGTH]; 91 | this.GetString("timestamp", szDate, sizeof(szDate)); 92 | return DateTime.TryParse(szDate, out); 93 | } 94 | 95 | /** 96 | * type of embed (always "rich" for webhook embeds) 97 | * ( https://discord.com/developers/docs/resources/channel#embed-object-embed-types ) 98 | */ 99 | public void SetType(const char[] type = "rich") 100 | { 101 | this.SetString("type", type); 102 | } 103 | 104 | /** 105 | * type of embed (always "rich" for webhook embeds) 106 | * ( https://discord.com/developers/docs/resources/channel#embed-object-embed-types ) 107 | */ 108 | public bool GetType(char[] output, int maxsize) 109 | { 110 | return this.GetString("type", output, maxsize); 111 | } 112 | 113 | /** 114 | * color code of the embed 115 | */ 116 | public void SetColor(const char[] hexcode) 117 | { 118 | this.SetInt("color", HexToDec(hexcode)); 119 | } 120 | 121 | /** 122 | * color code of the embed 123 | */ 124 | public void GetColor(char[] output, int maxsize) 125 | { 126 | int color = this.GetInt("color"); 127 | Format(output, maxsize, "#%X", color); 128 | } 129 | 130 | /** 131 | * author information 132 | */ 133 | public void WithAuthor(DiscordEmbedAuthor author) 134 | { 135 | this.SetObject("author", author); 136 | } 137 | 138 | /** 139 | * author information 140 | */ 141 | public DiscordEmbedAuthor GetAuthor() 142 | { 143 | return view_as(this.GetObject("author")); 144 | } 145 | 146 | /** 147 | * footer information 148 | */ 149 | public void WithFooter(DiscordEmbedFooter footer) 150 | { 151 | this.SetObject("footer", footer); 152 | } 153 | 154 | /** 155 | * footer information 156 | */ 157 | public DiscordEmbedFooter GetFooter() 158 | { 159 | return view_as(this.GetObject("footer")); 160 | } 161 | 162 | /** 163 | * image information 164 | */ 165 | public void WithImage(DiscordEmbedImage image) 166 | { 167 | this.SetObject("image", image); 168 | } 169 | 170 | /** 171 | * image information 172 | */ 173 | public DiscordEmbedImage GetImage() 174 | { 175 | return view_as(this.GetObject("image")); 176 | } 177 | 178 | /** 179 | * thumbnail information 180 | */ 181 | public void WithThumbnail(DiscordEmbedThumbnail thumbnail) 182 | { 183 | this.SetObject("thumbnail", thumbnail); 184 | } 185 | 186 | /** 187 | * thumbnail information 188 | */ 189 | public DiscordEmbedThumbnail GetThumbnail() 190 | { 191 | return view_as(this.GetObject("thumbnail")); 192 | } 193 | 194 | /** 195 | * video information 196 | */ 197 | public void WithVideo(DiscordEmbedVideo video) 198 | { 199 | this.SetObject("video", video); 200 | } 201 | 202 | /** 203 | * video information 204 | */ 205 | public DiscordEmbedVideo GetVideo() 206 | { 207 | return view_as(this.GetObject("video")); 208 | } 209 | 210 | /** 211 | * provider information 212 | */ 213 | public void WithProvider(DiscordEmbedProvider provider) 214 | { 215 | this.SetObject("provider", provider); 216 | } 217 | 218 | /** 219 | * provider information 220 | */ 221 | public DiscordEmbedProvider GetProvider() 222 | { 223 | return view_as(this.GetObject("provider")); 224 | } 225 | 226 | /** 227 | * fields information 228 | */ 229 | public JSON_Array GetFields() 230 | { 231 | return view_as(this.GetObject("fields")); 232 | } 233 | 234 | /** 235 | * add a new field to the embed 236 | */ 237 | public void AddField(DiscordEmbedField field) 238 | { 239 | if(!this.HasKey("fields")) 240 | this.SetObject("fields", new JSON_Array()); 241 | 242 | JSON_Array fields = this.GetFields(); 243 | if(fields.Length < MAX_EMBED_FIELDS) 244 | { 245 | fields.PushObject(field); 246 | this.SetObject("fields", fields); 247 | } else LogError("DiscordEmbed cannot have more than %i fields!", MAX_EMBED_FIELDS); 248 | } 249 | 250 | /** 251 | * remove a field from the embed 252 | */ 253 | public bool RemoveField(int index) 254 | { 255 | JSON_Array fields = this.GetFields(); 256 | bool result = fields.Remove(index); 257 | this.SetObject("fields", fields); 258 | return result; 259 | } 260 | 261 | /** 262 | * color code of the embed 263 | */ 264 | property int Color 265 | { 266 | public get() { return this.GetInt("color"); } 267 | public set(int value) { this.SetInt("color", value); } 268 | } 269 | 270 | /** 271 | * timestamp of embed content 272 | */ 273 | property DateTime Timestamp 274 | { 275 | public get() 276 | { 277 | char szDate[DATE_LENGTH]; 278 | this.GetString("timestamp", szDate, sizeof(szDate)); 279 | return DateTime.Parse(szDate); 280 | } 281 | 282 | public set(DateTime value) { this.WithTimestamp(value); } 283 | } 284 | 285 | /** 286 | * author information 287 | */ 288 | property DiscordEmbedAuthor Author 289 | { 290 | public get() { return this.GetAuthor(); } 291 | public set(DiscordEmbedAuthor value) { this.WithAuthor(value); } 292 | } 293 | 294 | /** 295 | * footer information 296 | */ 297 | property DiscordEmbedFooter Footer 298 | { 299 | public get() { return this.GetFooter(); } 300 | public set(DiscordEmbedFooter value) { this.WithFooter(value); } 301 | } 302 | 303 | /** 304 | * image information 305 | */ 306 | property DiscordEmbedImage Image 307 | { 308 | public get() { return this.GetImage(); } 309 | public set(DiscordEmbedImage value) { this.WithImage(value); } 310 | } 311 | 312 | /** 313 | * thumbnail information 314 | */ 315 | property DiscordEmbedThumbnail Thumbnail 316 | { 317 | public get() { return this.GetThumbnail(); } 318 | public set(DiscordEmbedThumbnail value) { this.WithThumbnail(value); } 319 | } 320 | 321 | /** 322 | * video information 323 | */ 324 | property DiscordEmbedVideo Video 325 | { 326 | public get() { return this.GetVideo(); } 327 | public set(DiscordEmbedVideo value) { this.WithVideo(value); } 328 | } 329 | 330 | /** 331 | * provider information 332 | */ 333 | property DiscordEmbedProvider Provider 334 | { 335 | public get() { return this.GetProvider(); } 336 | public set(DiscordEmbedProvider value) { this.WithProvider(value); } 337 | } 338 | 339 | /** 340 | * Release resources 341 | */ 342 | public void Dispose() 343 | { 344 | if(this == null) 345 | return; 346 | 347 | this.Cleanup(); 348 | delete this; 349 | } 350 | } 351 | 352 | public int HexToDec(const char[] hex) 353 | { 354 | //i = 1 to skip the # 355 | int i = 1, result, value; 356 | while((value = IsHex(hex[i++])) != -1) 357 | { 358 | result *= 16 + value; 359 | } 360 | 361 | return result 362 | } 363 | 364 | public int IsHex(char ch) 365 | { 366 | if(!ch) 367 | return -1; 368 | 369 | if('0' <= ch <= '9') 370 | return ch - '0'; 371 | 372 | ch &= ~0x20; 373 | if('A' <= ch <= 'F') 374 | return ch - 'A' + 10; 375 | 376 | return -1; 377 | } -------------------------------------------------------------------------------- /include/discord/DiscordEmbedAuthor.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordEmbedAuthor_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordEmbedAuthor_included_ 5 | 6 | #define MAX_AUTHOR_NAME_LENGTH 256 // https://discord.com/developers/docs/resources/channel#embed-limits-limits 7 | 8 | /** 9 | * author information 10 | */ 11 | methodmap DiscordEmbedAuthor < JSON_Object 12 | { 13 | public DiscordEmbedAuthor(const char[] name = "", const char[] url = "", const char[] iconUrl = "") 14 | { 15 | JSON_Object obj = new JSON_Object(); 16 | obj.SetString("name", name); 17 | obj.SetString("url", url); 18 | obj.SetString("icon_url", iconUrl); 19 | return view_as(obj); 20 | } 21 | 22 | /** 23 | * name of author 24 | */ 25 | public bool GetName(char[] output, int maxsize) 26 | { 27 | return this.GetString("name", output, maxsize); 28 | } 29 | 30 | /** 31 | * name of author 32 | */ 33 | public void SetName(const char[] name) 34 | { 35 | this.SetString("name", name); 36 | } 37 | 38 | /** 39 | * url of author 40 | */ 41 | public bool GetUrl(char[] output, int maxsize) 42 | { 43 | return this.GetString("url", output, maxsize); 44 | } 45 | 46 | /** 47 | * url of author 48 | */ 49 | public void SetUrl(const char[] url) 50 | { 51 | this.SetString("url", url); 52 | } 53 | 54 | /** 55 | * url of author icon (only supports http(s) and attachments) 56 | */ 57 | public bool GetIcon(char[] output, int maxsize) 58 | { 59 | return this.GetString("icon_url", output, maxsize); 60 | } 61 | 62 | /** 63 | * url of author icon (only supports http(s) and attachments) 64 | */ 65 | public void SetIcon(const char[] iconUrl) 66 | { 67 | this.SetString("icon_url", iconUrl); 68 | } 69 | 70 | /** 71 | * Release resources 72 | */ 73 | public void Dispose() 74 | { 75 | if(this == null) 76 | return; 77 | 78 | this.Cleanup(); 79 | delete this; 80 | } 81 | } -------------------------------------------------------------------------------- /include/discord/DiscordEmbedField.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordEmbedField_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordEmbedField_included_ 5 | 6 | #define MAX_FIELD_NAME_LENGTH 256 // https://discord.com/developers/docs/resources/channel#embed-limits-limits 7 | #define MAX_FIELD_VALUE_LENGTH 1024 // https://discord.com/developers/docs/resources/channel#embed-limits-limits 8 | 9 | /** 10 | * field information 11 | */ 12 | methodmap DiscordEmbedField < JSON_Object 13 | { 14 | public DiscordEmbedField(const char[] name = "", const char[] value = "", bool inline = false) 15 | { 16 | JSON_Object obj = new JSON_Object(); 17 | obj.SetString("name", name); 18 | obj.SetString("value", value); 19 | obj.SetBool("inline", inline); 20 | return view_as(obj); 21 | } 22 | 23 | /** 24 | * whether or not this field should display inline 25 | */ 26 | property bool Inline 27 | { 28 | public get() { return this.GetBool("inline"); } 29 | public set(bool value) { this.SetBool("inline", value); } 30 | } 31 | 32 | /** 33 | * name of the field 34 | */ 35 | public bool GetName(char[] output, int maxsize) 36 | { 37 | return this.GetString("name", output, maxsize); 38 | } 39 | 40 | /** 41 | * name of the field 42 | */ 43 | public void SetName(const char[] name) 44 | { 45 | this.SetString("name", name); 46 | } 47 | 48 | /** 49 | * value of the field 50 | */ 51 | public bool GetValue(char[] output, int maxsize) 52 | { 53 | return this.GetString("value", output, maxsize); 54 | } 55 | 56 | /** 57 | * value of the field 58 | */ 59 | public void SetValue(const char[] value) 60 | { 61 | this.SetString("value", value); 62 | } 63 | 64 | /** 65 | * Release resources 66 | */ 67 | public void Dispose() 68 | { 69 | if(this == null) 70 | return; 71 | 72 | this.Cleanup(); 73 | delete this; 74 | } 75 | } -------------------------------------------------------------------------------- /include/discord/DiscordEmbedFooter.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordEmbedFooter_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordEmbedFooter_included_ 5 | 6 | #define MAX_FOOTER_TEXT_LENGTH 2048 // https://discord.com/developers/docs/resources/channel#embed-limits-limits 7 | 8 | methodmap DiscordEmbedFooter < JSON_Object 9 | { 10 | public DiscordEmbedFooter(const char[] text = "", const char[] iconUrl = "") 11 | { 12 | JSON_Object obj = new JSON_Object(); 13 | obj.SetString("text", text); 14 | obj.SetString("icon_url", iconUrl); 15 | return view_as(obj); 16 | } 17 | 18 | /** 19 | * footer text 20 | */ 21 | public bool GetText(char[] output, int maxsize) 22 | { 23 | return this.GetString("text", output, maxsize); 24 | } 25 | 26 | /** 27 | * footer text 28 | */ 29 | public void SetText(const char[] text) 30 | { 31 | this.SetString("text", text); 32 | } 33 | 34 | /** 35 | * url of footer icon (only supports http(s) and attachments) 36 | */ 37 | public bool GetIcon(char[] output, int maxsize) 38 | { 39 | return this.GetString("icon_url", output, maxsize); 40 | } 41 | 42 | /** 43 | * url of footer icon (only supports http(s) and attachments) 44 | */ 45 | public void SetIcon(const char[] iconUrl) 46 | { 47 | this.SetString("icon_url", iconUrl); 48 | } 49 | 50 | /** 51 | * a proxied url of footer icon 52 | */ 53 | public bool GetIconProxyURL(char[] output, int maxsize) 54 | { 55 | return this.GetString("proxy_icon_url", output, maxsize); 56 | } 57 | 58 | /** 59 | * a proxied url of footer icon 60 | */ 61 | public void SetIconProxyURL(const char[] iconUrl) 62 | { 63 | this.SetString("proxy_icon_url", iconUrl); 64 | } 65 | 66 | /** 67 | * Release resources 68 | */ 69 | public void Dispose() 70 | { 71 | if(this == null) 72 | return; 73 | 74 | this.Cleanup(); 75 | delete this; 76 | } 77 | } -------------------------------------------------------------------------------- /include/discord/DiscordEmbedImage.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordEmbedImage_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordEmbedImage_included_ 5 | 6 | methodmap DiscordEmbedImage < JSON_Object 7 | { 8 | public DiscordEmbedImage(const char[] url = "", int height, int width) 9 | { 10 | JSON_Object obj = new JSON_Object(); 11 | obj.SetString("url", url); 12 | obj.SetInt("height", height); 13 | obj.SetInt("width", width); 14 | return view_as(obj); 15 | } 16 | 17 | /** 18 | * height of image 19 | */ 20 | property int Height 21 | { 22 | public get() { return this.GetInt("height"); } 23 | public set(int value) { this.SetInt("height", value); } 24 | } 25 | 26 | /** 27 | * width of image 28 | */ 29 | property int Width 30 | { 31 | public get() { return this.GetInt("width"); } 32 | public set(int value) { this.SetInt("width", value); } 33 | } 34 | 35 | /** 36 | * source url of image (only supports http(s) and attachments) 37 | */ 38 | public bool GetUrl(char[] output, int maxsize) 39 | { 40 | return this.GetString("url", output, maxsize); 41 | } 42 | 43 | /** 44 | * source url of image (only supports http(s) and attachments) 45 | */ 46 | public void SetUrl(const char[] url) 47 | { 48 | this.SetString("url", url); 49 | } 50 | 51 | /** 52 | * a proxied url of the image 53 | */ 54 | public bool GetProxyUrl(char[] output, int maxsize) 55 | { 56 | return this.GetString("proxy_url", output, maxsize); 57 | } 58 | 59 | /** 60 | * a proxied url of the image 61 | */ 62 | public void SetProxyUrl(const char[] url) 63 | { 64 | this.SetString("proxy_url", url); 65 | } 66 | 67 | /** 68 | * Release resources 69 | */ 70 | public void Dispose() 71 | { 72 | if(this == null) 73 | return; 74 | 75 | this.Cleanup(); 76 | delete this; 77 | } 78 | } -------------------------------------------------------------------------------- /include/discord/DiscordEmbedProvider.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordEmbedProvider_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordEmbedProvider_included_ 5 | 6 | /** 7 | * provider information 8 | */ 9 | methodmap DiscordEmbedProvider < JSON_Object 10 | { 11 | public DiscordEmbedProvider(const char[] name = "", const char[] url = "") 12 | { 13 | JSON_Object obj = new JSON_Object(); 14 | obj.SetString("name", name); 15 | obj.SetString("url", url); 16 | return view_as(obj); 17 | } 18 | 19 | /** 20 | * name of provider 21 | */ 22 | public bool GetName(char[] output, int maxsize) 23 | { 24 | return this.GetString("name", output, maxsize); 25 | } 26 | 27 | /** 28 | * name of provider 29 | */ 30 | public void SetName(const char[] name) 31 | { 32 | this.SetString("name", name); 33 | } 34 | 35 | /** 36 | * url of provider 37 | */ 38 | public bool GetUrl(char[] output, int maxsize) 39 | { 40 | return this.GetString("url", output, maxsize); 41 | } 42 | 43 | /** 44 | * url of provider 45 | */ 46 | public void SetUrl(const char[] url) 47 | { 48 | this.SetString("url", url); 49 | } 50 | 51 | /** 52 | * Release resources 53 | */ 54 | public void Dispose() 55 | { 56 | if(this == null) 57 | return; 58 | 59 | this.Cleanup(); 60 | delete this; 61 | } 62 | } -------------------------------------------------------------------------------- /include/discord/DiscordEmbedThumbnail.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordEmbedThumbnail_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordEmbedThumbnail_included_ 5 | 6 | /** 7 | * thumbnail information 8 | */ 9 | methodmap DiscordEmbedThumbnail < JSON_Object 10 | { 11 | public DiscordEmbedThumbnail(const char[] url = "", int height, int width) 12 | { 13 | JSON_Object obj = new JSON_Object(); 14 | obj.SetString("url", url); 15 | obj.SetInt("height", height); 16 | obj.SetInt("width", width); 17 | return view_as(obj); 18 | } 19 | 20 | /** 21 | * height of thumbnail 22 | */ 23 | property int Height 24 | { 25 | public get() { return this.GetInt("height"); } 26 | public set(int value) { this.SetInt("height", value); } 27 | } 28 | 29 | /** 30 | * width of thumbnail 31 | */ 32 | property int Width 33 | { 34 | public get() { return this.GetInt("width"); } 35 | public set(int value) { this.SetInt("width", value); } 36 | } 37 | 38 | /** 39 | * source url of thumbnail (only supports http(s) and attachments) 40 | */ 41 | public bool GetUrl(char[] output, int maxsize) 42 | { 43 | return this.GetString("url", output, maxsize); 44 | } 45 | 46 | /** 47 | * source url of thumbnail (only supports http(s) and attachments) 48 | */ 49 | public void SetUrl(const char[] url) 50 | { 51 | this.SetString("url", url); 52 | } 53 | 54 | /** 55 | * a proxied url of the thumbnail 56 | */ 57 | public bool GetProxyUrl(char[] output, int maxsize) 58 | { 59 | return this.GetString("proxy_url", output, maxsize); 60 | } 61 | 62 | /** 63 | * a proxied url of the thumbnail 64 | */ 65 | public void SetProxyUrl(const char[] url) 66 | { 67 | this.SetString("proxy_url", url); 68 | } 69 | 70 | /** 71 | * Release resources 72 | */ 73 | public void Dispose() 74 | { 75 | if(this == null) 76 | return; 77 | 78 | this.Cleanup(); 79 | delete this; 80 | } 81 | } -------------------------------------------------------------------------------- /include/discord/DiscordEmbedVideo.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordEmbedVideo_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordEmbedVideo_included_ 5 | 6 | methodmap DiscordEmbedVideo < JSON_Object 7 | { 8 | public DiscordEmbedVideo(const char[] url = "", int height, int width) 9 | { 10 | JSON_Object obj = new JSON_Object(); 11 | obj.SetString("url", url); 12 | obj.SetInt("height", height); 13 | obj.SetInt("width", width); 14 | return view_as(obj); 15 | } 16 | 17 | /** 18 | * height of video 19 | */ 20 | property int Height 21 | { 22 | public get() { return this.GetInt("height"); } 23 | public set(int value) { this.SetInt("height", value); } 24 | } 25 | 26 | /** 27 | * width of video 28 | */ 29 | property int Width 30 | { 31 | public get() { return this.GetInt("width"); } 32 | public set(int value) { this.SetInt("width", value); } 33 | } 34 | 35 | /** 36 | * source url of video 37 | */ 38 | public bool GetUrl(char[] output, int maxsize) 39 | { 40 | return this.GetString("url", output, maxsize); 41 | } 42 | 43 | /** 44 | * source url of video 45 | */ 46 | public void SetUrl(const char[] url) 47 | { 48 | this.SetString("url", url); 49 | } 50 | 51 | /** 52 | * a proxied url of the video 53 | */ 54 | public bool GetProxyUrl(char[] output, int maxsize) 55 | { 56 | return this.GetString("proxy_url", output, maxsize); 57 | } 58 | 59 | /** 60 | * a proxied url of the video 61 | */ 62 | public void SetProxyUrl(const char[] url) 63 | { 64 | this.SetString("proxy_url", url); 65 | } 66 | 67 | /** 68 | * Release resources 69 | */ 70 | public void Dispose() 71 | { 72 | if(this == null) 73 | return; 74 | 75 | this.Cleanup(); 76 | delete this; 77 | } 78 | } -------------------------------------------------------------------------------- /include/discord/DiscordEmoji.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordEmoji_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordEmoji_included_ 5 | 6 | methodmap DiscordEmoji < DiscordObject 7 | { 8 | /** 9 | * Roles allowed to use this emoji 10 | * 11 | * @return Array of role object ids 12 | */ 13 | property JSON_Array Roles 14 | { 15 | public get() { return view_as(this.GetObject("roles")); } 16 | } 17 | 18 | /** 19 | * User that created this emoji 20 | * 21 | * @return DiscordUser 'object' 22 | */ 23 | property DiscordUser User 24 | { 25 | public get() { return view_as(this.GetObject("user")); } 26 | } 27 | 28 | /** 29 | * Whether this emoji must be wrapped in colons 30 | */ 31 | property bool RequireColons 32 | { 33 | public get() { return this.GetBool("require_colons"); } 34 | } 35 | 36 | /** 37 | * Whether this emoji is managed 38 | */ 39 | property bool Managed 40 | { 41 | public get() { return this.GetBool("managed"); } 42 | } 43 | 44 | /** 45 | * Whether this emoji is animated 46 | */ 47 | property bool Animated 48 | { 49 | public get() { return this.GetBool("animated"); } 50 | } 51 | 52 | /** 53 | * Whether this emoji can be used, may be false due to loss of Server Boosts 54 | */ 55 | property bool Available 56 | { 57 | public get() { return this.GetBool("available"); } 58 | } 59 | 60 | /** 61 | * Get emoji name. 62 | * 63 | * @param output Output buffer. 64 | * @param maxsize Length of the buffer. 65 | * @return True on success, false otherwise. 66 | */ 67 | public bool GetName(char[] output, int maxsize) 68 | { 69 | return this.GetString("name", output, maxsize); 70 | } 71 | 72 | public static DiscordEmoji FromName(const char[] name) 73 | { 74 | DiscordEmoji emoji = view_as(new JSON_Object()); 75 | emoji.SetString("name", name); 76 | return emoji; 77 | } 78 | } -------------------------------------------------------------------------------- /include/discord/DiscordException.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordException_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordException_included_ 5 | 6 | methodmap DiscordException __nullable__ /* < Exception */ 7 | { 8 | public DiscordException(const char[] error, any ...) 9 | { 10 | char buffer[1024]; 11 | SetGlobalTransTarget(LANG_SERVER); 12 | VFormat(buffer, sizeof(buffer), error, 2); 13 | return view_as(LogError("Discord Exception: %s", buffer)); 14 | } 15 | } -------------------------------------------------------------------------------- /include/discord/DiscordGatewayPayload.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordGatewayPayload_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordGatewayPayload_included_ 5 | 6 | enum DiscordGatewayOpCode 7 | { 8 | Dispatch = 0, /* An event was dispatched. */ 9 | Heartbeat, /* Fired periodically by the client to keep the connection alive. */ 10 | Identify, /* Starts a new session during the initial handshake. */ 11 | PresenceUpdate, /* Update the client's presence. */ 12 | VoiceStateUpdate, /* Used to join/leave or move between voice channels. */ 13 | Resume, /* Resume a previous session that was disconnected. */ 14 | Reconnect, /* You should attempt to reconnect and resume immediately. */ 15 | RequestGuildMembers, /* Request information about offline guild members in a large guild. */ 16 | InvalidSession, /* The session has been invalidated. You should reconnect and identify/resume accordingly. */ 17 | Hello, /* Sent immediately after connecting, contains the heartbeat_interval to use. */ 18 | HEartbeatACK /* Sent in response to receiving a heartbeat to acknowledge that it has been received. */ 19 | } 20 | 21 | methodmap DiscordGatewayPayload < JSON_Object 22 | { 23 | public DiscordGatewayPayload(DiscordGatewayOpCode op, JSON_Object d = null, int s = 0, const char[] t = "") 24 | { 25 | JSON_Object obj = new JSON_Object(); 26 | obj.SetInt("op", view_as(op)); 27 | obj.SetObject("d", d); 28 | obj.SetInt("s", s); 29 | obj.SetString("t", t); 30 | return view_as(obj); 31 | } 32 | } -------------------------------------------------------------------------------- /include/discord/DiscordGuild.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordGuild_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordGuild_included_ 5 | 6 | enum DiscordGuildVerificationLevel 7 | { 8 | UNRESTRICTED = 0, /* unrestricted */ 9 | LOW = 1, /* must have verified email on account */ 10 | MEDIUM = 2, /* must be registered on Discord for longer than 5 minutes */ 11 | HIGH = 3, /* must be a member of the server for longer than 10 minutes */ 12 | VERY_HIGH = 4 /* must have a verified phone number */ 13 | } 14 | 15 | enum DiscordGuildMessageNotificationLevel 16 | { 17 | ALL_MESSAGES = 0, /* members will receive notifications for all messages by default */ 18 | ONLY_MENTIONS = 1 /* members will receive notifications only for messages that @mention them by default */ 19 | } 20 | 21 | enum DiscordGuildExplicitContentFilterLevel 22 | { 23 | DISABLED = 0, /* media content will not be scanned */ 24 | MEMBERS_WITHOUT_ROLES, /* media content sent by members without roles will be scanned */ 25 | ALL_MEMBERS /* media content sent by all members will be scanned */ 26 | } 27 | 28 | enum DiscordGuildMFALevel 29 | { 30 | MFALevel_NONE = 0, /* guild has no MFA/2FA requirement for moderation actions */ 31 | ELEVATED /* guild has a 2FA requirement for moderation actions */ 32 | } 33 | 34 | enum DiscordGuildNSFWLevel 35 | { 36 | DEFAULT = 0, 37 | EXPLICIT, 38 | SAFE, 39 | AGE_RESTRICTED 40 | } 41 | 42 | enum DiscordGuildPremiumTier 43 | { 44 | TIER_NONE = 0, /* guild has not unlocked any Server Boost perks */ 45 | TIER_1 = 1, /* guild has unlocked Server Boost level 1 perks */ 46 | TIER_2 = 2, /* guild has unlocked Server Boost level 2 perks */ 47 | TIER_3 = 3 /* guild has unlocked Server Boost level 3 perks */ 48 | } 49 | 50 | enum DiscordGuildSystemChannelFlags 51 | { 52 | SUPPRESS_JOIN_NOTIFICATIONS = (1 << 0), /* Suppress member join notifications */ 53 | SUPPRESS_PREMIUM_SUBSCRIPTIONS = (1 << 1), /* Suppress server boost notifications */ 54 | SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = (1 << 2), /* Suppress server setup tips */ 55 | SUPPRESS_JOIN_NOTIFICATION_REPLIES = (1 << 3) /* Hide member join sticker reply buttons */ 56 | } 57 | 58 | enum DiscordGuildIntegrationExpireBehaviour 59 | { 60 | REMOVE_ROLE = 0, 61 | KICK = 1 62 | } 63 | 64 | enum DiscordGuildScheduledEventPrivacyLevel 65 | { 66 | GUILD_ONLY = 2 /* the scheduled event is only accessible to guild members */ 67 | } 68 | 69 | enum DiscordGuildScheduledEventEntityType 70 | { 71 | STAGE_INSTANCE = 1, 72 | VOICE = 2, 73 | EXTERNAL = 3 74 | } 75 | 76 | /* 77 | * Once status is set to COMPLETED or CANCELED, the status can no longer be updated 78 | * Valid Guild Scheduled Event Status Transitions 79 | * SCHEDULED --> ACTIVE 80 | * ACTIVE --------> COMPLETED 81 | * SCHEDULED --> CANCELED 82 | */ 83 | enum DiscordGuildScheduledEventStatus 84 | { 85 | SCHEDULED = 1, 86 | ACTIVE = 2, 87 | COMPLETED = 3, 88 | CANCELED = 4 89 | } 90 | 91 | /** DiscordBot.CreateGuild 92 | * 93 | * Called as callback after a successful request. 94 | * 95 | */ 96 | typeset OnDiscordGuildCreated 97 | { 98 | /** 99 | * 100 | * @param bot same handle as the bot you have used to call the native. 101 | * @param guild DiscordGuild object received. 102 | * DiscordGuild handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 103 | * 104 | * @noreturn 105 | */ 106 | function void (DiscordBot bot, DiscordGuild guild); 107 | 108 | /** 109 | * 110 | * @param bot same handle as the bot you have used to call the native. 111 | * @param guild DiscordGuild object received. 112 | * DiscordGuild handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 113 | * @param data custom data passed through the request to use in the callback 114 | * 115 | * @noreturn 116 | */ 117 | function void (DiscordBot bot, DiscordGuild guild, any data); 118 | 119 | /** 120 | * 121 | * @param bot same handle as the bot you have used to call the native. 122 | * @param guild DiscordGuild object received. 123 | * DiscordGuild handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 124 | * @param data custom data passed through the request to use in the callback 125 | * @param data2 custom data passed through the request to use in the callback 126 | * 127 | * @noreturn 128 | */ 129 | function void (DiscordBot bot, DiscordGuild guild, any data, any data2); 130 | } 131 | 132 | /** DiscordBot.GetGuild 133 | * 134 | * Called as callback after a successful request. 135 | * 136 | */ 137 | typeset OnGetDiscordGuild 138 | { 139 | /** 140 | * 141 | * @param bot same handle as the bot you have used to call the native. 142 | * @param guild DiscordGuild object received. 143 | * DiscordGuild handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 144 | * 145 | * @noreturn 146 | */ 147 | function void (DiscordBot bot, DiscordGuild guild); 148 | 149 | /** 150 | * 151 | * @param bot same handle as the bot you have used to call the native. 152 | * @param guild DiscordGuild object received. 153 | * DiscordGuild handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 154 | * @param data custom data passed through the request to use in the callback 155 | * 156 | * @noreturn 157 | */ 158 | function void (DiscordBot bot, DiscordGuild guild, any data); 159 | 160 | /** 161 | * 162 | * @param bot same handle as the bot you have used to call the native. 163 | * @param guild DiscordGuild object received. 164 | * DiscordGuild handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 165 | * @param data custom data passed through the request to use in the callback 166 | * @param data2 custom data passed through the request to use in the callback 167 | * 168 | * @noreturn 169 | */ 170 | function void (DiscordBot bot, DiscordGuild guild, any data, any data2); 171 | } 172 | 173 | /** DiscordBot.GetGuildMember | DiscordBot.GetGuildMemberID 174 | * 175 | * Called as callback after a successful request. 176 | * 177 | */ 178 | typeset OnGetDiscordGuildUser 179 | { 180 | /** 181 | * 182 | * @param bot same handle as the bot you have used to call the native. 183 | * @param guildUser DiscordGuildUser object received. 184 | * DiscordGuildUser handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 185 | * 186 | * @noreturn 187 | */ 188 | function void (DiscordBot bot, DiscordGuildUser guildUser); 189 | 190 | /** 191 | * 192 | * @param bot same handle as the bot you have used to call the native. 193 | * @param guildUser DiscordGuildUser object received. 194 | * DiscordGuildUser handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 195 | * @param data custom data passed through the request to use in the callback 196 | * 197 | * @noreturn 198 | */ 199 | function void (DiscordBot bot, DiscordGuildUser guildUser, any data); 200 | 201 | /** 202 | * 203 | * @param bot same handle as the bot you have used to call the native. 204 | * @param guildUser DiscordGuildUser object received. 205 | * DiscordGuildUser handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 206 | * @param data custom data passed through the request to use in the callback 207 | * @param data2 custom data passed through the request to use in the callback 208 | * 209 | * @noreturn 210 | */ 211 | function void (DiscordBot bot, DiscordGuildUser guildUser, any data, any data2); 212 | } 213 | 214 | /** DiscordBot.GetGuildScheduledEvent 215 | * 216 | * Called as callback after a successful request. 217 | * 218 | */ 219 | typeset OnGetDiscordGuildScheduledEvent 220 | { 221 | /** 222 | * 223 | * @param bot same handle as the bot you have used to call the native. 224 | * @param guild DiscordGuildScheduledEvent object received. 225 | * DiscordGuildScheduledEvent handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 226 | * 227 | * @noreturn 228 | */ 229 | function void (DiscordBot bot, DiscordGuildScheduledEvent event); 230 | 231 | /** 232 | * 233 | * @param bot same handle as the bot you have used to call the native. 234 | * @param guild DiscordGuildScheduledEvent object received. 235 | * DiscordGuildScheduledEvent handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 236 | * @param data custom data passed through the request to use in the callback 237 | * 238 | * @noreturn 239 | */ 240 | function void (DiscordBot bot, DiscordGuildScheduledEvent event, any data); 241 | 242 | /** 243 | * 244 | * @param bot same handle as the bot you have used to call the native. 245 | * @param guild DiscordGuildScheduledEvent object received. 246 | * DiscordGuildScheduledEvent handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 247 | * @param data custom data passed through the request to use in the callback 248 | * @param data2 custom data passed through the request to use in the callback 249 | * 250 | * @noreturn 251 | */ 252 | function void (DiscordBot bot, DiscordGuildScheduledEvent event, any data, any data2); 253 | } 254 | 255 | methodmap ScheduledEventMetaData < JSON_Object 256 | { 257 | /** 258 | * location of the event (1-100 characters) 259 | */ 260 | public bool GetLocation(char[] output, int maxsize) 261 | { 262 | return this.GetString("location", output, maxsize); 263 | } 264 | 265 | } 266 | 267 | methodmap DiscordGuildScheduledEventUser < JSON_Object 268 | { 269 | /** 270 | * user which subscribed to an event 271 | */ 272 | property DiscordUser User 273 | { 274 | public get() { return view_as(this.GetObject("user")); } 275 | } 276 | 277 | /** 278 | * guild member data for this user for the guild which this event belongs to, if any 279 | */ 280 | property DiscordGuildUser Member 281 | { 282 | public get() { return view_as(this.GetObject("member")); } 283 | } 284 | 285 | /** 286 | * the scheduled event id which the user subscribed to 287 | */ 288 | public bool GetEventID(char[] output, int maxsize) 289 | { 290 | return this.GetString("guild_scheduled_event_id", output, maxsize); 291 | } 292 | } 293 | 294 | /** 295 | * A representation of a scheduled event in a guild. 296 | */ 297 | methodmap DiscordGuildScheduledEvent < DiscordObject 298 | { 299 | /** 300 | * the user that created the scheduled event 301 | */ 302 | property DiscordUser Creator 303 | { 304 | public get() { return view_as(this.GetObject("creator")); } 305 | } 306 | 307 | /** 308 | * the number of users subscribed to the scheduled event 309 | */ 310 | property int UserCount 311 | { 312 | public get() { return this.GetInt("user_count"); } 313 | } 314 | 315 | /** 316 | * the status of the scheduled event 317 | */ 318 | property DiscordGuildScheduledEventStatus Status 319 | { 320 | public get() { return view_as(this.GetInt("status")); } 321 | } 322 | 323 | /** 324 | * the privacy level of the scheduled event 325 | */ 326 | property DiscordGuildScheduledEventPrivacyLevel PrivacyLevel 327 | { 328 | public get() { return view_as(this.GetInt("privacy_level")); } 329 | } 330 | 331 | /** 332 | * the type of the scheduled event 333 | */ 334 | property DiscordGuildScheduledEventEntityType Type 335 | { 336 | public get() { return view_as(this.GetInt("entity_type")); } 337 | } 338 | 339 | /** 340 | * additional metadata for the guild scheduled event 341 | */ 342 | property ScheduledEventMetaData MetaData 343 | { 344 | public get() { return view_as(this.GetObject("entity_metadata")); } 345 | } 346 | 347 | /** 348 | * the guild id which the scheduled event belongs to 349 | */ 350 | public bool GetGuildID(char[] output, int maxsize) 351 | { 352 | return this.GetString("guild_id", output, maxsize); 353 | } 354 | 355 | /** 356 | * the id of an entity associated with a guild scheduled event 357 | */ 358 | public bool GetEntityID(char[] output, int maxsize) 359 | { 360 | return this.GetString("entity_id", output, maxsize); 361 | } 362 | 363 | /** 364 | * the channel id in which the scheduled event will be hosted, or null if scheduled entity type is EXTERNAL 365 | */ 366 | public bool GetChannelID(char[] output, int maxsize) 367 | { 368 | return this.GetString("channel_id", output, maxsize); 369 | } 370 | 371 | /** 372 | * the id of the user that created the scheduled event 373 | */ 374 | public bool GetCreatorID(char[] output, int maxsize) 375 | { 376 | return this.GetString("creator_id", output, maxsize); 377 | } 378 | 379 | /** 380 | * the name of the scheduled event (1-100 characters) 381 | */ 382 | public bool GetName(char[] output, int maxsize) 383 | { 384 | return this.GetString("name", output, maxsize); 385 | } 386 | 387 | /** 388 | * the description of the scheduled event (1-1000 characters) 389 | */ 390 | public bool GetDescription(char[] output, int maxsize) 391 | { 392 | return this.GetString("description", output, maxsize); 393 | } 394 | 395 | /** 396 | the cover image hash of the scheduled event 397 | ( https://discord.com/developers/docs/reference#image-formatting ) 398 | */ 399 | public bool GetImage(char[] output, int maxsize) 400 | { 401 | return this.GetString("image", output, maxsize); 402 | } 403 | 404 | /** 405 | * the time the scheduled event will start 406 | */ 407 | public bool GetScheduledStart(DateTime& out) 408 | { 409 | char szDate[DATE_LENGTH]; 410 | this.GetString("scheduled_start_time", szDate, sizeof(szDate)); 411 | return DateTime.TryParse(szDate, out); 412 | } 413 | 414 | /** 415 | * the time the scheduled event will end, required if entity_type is EXTERNAL 416 | */ 417 | public bool GetScheduledEnd(DateTime& out) 418 | { 419 | char szDate[DATE_LENGTH]; 420 | this.GetString("scheduled_end_time", szDate, sizeof(szDate)); 421 | return DateTime.TryParse(szDate, out); 422 | } 423 | } 424 | 425 | methodmap DiscordIntegrationAccount < JSON_Object 426 | { 427 | /** 428 | * id of the account 429 | */ 430 | public bool GetID(char[] output, int maxsize) 431 | { 432 | return this.GetString("id", output, maxsize); 433 | } 434 | 435 | /** 436 | * name of the account 437 | */ 438 | public bool GetName(char[] output, int maxsize) 439 | { 440 | return this.GetString("name", output, maxsize); 441 | } 442 | } 443 | 444 | methodmap DiscordIntegrationApplication < DiscordObject 445 | { 446 | /** 447 | * the bot associated with this application 448 | */ 449 | property DiscordUser Bot 450 | { 451 | public get() { return view_as(this.GetObject("bot")); } 452 | } 453 | 454 | /** 455 | * the name of the app 456 | */ 457 | public bool GetName(char[] output, int maxsize) 458 | { 459 | return this.GetString("name", output, maxsize); 460 | } 461 | 462 | /** 463 | * the icon hash of the app 464 | * ( https://discord.com/developers/docs/reference#image-formatting ) 465 | */ 466 | public bool GetIcon(char[] output, int maxsize) 467 | { 468 | return this.GetString("icon", output, maxsize); 469 | } 470 | 471 | /** 472 | * the description of the app 473 | */ 474 | public bool GetDescription(char[] output, int maxsize) 475 | { 476 | return this.GetString("description", output, maxsize); 477 | } 478 | } 479 | 480 | methodmap DiscordBanObject < JSON_Object 481 | { 482 | /** 483 | * the banned user 484 | */ 485 | property DiscordUser User 486 | { 487 | public get() { return view_as(this.GetObject("user")); } 488 | } 489 | 490 | /** 491 | * the reason for the ban 492 | */ 493 | public bool GetReason(char[] output, int maxsize) 494 | { 495 | return this.GetString("channel_id", output, maxsize); 496 | } 497 | } 498 | 499 | methodmap DiscordWelcomeScreenChannel < JSON_Object 500 | { 501 | /** 502 | * the channel's id 503 | */ 504 | public bool GetChannelID(char[] output, int maxsize) 505 | { 506 | return this.GetString("channel_id", output, maxsize); 507 | } 508 | 509 | /** 510 | * the description shown for the channel 511 | */ 512 | public bool GetDescription(char[] output, int maxsize) 513 | { 514 | return this.GetString("description", output, maxsize); 515 | } 516 | 517 | /** 518 | * the emoji name if custom, the unicode character if standard, or null if no emoji is set 519 | */ 520 | public bool GetEmojiName(char[] output, int maxsize) 521 | { 522 | return this.GetString("emoji_name", output, maxsize); 523 | } 524 | 525 | /** 526 | * the emoji id, if the emoji is custom 527 | */ 528 | public bool GetEmojiID(char[] output, int maxsize) 529 | { 530 | return this.GetString("emoji_id", output, maxsize); 531 | } 532 | } 533 | 534 | methodmap DiscordWelcomeScreen < JSON_Object 535 | { 536 | /** 537 | * the channels shown in the welcome screen, up to 5 538 | */ 539 | property JSON_Array WelcomeChannels 540 | { 541 | public get() { return view_as(this.GetObject("welcome_channels")); } 542 | } 543 | 544 | /** 545 | * the server description shown in the welcome screen 546 | */ 547 | public bool GetDescription(char[] output, int maxsize) 548 | { 549 | return this.GetString("description", output, maxsize); 550 | } 551 | } 552 | 553 | /** 554 | * Guilds in Discord represent an isolated collection of users and channels, and are often referred to as "servers" in the UI. 555 | */ 556 | methodmap DiscordGuild < DiscordObject 557 | { 558 | /** 559 | * true if the user is the owner of the guild 560 | */ 561 | property bool IsOwner 562 | { 563 | public get() { return this.GetBool("owner"); } 564 | } 565 | 566 | /** 567 | * true if the server widget is enabled 568 | */ 569 | property bool Widget 570 | { 571 | public get() { return this.GetBool("widget_enabled"); } 572 | } 573 | 574 | #pragma deprecated This property has been removed by Discord. 575 | /** 576 | * whether the guild is large 577 | */ 578 | property bool IsLarge 579 | { 580 | public get() { return this.GetBool("large"); } 581 | } 582 | 583 | /** 584 | * whether the guild is unavailable 585 | */ 586 | property bool IsUnavailable 587 | { 588 | public get() { return this.GetBool("unavailable"); } 589 | } 590 | 591 | /** 592 | * afk timeout in seconds 593 | */ 594 | property int AfkTimeout 595 | { 596 | public get() { return this.GetInt("afk_timeout"); } 597 | } 598 | 599 | #pragma deprecated This property has been removed by Discord. 600 | /** 601 | * the number of members this guild currently has 602 | */ 603 | property int MemberCount 604 | { 605 | public get() { return this.GetInt("member_count"); } 606 | } 607 | 608 | /** 609 | * the maximum amount of users in a video channel 610 | */ 611 | property int MaxVideoChannelUsers 612 | { 613 | public get() { return this.GetInt("max_video_channel_users"); } 614 | } 615 | 616 | /** 617 | * approximate number of members in this guild, returned from the GET /guilds/ endpoint when with_counts is true 618 | */ 619 | property int ApproximateMemberCount 620 | { 621 | public get() { return this.GetInt("approximate_member_count"); } 622 | } 623 | 624 | /** 625 | * approximate number of non-offline members in this guild, returned from the GET /guilds/ endpoint when with_counts is true 626 | */ 627 | property int ApproximatePresenceCount 628 | { 629 | public get() { return this.GetInt("approximate_presence_count"); } 630 | } 631 | 632 | /** 633 | * the number of boosts this guild currently has 634 | */ 635 | property int BoostCount 636 | { 637 | public get() { return this.GetInt("premium_subscription_count"); } 638 | } 639 | 640 | /** 641 | * whether the guild has the boost progress bar enabled 642 | */ 643 | property bool PremiumProgressBarEnabled 644 | { 645 | public get() { return this.GetBool("premium_progress_bar_enabled"); } 646 | } 647 | 648 | /** 649 | * premium tier (Server Boost level) 650 | */ 651 | property DiscordGuildPremiumTier PremiumTier 652 | { 653 | public get() { return view_as(this.GetInt("premium_tier")); } 654 | } 655 | 656 | /** 657 | * the welcome screen of a Community guild, shown to new members, returned in an Invite's guild object 658 | */ 659 | property DiscordWelcomeScreen WelcomeScreen 660 | { 661 | public get() { return view_as(this.GetObject("welcome_screen")); } 662 | } 663 | 664 | /** 665 | * roles in the guild 666 | */ 667 | property JSON_Array Stickers 668 | { 669 | public get() { return view_as(this.GetObject("stickers")); } 670 | } 671 | 672 | /** 673 | * roles in the guild 674 | */ 675 | property JSON_Array Roles 676 | { 677 | public get() { return view_as(this.GetObject("roles")); } 678 | } 679 | 680 | /** 681 | * custom guild emojis 682 | */ 683 | property JSON_Array Emojis 684 | { 685 | public get() { return view_as(this.GetObject("emojis")); } 686 | } 687 | 688 | #pragma deprecated This property has been removed by Discord. 689 | /** 690 | * members in the guild 691 | */ 692 | property JSON_Array Members 693 | { 694 | public get() { return view_as(this.GetObject("members")); } 695 | } 696 | 697 | #pragma deprecated This property has been removed by Discord. 698 | /** 699 | * channels in the guild 700 | */ 701 | property JSON_Array Channels 702 | { 703 | public get() { return view_as(this.GetObject("channels")); } 704 | } 705 | 706 | /** 707 | * enabled guild features 708 | */ 709 | property JSON_Array Features 710 | { 711 | public get() { return view_as(this.GetObject("features")); } 712 | } 713 | 714 | /** 715 | * verification level required for the guild 716 | */ 717 | property DiscordGuildVerificationLevel VerificationLevel 718 | { 719 | public get() { return view_as(this.GetInt("verification_level")); } 720 | } 721 | 722 | /** 723 | * default message notifications level 724 | */ 725 | property DiscordGuildMessageNotificationLevel NotificationLevel 726 | { 727 | public get() { return view_as(this.GetInt("default_message_notifications")); } 728 | } 729 | 730 | /** 731 | * explicit content filter level 732 | */ 733 | property DiscordGuildExplicitContentFilterLevel ExplicitContentFilter 734 | { 735 | public get() { return view_as(this.GetInt("explicit_content_filter")); } 736 | } 737 | 738 | /** 739 | * required MFA level for the guild 740 | */ 741 | property DiscordGuildMFALevel MFALevel 742 | { 743 | public get() { return view_as(this.GetInt("mfa_level")); } 744 | } 745 | 746 | /** 747 | * guild NSFW level 748 | */ 749 | property DiscordGuildNSFWLevel NSFWLevel 750 | { 751 | public get() { return view_as(this.GetInt("nsfw_level")); } 752 | } 753 | 754 | /** 755 | * DiscordGuildSystemChannelFlags 756 | */ 757 | property int DiscordGuildSystemChannelFlags 758 | { 759 | public get() { return this.GetInt("system_channel_flags"); } 760 | } 761 | 762 | /** 763 | * the maximum number of presences for the guild (null is always returned, apart from the largest of guilds) 764 | */ 765 | property int MaxPresences 766 | { 767 | public get() { return this.GetInt("max_presences"); } 768 | } 769 | 770 | /** 771 | * the maximum number of members for the guild 772 | */ 773 | property int MaxMembers 774 | { 775 | public get() { return this.GetInt("max_members"); } 776 | } 777 | 778 | /** 779 | * roles in the guild 780 | */ 781 | public JSON_Array GetRoles() 782 | { 783 | return this.Roles; 784 | } 785 | 786 | /** 787 | * custom guild emojis 788 | */ 789 | public JSON_Array GetEmojis() 790 | { 791 | return this.Emojis; 792 | } 793 | 794 | #pragma deprecated This property has been removed by Discord. 795 | /** 796 | * members in the guild 797 | */ 798 | public JSON_Array GetMembers() 799 | { 800 | return this.Members; 801 | } 802 | 803 | #pragma deprecated This property has been removed by Discord. 804 | /** 805 | * roles in the guild 806 | */ 807 | public JSON_Array GetChannels() 808 | { 809 | return this.Channels; 810 | } 811 | 812 | /** 813 | * enabled guild features 814 | */ 815 | public JSON_Array GetFeatures() 816 | { 817 | return this.Features; 818 | } 819 | 820 | /** 821 | * guild name (2-100 characters, excluding trailing and leading whitespace) 822 | */ 823 | public bool GetName(char[] output, int maxsize) 824 | { 825 | return this.GetString("name", output, maxsize); 826 | } 827 | 828 | /** 829 | * the description of a guild 830 | */ 831 | public bool GetDescription(char[] output, int maxsize) 832 | { 833 | return this.GetString("description", output, maxsize); 834 | } 835 | 836 | /** 837 | * banner hash 838 | * ( https://discord.com/developers/docs/reference#image-formatting ) 839 | */ 840 | public bool GetBanner(char[] output, int maxsize) 841 | { 842 | return this.GetString("banner", output, maxsize); 843 | } 844 | 845 | /** 846 | * discovery splash hash; only present for guilds with the "DISCOVERABLE" feature 847 | * ( https://discord.com/developers/docs/reference#image-formatting ) 848 | */ 849 | public bool GetDiscoverySplash(char[] output, int maxsize) 850 | { 851 | return this.GetString("discovery_splash", output, maxsize); 852 | } 853 | 854 | /** 855 | * icon hash 856 | * ( https://discord.com/developers/docs/reference#image-formatting ) 857 | */ 858 | public bool GetIcon(char[] output, int maxsize) 859 | { 860 | return this.GetString("icon", output, maxsize); 861 | } 862 | 863 | /** 864 | * icon hash, returned when in the template object 865 | * ( https://discord.com/developers/docs/reference#image-formatting ) 866 | */ 867 | public bool GetIconHash(char[] output, int maxsize) 868 | { 869 | return this.GetString("icon_hash", output, maxsize); 870 | } 871 | 872 | /** 873 | * splash hash 874 | * ( https://discord.com/developers/docs/reference#image-formatting ) 875 | */ 876 | public bool GetSplash(char[] output, int maxsize) 877 | { 878 | return this.GetString("splash", output, maxsize); 879 | } 880 | 881 | #pragma deprecated This property has been marked as deprecated by Discord. 882 | /** 883 | * voice region id for the guild (deprecated) 884 | */ 885 | public bool GetRegion(char[] output, int maxsize) 886 | { 887 | return this.GetString("region", output, maxsize); 888 | } 889 | 890 | /** 891 | * the preferred locale of a Community guild 892 | * used in server discovery and notices from Discord, and sent in interactions 893 | * defaults to "en-US" ( https://discord.com/developers/docs/reference#locales ) 894 | */ 895 | public bool GetPreferredLanguage(char[] output, int maxsize) 896 | { 897 | return this.GetString("preferred_locale", output, maxsize); 898 | } 899 | 900 | /** 901 | * id of afk channel 902 | */ 903 | public bool GetAfkChannelID(char[] output, int maxsize) 904 | { 905 | return this.GetString("afk_channel_id", output, maxsize); 906 | } 907 | 908 | /** 909 | * id of owner 910 | */ 911 | public bool GetOwnerID(char[] output, int maxsize) 912 | { 913 | return this.GetString("owner_id", output, maxsize); 914 | } 915 | 916 | /** 917 | * total permissions for the user in the guild (excludes overwrites) 918 | */ 919 | public bool GetPermissions(char[] output, int maxsize) 920 | { 921 | return this.GetString("permissions", output, maxsize); 922 | } 923 | 924 | /** 925 | * the channel id that the widget will generate an invite to, or null if set to no invite 926 | */ 927 | public bool GetWidgetChannelID(char[] output, int maxsize) 928 | { 929 | return this.GetString("widget_channel_id", output, maxsize); 930 | } 931 | 932 | /** 933 | * application id of the guild creator if it is bot-created 934 | */ 935 | public bool GetApplicationID(char[] output, int maxsize) 936 | { 937 | return this.GetString("application_id", output, maxsize); 938 | } 939 | 940 | /** 941 | * the id of the channel where guild notices such as welcome messages and boost events are posted 942 | */ 943 | public bool GetSystemChannelID(char[] output, int maxsize) 944 | { 945 | return this.GetString("system_channel_id", output, maxsize); 946 | } 947 | 948 | /** 949 | * the id of the channel where Community guilds can display rules and/or guidelines 950 | */ 951 | public bool GetRulesChannelID(char[] output, int maxsize) 952 | { 953 | return this.GetString("rules_channel_id", output, maxsize); 954 | } 955 | 956 | /** 957 | * the vanity url code for the guild 958 | */ 959 | public bool GetVanityURL(char[] output, int maxsize) 960 | { 961 | return this.GetString("vanity_url_code", output, maxsize); 962 | } 963 | 964 | /** 965 | * the id of the channel where admins and moderators of Community guilds receive notices from Discord 966 | */ 967 | public bool GetPublicUpdatesChannelID(char[] output, int maxsize) 968 | { 969 | return this.GetString("public_updates_channel_id", output, maxsize); 970 | } 971 | } -------------------------------------------------------------------------------- /include/discord/DiscordGuildUser.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordGuildUser_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordGuildUser_included_ 5 | 6 | #include 7 | 8 | #define MAX_DISCORD_NICKNAME_LENGTH 32 9 | 10 | methodmap DiscordGuildUser < JSON_Object 11 | { 12 | /** 13 | * the user this guild member represents 14 | */ 15 | public DiscordUser GetUser() 16 | { 17 | return view_as(this.GetObject("user")); 18 | } 19 | 20 | /** 21 | * whether the user is deafened in voice channels 22 | */ 23 | property bool IsDeafened 24 | { 25 | public get() { return this.GetBool("deaf"); } 26 | } 27 | 28 | /** 29 | * whether the user is muted in voice channels 30 | */ 31 | property bool IsMuted 32 | { 33 | public get() { return this.GetBool("mute"); } 34 | } 35 | 36 | /** 37 | * whether the user has not yet passed the guild's Membership Screening requirements 38 | */ 39 | property bool IsPending 40 | { 41 | public get() { return this.GetBool("pending"); } 42 | } 43 | 44 | /** 45 | * the member's guild avatar hash 46 | * ( https://discord.com/developers/docs/reference#image-formatting ) 47 | */ 48 | public bool GetAvatar(char[] output, int maxsize) 49 | { 50 | return this.GetString("avatar", output, maxsize); 51 | } 52 | 53 | /** 54 | * this user's guild nickname 55 | */ 56 | public bool GetNickname(char[] output, int maxsize) 57 | { 58 | return this.GetString("nick", output, maxsize); 59 | } 60 | 61 | /** 62 | * total permissions of the member in the channel, including overwrites, returned when in the interaction object 63 | */ 64 | public bool GetPermissions(char[] output, int maxsize) 65 | { 66 | return this.GetString("permissions", output, maxsize); 67 | } 68 | 69 | /** 70 | * when the user joined the guild 71 | */ 72 | public bool GetJoinedDate(char[] buffer, int maxsize) 73 | { 74 | return this.GetString("joined_at", buffer, maxsize); 75 | } 76 | 77 | /** 78 | * when the user joined the guild 79 | */ 80 | public bool GetJoinedDateTime(DateTime& out) 81 | { 82 | char szDate[DATE_LENGTH]; 83 | this.GetString("joined_at", szDate, sizeof(szDate)); 84 | return DateTime.TryParse(szDate, out); 85 | } 86 | 87 | /** 88 | * when the user started boosting the guild 89 | */ 90 | public bool GetBoostingSince(char[] buffer, int maxsize) 91 | { 92 | return this.GetString("premium_since", buffer, maxsize); 93 | } 94 | 95 | /** 96 | * when the user started boosting the guild 97 | */ 98 | public bool GetBoostingSinceDateTime(DateTime& out) 99 | { 100 | char szDate[DATE_LENGTH]; 101 | this.GetString("premium_since", szDate, sizeof(szDate)); 102 | return DateTime.TryParse(szDate, out); 103 | } 104 | 105 | /** 106 | * when the user's timeout will expire and the user will be able to communicate in the guild again, null or a time in the past if the user is not timed out 107 | */ 108 | public bool GetTimeoutDate(char[] buffer, int maxsize) 109 | { 110 | return this.GetString("communication_disabled_until", buffer, maxsize); 111 | } 112 | 113 | /** 114 | * when the user's timeout will expire and the user will be able to communicate in the guild again, null or a time in the past if the user is not timed out 115 | */ 116 | public bool GetTimeoutDateTime(DateTime& out) 117 | { 118 | char szDate[DATE_LENGTH]; 119 | this.GetString("communication_disabled_until", szDate, sizeof(szDate)); 120 | return DateTime.TryParse(szDate, out); 121 | } 122 | 123 | /** 124 | * array of role object ids 125 | * ! array of snowflakes ! 126 | */ 127 | public DiscordRoleList GetRoles() 128 | { 129 | return view_as(this.GetObject("roles")); 130 | } 131 | 132 | /** 133 | * Release resources 134 | */ 135 | public void Dispose() 136 | { 137 | if(this == null) 138 | return; 139 | 140 | this.Cleanup(); 141 | delete this; 142 | } 143 | } -------------------------------------------------------------------------------- /include/discord/DiscordIdentifyProperties.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordIdentifyProperties_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordIdentifyProperties_included_ 5 | 6 | methodmap DiscordIdentifyProperties < JSON_Object 7 | { 8 | public DiscordIdentifyProperties(const char[] os = "linux", const char[] browser = "disco", const char[] device = "disco") 9 | { 10 | JSON_Object obj = new JSON_Object(); 11 | obj.SetString("$os", os); 12 | obj.SetString("$browser", browser); 13 | obj.SetString("$device", device); 14 | return view_as(obj); 15 | } 16 | } -------------------------------------------------------------------------------- /include/discord/DiscordMessage.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordMessage_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordMessage_included_ 5 | 6 | #include 7 | //#include 8 | 9 | enum DiscordMessageActivityTypes 10 | { 11 | JOIN = 1, 12 | SPECTATE = 2, 13 | LISTEN = 3, 14 | JOIN_REQUEST = 4 15 | } 16 | 17 | enum DiscordMessageFlags 18 | { 19 | CROSSPOSTED = (1 << 0), /* this message has been published to subscribed channels (via Channel Following) */ 20 | IS_CROSSPOST = (1 << 1), /* this message originated from a message in another channel (via Channel Following) */ 21 | SUPPRESS_EMBEDS = (1 << 2), /* do not include any embeds when serializing this message */ 22 | SOURCE_MESSAGE_DELETED = (1 << 3), /* the source message for this crosspost has been deleted (via Channel Following) */ 23 | URGENT = (1 << 4), /* this message came from the urgent message system */ 24 | HAS_THREAD = (1 << 5), /* this message has an associated thread, with the same id as the message */ 25 | EPHEMERAL = (1 << 6), /* this message is only visible to the user who invoked the Interaction */ 26 | LOADING = (1 << 7), /* this message is an Interaction Response and the bot is "thinking" */ 27 | FAILED_TO_MENTION_SOME_ROLES_IN_THREAD = (1 << 8) /* this message failed to mention some roles and add their members to the thread */ 28 | } 29 | 30 | enum DiscordMessageStickerFormat 31 | { 32 | PNG = 1, 33 | APNG = 2, 34 | LOTTIE = 3 35 | } 36 | 37 | enum DiscordMessageStickerType 38 | { 39 | STANDARD = 1, /* an official sticker in a pack, part of Nitro or in a removed purchasable pack */ 40 | GUILD /* a sticker uploaded to a Boosted guild for the guild's members */ 41 | } 42 | 43 | /** 44 | * Type 19 and 20 are only in API v8. In v6, they are still type 0. Type 21 is only in API v9. 45 | */ 46 | enum DiscordMessageType 47 | { 48 | Type_DEFAULT = 0, 49 | RECIPIENT_ADD = 1, 50 | RECIPIENT_REMOVE = 2, 51 | CALL = 3, 52 | CHANNEL_NAME_CHANGE = 4, 53 | CHANNEL_ICON_CHANGE = 5, 54 | CHANNEL_PINNED_MESSAGE = 6, 55 | GUILD_MEMBER_JOIN = 7, 56 | USER_PREMIUM_GUILD_SUBSCRIPTION = 8, 57 | USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 = 9, 58 | USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 = 10, 59 | USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 = 11, 60 | CHANNEL_FOLLOW_ADD = 12, 61 | GUILD_DISCOVERY_DISQUALIFIED = 14, 62 | GUILD_DISCOVERY_REQUALIFIED = 15, 63 | GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING = 16, 64 | GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING = 17, 65 | THREAD_CREATED = 18, 66 | REPLY = 19, 67 | APPLICATION_COMMAND = 20, 68 | THREAD_STARTER_MESSAGE = 21, 69 | GUILD_INVITE_REMINDER = 22, 70 | CONTEXT_MENU_COMMAND = 23 71 | } 72 | 73 | /** DiscordBot.GetChannelMessages | DiscordBot.GetChannelMessagesID 74 | * 75 | * Called as callback after a successful request. 76 | * 77 | */ 78 | typeset OnGetDiscordChannelMessages 79 | { 80 | /** 81 | * 82 | * @param bot same handle as the bot you have used to call the native. 83 | * @param messages DiscordMessageList object received. 84 | * DiscordMessageList handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 85 | * 86 | * @noreturn 87 | */ 88 | function void (DiscordBot bot, DiscordMessageList messages); 89 | 90 | /** 91 | * 92 | * @param bot same handle as the bot you have used to call the native. 93 | * @param messages DiscordMessageList object received. 94 | * DiscordMessageList handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 95 | * @param data custom data passed through the request to use in the callback 96 | * 97 | * @noreturn 98 | */ 99 | function void (DiscordBot bot, DiscordMessageList messages, any data); 100 | 101 | /** 102 | * 103 | * @param bot same handle as the bot you have used to call the native. 104 | * @param messages DiscordMessageList object received. 105 | * DiscordMessageList handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 106 | * @param data custom data passed through the request to use in the callback 107 | * @param data2 custom data passed through the request to use in the callback 108 | * 109 | * @noreturn 110 | */ 111 | function void (DiscordBot bot, DiscordMessageList messages, any data, any data2); 112 | } 113 | 114 | /** DiscordBot.GetPinnedMessages | DiscordBot.GetPinnedMessagesID 115 | * 116 | * Called as callback after a successful request. 117 | * 118 | */ 119 | typeset OnGetDiscordChannelPinnedMessages 120 | { 121 | /** 122 | * 123 | * @param bot same handle as the bot you have used to call the native. 124 | * @param messages DiscordMessageList object received. 125 | * DiscordMessageList handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 126 | * 127 | * @noreturn 128 | */ 129 | function void (DiscordBot bot, DiscordMessageList messages); 130 | 131 | /** 132 | * 133 | * @param bot same handle as the bot you have used to call the native. 134 | * @param messages DiscordMessageList object received. 135 | * DiscordMessageList handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 136 | * @param data custom data passed through the request to use in the callback 137 | * 138 | * @noreturn 139 | */ 140 | function void (DiscordBot bot, DiscordMessageList messages, any data); 141 | 142 | /** 143 | * 144 | * @param bot same handle as the bot you have used to call the native. 145 | * @param messages DiscordMessageList object received. 146 | * DiscordMessageList handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 147 | * @param data custom data passed through the request to use in the callback 148 | * @param data2 custom data passed through the request to use in the callback 149 | * 150 | * @noreturn 151 | */ 152 | function void (DiscordBot bot, DiscordMessageList messages, any data, any data2); 153 | } 154 | 155 | /** DiscordBot.GetChannelMessage | DiscordBot.GetChannelMessageID 156 | * 157 | * Called as callback after a successful request. 158 | * 159 | */ 160 | typeset OnGetDiscordChannelMessage 161 | { 162 | /** 163 | * 164 | * @param bot same handle as the bot you have used to call the native. 165 | * @param message DiscordMessage object received. 166 | * DiscordMessage handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 167 | * 168 | * @noreturn 169 | */ 170 | function void (DiscordBot bot, DiscordMessage message); 171 | 172 | /** 173 | * 174 | * @param bot same handle as the bot you have used to call the native. 175 | * @param message DiscordMessage object received. 176 | * DiscordMessage handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 177 | * @param data custom data passed through the request to use in the callback 178 | * 179 | * @noreturn 180 | */ 181 | function void (DiscordBot bot, DiscordMessage message, any data); 182 | 183 | /** 184 | * 185 | * @param bot same handle as the bot you have used to call the native. 186 | * @param message DiscordMessage object received. 187 | * DiscordMessage handle will not be deleted automatically when the callback function returns, it is your responsibility to manage memory. 188 | * @param data custom data passed through the request to use in the callback 189 | * @param data2 custom data passed through the request to use in the callback 190 | * 191 | * @noreturn 192 | */ 193 | function void (DiscordBot bot, DiscordMessage message, any data, any data2); 194 | } 195 | 196 | /** 197 | * Represents a sticker that can be sent in messages. 198 | */ 199 | methodmap DiscordMessageSticker < DiscordObject 200 | { 201 | /** 202 | * type of sticker format ( DiscordMessageStickerFormat ) 203 | */ 204 | property DiscordMessageStickerFormat Format 205 | { 206 | public get() { return view_as(this.GetInt("format_type")); } 207 | } 208 | 209 | /** 210 | * type of sticker format ( DiscordMessageStickerType ) 211 | */ 212 | property DiscordMessageStickerType Type 213 | { 214 | public get() { return view_as(this.GetInt("type")); } 215 | } 216 | 217 | /** 218 | * whether this guild sticker can be used, may be false due to loss of Server Boosts 219 | */ 220 | property bool Available 221 | { 222 | public get() { return this.GetBool("available"); } 223 | } 224 | 225 | /** 226 | * the standard sticker's sort order within its pack 227 | */ 228 | property int SortValue 229 | { 230 | public get() { return this.GetInt("sort_value"); } 231 | } 232 | 233 | /* the user that uploaded the sticker */ 234 | public DiscordUser GetUser() 235 | { 236 | return view_as(this.GetObject("user")); 237 | } 238 | 239 | /** 240 | * for standard stickers, id of the pack the sticker is from 241 | */ 242 | public bool GetPackID(char[] output, int maxsize) 243 | { 244 | return this.GetString("pack_id", output, maxsize); 245 | } 246 | 247 | /** 248 | * id of the guild that owns this sticker 249 | */ 250 | public bool GetGuildID(char[] output, int maxsize) 251 | { 252 | return this.GetString("guild_id", output, maxsize); 253 | } 254 | 255 | /** 256 | * name of the sticker 257 | */ 258 | public bool GetName(char[] output, int maxsize) 259 | { 260 | return this.GetString("name", output, maxsize); 261 | } 262 | 263 | /** 264 | * description of the sticker 265 | */ 266 | public bool GetDescription(char[] output, int maxsize) 267 | { 268 | return this.GetString("description", output, maxsize); 269 | } 270 | 271 | /** 272 | * autocomplete/suggestion tags for the sticker (max 200 characters) 273 | */ 274 | public bool GetTags(char[] output, int maxsize) 275 | { 276 | return this.GetString("tags", output, maxsize); 277 | } 278 | 279 | /** 280 | * Deprecated 281 | * previously the sticker asset hash, now an empty string 282 | */ 283 | public bool GetAsset(char[] output, int maxsize) 284 | { 285 | return this.GetString("asset", output, maxsize); 286 | } 287 | } 288 | 289 | methodmap DiscordMessageActivity < JSON_Object 290 | { 291 | /** 292 | * type of message activity 293 | */ 294 | property DiscordMessageActivityTypes Type 295 | { 296 | public get() { return view_as(this.GetInt("type")); } 297 | } 298 | 299 | /** 300 | * party_id from a Rich Presence event 301 | * ( https://discord.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload-fields ) 302 | */ 303 | public bool GetPartyID(char[] output, int maxsize) 304 | { 305 | return this.GetString("party_id", output, maxsize); 306 | } 307 | 308 | } 309 | 310 | /** 311 | * Represents a message sent in a channel within Discord. 312 | */ 313 | methodmap DiscordMessage < DiscordObject 314 | { 315 | /** 316 | * whether this message mentions everyone 317 | */ 318 | property bool MentionsEveryone 319 | { 320 | public get() { return this.GetBool("mention_everyone"); } 321 | } 322 | 323 | /** 324 | * message flags combined as a bitfield 325 | */ 326 | property int Flags 327 | { 328 | public get() { return this.GetInt("flags"); } 329 | } 330 | 331 | /** 332 | * whether this was a TTS message 333 | */ 334 | property bool TTS 335 | { 336 | public get() { return this.GetBool("tts"); } 337 | } 338 | 339 | /** 340 | * whether this message is pinned 341 | */ 342 | property bool Pinned 343 | { 344 | public get() { return this.GetBool("pinned"); } 345 | } 346 | 347 | /** 348 | * the thread that was started from this message, includes thread member object 349 | */ 350 | property DiscordChannel Thread 351 | { 352 | public get() { return view_as(this.GetObject("thread")); } 353 | } 354 | 355 | /** 356 | * sent if the message contains components like buttons, action rows, or other interactive components 357 | * https://discord.com/developers/docs/interactions/message-components#component-object 358 | */ 359 | property JSON_Object Components 360 | { 361 | public get() { return this.GetObject("components"); } 362 | } 363 | 364 | /** 365 | * type of message 366 | */ 367 | property DiscordMessageType Type 368 | { 369 | public get() { return view_as(this.GetInt("type")); } 370 | } 371 | 372 | /** 373 | * sent with Rich Presence-related chat embeds 374 | */ 375 | property DiscordMessageActivity Activity 376 | { 377 | public get() { return view_as(this.GetObject("activity")); } 378 | } 379 | 380 | /** 381 | * the author of this message (not guaranteed to be a valid user, see below) 382 | * The author object follows the structure of the user object, but is only a valid user in the case where the message is generated by a user or bot user. 383 | * If the message is generated by a webhook, the author object corresponds to the webhook's id, username, and avatar. 384 | * You can tell if a message is generated by a webhook by checking for the webhook_id on the message object. 385 | */ 386 | property DiscordUser Author 387 | { 388 | public get() { return view_as(this.GetObject("author")); } 389 | } 390 | 391 | /** 392 | * member properties for this message's author 393 | * ! partial ! guild member object 394 | */ 395 | property DiscordGuildUser Member 396 | { 397 | public get() { return view_as(this.GetObject("member")); } 398 | } 399 | 400 | public DiscordMessage(const char[] content = "", DiscordEmbed embed = null) 401 | { 402 | JSON_Object obj = new JSON_Object(); 403 | obj.SetString("content", content); 404 | 405 | if(embed != null) 406 | { 407 | JSON_Array embeds = new JSON_Array(); 408 | embeds.PushObject(embed); 409 | obj.SetObject("embeds", embeds); 410 | } 411 | 412 | return view_as(obj); 413 | } 414 | 415 | /** 416 | * if the message is generated by a webhook, this is the webhook's id 417 | */ 418 | public bool GetWebhookID(char[] output, int maxsize) 419 | { 420 | return this.GetString("webhook_id", output, maxsize); 421 | } 422 | 423 | /** 424 | * id of the channel the message was sent in 425 | */ 426 | public bool GetChannelID(char[] output, int maxsize) 427 | { 428 | return this.GetString("channel_id", output, maxsize); 429 | } 430 | 431 | /** 432 | * id of the guild the message was sent in 433 | */ 434 | public bool GetGuildID(char[] output, int maxsize) 435 | { 436 | return this.GetString("guild_id", output, maxsize); 437 | } 438 | 439 | /** 440 | * if the message is an Interaction or application-owned webhook, this is the id of the application 441 | * ( https://discord.com/developers/docs/interactions/receiving-and-responding ) 442 | */ 443 | public bool GetApplicationID(char[] output, int maxsize) 444 | { 445 | return this.GetString("application_id", output, maxsize); 446 | } 447 | 448 | /** 449 | * the author of this message (not guaranteed to be a valid user, see below) 450 | * The author object follows the structure of the user object, but is only a valid user in the case where the message is generated by a user or bot user. 451 | * If the message is generated by a webhook, the author object corresponds to the webhook's id, username, and avatar. 452 | * You can tell if a message is generated by a webhook by checking for the webhook_id on the message object. 453 | */ 454 | public DiscordUser GetAuthor() 455 | { 456 | return this.Author; 457 | } 458 | 459 | /** 460 | * member properties for this message's author 461 | * ! partial ! guild member object 462 | */ 463 | public DiscordGuildUser GetMember() 464 | { 465 | return this.Member; 466 | } 467 | 468 | /** 469 | * contents of the message 470 | */ 471 | public bool GetContent(char[] output, int maxsize) 472 | { 473 | return this.GetString("content", output, maxsize); 474 | } 475 | 476 | /** 477 | * when this message was sent 478 | */ 479 | public bool GetTimestamp(char[] buffer, int maxsize) 480 | { 481 | return this.GetString("timestamp", buffer, maxsize); 482 | } 483 | 484 | /** 485 | * when this message was sent 486 | */ 487 | public bool GetTimestampDateTime(DateTime& out) 488 | { 489 | char szDate[DATE_LENGTH]; 490 | this.GetString("timestamp", szDate, sizeof(szDate)); 491 | return DateTime.TryParse(szDate, out); 492 | } 493 | 494 | /** 495 | * when this message was edited (or null if never) 496 | */ 497 | public bool GetEditedTimestamp(char[] buffer, int maxsize) 498 | { 499 | return this.GetString("edited_timestamp", buffer, maxsize); 500 | } 501 | 502 | /** 503 | * when this message was edited (or null if never) 504 | */ 505 | public bool GetEditedTimestampDateTime(DateTime& out) 506 | { 507 | char szDate[DATE_LENGTH]; 508 | this.GetString("edited_timestamp", szDate, sizeof(szDate)); 509 | return DateTime.TryParse(szDate, out); 510 | } 511 | 512 | /** 513 | * users specifically mentioned in the message 514 | * The user objects in the mentions array will only have the partial member field present in MESSAGE_CREATE and MESSAGE_UPDATE events from text-based guild channels. 515 | */ 516 | public JSON_Array GetMentionedUsers() 517 | { 518 | return view_as(this.GetObject("mentions")); 519 | } 520 | 521 | /** 522 | * any attached files 523 | * array of attachment objects 524 | */ 525 | public JSON_Array GetAttachments() 526 | { 527 | return view_as(this.GetObject("attachments")); 528 | } 529 | 530 | /** 531 | * roles specifically mentioned in this message 532 | */ 533 | public JSON_Array GetMentionedRoles() 534 | { 535 | return view_as(this.GetObject("mention_roles")); 536 | } 537 | 538 | /** 539 | * channels specifically mentioned in this message 540 | */ 541 | public JSON_Array GetMentionedChannels() 542 | { 543 | return view_as(this.GetObject("mention_channels")); 544 | } 545 | 546 | /** 547 | * any embedded content 548 | * array of embed objects 549 | */ 550 | public JSON_Array GetEmbeds() 551 | { 552 | return view_as(this.GetObject("embeds")); 553 | } 554 | 555 | /** 556 | * reactions to the message 557 | * array of reaction objects 558 | */ 559 | public JSON_Array GetReactions() 560 | { 561 | return view_as(this.GetObject("reactions")); 562 | } 563 | 564 | /** 565 | * Array of DiscordMessageSticker but only with id, name and format_type fields 566 | * ( https://discord.com/developers/docs/resources/sticker#sticker-item-object ) 567 | */ 568 | public JSON_Array GetStickerItems() 569 | { 570 | return view_as(this.GetObject("sticker_items")); 571 | } 572 | 573 | /** 574 | * Deprecated 575 | * the stickers sent with the message 576 | * array of sticker objects 577 | */ 578 | public JSON_Array GetStickers() 579 | { 580 | return view_as(this.GetObject("stickers")); 581 | } 582 | 583 | /** 584 | * data showing the source of a crosspost, channel follow add, pin, or reply message 585 | */ 586 | public DiscordMessageReference GetReference() 587 | { 588 | return view_as(this.GetObject("message_reference")); 589 | } 590 | 591 | /** 592 | * the message associated with the message_reference 593 | */ 594 | public DiscordMessage GetReferencedMessage() 595 | { 596 | return view_as(this.GetObject("referenced_message")); 597 | } 598 | 599 | /** 600 | * Add embed object to the embeds array. 601 | */ 602 | public void Embed(DiscordEmbed embed) 603 | { 604 | if(!this.HasKey("embeds")) 605 | this.SetObject("embeds", new JSON_Array()); 606 | 607 | JSON_Array embeds = this.GetEmbeds(); 608 | embeds.PushObject(embed); 609 | this.SetObject("embeds", embeds); 610 | } 611 | } -------------------------------------------------------------------------------- /include/discord/DiscordMessageReference.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordMessageReference_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordMessageReference_included_ 5 | 6 | methodmap DiscordMessageReference < JSON_Object 7 | { 8 | /** 9 | * when sending, whether to error if the referenced message doesn't exist instead of sending as a normal (non-reply) message, default true 10 | */ 11 | property bool FailIfNotExists 12 | { 13 | public get() { return this.GetBool("fail_if_not_exists"); } 14 | public set(bool value) { this.SetBool("fail_if_not_exists", value); } 15 | } 16 | 17 | public DiscordMessageReference(const char[] message_id, const char[] channel_id, const char[] guild_id, bool fail_if_not_exists) 18 | { 19 | JSON_Object obj = new JSON_Object(); 20 | obj.SetString("message_id", message_id); 21 | obj.SetString("channel_id", channel_id); 22 | obj.SetString("guild_id", guild_id); 23 | obj.SetBool("fail_if_not_exists", fail_if_not_exists); 24 | return view_as(obj); 25 | } 26 | 27 | /** 28 | * id of the originating message 29 | */ 30 | public bool GetMessageID(char[] output, int maxsize) 31 | { 32 | return this.GetString("message_id", output, maxsize); 33 | } 34 | 35 | /** 36 | * id of the originating message 37 | */ 38 | public void SetMessageID(const char[] messageid) 39 | { 40 | this.SetString("message_id", messageid); 41 | } 42 | 43 | /** 44 | * id of the originating message's channel 45 | */ 46 | public bool GetChannelID(char[] output, int maxsize) 47 | { 48 | return this.GetString("channel_id", output, maxsize); 49 | } 50 | 51 | /** 52 | * id of the originating message's channel 53 | */ 54 | public void SetChannelID(const char[] channelid) 55 | { 56 | this.SetString("channel_id", channelid); 57 | } 58 | 59 | /** 60 | * id of the originating message's guild 61 | */ 62 | public bool GetGuildID(char[] output, int maxsize) 63 | { 64 | return this.GetString("guild_id", output, maxsize); 65 | } 66 | 67 | /** 68 | * id of the originating message's guild 69 | */ 70 | public void SetGuildID(const char[] guildid) 71 | { 72 | this.SetString("guild_id", guildid); 73 | } 74 | } -------------------------------------------------------------------------------- /include/discord/DiscordObject.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordObject_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordObject_included_ 5 | 6 | /** 7 | * Discord objects that has an unique snowflake inherits from this methodmap. 8 | */ 9 | methodmap DiscordObject < JSON_Object 10 | { 11 | /** 12 | * Get unique snowflake for this object. 13 | * 14 | * @param output Output buffer. 15 | * @param maxsize Length of the buffer. 16 | * @return True on success, false otherwise. 17 | */ 18 | public bool GetID(char[] output, int maxsize) 19 | { 20 | return this.GetString("id", output, maxsize); 21 | } 22 | 23 | /** 24 | * Release resources 25 | */ 26 | public void Dispose() 27 | { 28 | if(this == null) 29 | return; 30 | 31 | this.Cleanup(); 32 | delete this; 33 | } 34 | } -------------------------------------------------------------------------------- /include/discord/DiscordPermission.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordPermission_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordPermission_included_ 5 | 6 | /** 7 | * Permissions are a way to limit and grant certain abilities to users in Discord. 8 | * A set of base permissions can be configured at the guild level for different roles. 9 | * When these roles are attached to users, they grant or revoke specific privileges within the guild. 10 | * Along with the guild-level permissions, Discord also supports permission overwrites that can be assigned to individual roles or members on a per-channel basis. 11 | */ 12 | enum DiscordPermission 13 | { 14 | CREATE_INSTANT_INVITE = (1 << 0), /* Allows creation of instant invites*/ 15 | KICK_MEMBERS = (1 << 1), /* Allows kicking members */ 16 | BAN_MEMBERS = (1 << 2), /* Allows banning members */ 17 | ADMINISTRATOR = (1 << 3), /* Allows all permissions and bypasses channel permission overwrites */ 18 | MANAGE_CHANNELS = (1 << 4), /* Allows management and editing of channels */ 19 | MANAGE_GUILD = (1 << 5), /* Allows management and editing of the guild */ 20 | ADD_REACTIONS = (1 << 6), /* Allows for the addition of reactions to messages */ 21 | VIEW_AUDIT_LOG = (1 << 7), /* Allows for viewing of audit logs */ 22 | PRIORITY_SPEAKER = (1 << 8), /* Allows for using priority speaker in a voice channel */ 23 | STREAM = (1 << 9), /* Allows the user to go live */ 24 | VIEW_CHANNEL = (1 << 10), /* Allows guild members to view a channel, which includes reading messages in text channels and joining voice channels */ 25 | SEND_MESSAGES = (1 << 11), /* Allows for sending messages in a channel and creating threads in a forum (does not allow sending messages in threads) */ 26 | SEND_TTS_MESSAGES = (1 << 12), /* Allows for sending of /tts messages */ 27 | MANAGE_MESSAGES = (1 << 13), /* Allows for deletion of other users messages */ 28 | EMBED_LINKS = (1 << 14), /* Links sent by users with this permission will be auto-embedded */ 29 | ATTACH_FILES = (1 << 15), /* Allows for uploading images and files */ 30 | READ_MESSAGE_HISTORY = (1 << 16), /* Allows for reading of message history */ 31 | MENTION_EVERYONE = (1 << 17), /* Allows for using the @everyone tag to notify all users in a channel, and the @here tag to notify all online users in a channel */ 32 | USE_EXTERNAL_EMOJIS = (1 << 18), /* Allows the usage of custom emojis from other servers */ 33 | VIEW_GUILD_INSIGHTS = (1 << 19), /* Allows for viewing guild insights */ 34 | CONNECT = (1 << 20), /* Allows for joining of a voice channel */ 35 | SPEAK = (1 << 21), /* Allows for speaking in a voice channel */ 36 | MUTE_MEMBERS = (1 << 22), /* Allows for muting members in a voice channel */ 37 | DEAFEN_MEMBERS = (1 << 23), /* Allows for deafening of members in a voice channel */ 38 | MOVE_MEMBERS = (1 << 24), /* Allows for moving of members between voice channels */ 39 | USE_VAD = (1 << 25), /* Allows for using voice-activity-detection in a voice channel */ 40 | CHANGE_NICKNAME = (1 << 26), /* Allows for modification of own nickname */ 41 | MANAGE_NICKNAMES = (1 << 27), /* Allows for modification of other users nicknames */ 42 | MANAGE_ROLES = (1 << 28), /* Allows management and editing of roles */ 43 | MANAGE_WEBHOOKS = (1 << 29), /* Allows management and editing of webhooks */ 44 | MANAGE_EMOJIS_AND_STICKERS = (1 << 30), /* Allows management and editing of emojis and stickers */ 45 | USE_APPLICATION_COMMANDS = (1 << 31), /* Allows members to use application commands, including slash commands and context menu commands. */ 46 | REQUEST_TO_SPEAK = (1 << 32), /* Allows for requesting to speak in stage channels. (This permission is under active development and may be changed or removed.) */ 47 | MANAGE_EVENTS = (1 << 33), /* Allows for creating, editing, and deleting scheduled events */ 48 | MANAGE_THREADS = (1 << 34), /* Allows for deleting and archiving threads, and viewing all private threads */ 49 | CREATE_PUBLIC_THREADS = (1 << 35), /* Allows for creating public and announcement threads */ 50 | CREATE_PRIVATE_THREADS = (1 << 36), /* Allows for creating private threads */ 51 | USE_EXTERNAL_STICKERS = (1 << 37), /* Allows the usage of custom stickers from other servers */ 52 | SEND_MESSAGES_IN_THREADS = (1 << 38), /* Allows for sending messages in threads */ 53 | USE_EMBEDDED_ACTIVITIES = (1 << 39), /* Allows for using Activities (applications with the EMBEDDED flag) in a voice channel */ 54 | MODERATE_MEMBERS = (1 << 40) /* Allows for timing out users to prevent them from sending or reacting to messages in chat and threads, and from speaking in voice and stage channels */ 55 | } -------------------------------------------------------------------------------- /include/discord/DiscordPresence.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordPresence_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordPresence_included_ 5 | 6 | enum DiscordPresenceStatus 7 | { 8 | STATUS_ONLINE = 0, /* Online */ 9 | STATUS_DND, /* Do Not Disturb */ 10 | STATUS_IDLE, /* AFK */ 11 | STATUS_INVISIBLE, /* Invisible and shown as offline */ 12 | STATUS_OFFLINE /* Offline */ 13 | } 14 | 15 | methodmap DiscordPresence < JSON_Object 16 | { 17 | public DiscordPresence(DiscordActivity activity, DiscordPresenceStatus status, bool afk = false, DateTime since) 18 | { 19 | JSON_Object obj = new JSON_Object(); 20 | obj.SetInt("since", since.Unix); 21 | obj.SetBool("afk", afk); 22 | 23 | switch(status) 24 | { 25 | case STATUS_ONLINE: obj.SetString("status", "online"); 26 | case STATUS_DND: obj.SetString("status", "dnd"); 27 | case STATUS_IDLE: obj.SetString("status", "idle"); 28 | case STATUS_INVISIBLE: obj.SetString("status", "invisible"); 29 | case STATUS_OFFLINE: obj.SetString("status", "offline"); 30 | } 31 | 32 | JSON_Array activities = new JSON_Array(); 33 | activities.PushObject(activity); 34 | obj.SetObject("activities", activities); 35 | return view_as(obj); 36 | } 37 | } -------------------------------------------------------------------------------- /include/discord/DiscordReaction.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordReaction_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordReaction_included_ 5 | 6 | methodmap DiscordReaction < JSON_Object 7 | { 8 | property int Count 9 | { 10 | public get() { return this.GetInt("count"); } 11 | } 12 | 13 | property bool Me 14 | { 15 | public get() { return this.GetBool("me"); } 16 | } 17 | 18 | property DiscordEmoji Emoji 19 | { 20 | public get() { return view_as(this.GetObject("emoji")); } 21 | } 22 | } -------------------------------------------------------------------------------- /include/discord/DiscordRequest.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordRequest_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordRequest_included_ 5 | 6 | #include 7 | 8 | public int OnHTTPRequestComplete(Handle request, bool failure, bool requestSuccessful, EHTTPStatusCode statuscode) { } 9 | 10 | public int OnHTTPDataReceive(Handle request, bool failure, int offset, int statuscode) 11 | { 12 | if(failure || (statuscode != 200 && statuscode != 204)) 13 | { 14 | if(statuscode == 400) 15 | { 16 | SteamWorks_GetHTTPResponseBodyCallback(request, ReceivedData); 17 | } 18 | 19 | new DiscordException("OnHTTPDataReceive - Fail %i %i", failure, statuscode); 20 | } 21 | 22 | delete request; 23 | } 24 | 25 | static int ReceivedData(const char[] data) 26 | { 27 | PrintToServer("[DISCORD-API]: %s", data); 28 | } 29 | 30 | methodmap DiscordRequest < Handle 31 | { 32 | public DiscordRequest(const char[] url, EHTTPMethod method) 33 | { 34 | return view_as(SteamWorks_CreateHTTPRequest(method, url)); 35 | } 36 | 37 | public void SetJsonBody(JSON_Object obj) 38 | { 39 | static char jsonString[16384]; 40 | jsonString = NULL_STRING; 41 | if(obj != null) 42 | json_encode(obj, jsonString, sizeof(jsonString), JSON_NONE); 43 | 44 | SteamWorks_SetHTTPRequestRawPostBody(this, "application/json; charset=UTF-8", jsonString, strlen(jsonString)); 45 | } 46 | 47 | property int Timeout 48 | { 49 | public set(int timeout) { SteamWorks_SetHTTPRequestNetworkActivityTimeout(this, timeout); } 50 | } 51 | 52 | public void SetContentSize(const char[] size = "0") 53 | { 54 | SteamWorks_SetHTTPRequestHeaderValue(this, "Content-Length", size); 55 | } 56 | 57 | public void SetCallbacks(SteamWorksHTTPRequestCompleted OnComplete = INVALID_FUNCTION, SteamWorksHTTPHeadersReceived OnHeadersReceived = INVALID_FUNCTION, SteamWorksHTTPDataReceived OnDataReceived = INVALID_FUNCTION) 58 | { 59 | SteamWorks_SetHTTPCallbacks(this, OnComplete, OnHeadersReceived, OnDataReceived); 60 | } 61 | 62 | public void SetContextValue(any data1 = 0, any data2 = 0) 63 | { 64 | SteamWorks_SetHTTPRequestContextValue(this, data1, data2); 65 | } 66 | 67 | public void SetBot(DiscordBot __bot) 68 | { 69 | char szBuffer[256]; 70 | char szToken[196]; 71 | __bot.GetString("token", szToken, sizeof(szToken)); 72 | FormatEx(szBuffer, sizeof(szBuffer), "Bot %s", szToken); 73 | SteamWorks_SetHTTPRequestHeaderValue(this, "Authorization", szBuffer); 74 | } 75 | 76 | public bool Send() 77 | { 78 | return SteamWorks_SendHTTPRequest(this); 79 | } 80 | } -------------------------------------------------------------------------------- /include/discord/DiscordRole.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordRole_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordRole_included_ 5 | 6 | methodmap DiscordRoleTag < JSON_Object 7 | { 8 | //TODO 9 | } 10 | 11 | methodmap DiscordRole < DiscordObject 12 | { 13 | property int Color 14 | { 15 | public get() { return this.GetInt("color"); } 16 | } 17 | 18 | property int Position 19 | { 20 | public get() { return this.GetInt("position"); } 21 | } 22 | 23 | property bool Hoist 24 | { 25 | public get() { return this.GetBool("hoist"); } 26 | } 27 | 28 | property bool Managed 29 | { 30 | public get() { return this.GetBool("managed"); } 31 | } 32 | 33 | property bool Mentionable 34 | { 35 | public get() { return this.GetBool("mentionable"); } 36 | } 37 | 38 | property DiscordRoleTag Tags 39 | { 40 | public get() { return view_as(this.GetObject("tags")); } 41 | } 42 | 43 | public bool GetName(char[] output, int maxsize) 44 | { 45 | return this.GetString("name", output, maxsize); 46 | } 47 | 48 | public bool GetPermissions(char[] output, int maxsize) 49 | { 50 | return this.GetString("permissions", output, maxsize); 51 | } 52 | 53 | public int GetColor() 54 | { 55 | return this.Color; 56 | } 57 | } -------------------------------------------------------------------------------- /include/discord/DiscordTypeExtensions.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordTypeExtensions_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordTypeExtensions_included_ 5 | 6 | methodmap DiscordTypeExtension < JSON_Array 7 | { 8 | /** 9 | * Release resources 10 | */ 11 | public void Dispose() 12 | { 13 | if(this == null) 14 | return; 15 | 16 | this.Cleanup(); 17 | delete this; 18 | } 19 | } 20 | 21 | methodmap DiscordRoleList < DiscordTypeExtension { } 22 | methodmap DiscordMessageList < DiscordTypeExtension { } 23 | methodmap DiscordChannelList < DiscordTypeExtension { } 24 | methodmap DiscordGuildList < DiscordTypeExtension { } 25 | methodmap DiscordGuildScheduledEventList < DiscordTypeExtension { } -------------------------------------------------------------------------------- /include/discord/DiscordUser.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordUser_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordUser_included_ 5 | 6 | enum DiscordUserFlags 7 | { 8 | UserFlags_None = 0, /* None */ 9 | STAFF = (1 << 0), /* Discord Employee */ 10 | PARTNER = (1 << 1), /* Partner or Partnered Server Owner */ 11 | HYPESQUAD = (1 << 2), /* HypeSquad Events */ 12 | BUG_HUNTER_LEVEL_1 = (1 << 3), /* Bug Hunter Level 1 */ 13 | HYPESQUAD_ONLINE_HOUSE_1 = (1 << 6), /* House Bravery */ 14 | HYPESQUAD_ONLINE_HOUSE_2 = (1 << 7), /* House Brilliance */ 15 | HYPESQUAD_ONLINE_HOUSE_3 = (1 << 8), /* House Balance */ 16 | PREMIUM_EARLY_SUPPORTER = (1 << 9), /* Early Supporter */ 17 | TEAM_PSEUDO_USER = (1 << 10), /* Team User */ 18 | BUG_HUNTER_LEVEL_2 = (1 << 14), /* Bug Hunter Level 2 */ 19 | VERIFIED_BOT = (1 << 16), /* Verified Bot */ 20 | VERIFIED_DEVELOPER = (1 << 17), /* Early Verified Bot Developer */ 21 | CERTIFIED_MODERATOR = (1 << 18), /* Discord Certified Moderator */ 22 | BOT_HTTP_INTERACTIONS = (1 << 19) /* Bot uses only HTTP interactions and is shown in the online member list */ 23 | } 24 | 25 | enum DiscordPremiumTypes 26 | { 27 | PremiumType_None = 0, 28 | NitroClassic = 1, 29 | Nitro = 2 30 | } 31 | 32 | #define MAX_DISCORD_USERNAME_LENGTH 32 33 | #define MAX_DISCORD_DISCRIMINATOR_LENGTH 5 34 | 35 | /** 36 | * Users in Discord are generally considered the base entity. 37 | * Users can spawn across the entire platform, be members of guilds, participate in text and voice chat, and much more. 38 | * Users are separated by a distinction of "bot" vs "normal." Although they are similar, bot users are automated users that are "owned" by another user. 39 | * Unlike normal users, bot users do not have a limitation on the number of Guilds they can be a part of. 40 | */ 41 | methodmap DiscordUser < DiscordObject 42 | { 43 | /** 44 | * whether the user belongs to an OAuth2 application 45 | */ 46 | property bool IsBot 47 | { 48 | public get() { return this.GetBool("bot"); } 49 | } 50 | 51 | /** 52 | * whether the user is an Official Discord System user (part of the urgent message system) 53 | */ 54 | property bool IsSystem 55 | { 56 | public get() { return this.GetBool("system"); } 57 | } 58 | 59 | /** 60 | * whether the user has two factor enabled on their account 61 | */ 62 | property bool HasTwoFactor 63 | { 64 | public get() { return this.GetBool("mfa_enabled"); } 65 | } 66 | 67 | /** 68 | * whether the email on this account has been verified 69 | */ 70 | property bool IsVerified 71 | { 72 | public get() { return this.GetBool("verified"); } 73 | } 74 | 75 | /** 76 | * the user's banner color encoded as an integer representation of hexadecimal color code 77 | */ 78 | property int BannerColor 79 | { 80 | public get() { return this.GetInt("accent_color"); } 81 | } 82 | 83 | /** 84 | * the flags on a user's account 85 | * DiscordUserFlags 86 | */ 87 | property int Flags 88 | { 89 | public get() { return this.GetInt("flags"); } 90 | } 91 | 92 | /** 93 | * the public flags on a user's account 94 | * DiscordUserFlags 95 | */ 96 | property int PublicFlags 97 | { 98 | public get() { return this.GetInt("public_flags"); } 99 | } 100 | 101 | /** 102 | * the type of Nitro subscription on a user's account 103 | * ( https://discord.com/developers/docs/resources/user#user-object-premium-types ) 104 | */ 105 | property DiscordPremiumTypes PremiumType 106 | { 107 | public get() { return view_as(this.GetInt("premium_type")); } 108 | } 109 | 110 | /** 111 | * the user's username, not unique across the platform 112 | */ 113 | public bool GetUsername(char[] output, int maxsize) 114 | { 115 | return this.GetString("username", output, maxsize); 116 | } 117 | 118 | /** 119 | * the user's 4-digit discord-tag 120 | */ 121 | public bool GetDiscriminator(char[] output, int maxsize) 122 | { 123 | return this.GetString("discriminator", output, maxsize); 124 | } 125 | 126 | /** 127 | * the user's avatar hash 128 | * ( https://discord.com/developers/docs/reference#image-formatting ) 129 | */ 130 | public bool GetAvatar(char[] output, int maxsize) 131 | { 132 | return this.GetString("avatar", output, maxsize); 133 | } 134 | 135 | /** 136 | * the user's banner hash 137 | * ( https://discord.com/developers/docs/reference#image-formatting ) 138 | */ 139 | public bool GetBanner(char[] output, int maxsize) 140 | { 141 | return this.GetString("banner", output, maxsize); 142 | } 143 | 144 | /** 145 | * the user's chosen language option 146 | * ( https://discord.com/developers/docs/reference#locales ) 147 | */ 148 | public bool GetLanguage(char[] output, int maxsize) 149 | { 150 | return this.GetString("locale", output, maxsize); 151 | } 152 | 153 | /** 154 | * the user's email 155 | */ 156 | public bool GetEmail(char[] output, int maxsize) 157 | { 158 | return this.GetString("email", output, maxsize); 159 | } 160 | 161 | /** 162 | * Get user mention string 163 | */ 164 | public bool GetMention(char[] output, int maxsize) 165 | { 166 | char szID[32]; 167 | if(!this.GetID(szID, sizeof(szID))) 168 | return false; 169 | 170 | Format(szID, sizeof(szID), "<@%s>", szID); 171 | return true; 172 | } 173 | } -------------------------------------------------------------------------------- /include/discord/DiscordVoiceRegion.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordVoiceRegion_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordVoiceRegion_included_ 5 | 6 | methodmap DiscordVoiceRegion < JSON_Object 7 | { 8 | /** 9 | * whether this is a vip voice region 10 | */ 11 | property bool VipOnly 12 | { 13 | public get() { return this.GetBool("vip"); } 14 | } 15 | 16 | /** 17 | * true for a single server that is closest to the current user's client 18 | */ 19 | property bool Optimal 20 | { 21 | public get() { return this.GetBool("optimal"); } 22 | } 23 | 24 | /** 25 | * whether this is a deprecated voice region (avoid switching to these) 26 | */ 27 | property bool Deprecated 28 | { 29 | public get() { return this.GetBool("deprecated"); } 30 | } 31 | 32 | /** 33 | * whether this is a custom voice region (used for events/etc) 34 | */ 35 | property bool Custom 36 | { 37 | public get() { return this.GetBool("custom"); } 38 | } 39 | 40 | /** 41 | * name of the region 42 | */ 43 | public bool GetName(char[] output, int maxsize) 44 | { 45 | return this.GetString("name", output, maxsize); 46 | } 47 | 48 | /** 49 | * unique ID for the region 50 | */ 51 | public bool GetID(char[] output, int maxsize) 52 | { 53 | return this.GetString("id", output, maxsize); 54 | } 55 | } -------------------------------------------------------------------------------- /include/discord/DiscordWebHook.inc: -------------------------------------------------------------------------------- 1 | #if defined _DiscordWebHook_included_ 2 | #endinput 3 | #endif 4 | #define _DiscordWebHook_included_ 5 | 6 | #include 7 | 8 | #define MAX_WEBHOOK_EMBEDS 10 9 | 10 | methodmap DiscordWebHook < JSON_Object 11 | { 12 | public DiscordWebHook(const char[] endpoint) 13 | { 14 | JSON_Object obj = new JSON_Object(); 15 | obj.SetString("__endpoint", endpoint); 16 | obj.SetKeyHidden("__endpoint", true); 17 | return view_as(obj); 18 | } 19 | 20 | property bool TTS 21 | { 22 | public get() { return this.GetBool("tts"); } 23 | public set(bool value) { this.SetBool("tts", value); } 24 | } 25 | 26 | public void SetEndpoint(const char[] endpoint) 27 | { 28 | this.SetString("__endpoint", endpoint); 29 | } 30 | 31 | public bool GetEndpoint(char[] output, int maxsize) 32 | { 33 | return this.GetString("__endpoint", output, maxsize); 34 | } 35 | 36 | public void SetUsername(const char[] userName) 37 | { 38 | this.SetString("username", userName); 39 | } 40 | 41 | public bool GetUsername(char[] output, int maxsize) 42 | { 43 | return this.GetString("username", output, maxsize); 44 | } 45 | 46 | public void SetAvatar(const char[] avatarUrl) 47 | { 48 | this.SetString("avatar_url", avatarUrl); 49 | } 50 | 51 | public bool GetAvatar(char[] output, int maxsize) 52 | { 53 | return this.GetString("avatar_url", output, maxsize); 54 | } 55 | 56 | public JSON_Array GetEmbeds() 57 | { 58 | return view_as(this.GetObject("embeds")); 59 | } 60 | 61 | public void Embed(DiscordEmbed embed) 62 | { 63 | if(!this.HasKey("embeds")) 64 | this.SetObject("embeds", new JSON_Array()); 65 | 66 | JSON_Array embeds = this.GetEmbeds(); 67 | if(embeds.Length < MAX_WEBHOOK_EMBEDS) 68 | { 69 | embeds.PushObject(embed); 70 | this.SetObject("embeds", embeds); 71 | } else LogError("DiscordWebHook cannot have more than %i embeds!", MAX_WEBHOOK_EMBEDS); 72 | } 73 | 74 | public bool RemoveEmbed(int index) 75 | { 76 | JSON_Array embeds = this.GetEmbeds(); 77 | bool result = embeds.Remove(index); 78 | this.SetObject("embeds", embeds); 79 | return result; 80 | } 81 | 82 | public void SetContent(const char[] content) 83 | { 84 | this.SetString("content", content); 85 | } 86 | 87 | public bool GetContent(char[] output, int maxsize) 88 | { 89 | return this.GetString("content", output, maxsize); 90 | } 91 | 92 | public void Send() 93 | { 94 | char url[256]; 95 | this.GetEndpoint(url, sizeof(url)); 96 | 97 | DiscordRequest request = new DiscordRequest(url, k_EHTTPMethodPOST); 98 | request.SetCallbacks(OnHTTPRequestComplete, _, OnHTTPDataReceive); 99 | request.SetJsonBody(this); 100 | request.Send(); 101 | } 102 | 103 | /** 104 | * Release resources 105 | */ 106 | public void Dispose() 107 | { 108 | if(this == null) 109 | return; 110 | 111 | this.Cleanup(); 112 | delete this; 113 | } 114 | } --------------------------------------------------------------------------------