Skip to content

Commit

Permalink
Fixed #3
Browse files Browse the repository at this point in the history
- I can't say I understand why it works now, but it does and I'm not about to question it
- Recreated the extension in a new project targeting .NET Framework 4.7.2
- Added a bunch of packages to the extension because VS has a mind of its own
- Some minor indentation/file encoding changes because VS deemed it necessary
  • Loading branch information
ConnorAU committed Jul 18, 2022
1 parent f5242ca commit a60f84e
Show file tree
Hide file tree
Showing 10 changed files with 426 additions and 79 deletions.
34 changes: 17 additions & 17 deletions extension/DiscordEmbedBuilder.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2026
# Visual Studio Version 16
VisualStudioVersion = 16.0.32630.194
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscordEmbedBuilder", "DiscordEmbedBuilder\DiscordEmbedBuilder.csproj", "{07E66298-71C7-4A9F-896B-9BA0865BFE98}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscordEmbedBuilder", "DiscordEmbedBuilder\DiscordEmbedBuilder.csproj", "{C71A1E67-9C19-493D-A69E-04A1AA18BE19}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,23 +15,23 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{07E66298-71C7-4A9F-896B-9BA0865BFE98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07E66298-71C7-4A9F-896B-9BA0865BFE98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07E66298-71C7-4A9F-896B-9BA0865BFE98}.Debug|x64.ActiveCfg = Debug|x64
{07E66298-71C7-4A9F-896B-9BA0865BFE98}.Debug|x64.Build.0 = Debug|x64
{07E66298-71C7-4A9F-896B-9BA0865BFE98}.Debug|x86.ActiveCfg = Debug|x86
{07E66298-71C7-4A9F-896B-9BA0865BFE98}.Debug|x86.Build.0 = Debug|x86
{07E66298-71C7-4A9F-896B-9BA0865BFE98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07E66298-71C7-4A9F-896B-9BA0865BFE98}.Release|Any CPU.Build.0 = Release|Any CPU
{07E66298-71C7-4A9F-896B-9BA0865BFE98}.Release|x64.ActiveCfg = Release|x64
{07E66298-71C7-4A9F-896B-9BA0865BFE98}.Release|x64.Build.0 = Release|x64
{07E66298-71C7-4A9F-896B-9BA0865BFE98}.Release|x86.ActiveCfg = Release|x86
{07E66298-71C7-4A9F-896B-9BA0865BFE98}.Release|x86.Build.0 = Release|x86
{C71A1E67-9C19-493D-A69E-04A1AA18BE19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C71A1E67-9C19-493D-A69E-04A1AA18BE19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C71A1E67-9C19-493D-A69E-04A1AA18BE19}.Debug|x64.ActiveCfg = Debug|x64
{C71A1E67-9C19-493D-A69E-04A1AA18BE19}.Debug|x64.Build.0 = Debug|x64
{C71A1E67-9C19-493D-A69E-04A1AA18BE19}.Debug|x86.ActiveCfg = Debug|x86
{C71A1E67-9C19-493D-A69E-04A1AA18BE19}.Debug|x86.Build.0 = Debug|x86
{C71A1E67-9C19-493D-A69E-04A1AA18BE19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C71A1E67-9C19-493D-A69E-04A1AA18BE19}.Release|Any CPU.Build.0 = Release|Any CPU
{C71A1E67-9C19-493D-A69E-04A1AA18BE19}.Release|x64.ActiveCfg = Release|x64
{C71A1E67-9C19-493D-A69E-04A1AA18BE19}.Release|x64.Build.0 = Release|x64
{C71A1E67-9C19-493D-A69E-04A1AA18BE19}.Release|x86.ActiveCfg = Release|x86
{C71A1E67-9C19-493D-A69E-04A1AA18BE19}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D1581F77-E115-4371-B2E5-6818BD8CC17C}
SolutionGuid = {7DA7F002-29BF-460E-BD33-3D97DFAF923C}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion extension/DiscordEmbedBuilder/Discord.Types.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DiscordEmbedBuilder
namespace DiscordEmbedBuilder
{
public class Types
{
Expand Down
42 changes: 24 additions & 18 deletions extension/DiscordEmbedBuilder/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using Maca134.Arma.Serializer;
using System.Text.RegularExpressions;
using System.Net;

namespace DiscordEmbedBuilder
{
Expand All @@ -20,10 +21,10 @@ internal static async Task HandleRequest(string[] args)
{
// Remove arma quotations
string url = args[0].Trim('"').Replace("\"\"", "\"");
string content = args[1].Trim('"').Replace("\"\"", "\"");
string content = args[1].Trim('"').Replace("\"\"", "\"");
string username = args[2].Trim('"').Replace("\"\"", "\"");
string avatar = args[3].Trim('"').Replace("\"\"", "\"");
bool tts = Convert.ToBoolean(args[4]);
string avatar = args[3].Trim('"').Replace("\"\"", "\"");
bool tts = Convert.ToBoolean(args[4]);
Types.EmbedsArray embeds = DeserializeObject<Types.EmbedsArray>(args[5]);

// Discord 2000 character limit
Expand All @@ -50,6 +51,11 @@ internal static async Task HandleRequest(string[] args)
if (embedProperty.Count() > 0) package.Add(new JProperty("embeds", embedProperty));

// Execute webhook
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 |
SecurityProtocolType.Tls |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Ssl3;
using (HttpClient APIClient = new HttpClient())
{
APIClient.BaseAddress = new Uri("https://discord.com/api/webhooks/");
Expand All @@ -64,21 +70,21 @@ internal static async Task HandleRequest(string[] args)
}
}

private static T DeserializeObject<T>(string value)
{
value = value.Replace("\"\"", "\\\"\\\"");
value = new Regex("([[,]?)nil([],]+)").Replace(value, "$1null$2");
Tools.Logger(null, value);
return JsonConvert.DeserializeObject<T>(value, new JsonConverter[]
{
new ArmaJsonConverter()
});
}

// The arma array deserializer doesnt like empty strings and I dont know how to fix it, so heres a shit work around
private static string RemoveReservedString(string input) => input == $"{(char)1}" ? "" : input;

private static JObject BuildEmbedObject(Types.EmbedArray embed)
private static T DeserializeObject<T>(string value)
{
value = value.Replace("\"\"", "\\\"\\\"");
value = new Regex("([[,]?)nil([],]+)").Replace(value, "$1null$2");
Tools.Logger(null, value);
return JsonConvert.DeserializeObject<T>(value, new JsonConverter[]
{
new ArmaJsonConverter()
});
}

// The arma array deserializer doesnt like empty strings and I dont know how to fix it, so heres a shit work around
private static string RemoveReservedString(string input) => input == $"{(char)1}" ? "" : input;

private static JObject BuildEmbedObject(Types.EmbedArray embed)
{
JObject embedObject = new JObject();
Types.EmbedAuthor embedAuthor = embed.author;
Expand Down
Loading

0 comments on commit a60f84e

Please sign in to comment.