-
Notifications
You must be signed in to change notification settings - Fork 15
DiscordInviteCreateScriptEvent #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MrMaleficus
wants to merge
7
commits into
DenizenScript:master
Choose a base branch
from
MrMaleficus:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c9d57e8
DiscordInviteCreateScriptEvent
MrMaleficus 59ac4b2
Update DiscordInviteCreateScriptEvent.java
MrMaleficus 12c58c6
unused imports
MrMaleficus b64107d
channel switch not listened
MrMaleficus f6c86b8
fixes from review
MrMaleficus 5343955
Update DiscordInviteCreateScriptEvent.java
MrMaleficus c7a0bcd
Update DiscordInviteCreateScriptEvent.java
MrMaleficus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/com/denizenscript/ddiscordbot/events/DiscordInviteCreateScriptEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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 channel:<channel_id> to only process the event for a specified Discord channel. | ||
// @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 of the created invitation. | ||
// <context.channel> returns the DiscordChannelTag of the created invitation. | ||
// <context.user> returns the DiscordUserTag of the invitation creator. | ||
// <context.code> returns the invitation code (after the last "/" in the URL). | ||
// <context.url> returns the invitation URL. | ||
// --> | ||
|
||
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) { | ||
return switch (name) { | ||
case "channel" -> new DiscordChannelTag(botID, getEvent().getChannel()); | ||
case "group" -> new DiscordGroupTag(botID, getEvent().getGuild()); | ||
case "user" -> new DiscordUserTag(botID, getEvent().getInvite().getInviter()); | ||
case "code" -> new ElementTag(getEvent().getInvite().getCode(), true); | ||
case "url" -> new ElementTag(getEvent().getInvite().getUrl(), true); | ||
default -> super.getContext(name); | ||
}; | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.