private void SendNewFollowEvent(Guid profileId, Guid followerId)
        {
            var followEvent = new FollowEvent
            {
                ProfileId  = profileId,
                FollowerId = followerId
            };

            var createFollowEvent = new Event <FollowEvent>
            {
                Data = followEvent
            };

            _producer.Send("Create-Follow", createFollowEvent);
        }
Example #2
0
        public async Task CreateFollowWhileFollowExists()
        {
            var follow = new Follow {
                Profile = TestProfile1, Follower = TestProfile2
            };
            var followEvent = new FollowEvent {
                FollowerId = follow.Follower.Id, ProfileId = follow.Profile.Id
            };

            Context.Follows.Add(follow);
            await Context.SaveChangesAsync();

            var success = await _createFollowHandler.Consume(JsonConvert.SerializeObject(followEvent));

            Assert.False(success);
        }
Example #3
0
        protected override async Task OnFollowAsync(FollowEvent ev)
        {
            // Store source information which follows the bot.
            await sourceState.AddAsync(ev.Source.Type.ToString(), ev.Source.Id);

            var userName = "";

            if (!string.IsNullOrEmpty(ev.Source.Id))
            {
                var userProfile = await messagingClient.GetUserProfileAsync(ev.Source.Id);

                userName = userProfile?.DisplayName ?? "";
            }

            await messagingClient.ReplyMessageAsync(ev.ReplyToken, $"Hello {userName}! Thank you for following !");
        }
        public async Task DeleteFollowWhileFollowExists()
        {
            var followEvent = new FollowEvent
            {
                ProfileId  = TestProfile1.Id,
                FollowerId = TestProfile2.Id
            };

            Context.Follow.Add(new Follow {
                Id = new Guid(), Profile = TestProfile1, Follower = TestProfile2
            });
            await Context.SaveChangesAsync();

            var success = await _deleteFollowHandler.Consume(JsonConvert.SerializeObject(followEvent));

            Assert.True(success);
        }
Example #5
0
        protected override async Task OnFollowAsync(FollowEvent ev)
        {
            Log.WriteInfo($"SourceType:{ev.Source.Type}, SourceId:{ev.Source.Id}");

            await SourceState.AddAsync(ev.Source.Type.ToString(), ev.Source.Id);

            var userName = "";

            if (!string.IsNullOrEmpty(ev.Source.Id))
            {
                var userProfile = await MessagingClient.GetUserProfileAsync(ev.Source.Id);

                userName = userProfile?.DisplayName ?? "";
            }

            await MessagingClient.ReplyMessageAsync(ev.ReplyToken, $"Hello {userName}! Thank you for following !");
        }
Example #6
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            IController sender = actionInput.Controller;

            var myBehaviors = sender.Thing.Behaviors;

            var followingBehavior = myBehaviors.FindFirst <FollowingBehavior>();

            if (followingBehavior != null)
            {
                var target = followingBehavior.Target;
                if (target != null)
                {
                    var targetBehaviors  = target.Behaviors;
                    var followedBehavior = targetBehaviors.FindFirst <FollowedBehavior>();
                    if (followedBehavior != null)
                    {
                        lock (followedBehavior.Followers)
                        {
                            followedBehavior.Followers.Remove(sender.Thing);
                            if (followedBehavior.Followers.Count == 0)
                            {
                                targetBehaviors.Remove(followedBehavior);
                            }
                        }
                    }
                }

                myBehaviors.Remove(followingBehavior);
            }
            else
            {
                var message = new ContextualString(sender.Thing, null)
                {
                    ToOriginator = "You aren't following anybody."
                };

                var senseMessage = new SensoryMessage(SensoryType.All, 100, message);

                var followEvent = new FollowEvent(sender.Thing, senseMessage, sender.Thing, null);

                // Broadcast the event
                sender.Thing.Eventing.OnMiscellaneousEvent(followEvent, EventScope.ParentsDown);
            }
        }
Example #7
0
        // 友達追加時の処理
        protected override async Task OnFollowAsync(FollowEvent ev)
        {
            // LINEのユーザ名を取得
            var userName = "";

            if (!string.IsNullOrEmpty(ev.Source.Id))
            {
                var userProfile = await messagingClient.GetUserProfileAsync(ev.Source.Id);

                userName = userProfile?.DisplayName ?? "";
            }

            // 使い方をリプライ
            await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                    $"{userName}さん! 友達追加ありがとうございます!\n\n" +
                                                    "本Botでは「おすすめ」と呟くと、ここ最近の人気レシピを4品お知らせします。\n" +
                                                    "それ以外の言葉(食材名など)を呟くと、それを使用したレシピを4品お知らせします。");
        }
        public async Task <bool> Consume(string message)
        {
            FollowEvent followEvent = JsonConvert.DeserializeObject <FollowEvent>(message);

            Domain.Entities.Profile profile = await _context.Profiles.FindAsync(followEvent.ProfileId);

            Domain.Entities.Profile follower = await _context.Profiles.FindAsync(followEvent.FollowerId);

            Domain.Entities.Follow follow = await _context.Follows.FirstOrDefaultAsync(x =>
                                                                                       x.Profile == profile && x.Follower == follower);

            if (follow != null)
            {
                _context.Follows.Remove(follow);
                return(await _context.SaveChangesAsync() > 0);
            }

            return(false);
        }
Example #9
0
        /// <summary>Adds the new target.</summary>
        /// <remarks>Precondition: this.target is null, newTarget is non-null.</remarks>
        /// <param name="newTarget">The new target.</param>
        private void AddTarget(Thing newTarget)
        {
            var self = this.Parent;

            if (self != null)
            {
                var message     = this.CreateFollowMessage(self, newTarget);
                var followEvent = new FollowEvent(self, message, self, newTarget);

                self.Eventing.OnMovementRequest(followEvent, EventScope.ParentsDown);

                if (!followEvent.IsCancelled)
                {
                    this.target = new SimpleWeakReference <Thing>(newTarget);
                    newTarget.Eventing.MovementEvent += this.ProcessMovementEvent;
                    self.Eventing.OnMovementEvent(followEvent, EventScope.ParentsDown);
                }
            }
        }
Example #10
0
 protected override async Task OnFollowAsync(FollowEvent ev)
 {
     await _messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                              new List <ISendMessage> {
         new TextMessage("機器人可查詢附近口罩庫存數量"),
         new TextMessage("查詢方式: 傳送 LINE 定位"),
         new TextMessage("資料來源: 健康保險資料開放服務"),
         new ImageMessage(
             "https://fysh711426.github.io/iMaskMap/image/mask_info.jpg",
             "https://fysh711426.github.io/iMaskMap/image/mask_info_preview.jpg",
             new QuickReply
         {
             Items = new List <QuickReplyButtonObject>
             {
                 new QuickReplyButtonObject(
                     new LocationTemplateAction("查詢"))
             }
         })
     });
 }
Example #11
0
        /// <summary>
        /// Stops following the current target.
        /// Precondition: this.target is non-null.
        /// </summary>
        private void RemoveTarget()
        {
            var self = this.Parent;
            if (self != null)
            {
                var oldTarget = this.target.Target;

                if (oldTarget != null)
                {
                    // Stop tracking the old target's movements
                    this.target.Target.Eventing.MovementEvent -= this.ProcessMovementEvent;

                    // Create an event with the appropriate "unfollow" sensory messages
                    var message = this.CreateUnfollowMessage(this.Parent, oldTarget);
                    var followEvent = new FollowEvent(this.Parent, message, this.Parent, oldTarget);

                    this.Parent.Eventing.OnMovementRequest(followEvent, EventScope.ParentsDown);

                    if (!followEvent.IsCancelled)
                    {
                        // Finally make the change
                        this.target.Target = null;

                        // Broadcast the change
                        this.Parent.Eventing.OnMovementEvent(followEvent, EventScope.ParentsDown);
                    }
                }
            }
        }
Example #12
0
 /// <summary>
 /// 友達追加時の処理
 /// </summary>
 protected override async Task OnFollowAsync(FollowEvent ev)
 {
     // Botの使い方をリプライ
     await this.messagingClient.ReplyMessageAsync(ev.ReplyToken, this.descriptionMessage);
 }
Example #13
0
 protected virtual Task HandleFollow(FollowEvent ev)
 {
     return(Task.CompletedTask);
 }
Example #14
0
 protected virtual Task OnFollowAsync(FollowEvent ev) => Task.CompletedTask;
Example #15
0
        /// <summary>
        /// Adds the new target.
        /// Precondition: this.target is null, newTarget is non-null
        /// </summary>
        /// <param name="newTarget">The new target.</param>
        private void AddTarget(Thing newTarget)
        {
            var self = this.Parent;
            if (self != null)
            {
                var message = this.CreateFollowMessage(self, newTarget);
                var followEvent = new FollowEvent(self, message, self, newTarget);

                self.Eventing.OnMovementRequest(followEvent, EventScope.ParentsDown);

                if (!followEvent.IsCancelled)
                {
                    this.target = new WeakReference<Thing>(newTarget);
                    newTarget.Eventing.MovementEvent += this.ProcessMovementEvent;
                    self.Eventing.OnMovementEvent(followEvent, EventScope.ParentsDown);
                }
            }
        }
Example #16
0
 protected override async Task OnFollowAsync(FollowEvent ev)
 {
     log.LogInformation("OnFollow");
     await InsertOrReplaceAccount(ev);
 }
Example #17
0
 protected override async Task OnFollowAsync(FollowEvent ev)
 {
     throw new NotImplementedException();
 }
Example #18
0
 protected override Task OnFollowAsync(FollowEvent ev) => ExecuteAsync(ev);
Example #19
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            IController sender = actionInput.Controller;

            var myBehaviors = sender.Thing.Behaviors;

            var followingBehavior = myBehaviors.FindFirst<FollowingBehavior>();
            if (followingBehavior != null)
            {
                var target = followingBehavior.Target;
                if (target != null)
                {
                    var targetBehaviors = target.Behaviors;
                    var followedBehavior = targetBehaviors.FindFirst<FollowedBehavior>();
                    if (followedBehavior != null)
                    {
                        lock (followedBehavior.Followers)
                        {
                            followedBehavior.Followers.Remove(sender.Thing);
                            if (followedBehavior.Followers.Count == 0)
                            {
                                targetBehaviors.Remove(followedBehavior);
                            }
                        }
                    }
                }

                myBehaviors.Remove(followingBehavior);
            }
            else
            {
                var message = new ContextualString(sender.Thing, null)
                {
                    ToOriginator = "You aren't following anybody."
                };

                var senseMessage = new SensoryMessage(SensoryType.All, 100, message);

                var followEvent = new FollowEvent(sender.Thing, senseMessage, sender.Thing, null);

                // Broadcast the event
                sender.Thing.Eventing.OnMiscellaneousEvent(followEvent, EventScope.ParentsDown);
            }
        }
 protected override async Task OnFollowAsync(FollowEvent ev)
 {
     //フォローイベント
     //リプライ可能
     //https://developers.line.biz/ja/reference/messaging-api/#follow-event
 }