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
Danny
committed
Mar 31, 2024
1 parent
a7ad4ac
commit 051a4e4
Showing
3 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/main/java/com/trason/skitch/elements/effects/EffAddChannelVip.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,82 @@ | ||
package com.trason.skitch.elements.effects; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.util.Kleenean; | ||
import com.github.twitch4j.helix.domain.User; | ||
import com.netflix.hystrix.exception.HystrixRuntimeException; | ||
import com.trason.skitch.elements.events.bukkit.BridgeEventChat; | ||
import com.trason.skitch.elements.events.custom.CommandEvent; | ||
import com.trason.skitch.util.ConsoleMessages.console; | ||
import org.apache.commons.lang3.exception.ContextedRuntimeException; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static com.trason.skitch.elements.effects.EffLoginTwitchBot.client; | ||
|
||
@Name("Twitch Add Channel VIP") | ||
@Description("Adds a VIP to the broadcaster’s chat room.\n" + | ||
"The bot needs broadcaster permission!!! (So only selfbots work here!)") | ||
@Examples("add twitch channel vip \"username\"") | ||
@Since("1.4.1") | ||
public class EffAddChannelVip extends Effect { | ||
static { | ||
// This is the registration of the effect | ||
Skript.registerEffect(EffAddChannelVip.class, "add [twitch] channel vip %string%"); | ||
} | ||
|
||
private Expression<String> exprUserName; | ||
@Override | ||
protected void execute(@NotNull Event event) { | ||
try { | ||
if (event instanceof BridgeEventChat) { | ||
String broadcasterID = ((BridgeEventChat) event).getEvent().getChannel().getId(); | ||
List<User> userName = client.getHelix().getUsers(null, null, Collections.singletonList(exprUserName.getSingle(event))).execute().getUsers(); | ||
String userId = userName.get(0).getId(); | ||
client.getHelix().addChannelVip(null, broadcasterID,userId).execute(); | ||
} | ||
else if (event instanceof CommandEvent) { | ||
String broadcasterID = ((CommandEvent) event).getEvent().getChannel().getId(); | ||
List<User> userName = client.getHelix().getUsers(null, null, Collections.singletonList(exprUserName.getSingle(event))).execute().getUsers(); | ||
String userId = userName.get(0).getId(); | ||
client.getHelix().addChannelVip(null, broadcasterID,userId).execute(); | ||
} | ||
} catch (HystrixRuntimeException e) { | ||
Throwable cause = e.getCause(); | ||
if (cause instanceof ContextedRuntimeException) { | ||
ContextedRuntimeException cre = (ContextedRuntimeException) cause; | ||
Object error = cre.getFirstContextValue("errorMessage"); | ||
if (error == null) { | ||
console.error("Error:[AddChannelVip] You don't have the broadcaster permission to add a vip."); | ||
} | ||
else { | ||
console.error("Error:[AddChannelVip] " + error); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
@Override | ||
public @NotNull String toString(Event event, boolean debug) { | ||
return "add [twitch] channel vip " + exprUserName.toString(event, debug); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public boolean init(Expression<?>[] expressions, int i, @NotNull Kleenean kleenean, SkriptParser.@NotNull ParseResult parseResult) { | ||
this.exprUserName = (Expression<String>) expressions[0]; | ||
return true; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/com/trason/skitch/elements/effects/EffRemoveChannelVip.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,83 @@ | ||
package com.trason.skitch.elements.effects; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.util.Kleenean; | ||
import com.github.twitch4j.helix.domain.User; | ||
import com.netflix.hystrix.exception.HystrixRuntimeException; | ||
import com.trason.skitch.elements.events.bukkit.BridgeEventChat; | ||
import com.trason.skitch.elements.events.custom.CommandEvent; | ||
import com.trason.skitch.util.ConsoleMessages.console; | ||
import jdk.jfr.Name; | ||
import org.apache.commons.lang3.exception.ContextedRuntimeException; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static com.trason.skitch.elements.effects.EffLoginTwitchBot.client; | ||
|
||
@Name("Twitch Remove Channel VIP") | ||
@Description("Removes a VIP from the broadcaster’s chat room.\n" + | ||
"The bot needs broadcaster permission!!! (So only selfbots work here!)") | ||
@Examples("remove twitch channel vip \"username\"") | ||
@Since("1.4.1") | ||
public class EffRemoveChannelVip extends Effect { | ||
static { | ||
// This is the registration of the effect | ||
Skript.registerEffect(EffRemoveChannelVip.class, "remove [twitch] channel vip %string%"); | ||
} | ||
|
||
private Expression<String> exprUserName; | ||
@Override | ||
protected void execute(@NotNull Event event) { | ||
try { | ||
if (event instanceof BridgeEventChat) { | ||
String broadcasterID = ((BridgeEventChat) event).getEvent().getChannel().getId(); | ||
List<User> userName = client.getHelix().getUsers(null, null, Collections.singletonList(exprUserName.getSingle(event))).execute().getUsers(); | ||
String userId = userName.get(0).getId(); | ||
client.getHelix().removeChannelVip(null, broadcasterID,userId).execute(); | ||
} | ||
else if (event instanceof CommandEvent) { | ||
String broadcasterID = ((CommandEvent) event).getEvent().getChannel().getId(); | ||
List<User> userName = client.getHelix().getUsers(null, null, Collections.singletonList(exprUserName.getSingle(event))).execute().getUsers(); | ||
String userId = userName.get(0).getId(); | ||
client.getHelix().removeChannelVip(null, broadcasterID,userId).execute(); | ||
} | ||
} catch (HystrixRuntimeException e) { | ||
Throwable cause = e.getCause(); | ||
if (cause instanceof ContextedRuntimeException) { | ||
ContextedRuntimeException cre = (ContextedRuntimeException) cause; | ||
Object error = cre.getFirstContextValue("errorMessage"); | ||
if (error == null) { | ||
console.error("Error:[RemoveChannelVip] You don't have the broadcaster permission to add a vip."); | ||
} | ||
else { | ||
console.error("Error:[RemoveChannelVip] " + error); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
@Override | ||
public @NotNull String toString(Event event, boolean debug) { | ||
return "add [twitch] channel vip " + exprUserName.toString(event, debug); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public boolean init(Expression<?>[] expressions, int i, @NotNull Kleenean kleenean, SkriptParser.@NotNull ParseResult parseResult) { | ||
this.exprUserName = (Expression<String>) expressions[0]; | ||
return true; | ||
} | ||
} | ||
|
71 changes: 71 additions & 0 deletions
71
src/main/java/com/trason/skitch/elements/expressions/ExprChannelVips.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,71 @@ | ||
package com.trason.skitch.elements.expressions; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import com.github.twitch4j.helix.domain.ChannelVip; | ||
import com.github.twitch4j.helix.domain.ChannelVipList; | ||
import com.trason.skitch.elements.events.bukkit.BridgeEventChat; | ||
import com.trason.skitch.elements.events.custom.CommandEvent; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
|
||
import static com.trason.skitch.elements.effects.EffLoginTwitchBot.client; | ||
|
||
@Name("Channel Vips") | ||
@Description("Gets a list of the channel’s VIPs.") | ||
@Examples("set {_vips::*} to channel vips") | ||
@Since("1.4.1") | ||
public class ExprChannelVips extends SimpleExpression<String> { | ||
|
||
static { | ||
// This is the registration of the expression | ||
Skript.registerExpression(ExprChannelVips.class, String.class, ExpressionType.SIMPLE, "[event-]channel vips"); | ||
} | ||
|
||
@Override | ||
protected String @NotNull [] get(@NotNull Event event) { | ||
if (event instanceof BridgeEventChat) { | ||
String channelId = ((BridgeEventChat) event).getEvent().getChannel().getId(); | ||
ChannelVipList vipList = client.getHelix().getChannelVips(null, channelId, null, 100, null).execute(); | ||
String[] vips = vipList.getData().stream().map(ChannelVip::getUserName).toArray(String[]::new); | ||
return vips; | ||
} | ||
else if (event instanceof CommandEvent) { | ||
String channelId = ((CommandEvent) event).getEvent().getChannel().getId(); | ||
ChannelVipList vipList = client.getHelix().getChannelVips(null, channelId, null, 100, null).execute(); | ||
String[] vips = vipList.getData().stream().map(ChannelVip::getUserName).toArray(String[]::new); | ||
return vips; | ||
} | ||
else | ||
return new String[0]; | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Class<? extends String> getReturnType() { | ||
return String.class; | ||
} | ||
|
||
@Override | ||
public @NotNull String toString(Event event, boolean b) { | ||
return "channel vips"; | ||
} | ||
|
||
@Override | ||
public boolean init(Expression<?>[] expressions, int i, @NotNull Kleenean kleenean, SkriptParser.@NotNull ParseResult parseResult) { | ||
return true; | ||
} | ||
} |