Skip to content

Commit d2a736e

Browse files
sex
1 parent 08b7cdb commit d2a736e

File tree

10 files changed

+210
-1
lines changed

10 files changed

+210
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using JetBrains.Annotations;
2+
using SER.Code.ArgumentSystem.Arguments;
3+
using SER.Code.ArgumentSystem.BaseArguments;
4+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
5+
using UnityEngine;
6+
7+
namespace SER.Code.MethodSystem.Methods.ColorsMethods;
8+
9+
[UsedImplicitly]
10+
public class CreateColorMethod : ReferenceReturningMethod<Color>
11+
{
12+
public override string Description => "Creates a color object.";
13+
14+
public override Argument[] ExpectedArguments { get; } =
15+
[
16+
new FloatArgument("red component", 0, 255),
17+
new FloatArgument("green component", 0, 255),
18+
new FloatArgument("blue component", 0, 255)
19+
];
20+
21+
public override void Execute()
22+
{
23+
var red = Args.GetFloat("red component");
24+
var green = Args.GetFloat("green component");
25+
var blue = Args.GetFloat("blue component");
26+
27+
ReturnValue = new(red / 255f, green / 255f, blue / 255f);
28+
}
29+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using JetBrains.Annotations;
2+
using Newtonsoft.Json.Linq;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
6+
using SER.Code.MethodSystem.Methods.DiscordMethods.Structures;
7+
8+
namespace SER.Code.MethodSystem.Methods.DiscordMethods;
9+
10+
[UsedImplicitly]
11+
public class CreateDiscordEmbedAuthor : ReferenceReturningMethod<DEmbedAuthor>
12+
{
13+
public override string Description => "Creates an author object that can be used in discord embeds.";
14+
15+
public override Argument[] ExpectedArguments { get; } =
16+
[
17+
new TextArgument("name"),
18+
new TextArgument("url")
19+
{
20+
DefaultValue = new(null, "none")
21+
},
22+
new TextArgument("icon url")
23+
{
24+
DefaultValue = new(null, "none")
25+
},
26+
new TextArgument("proxy icon url")
27+
{
28+
DefaultValue = new(null, "none")
29+
}
30+
];
31+
32+
public override void Execute()
33+
{
34+
var author = new JObject
35+
{
36+
["name"] = Args.GetText("name")
37+
};
38+
39+
if (Args.GetText("url") is {} url) author["url"] = url;
40+
if (Args.GetText("icon url") is {} iconUrl) author["icon_url"] = iconUrl;
41+
if (Args.GetText("proxy icon url") is {} proxyIconUrl) author["proxy_icon_url"] = proxyIconUrl;
42+
43+
ReturnValue = new(author);
44+
}
45+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using JetBrains.Annotations;
2+
using SER.Code.ArgumentSystem.Arguments;
3+
using SER.Code.ArgumentSystem.BaseArguments;
4+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
5+
using SER.Code.MethodSystem.Methods.DiscordMethods.Structures;
6+
7+
namespace SER.Code.MethodSystem.Methods.DiscordMethods;
8+
9+
[UsedImplicitly]
10+
public class CreateDiscordEmbedFooterMethod : ReferenceReturningMethod<DEmbedFooter>
11+
{
12+
public override string Description => "Creates a footer that can be used in discord embeds.";
13+
14+
public override Argument[] ExpectedArguments { get; } =
15+
[
16+
new TextArgument("content"),
17+
new TextArgument("icon url")
18+
];
19+
20+
public override void Execute()
21+
{
22+
ReturnValue = new(new()
23+
{
24+
["text"] = Args.GetText("content"),
25+
["icon_url"] = Args.GetText("icon url")
26+
});
27+
}
28+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using JetBrains.Annotations;
2+
using Newtonsoft.Json.Linq;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
6+
using SER.Code.MethodSystem.Methods.DiscordMethods.Structures;
7+
using UnityEngine;
8+
9+
namespace SER.Code.MethodSystem.Methods.DiscordMethods;
10+
11+
[UsedImplicitly]
12+
public class CreateDiscordEmbedMethod : ReferenceReturningMethod<DEmbed>
13+
{
14+
public override string Description => "Creates an embed which can later be sent to discord via webhook.";
15+
16+
public override Argument[] ExpectedArguments { get; } =
17+
[
18+
new TextArgument("title")
19+
{
20+
DefaultValue = new(null, "none")
21+
},
22+
new TextArgument("description")
23+
{
24+
DefaultValue = new(null, "none")
25+
},
26+
new ColorArgument("color")
27+
{
28+
DefaultValue = new(new Color(0, 0, 0, 1), "default")
29+
},
30+
new ReferenceArgument<DEmbedFooter>("footer")
31+
{
32+
DefaultValue = new(null, "none")
33+
}
34+
];
35+
36+
public override void Execute()
37+
{
38+
var embed = new JObject();
39+
40+
if (Args.GetText("title") is { } title) embed["title"] = title;
41+
if (Args.GetText("description") is { } description) embed["description"] = description;
42+
if (Args.GetColor("color") is { a: < 1 } color)
43+
{
44+
int r = Mathf.RoundToInt(color.r * 255);
45+
int g = Mathf.RoundToInt(color.g * 255);
46+
int b = Mathf.RoundToInt(color.b * 255);
47+
48+
embed["color"] = (r << 16) | (g << 8) | b;
49+
}
50+
if (Args.GetReference<DEmbedFooter>("footer") is { } footer) embed["footer"] = footer.Footer;
51+
52+
ReturnValue = new(embed);
53+
}
54+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using MEC;
2+
using SER.Code.ArgumentSystem.Arguments;
3+
using SER.Code.ArgumentSystem.BaseArguments;
4+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
5+
using SER.Code.MethodSystem.Methods.DiscordMethods.Structures;
6+
using SER.Code.MethodSystem.Methods.HTTPMethods;
7+
8+
namespace SER.Code.MethodSystem.Methods.DiscordMethods;
9+
10+
public class SendDiscordEmbedsMethod : SynchronousMethod
11+
{
12+
public override string Description => "tes";
13+
14+
public override Argument[] ExpectedArguments { get; } =
15+
[
16+
new TextArgument("url"),
17+
new ReferenceArgument<DEmbed>("embed")
18+
];
19+
20+
public override void Execute()
21+
{
22+
var url = Args.GetText("url");
23+
var embed = Args.GetReference<DEmbed>("embed");
24+
25+
HTTPPostMethod.SendPost(this, url, embed.ToString()).RunCoroutine();
26+
}
27+
}

Code/MethodSystem/Methods/DiscordMethods/SendDiscordMessageMethod.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ public override void Execute()
4040

4141
JObject json = new()
4242
{
43-
["content"] = messageContent
43+
["content"] = messageContent,
44+
["allowed_mentions"] = new JObject
45+
{
46+
["parse"] = new JArray("roles", "users", "everyone")
47+
}
4448
};
4549

4650
if (webhookName != null) json["username"] = webhookName;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using Newtonsoft.Json.Linq;
2+
3+
namespace SER.Code.MethodSystem.Methods.DiscordMethods.Structures;
4+
5+
public record DEmbed(JObject Embed);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using Newtonsoft.Json.Linq;
2+
3+
namespace SER.Code.MethodSystem.Methods.DiscordMethods.Structures;
4+
5+
public record DEmbedAuthor(JObject Author);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using Newtonsoft.Json.Linq;
2+
3+
namespace SER.Code.MethodSystem.Methods.DiscordMethods.Structures;
4+
5+
public record DEmbedFooter(JObject Footer);

SER.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,15 @@
148148
return null;
149149
};
150150
151+
try
152+
{
151153
// 2. Attach Resolver
152154
AppDomain.CurrentDomain.AssemblyResolve += resolver;
155+
}
156+
catch (Exception e)
157+
{
158+
Log.LogMessage(MessageImportance.High, e);
159+
}
153160
154161
try
155162
{

0 commit comments

Comments
 (0)