コード例 #1
0
 //public string Name { get; set; }
 public Task Execute(IJobExecutionContext context)
 {
     return(Task.Factory.StartNew(async() =>
     {
         await FacebookToolHelper.ReactionAllPost();
     }));
 }
コード例 #2
0
        protected override async Task onMessage(string mid = null, string author_id = null, string message = null, FB_Message message_object = null, string thread_id = null, ThreadType?thread_type = null, long ts = 0, JToken metadata = null, JToken msg = null)
        {
            //authorId: người gửi
            //thread_id: thread hiện tại
            var userId = this.GetUserUid();

            if (userId != author_id)
            {
                var specialMessage = await FacebookToolHelper.CheckSpecialMessage(message, thread_id);

                switch (specialMessage)
                {
                case Facebook.DAL.Enum.EnumFeature.NoSpecialFeature:
                case Facebook.DAL.Enum.EnumFeature.StopAll:
                case Facebook.DAL.Enum.EnumFeature.RemoveStopAll:
                case Facebook.DAL.Enum.EnumFeature.Stop5Min:
                    return;

                case Facebook.DAL.Enum.EnumFeature.TroLyAo:
                    await this.send(new FB_Message
                    {
                        text = ListHelper <string> .GetRandomItemInListObject(Constant.ListConfirmAgreeUseTroLyAoMessage)
                    }, thread_id, ThreadType.USER);

                    return;

                case Facebook.DAL.Enum.EnumFeature.GirlXinh:
                    string fileNameWithExtension = DownloadHelper.DownloadImageFromUrl(DownloadHelper.RandomImageIdGirl());
                    using (FileStream stream = File.OpenRead(fileNameWithExtension))
                    {
                        await sendLocalFiles(
                            file_paths : new Dictionary <string, Stream>()
                        {
                            { fileNameWithExtension, stream }
                        },
                            message : null,
                            thread_id : author_id,
                            thread_type : ThreadType.USER);
                    }
                    return;

                case Facebook.DAL.Enum.EnumFeature.TruyenCuoi:
                    List <string> listTruyenCuoi = await FacebookToolHelper.GetListTruyenCuoi();

                    await this.send(new FB_Message
                    {
                        text = ListHelper <string> .GetRandomItemInListObject(listTruyenCuoi)
                    }, thread_id, ThreadType.USER);

                    return;

                case Facebook.DAL.Enum.EnumFeature.TinTuc:
                    List <NewfeedRss> newfeedRsses = RSSHelper.GetTinMoiNhat();
                    foreach (var newfeed in newfeedRsses)
                    {
                        await this.send(new FB_Message
                        {
                            text = $"{ newfeed.Title} \n{newfeed.Link}"
                        }, thread_id, ThreadType.USER);
                    }
                    return;

                case Facebook.DAL.Enum.EnumFeature.NoiTu:
                    await FacebookToolHelper.SetUserNoiTu(author_id);

                    await this.send(new FB_Message
                    {
                        text = $"Bắt đầu chơi nối từ tiếng việt thôi!!!"
                    }, thread_id, ThreadType.USER);

                    return;

                case Facebook.DAL.Enum.EnumFeature.StopNoiTu:
                    await FacebookToolHelper.SetUserStopNoiTu(author_id);

                    await this.send(new FB_Message
                    {
                        text = $"Đã dừng chơi nối từ tiếng việt!"
                    }, thread_id, ThreadType.USER);

                    return;

                case Facebook.DAL.Enum.EnumFeature.NoiTuTiengAnh:
                    await FacebookToolHelper.SetUserNoiTuTiengAnh(author_id);

                    await this.send(new FB_Message
                    {
                        text = $"Bắt đầu chơi nối từ tiếng Anh thôi!!!"
                    }, thread_id, ThreadType.USER);

                    return;

                case Facebook.DAL.Enum.EnumFeature.StopNoiTuTiengAnh:
                    await FacebookToolHelper.SetUserStopNoiTuTiengAnh(author_id);

                    await this.send(new FB_Message
                    {
                        text = $"Đã dừng chơi nối từ tiếng Anh!"
                    }, thread_id, ThreadType.USER);

                    return;

                default:
                    break;
                }
                ConsoleLogHelper.WriteToConsole($"Got new message from {author_id}: {message}");
                var isBlock = await FacebookToolHelper.CheckIsBlockOrNot(author_id);

                if (isBlock)
                {
                    return;
                }
                else
                {
                    //Co the send message o day
                    var agreeSimsimi = await FacebookToolHelper.CheckUserAgreeSimsimi(thread_id);

                    if (await FacebookToolHelper.CheckIsNoiTuTiengVietOrNot(thread_id))
                    {
                        var    dic         = TuDienHelper.GenerateVietNameseDictionary();
                        var    lastWord    = message.LastWord();
                        var    listNewWord = dic.Keys.Where(x => String.Equals(x.FirstWord(), lastWord, StringComparison.OrdinalIgnoreCase) && x.Contains(" ")).ToList();
                        string textSend    = listNewWord.Count == 0 ? "Chịu thua rồi, ko tìm thấy từ nào cả :((" : $"Nối từ: {ListHelper<string>.GetRandomItemInListObject(listNewWord)}";
                        await this.send(new FB_Message
                        {
                            text = textSend
                        }, thread_id, ThreadType.USER);

                        return;
                    }
                    else if (await FacebookToolHelper.CheckIsNoiTuTiengAnhOrNot(thread_id))
                    {
                        var    dic         = TuDienHelper.GenerateVietNameseDictionary();
                        var    lastWord    = message.LastWord();
                        var    listNewWord = dic.Keys.Where(x => String.Equals(x.FirstWord(), lastWord, StringComparison.OrdinalIgnoreCase) && x.Contains(" ")).ToList();
                        string textSend    = listNewWord.Count == 0 ? "Chịu thua rồi, ko tìm thấy từ nào cả :((" : $"Nối từ: {ListHelper<string>.GetRandomItemInListObject(listNewWord)}";
                        await this.send(new FB_Message
                        {
                            text = textSend
                        }, thread_id, ThreadType.USER);

                        return;
                    }
                    else if (!agreeSimsimi)
                    {
                        await this.send(new FB_Message
                        {
                            text = ListHelper <string> .GetRandomItemInListObject(Constant.ListTroLyAoMessage)
                        }, thread_id, ThreadType.USER);

                        await FacebookToolHelper.AddUser10Min(thread_id);
                    }
                    else
                    {
                        string simsimiMessage = await SimsimiHelper.SendSimsimi(message);

                        await this.send(new FB_Message
                        {
                            text = "Trợ lý ảo: " + simsimiMessage
                        }, thread_id, ThreadType.USER);

                        ConsoleLogHelper.WriteToConsole($"Send message = {simsimiMessage} to {thread_id}");
                    }
                }
            }
            else
            {
                //Tự mình gửi đi
                var specialMessage = await FacebookToolHelper.CheckSpecialMessage(message, thread_id);

                switch (specialMessage)
                {
                case EnumFeature.NoiTu:
                    await FacebookToolHelper.SetUserNoiTu(thread_id);

                    break;

                case EnumFeature.StopNoiTu:
                    await FacebookToolHelper.SetUserStopNoiTu(thread_id);

                    break;
                }
                await Task.Yield();
            }
        }