Skip to content

Commit

Permalink
swap TimeTag property to modern Extension
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 22, 2023
1 parent 09e13b5 commit bf7b023
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.denizenscript.ddiscordbot.commands.*;
import com.denizenscript.ddiscordbot.events.*;
import com.denizenscript.ddiscordbot.objects.*;
import com.denizenscript.ddiscordbot.properties.DiscordTimeTagProperties;
import com.denizenscript.ddiscordbot.properties.DiscordTimeTagExtensions;
import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.core.TimeTag;
Expand Down Expand Up @@ -97,8 +97,8 @@ public void onEnable() {
ObjectFetcher.registerWithObjectFetcher(DiscordSelectionTag.class, DiscordSelectionTag.tagProcessor);
ObjectFetcher.registerWithObjectFetcher(DiscordTextInputTag.class, DiscordTextInputTag.tagProcessor);
ObjectFetcher.registerWithObjectFetcher(DiscordUserTag.class, DiscordUserTag.tagProcessor);
// Extension properties
PropertyParser.registerProperty(DiscordTimeTagProperties.class, TimeTag.class);
// Extensions
DiscordTimeTagExtensions.register();

// <--[tag]
// @attribute <discord_bots>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.denizenscript.ddiscordbot.properties;

import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.TimeTag;

public class DiscordTimeTagExtensions {

public static void register() {

// <--[tag]
// @attribute <TimeTag.format_discord[(<style>)]>
// @returns ElementTag
// @group properties
// @Plugin dDiscordBot
// @description
// Returns the time formatted for display on Discord, optionally using the specified style from <@link url https://discord.com/developers/docs/reference#message-formatting-timestamp-styles>.
// For example: <util.time_now.format_discord> or <util.time_now.format_discord[R]>
// Note that style input, if used, is case sensitive.
// -->
TimeTag.tagProcessor.registerStaticTag(ElementTag.class, "format_discord", (attribute, time) -> {
long stamp = time.millis() / 1000;
if (attribute.hasParam()) {
return new ElementTag("<t:" + stamp + ":" + attribute.getParam() + ">");
}
return new ElementTag("<t:" + stamp + ">");
});
}
}

This file was deleted.

0 comments on commit bf7b023

Please sign in to comment.