Skip to content

Commit

Permalink
Added Types
Browse files Browse the repository at this point in the history
  • Loading branch information
aabssmc committed Mar 11, 2024
1 parent 596e7f8 commit cc88ec4
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 2 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ repositories {
maven {url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"}
maven {url = "https://oss.sonatype.org/content/groups/public/"}
maven {url = "https://repo.skriptlang.org/releases"}
maven {url = "https://jitpack.io"}
}

dependencies {
implementation 'org.jetbrains:annotations:24.0.0'
implementation "org.jetbrains:annotations:24.0.0"
compileOnly "org.spigotmc:spigot-api:1.20.4-R0.1-SNAPSHOT"
implementation "com.github.SkriptLang:Skript:2.7.0"
implementation "com.github.ItsRadiiX:Definity-Webhooks:f051e1fa3e"
}

def targetJavaVersion = 17
Expand Down
130 changes: 130 additions & 0 deletions src/main/java/lol/aabss/skhttp/elements/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import ch.njol.skript.classes.Parser;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.registrations.Classes;
import com.itsradiix.discordwebhook.DiscordWebHook;
import com.itsradiix.discordwebhook.embed.Embed;
import com.itsradiix.discordwebhook.embed.models.Author;
import com.itsradiix.discordwebhook.embed.models.Field;
import com.itsradiix.discordwebhook.embed.models.Footer;
import org.jetbrains.annotations.NotNull;

import java.net.http.HttpClient;
Expand Down Expand Up @@ -84,5 +89,130 @@ public boolean canParse(@NotNull ParseContext context) {
}
)
);

Classes.registerClass(new ClassInfo<>(DiscordWebHook.class, "discordwebhook")
.name("Discord Webhook")
.description("Represents a discord webhook.")
.user("discord ?webhooks?")
.since("1.1")
.parser(new Parser<>() {

@Override
public boolean canParse(@NotNull ParseContext context) {
return false;
}

@Override
public @NotNull String toString(DiscordWebHook o, int flags) {
return toVariableNameString(o);
}

@Override
public @NotNull String toVariableNameString(DiscordWebHook o) {
return o.getContent();
}
}
)
);

Classes.registerClass(new ClassInfo<>(Embed.class, "discordembed")
.name("Discord Embed")
.description("Represents a discord embed.")
.user("discord ?embeds?")
.since("1.1")
.parser(new Parser<>() {

@Override
public boolean canParse(@NotNull ParseContext context) {
return false;
}

@Override
public @NotNull String toString(Embed o, int flags) {
return toVariableNameString(o);
}

@Override
public @NotNull String toVariableNameString(Embed o) {
return o.getTitle();
}
}
)
);

Classes.registerClass(new ClassInfo<>(Footer.class, "discordfooter")
.name("Discord Footer")
.description("Represents a discord embed footer.")
.user("discord ?footers?")
.since("1.1")
.parser(new Parser<>() {

@Override
public boolean canParse(@NotNull ParseContext context) {
return false;
}

@Override
public @NotNull String toString(Footer o, int flags) {
return toVariableNameString(o);
}

@Override
public @NotNull String toVariableNameString(Footer o) {
return o.getText();
}
}
)
);

Classes.registerClass(new ClassInfo<>(Author.class, "discordauthor")
.name("Discord Author")
.description("Represents a discord embed author.")
.user("discord ?authors?")
.since("1.1")
.parser(new Parser<>() {

@Override
public boolean canParse(@NotNull ParseContext context) {
return false;
}

@Override
public @NotNull String toString(Author o, int flags) {
return toVariableNameString(o);
}

@Override
public @NotNull String toVariableNameString(Author o) {
return o.getName();
}
}
)
);

Classes.registerClass(new ClassInfo<>(Field.class, "discordfield")
.name("Discord Field")
.description("Represents a discord embed field.")
.user("discord ?fields?")
.since("1.1")
.parser(new Parser<>() {

@Override
public boolean canParse(@NotNull ParseContext context) {
return false;
}

@Override
public @NotNull String toString(Field o, int flags) {
return toVariableNameString(o);
}

@Override
public @NotNull String toVariableNameString(Field o) {
return o.getName();
}
}
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class ExprVersion extends PropertyExpression<Object, String> {

static {
register(ExprVersion.class, String.class, "[repsonse|request] ur(l|i)", "httpresponses/httprequests/httpclients");
register(ExprVersion.class, String.class, "[repsonse|request] version", "httpresponses/httprequests/httpclients");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"\turl: \"https://www.someurl.com\"",
"\tmethod: \"GET\"",
"\tbody: \"some body text\"",
"\theaders: \"some header texts\"",
"\tvariable: {_var}"
})
@Since("1.0")
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/lang/default.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 1.1

types:
httpclient: httpclient¦s @an
httprequest: httprequest¦s @an
httpresponse: httpresposne¦s @an
discordwebhook: discordwebhook¦s @a

discordembed: discordembed¦s @a
discordfooter: discordfooter¦s @a
discordauthor: discordauthor¦s @a
discordfield: discordfiled¦s @a

0 comments on commit cc88ec4

Please sign in to comment.