コード例 #1
0
        public UserData GetMyInfo()
        {
            if (!_account.IsAuthenticated)
            {
                _account.RaiseError("Authentication is required to use this query. Set the Dlive.AuthorizationToken property with your user token to authenticate");
                return(new UserData());
            }

            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLResponse response = _account.Client.SendQueryAsync(GraphqlHelper.GetQueryString(QueryType.ME)).Result;

            if (response.Data.me == null)
            {
                throw new AccountException($"User data was not received, this could be caused by an expired user token!");
            }

            RawUserData userData = response.GetDataFieldAs <RawUserData>("me");

            return(userData.ToUserData());
        }
コード例 #2
0
        public void SetAboutPanelOrder(AboutPanel[] panels)
        {
            if (!_account.IsAuthenticated)
            {
                _account.RaiseError(
                    "Authentication is required to use mutations. Set the AuthorizationToken property with your user token to authenticate");
            }

            List <int> ids = new List <int>();

            foreach (AboutPanel panel in panels)
            {
                ids.Add(panel.PanelId);
            }

            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLRequest _req = new GraphQLRequest
            {
                Query = $"mutation{{panelDelete(input:{{ ids: {ids.ToArray()} }}) {{ err {{ message }}}}}}"
            };

            GraphQLResponse res = Task.Run(() => _account.Client.SendMutationAsync(_req)).Result;

            if (res.Errors != null)
            {
                _account.RaiseError($"An error occured while updating panel order: {res.Errors[0].Message}");
            }
        }
コード例 #3
0
        public void RemoveModerator(string moderatorUsername)
        {
            if (!_account.IsAuthenticated)
            {
                _account.RaiseError(
                    "Authentication is required to use mutations. Set the AuthorizationToken property with your user token to authenticate");
            }

            GraphQLRequest _req = new GraphQLRequest
            {
                Query = $"mutation{{moderatorRemove(username: \"{moderatorUsername}\") {{ err {{ message }}}}}}"
            };

            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLResponse res = Task.Run(() => _account.Client.SendMutationAsync(_req)).Result;

            if (res.Errors != null)
            {
                _account.RaiseError($"An error occured while removing moderator: {res.Errors[0].Message}");
            }
        }
コード例 #4
0
        public void UpdateAboutPanel(AboutPanel panel)
        {
            if (!_account.IsAuthenticated)
            {
                _account.RaiseError(
                    "Authentication is required to use mutations. Set the AuthorizationToken property with your user token to authenticate");
            }

            GraphQLRequest _req = new GraphQLRequest
            {
                Query =
                    $"mutation{{panelUpdate(input:{{ id: {panel.PanelId}, title: \"{panel.PanelTitle}\", body: \"{panel.PanelText}\", imageURL: \"{(panel.PanelImageUrl == null ? "" : panel.PanelImageUrl.ToString())}\", imageLinkURL: \"{(panel.PanelUrlDestination == null ? "" : panel.PanelUrlDestination.ToString())}\" }}) {{ err {{ message }}}}}}"
            };

            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLResponse res = Task.Run(() => _account.Client.SendMutationAsync(_req)).Result;

            if (res.Errors != null)
            {
                _account.RaiseError($"An error occured while updating panel: {res.Errors[0].Message}");
            }
        }
コード例 #5
0
        public void DeleteAboutPanel(int id)
        {
            if (!_account.IsAuthenticated)
            {
                _account.RaiseError(
                    "Authentication is required to use mutations. Set the AuthorizationToken property with your user token to authenticate");
            }

            GraphQLRequest _req = new GraphQLRequest
            {
                Query = $"mutation{{panelDelete(input:{{ id: {id} }}) {{ err {{ message }}}}}}"
            };

            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLResponse res = Task.Run(() => _account.Client.SendMutationAsync(_req)).Result;

            if (res.Errors != null)
            {
                _account.RaiseError($"An error occured while deleting panel: {res.Errors[0].Message}");
            }
        }
コード例 #6
0
        public void AddChestValue(int amountToAdd)
        {
            if (!_account.IsAuthenticated)
            {
                _account.RaiseError(
                    "Authentication is required to use mutations. Set the AuthorizationToken property with your user token to authenticate");
            }

            GraphQLRequest _req = new GraphQLRequest
            {
                Query = $"mutation{{treasureChestUserTransfer(amount:\"{amountToAdd}\") {{ err {{ message }}}}}}"
            };

            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLResponse res = Task.Run(() => _account.Client.SendMutationAsync(_req)).Result;

            if (res.Errors != null)
            {
                _account.RaiseError($"An error occured while adding value to chest: {res.Errors[0].Message}");
            }
        }
コード例 #7
0
        public void AddAboutPanel(AboutPanel panel)
        {
            if (!_account.IsAuthenticated)
            {
                _account.RaiseError(
                    "Authentication is required to use mutations. Set the AuthorizationToken property with your user token to authenticate");
            }

            GraphQLRequest _req = new GraphQLRequest
            {
                Query =
                    $"mutation{{panelAdd(input:{{ type: {panel.PanelType} }}) {{ err {{ message }} panel {{ id }}}}}}"
            };

            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLResponse res = Task.Run(() => _account.Client.SendMutationAsync(_req)).Result;

            if (res.Errors != null)
            {
                _account.RaiseError($"An error occured while creating a new panel: {res.Errors[0].Message}");
            }

            UpdateAboutPanel(new AboutPanel(int.Parse(res.Data.panel.id.ToString()), panel.PanelType, panel.PanelTitle,
                                            panel.PanelText, panel.PanelImageUrl, panel.PanelUrlDestination));
        }
コード例 #8
0
        public void SetSubSettings(string badgeText, string badgeColor, string textColor, string[] benefits)
        {
            if (!_account.IsAuthenticated)
            {
                _account.RaiseError(
                    "Authentication is required to use mutations. Set the AuthorizationToken property with your user token to authenticate");
            }

            GraphQLRequest _req = new GraphQLRequest
            {
                Query =
                    $"mutation{{subSettingSet(subSetting:{{ badgeText: \"{badgeText}\", badgeColor: \"{badgeColor}\", textColor: \"{textColor}\", benefits: {benefits} }}) {{ err {{ message }}}}}}"
            };

            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLResponse res = Task.Run(() => _account.Client.SendMutationAsync(_req)).Result;

            if (res.Errors != null)
            {
                _account.RaiseError($"An error occured while setting sub settings: {res.Errors[0].Message}");
            }
        }
コード例 #9
0
        public void SetChatCooldown(int cooldownSeconds)
        {
            if (!_account.IsAuthenticated)
            {
                _account.RaiseError(
                    "Authentication is required to use mutations. Set the AuthorizationToken property with your user token to authenticate");
            }

            GraphQLRequest _req = new GraphQLRequest
            {
                Query = $"mutation{{chatIntervalSet(seconds: {cooldownSeconds}) {{ err {{ message }}}}}}"
            };

            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLResponse res = Task.Run(() => _account.Client.SendMutationAsync(_req)).Result;

            if (res.Errors != null)
            {
                _account.RaiseError($"An error occured while changing chat cooldown: {res.Errors[0].Message}");
            }
        }
コード例 #10
0
        public void SetEmoteMode(bool disallowPersonalEmotes, bool disallowChannelEmotes,
                                 bool disallowGlobalEmotes)
        {
            if (!_account.IsAuthenticated)
            {
                _account.RaiseError(
                    "Authentication is required to use mutations. Set the AuthorizationToken property with your user token to authenticate");
            }

            GraphQLRequest _req = new GraphQLRequest
            {
                Query =
                    $"mutation{{emoteModeSet(emoteMode:{{ NoMineEmote: {disallowPersonalEmotes}, NoAllEmote: {disallowChannelEmotes}, NoGlobalEmote: {disallowGlobalEmotes}}}) {{ err {{ message }}}}}}"
            };

            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLResponse res = Task.Run(() => _account.Client.SendMutationAsync(_req)).Result;

            if (res.Errors != null)
            {
                _account.RaiseError($"An error occured while changing emoteMode: {res.Errors[0].Message}");
            }
        }
コード例 #11
0
        public void TimeoutUser(string streamer, string timeoutUsername, int minutes)
        {
            if (!_account.IsAuthenticated)
            {
                _account.RaiseError(
                    "Authentication is required to use mutations. Set the AuthorizationToken property with your user token to authenticate");
            }

            GraphQLRequest _req = new GraphQLRequest
            {
                Query =
                    $"mutation{{userTimeoutSet(streamer: \"{streamer}\", username: \"{timeoutUsername}\", duration: {minutes}) {{ err {{ message }}}}}}"
            };

            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLResponse res = Task.Run(() => _account.Client.SendMutationAsync(_req)).Result;

            if (res.Errors != null)
            {
                _account.RaiseError($"An error occured while setting timeout for user: {res.Errors[0].Message}");
            }
        }
コード例 #12
0
        public void SendChatMessage(string channelUsername, string message)
        {
            if (!_account.IsAuthenticated)
            {
                _account.RaiseError(
                    "Authentication is required to use mutations. Set the AuthorizationToken property with your user token to authenticate");
            }

            GraphQLRequest _req = new GraphQLRequest
            {
                Query =
                    $"mutation{{sendStreamchatMessage(input:{{ streamer: \"{channelUsername}\", message: \"{message}\", roomRole: Owner, subscribing: true}}) {{ err {{ message }}}}}}"
            };

            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLResponse res = Task.Run(() => _account.Client.SendMutationAsync(_req)).Result;

            if (res.Errors != null)
            {
                _account.RaiseError($"An error occured while sending chat message: {res.Errors[0].Message}");
            }
        }
コード例 #13
0
        /// <summary>
        /// This method might take some time to complete depending on the number of subscribers and other queries
        /// that are sent while it's running.
        /// </summary>
        /// <returns>An array of public user data objects, one for each subscriber</returns>
        public async Task <PublicUserData[]> GetSubscribers()
        {
            List <PublicUserData> subscribers = new List <PublicUserData>();

            if (!_account.IsAuthenticated)
            {
                _account.RaiseError("Authentication is required to use this query. Set the Dlive.AuthorizationToken property with your user token to authenticate");
                return(subscribers.ToArray());
            }

            int cursor = -1;

            UserData userData = _account.Query.GetMyInfo();

            if (userData.Private.SubscriberCount == 0)
            {
                return(subscribers.ToArray());
            }

            do
            {
                if (!Dlive.CanExecuteQuery())
                {
                    await Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds);
                }
                Dlive.IncreaseQueryCounter();

                GraphQLResponse response = _account.Client.SendQueryAsync(GraphqlHelper.GetQueryString(QueryType.SUBSCRIBERS,
                                                                                                       new string[] { userData.Public.Username, "50", cursor.ToString() })).Result;

                JArray subscriberList = [email protected];

                foreach (JObject subscriber in subscriberList)
                {
                    RawUserData subscriberData = new RawUserData(subscriber["subscriber"] as JObject);
                    subscribers.Add(subscriberData.ToPublicUserData());
                }

                cursor += 50;
                if (userData.Private.SubscriberCount > 50)
                {
                    await Task.Delay(200);
                }
            }while (cursor < userData.Private.SubscriberCount);

            return(subscribers.ToArray());
        }
コード例 #14
0
ファイル: PublicQuery.cs プロジェクト: OfficialHisha/DSharp
        public static async Task <PublicUserData[]> GetFollowersForUser(string username)
        {
            int cursor = -1;

            List <PublicUserData> followers = new List <PublicUserData>();

            PublicUserData userData = GetPublicInfo(username);

            if (userData.NumFollowers == 0)
            {
                return(followers.ToArray());
            }

            do
            {
                if (!Dlive.CanExecuteQuery())
                {
                    await Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds);
                }
                Dlive.IncreaseQueryCounter();

                GraphQLResponse response = _publicClient.SendQueryAsync(GraphqlHelper.GetQueryString(QueryType.FOLLOWERS,
                                                                                                     new string[] { userData.Username, "50", cursor.ToString() })).Result;

                JArray followerList = response.Data.user.followers.list;

                foreach (JObject follower in followerList)
                {
                    RawUserData followerData = new RawUserData(follower);
                    followers.Add(followerData.ToPublicUserData());
                }

                cursor += 50;
                if (userData.NumFollowers > 50)
                {
                    await Task.Delay(200);
                }
            }while (cursor < userData.NumFollowers);

            return(followers.ToArray());
        }
コード例 #15
0
ファイル: PublicQuery.cs プロジェクト: OfficialHisha/DSharp
        public static PublicUserData GetPublicInfo(string username)
        {
            if (!Dlive.CanExecuteQuery())
            {
                Task.Delay((Dlive.NextIntervalReset - DateTime.Now).Milliseconds).Wait();
            }
            Dlive.IncreaseQueryCounter();

            GraphQLResponse response = _publicClient.SendQueryAsync(GraphqlHelper.GetQueryString(QueryType.USER, new string[] { username })).Result;

            PublicUserData userData;

            if (response.Data.user != null)
            {
                userData = response.GetDataFieldAs <RawUserData>("user").ToPublicUserData();
            }
            else
            {
                userData = new PublicUserData("invalid user", "Invalid User", PartnerStatus.NONE, false, "", null, true, null, null, 0, 0, 0, 0);
            }

            return(userData);
        }