예제 #1
0
    public void Init()
    {
        if (hasInitialized)
        {
            return;
        }
        hasInitialized = true;

        // Checks
        if (configurationPath == "")
        {
            configurationPath = Application.persistentDataPath + "/config.json";
        }
        if (commandPrefix == "" || commandPrefix == null)
        {
            commandPrefix = "!";
        }
        if (commandPrefix.Length > 1)
        {
            Debug.LogError($"TwitchChatClient.Init :: Command prefix length should contain only 1 character. Command prefix: {commandPrefix}");
            return;
        }

        data = TwitchConfiguration.Load(configurationPath);
        if (data == null)
        {
            return;
        }
        Login();
    }
예제 #2
0
    void ShowCommand(TwitchChatCommand chatCommand)
    {
        TwitchConnectData a          = ScriptableObject.CreateInstance <TwitchConnectData>();
        string            parameters = string.Join(" - ", chatCommand.Parameters);
        string            message    =
            $"Command: '{chatCommand.Command}' - Username: {chatCommand.User.DisplayName} - Bits: {chatCommand.Bits} - Sub: {chatCommand.User.IsSub} - Parameters: {parameters}";

        TwitchChatClient.instance.SendChatMessage($"Hello {chatCommand.User.DisplayName}! I received your message.");
        TwitchChatClient.instance.SendChatMessage(
            $"Hello {chatCommand.User.DisplayName}! This message will be sent in 5 seconds.", 5);

        AddText(message);
    }
예제 #3
0
    public static TwitchConnectData Load(string path)
    {
        if (File.Exists(path))
        {
            string            fileText          = File.ReadAllText(path);
            TwitchConnectData twitchConnectData = JsonConvert.DeserializeObject <TwitchConnectData>(fileText);
            if (!twitchConnectData.IsValid())
            {
                Debug.Log(twitchConnectData.username);
                Debug.LogError($"TwitchConfiguration.Load :: Some mandatory fields are empty: {path}");
                return(null);
            }


            return(twitchConnectData);
        }
        Debug.LogError($"TwitchConfiguration.Load :: Error loading the data, path does not exist: {path}");
        return(null);
    }
예제 #4
0
    private void ShowCommand(TwitchChatCommand chatCommand)
    {
        TwitchConnectData a          = ScriptableObject.CreateInstance <TwitchConnectData>();
        string            parameters = string.Join(" - ", chatCommand.Parameters);
        string            message    =
            $"Command: '{chatCommand.Command}' - " +
            $"Username: {chatCommand.User.DisplayName} - " +
            $"Bits: {chatCommand.Bits} - " +
            $"Sub: {chatCommand.User.IsSub} - " +
            $"Badges count: {chatCommand.User.Badges.Count} - " +
            $"Badges: {string.Join("/", chatCommand.User.Badges.Select(badge => badge.Name))} - " +
            $"Badge versions: {string.Join("/", chatCommand.User.Badges.Select(badge => badge.Version))} - " +
            $"Parameters: {parameters}";

        TwitchChatClient.instance.SendChatMessage($"Hello {chatCommand.User.DisplayName}! I received your message.");
        TwitchChatClient.instance.SendChatMessage(
            $"Hello {chatCommand.User.DisplayName}! This message will be sent in 5 seconds.", 5);

        AddText(message);
    }