Skip to content

Commit

Permalink
Use a different short domain for non devs
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Jul 23, 2021
1 parent 8fedcec commit 3929525
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/main/java/ml/duncte123/skybot/utils/AirUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,17 @@ public static void setJDAContext(JDA jda) {
((JDAImpl) jda).setContext();
}

@Nonnull
public static PendingRequest<String> shortenUrl(String url, String googleKey, ObjectMapper mapper) {
return shortenUrl(url, googleKey, mapper, "duncte.bot");
}

@Nonnull
public static PendingRequest<String> shortenUrl(String url, String googleKey, ObjectMapper mapper, String prefix) {
final ObjectNode json = mapper.createObjectNode();

json.set("dynamicLinkInfo",
mapper.createObjectNode()
.put("domainUriPrefix", "duncte.bot")
.put("domainUriPrefix", prefix)
.put("link", url)
);
json.set("suffix",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ml.duncte123.skybot.objects.command.Command
import ml.duncte123.skybot.objects.command.CommandContext
import ml.duncte123.skybot.utils.AirUtils.isURL
import ml.duncte123.skybot.utils.AirUtils.shortenUrl
import ml.duncte123.skybot.utils.CommandUtils.isDev

class ShortenCommand : Command() {

Expand All @@ -42,7 +43,9 @@ class ShortenCommand : Command() {
return
}

shortenUrl(args[0], ctx.config.apis.googl, ctx.variables.jackson).async(
val prefix = if (isDev(ctx.author)) "duncte.bot" else "dunctebot.page.link"

shortenUrl(args[0], ctx.config.apis.googl, ctx.variables.jackson, prefix).async(
{
sendMsg(ctx, "Here is your shortened url: <$it>")
},
Expand Down

0 comments on commit 3929525

Please sign in to comment.