88
99import org .togetherjava .tjbot .features .MessageReceiverAdapter ;
1010
11+ import java .util .Map ;
12+
1113/**
1214 * Listener that tracks custom emoji usage across all channels for analytics purposes.
1315 * <p>
1820 * custom emojis are tracked separately (e.g. {@code emoji-custom-animated-123456789}).
1921 */
2022public final class EmojiTrackerListener extends MessageReceiverAdapter {
23+ private static final String METRIC_NAME = "emoji" ;
2124 private final Metrics metrics ;
2225
2326 /**
@@ -37,7 +40,11 @@ public void onMessageReceived(MessageReceivedEvent event) {
3740 return ;
3841 }
3942
40- event .getMessage ().getMentions ().getCustomEmojis ().forEach (this ::trackCustomEmoji );
43+ event .getMessage ()
44+ .getMentions ()
45+ .getCustomEmojis ()
46+ .forEach (customEmoji -> metrics .count (METRIC_NAME , Map .of ("type" , "message" , "id" ,
47+ customEmoji .getIdLong (), "animated" , customEmoji .isAnimated ())));
4148 }
4249
4350 @ Override
@@ -47,11 +54,12 @@ public void onMessageReactionAdd(MessageReactionAddEvent event) {
4754 return ;
4855 }
4956
50- trackCustomEmoji (emoji .asCustom ());
57+ CustomEmoji customEmoji = emoji .asCustom ();
58+
59+ trackCustomEmoji ("reaction" , customEmoji .getIdLong (), customEmoji .isAnimated ());
5160 }
5261
53- private void trackCustomEmoji (CustomEmoji emoji ) {
54- String prefix = emoji .isAnimated () ? "emoji-custom-animated-" : "emoji-custom-" ;
55- metrics .count (prefix + emoji .getIdLong ());
62+ private void trackCustomEmoji (String type , long id , boolean isAnimated ) {
63+ metrics .count (METRIC_NAME , Map .of ("type" , type , "id" , id , "animated" , isAnimated ));
5664 }
5765}
0 commit comments