Squiso is een gratis, krachtige automatiseringstool waarmee je je Twitch-stream kunt aanpassen met behulp van eenvoudige scripts.
Hoe je automatisch nieuwe Twitch-clips op Discord plaatst
In dit voorbeeld wordt elke 10 minuten gecontroleerd op nieuwe clips en of er nieuwe clips zijn gemaakt door een specifieke gebruiker. Vervolgens worden deze op een Discord-server geplaatst.
Scriptvoorbeeld
import com.squiso.*;
import com.squiso.exception.*;
import com.squiso.scripting.*;
import com.squiso.scripting.data.*;
import com.squiso.keyboard.*;
import com.squiso.twitch.*;
import com.squiso.datatypes.*;
import com.squiso.utils.*;
// Important - Please do not change the row below - otherwise you will get a compilation error!
public class Script_Example extends SquisoScript {
@Override
public void onEveryMinute(OnEveryMinuteData data, API api) throws SquisoException {
// Do this every 10 minutes
if (data.is(10)) {
// Save the time right now
SquisoDate now = SquisoDate.nowUTC();
api.log("[Example_AutomaticallyPostTwitchClipsDiscord] Time now is: " + now.toYYYYMMDDHHMMSS());
// Get all the 100 latest clips
SquisoList<TwitchClip> allClips = api.getTwitchClips();
api.log("[Example_AutomaticallyPostTwitchClipsDiscord] Found " + allClips.size() + " clips");
for (TwitchClip clip : allClips) {
// If the creator is not "Squiso", then skip and continue to the next clip
if (!clip.getCreator().equalsIgnoreCase("Squiso")) {
continue;
}
// Get the number of seconds since the clip was created from now
SquisoInteger secondsSinceCreated = clip.getCreated().getSecondsSince(now);
api.log("[Example_AutomaticallyPostTwitchClipsDiscord] The clip \"" + clip.getTitle() + "\" was created " + secondsSinceCreated + " seconds ago (" + clip.getCreated().toYYYYMMDDHHMMSS() + ") by \"" + clip.getCreator() + "\".");
// 10 minutes is 10*60=600 seconds
SquisoInteger threshold = new SquisoInteger(60 * 10);
// Just log the check
api.log("[Example_AutomaticallyPostTwitchClipsDiscord] Checking if clip is below the threshold (" + secondsSinceCreated + " < " + threshold + ")....");
// If the clip was created in the last 10 minutes
if (secondsSinceCreated.isLessThan(threshold.get())) {
api.log("[Example_AutomaticallyPostTwitchClipsDiscord] Posting clip \"" + clip.getTitle() + "\" to Discord");
// Compose a Discord message
SquisoString discordMessage = new SquisoString("");
discordMessage.append("A new clip was created by " + clip.getCreator() + "!");
discordMessage.append("\n");
discordMessage.append(clip.getURL());
// Send the message to the Discord channel
SquisoString discordWebhook = new SquisoString("https://discord.com/api/webhooks/abc/123");
api.sendSimpleDiscordMessage(discordWebhook, discordMessage);
}
}
}
}
}