This plugin is currently marked as broken and unavailable for download
MrBlue
Provides an API for integration with Twitch

Supported Games
GameServerKingsGameServerKings

Twitch provides a basic integration with Twitch.tv for plugins to utilize. There isn't really much use for it on its own, it merely acts as a gateway for other plugins to do things such as check when a user follows or unfollows a Twitch channel.

Permissions

  • twitch.admin -- Allows player to use the twitch user/channel commands

Commands

This plugin offers both chat and console commands. When using a command chat, prefix with a forward slash: /.

  • twitch user <twitch name or id> -- Checks if the user is a valid Twitch user and following the configured channel
  • twitch channel <twitch channel or id> -- Set the default Twitch channel to use if none provided via API

Configuration

{
  "Default Twitch channel ID": ""
}

Localization

For Developers

API

Get the default Twitch channel:

private string GetChannel()

Note: This will not provide any channel passed to this plugin from other plugins.

Get a Twitch user using the provided login or user ID:

private void GetTwitchUser(string loginOrUserId, Action<TwitchUser> callback)

Note: If no valid Twitch user is found, the callback will return null.

Check is the provided login or user ID is a follower on Twitch:

private void IsFollowing(string loginOrUserId, Action<bool?> callback)

Note: The callback result can be true, false, or null.

Check is the provided login or user ID is a follower on Twitch and stores in data cache:

private void IsFollowing(string loginOrUserId, IPlayer player, Action<bool?> callback)

If requiring this plugin for your own plugin to work, you can use this at the top of your plugin:

// Requires: Twitch

You should also be setting a PluginReference in the class where the hook calls will happen:

[PluginReference]
private Plugin Twitch;

Example:

private void CommandExample(IPlayer player, string command, string[] args)
{
    if (args.Length < 1)
    {
        player.Reply("Usage: /command <twitch user name>");
        return;
    }

    Action<bool?> callback = result =>
    {
        if (result != null && (bool)result)
        {
            player.Reply("Thanks for following!");
        }
        else
        {
            player.Reply("Please follow us on Twitch!");
        }
    };
    Twitch?.Call("IsFollowing", args[0], player, callback);
}

Hooks

Called when a player is recognized as a follower on Twitch

private void OnTwitchFollow(IPlayer player)

Called when a player is recognized as no longer following on Twitch

private void OnTwitchUnfollow(IPlayer player)

Example:

private void OnTwitchFollow(IPlayer player)
{
    Log($"{player.Name} ({player.Id}) is a follower on Twitch!");
}

MIT License, with distribution exclusivity for uMod.org


Copyright (c) 2020 Wulf


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:


The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.


THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.