MCPcopy Create free account
hub / github.com/egg82/fetcharr / Webhook

Class Webhook

Webhook/src/main/java/me/egg82/fwebhook/Webhook.java:29–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27import java.util.Map;
28
29public class Webhook implements Plugin {
30 private final Logger logger = LoggerFactory.getLogger(getClass());
31
32 private volatile boolean started = false;
33
34 public Webhook() {
35 logger.info("Webhook plugin ready to init");
36 }
37
38 @Override
39 public void init(@NotNull PluginContext context) throws Exception {
40 WebhookAPI api = new WebhookAPIImpl();
41
42 // This ensures that other plugins can retrieve WebhookAPI by calling
43 // WebhookAPIProvider.instance()
44 APIRegistrationUtil.register(api);
45
46 // This ensures that other plugins can retrieve WebhookAPI by calling
47 // FetcharrAPIProvider.instance().registry().getFirst(WebhookAPI.class)
48 FetcharrAPIProvider.instance().registry().register(this, WebhookAPI.class, api);
49
50 CommentedConfigurationNode config = loadConfig(new File(context.configDir(), "config.yaml"));
51 if (config == null) {
52 return;
53 }
54
55 for (Map.Entry<Object, CommentedConfigurationNode> child : config.node("webhooks").childrenMap().entrySet()) {
56 String id = (String) child.getKey();
57 String type = child.getValue().node("type").getString("").trim().toLowerCase(Locale.ROOT);
58 if (type.isEmpty()) {
59 logger.warn("Webhook {} type is not set", id);
60 continue;
61 }
62
63 WebhookTransform transform = null;
64 if (type.equalsIgnoreCase("discord")) {
65 transform = new DiscordWebhookTransform(child.getValue());
66 }
67 if (type.equalsIgnoreCase("notifiarr")) {
68 transform = new NotifiarrWebhookTransform(child.getValue());
69 }
70 if (transform == null) {
71 logger.warn("Could not find transform for type {}", type);
72 continue;
73 }
74
75 WebhookDestination destination = null;
76 if (type.equalsIgnoreCase("discord")) {
77 destination = new DiscordWebhookDestination(api, id, child.getValue(), transform);
78 }
79 if (type.equalsIgnoreCase("notifiarr")) {
80 destination = new NotifiarrWebhookDestination(api, id, child.getValue(), transform);
81 }
82 if (destination == null) {
83 logger.warn("Could not find destination for type {}", type);
84 continue;
85 }
86

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected