Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void onEnable() {
ScriptEvent.registerScriptEvent(DiscordUserLeavesScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordUserNicknameChangeScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordUserRoleChangeScriptEvent.class);
ScriptEvent.registerScriptEvent(DiscordInviteCreateScriptEvent.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the registration list is in alphabetical order (ie the order that your intellij file list should have them in anyway)

// Objects
ObjectFetcher.registerWithObjectFetcher(DiscordBotTag.class, DiscordBotTag.tagProcessor);
ObjectFetcher.registerWithObjectFetcher(DiscordButtonTag.class, DiscordButtonTag.tagProcessor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.dv8tion.jda.api.events.Event;
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent;
import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent;
import net.dv8tion.jda.api.events.guild.invite.GuildInviteCreateEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent;
Expand Down Expand Up @@ -165,6 +166,11 @@ public void onGenericSelectMenuInteraction(GenericSelectMenuInteractionEvent eve
autoHandle(event, DiscordSelectionUsedScriptEvent.instance);
}

@Override
public void onGuildInviteCreate(GuildInviteCreateEvent event) {
autoHandle(event, DiscordInviteCreateScriptEvent.instance);
}

@Override
public void onChannelCreate(@Nonnull ChannelCreateEvent event) {
autoHandle(event, DiscordChannelCreateScriptEvent.instance);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.denizenscript.ddiscordbot.events;

import com.denizenscript.ddiscordbot.DiscordScriptEvent;
import com.denizenscript.ddiscordbot.objects.DiscordChannelTag;
import com.denizenscript.ddiscordbot.objects.DiscordGroupTag;
import com.denizenscript.ddiscordbot.objects.DiscordUserTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import net.dv8tion.jda.api.events.guild.invite.GuildInviteCreateEvent;

public class DiscordInviteCreateScriptEvent extends DiscordScriptEvent {

// <--[event]
// @Events
// discord invitation created
//
// @Switch for:<bot> to only process the event for a specified Discord bot.
// @Switch group:<group_id> to only process the event for a specified Discord group.
//
// @Triggers when a Discord user creates an invitation.
//
// @Plugin dDiscordBot
//
// @Group Discord
//
// @Context
// <context.bot> returns the relevant DiscordBotTag.
// <context.group> returns the DiscordGroupTag.
// <context.channel> returns the DiscordChannelTag.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd provide context here for at least the channel (and maybe also the group?), as it's not super clear what is it on first read - I assume the channel the invite leads to?
Otherwise LGTM

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍🏻

// <context.user> returns the DiscordUserTag of the invitation creator.
// <context.code> returns the ElementTag of the invitation code (after the "/" in the URL.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

started a ( but didn't end it )

Also "the ElementTag of" is redundant

// <context.url> returns the ElementTag of the invitation URL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

. at end

// -->

public static DiscordInviteCreateScriptEvent instance;

public DiscordInviteCreateScriptEvent() {
instance = this;
registerCouldMatcher("discord invitation created");
registerSwitches("channel", "group");
}

public GuildInviteCreateEvent getEvent() {
return (GuildInviteCreateEvent) event;
}

@Override
public boolean matches(ScriptPath path) {
if (!tryChannel(path, getEvent().getChannel())) {
return false;
}
if (!tryGuild(path, getEvent().getGuild())) {
return false;
}
return super.matches(path);
}

@Override
public ObjectTag getContext(String name) {
switch (name) {
case "channel":
return new DiscordChannelTag(botID, getEvent().getChannel());
case "group":
return new DiscordGroupTag(botID, getEvent().getGuild());
case "user":
return new DiscordUserTag(botID, getEvent().getInvite().getInviter());
case "code":
return new ElementTag(getEvent().getInvite().getCode());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

, true on the elementtag constructors

case "url":
return new ElementTag(getEvent().getInvite().getUrl());
}
return super.getContext(name);
}
}