Skip to content

Commit

Permalink
Adds the .is_pinned mech (#58)
Browse files Browse the repository at this point in the history
* Add .is_pinned mech

* Unreordered

* Update DiscordMessageTag.java

* Update DiscordMessageTag.java

* stray space

* added booll check

* Moved bool check
  • Loading branch information
heypr committed May 16, 2024
1 parent 5ee8d81 commit 5814c4a
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ public static void register() {
// @attribute <DiscordMessageTag.is_pinned>
// @returns ElementTag(Boolean)
// @plugin dDiscordBot
// @mechanism DiscordMessageTag.is_pinned
// @description
// Returns whether this message is pinned.
// -->
Expand Down Expand Up @@ -471,6 +472,34 @@ public static void register() {
mechanism.echoError("Failed to crosspost message: " + ex.getClass().getCanonicalName() + ": " + ex.getMessage());
}
});

// <--[mechanism]
// @object DiscordMessageTag
// @name is_pinned
// @input ElementTag(Boolean)
// @description
// Sets whether the message is pinned.
// @tags
// <DiscordMessageTag.is_pinned>
// -->
tagProcessor.registerMechanism("is_pinned", false, ElementTag.class, (object, mechanism, input) -> {
if (!mechanism.requireBoolean()) {
return;
}
boolean pinned = input.asBoolean();
Message message = object.getMessage();
try {
if (pinned) {
message.pin().submit();
}
else {
message.unpin().submit();
}
}
catch (Throwable ex) {
mechanism.echoError("Failed to pin message: " + ex.getClass().getCanonicalName() + ": " + ex.getMessage());
}
});
}

public static ObjectTagProcessor<DiscordMessageTag> tagProcessor = new ObjectTagProcessor<>();
Expand Down

0 comments on commit 5814c4a

Please sign in to comment.