Giter VIP home page Giter VIP logo

vknetextend's People

Contributors

cactucatu4eckuu avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

modnick

vknetextend's Issues

Бесконечно вызывает событие

Если отправить боту сообщение, то он начинает его бесконечно отправлять, хотя это не подразумевается
Скриншот

class MainClass
    {
        private static VkApi api = new VkApi();
        public static void Init(string token)
        {
            ApiAuthParams authParams = new ApiAuthParams();
            authParams.AccessToken = token;
            api.Authorize(authParams);
            if (api.IsAuthorized)
                Task.Run(() => botStarted());
        }

        private static void botStarted()
        {
            MessageBox.Show("started", "started", MessageBoxButtons.OK, MessageBoxIcon.Information);
            MessageLongPollWatcherOptions options = new MessageLongPollWatcherOptions();
            VkNetExtMessageLongPollWatcher watcher = new VkNetExtMessageLongPollWatcher(options, api);
            watcher.NewMessages += newMessage;
            watcher.StartWatchAsync();
        }

        private static void newMessage(IMessageLongPollWatcher watcher, IEnumerable<Message> messages)
        {
            var messagesList = messages.ToArray();
            if (messagesList.Length < 1) return;
            //MessageBox.Show($"message count:{messagesList.Count}", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            for (int i = 0; i < messagesList.Length; i++)
            {
                var message = messagesList[i];
                string text = message.Text;
                long? peerId = message.PeerId != null ? message.PeerId : message.PeerId;
                long? userId = message.UserId != null ? message.UserId : message.PeerId;

                if (peerId == api.UserId) continue;

                if(peerId != userId)
                {

                }
                else
                {
                    MessagesSendParams messageSend = new MessagesSendParams();
                    messageSend.PeerId = userId;
                    messageSend.Message = text;
                    messageSend.RandomId = Environment.TickCount;
                    api.Messages.Send(messageSend);
                }
            }
            
        }

    }

Ссылка на объект не указывает на экземпляр объекта.

protected async Task WatchStepAsync(object state)
        {
            if (Active)
            {
                var history = await GetLongPollHistoryAsync().ConfigureAwait(true);

                if (history != null)
                {
                    if (history.History.Count > 0)
                    {
                        CurrentSleepSteps = 1;

                        NewEvents?.Invoke(this, history);
                        if (history.Messages.Count > 0)
                            NewMessages?.Invoke(this, history.Messages);
                    }
                    else
                    {
                        if (CurrentSleepSteps < _options.MaxSleepSteps)
                            CurrentSleepSteps++;
                    }
                    _watchTimer?.Change(CurrentSleepSteps * _options.StepSleepTimeMsec, Timeout.Infinite);
                }
                else
                {
                    // TODO: Define situation when exceptions occured
                    _watchTimer?.Change(CurrentSleepSteps * _options.StepSleepTimeMsec, Timeout.Infinite);
                }
            }
        }
        private void _watchStep(object state) => WatchStepAsync(state).GetAwaiter().GetResult();// исключение  в этой строке System.NullReferenceException

Мой код

void server()
        {
            var PollServer = api.Messages.GetLongPollServer(true);

            VkNetExtend.MessageLongPoll.MessageLongPollWatcherOptions longPollWatcherOptions = new VkNetExtend.MessageLongPoll.MessageLongPollWatcherOptions();
            VkNetExtend.MessageLongPoll.VkNetExtMessageLongPollWatcher Watcher = new VkNetExtend.MessageLongPoll.VkNetExtMessageLongPollWatcher(longPollWatcherOptions, api);
            VkNetExtend.MessageLongPoll.Models.StartWatchModel startWatchModel = new VkNetExtend.MessageLongPoll.Models.StartWatchModel();
            
            Watcher.StartWatchAsync(startWatchModel);
            Watcher.NewMessages += Watcher_NewMessages;

        }

        private void Watcher_NewMessages(VkNetExtend.MessageLongPoll.IMessageLongPollWatcher watcher,IEnumerable<VkNet.Model.Message> messages)
        {
            MessageBox.Show("Новое сообщение!");  
            var message = messages.ToArray();
            for (int i = 0; i < message.Length; i++)
            {
                commandReact(message[i].Body, message[i].FromId);
            }
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.