Exemple #1
0
        public Updates CallbackMessageHandler(Updates updates, VkCoreApiBase vkApi)
        {
            var msg = Message.FromJson(new VkResponse(updates.Object));

            vkApi.Core.Log.Debug($"message from Group:{updates.GroupId} and Chat:{msg.ChatId} by {msg.FromId} Action:{msg.Action?.Type?.ToString() ?? "text"}  \"{msg.Text}\"");
            return(updates);
        }
Exemple #2
0
        public Updates CallbackVkPayHandler(Updates updates, VkCoreApiBase vkApi)
        {
            var msg  = new VkResponse(updates.Object);
            var user = new User(vkApi, msg["from_id"]);

            vkApi.Core.Log.Debug($"amount: {msg["amount"] / 1000}, from: {user.FirstName} {user.LastName}, description: {msg["description"]}");
            return(updates);
        }
Exemple #3
0
        internal Group(VkCoreApiBase vkApi, long id)
        {
            VkApi = vkApi;
            Id    = id;
            var g = GetApiGroup();

            Name = g.Name;
        }
Exemple #4
0
        public static async Task <VkNet.Model.Group> GetApiGroupByIdAsync(VkCoreApiBase vkApi, long id)
        {
            IReadOnlyCollection <VkNet.Model.Group> groups;

            groups = await vkApi.Groups.GetByIdAsync(null, $"club{Math.Abs(-id)}", null);

            return(groups.First());
        }
Exemple #5
0
        internal void PluginCallbackHandler(ref Updates updates, VkCoreApiBase vkApi)
        {
            foreach (var method in _callbackHandlers)
            {
                if (!IsAvailable(method.Key, vkApi.GroupId))
                {
                    continue;
                }

                if (method.Value != updates.Type)
                {
                    continue;
                }
                var _method = method.Key;

                object pluginInstance = _plugins.FirstOrDefault(plugin => _method.DeclaringType.IsInstanceOfType(plugin)) ?? _method.DeclaringType;
                if (pluginInstance == null)
                {
                    continue;
                }

                updates = _method.Invoke(pluginInstance, new object[] { updates, vkApi }) as Updates;
            }
        }
Exemple #6
0
 public Chat(VkCoreApiBase vkApi, long peerId) : base(vkApi, peerId)
 {
     Settings = new ChatSettings(this);
 }
        public IActionResult Callback([FromBody] Updates updates)
        {
            try
            {
                if (updates.SecretKey != _secretKey)
                {
                    return(BadRequest("Secret key is incorrect!"));
                }

                if (updates.Type == CallbackReceive.Confirmation)
                {
                    return(Ok(Core.Configuration.GetValue($"Config:Groups:{updates.GroupId}:Confirmation", Core.Configuration["Config:Confirmation"])));
                }

                new Thread(() =>
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    try
                    {
                        VkCoreApiBase vkApi = Core.VkApi.Get(updates.GroupId);
                        Core.PluginManager.PluginCallbackHandler(ref updates, vkApi);
                        if (updates == null)
                        {
                            return;
                        }

                        var response = new VkResponse(updates.Object);

                        var update = GroupUpdate.FromJson(response);

                        switch (updates.Type)
                        {
                        case CallbackReceive.Message.New:
                            {
                                var msg = Message.FromJson(response);

                                if (msg.Date.HasValue && (DateTime.UtcNow - msg.Date.Value).TotalSeconds > _messageResendBlockTime)
                                {
                                    return;
                                }

                                IUser user    = vkApi.GetUser(msg.FromId.Value);
                                BaseChat chat = vkApi.GetChat(msg.PeerId.Value);

                                lock (chat)
                                {
                                    vkApi.MessageHandler.OnMessage(user, msg.Text, chat, msg);
                                }
                                break;
                            }

                        case CallbackReceive.Message.Event:
                            {
                                var msgEvent = MessageEvent.FromJson(response);

                                IUser user = vkApi.GetUser(msgEvent.UserId.Value);

                                if (user is User _user)
                                {
                                    BaseChat chat = vkApi.GetChat(msgEvent.PeerId.Value);

                                    lock (chat)
                                    {
                                        vkApi.MessageHandler.ClickButton(chat, _user, new UI.EventId(msgEvent.EventId), msgEvent.Payload);
                                    }
                                }
                                break;
                            }

                        case CallbackReceive.Group.OfficersEdit:
                            {
                                var msgEvent = GroupOfficersEdit.FromJson(response);

                                var userId = msgEvent.UserId.Value;

                                vkApi.Group.Managers.Remove(userId);

                                var level = (int)msgEvent.LevelNew.Value;

                                if (level > 0)
                                {
                                    var permissionLevel = (int)Math.Pow(10, level + 1);
                                    vkApi.Group.Managers.Add(userId, (UserPermission)level);
                                }
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Core.Log.Error(e.ToString());
                    }
                    Core.Log.Debug(stopwatch.ElapsedMilliseconds.ToString());
                    stopwatch.Stop();
                })
                {
                    IsBackground = true
                }.Start();
            }
Exemple #8
0
 public static VkNet.Model.Group GetApiGroupById(VkCoreApiBase vkApi, long id)
 {
     return(vkApi.Groups.GetById(null, $"club{Math.Abs(-id)}", null).First());
 }
Exemple #9
0
 public Conversation(VkCoreApiBase vkApi, long peerId) : base(vkApi, peerId)
 {
     User = vkApi.GetUser <User>(peerId);
 }
Exemple #10
0
 public LogChat(VkCoreApiBase vkApi) : base(vkApi, vkApi.Core.Configuration.GetValue <long>("Config:Log:ChatId", -1))
 {
     MinValue = Enum.Parse <LogValueType>(VkApi.Core.Configuration["Config:Log:MinValue"]);
     MaxValue = Enum.Parse <LogValueType>(VkApi.Core.Configuration["Config:Log:MaxValue"]);
 }