-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/main/java/info/itsthesky/disky/elements/effects/MakeBotLeave.java
This file contains 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,54 @@ | ||
package info.itsthesky.disky.elements.effects; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.util.AsyncEffect; | ||
import ch.njol.util.Kleenean; | ||
import info.itsthesky.disky.DiSky; | ||
import info.itsthesky.disky.core.Bot; | ||
import net.dv8tion.jda.api.entities.Guild; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class MakeBotLeave extends AsyncEffect { | ||
|
||
static { | ||
Skript.registerEffect( | ||
MakeBotLeave.class, | ||
"make [the] %bot% leave [the] [guild] %guild%" | ||
); | ||
} | ||
|
||
private Expression<Bot> exprBot; | ||
private Expression<Guild> exprGuild; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
exprBot = (Expression<Bot>) expressions[0]; | ||
exprGuild = (Expression<Guild>) expressions[1]; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(Event event) { | ||
final Bot bot = Bot.fromContext(exprBot, event); | ||
final Guild guild = exprGuild.getSingle(event); | ||
if (guild == null) | ||
return; | ||
|
||
try { | ||
final Guild botGuild = bot.getInstance().getGuildById(guild.getId()); | ||
if (botGuild == null) | ||
return; | ||
botGuild.leave().complete(); | ||
} catch (Exception ex) { | ||
DiSky.getErrorHandler().exception(event, ex); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "make bot " + exprBot.toString(event, debug) + " leave guild " + exprGuild.toString(event, debug); | ||
} | ||
} |