diff --git a/WebAPI/Services/AutoReplyCommands/ArArkCellGroupDinner.cs b/WebAPI/Services/AutoReplyCommands/ArArkCellGroupDinner.cs index a2092a7..6480e6a 100644 --- a/WebAPI/Services/AutoReplyCommands/ArArkCellGroupDinner.cs +++ b/WebAPI/Services/AutoReplyCommands/ArArkCellGroupDinner.cs @@ -198,7 +198,8 @@ namespace WebAPI.Services.AutoReplyCommands public bool Enabled(PastoralDomain pastoralDomain = null, string command = null) { - return COMMANDS.Any(c=>c.IndexOf(command)==0); + this.pastoralDomain = pastoralDomain; + return COMMANDS.Any(c=> c.IndexOf(command, StringComparison.OrdinalIgnoreCase)==0); } } } diff --git a/WebAPI/Services/AutoReplyCommands/ArArkCellGroupInfo.cs b/WebAPI/Services/AutoReplyCommands/ArArkCellGroupInfo.cs index 469750a..3274af4 100644 --- a/WebAPI/Services/AutoReplyCommands/ArArkCellGroupInfo.cs +++ b/WebAPI/Services/AutoReplyCommands/ArArkCellGroupInfo.cs @@ -12,14 +12,14 @@ namespace WebAPI.Services.AutoReplyCommands { private PastoralDomain pastoralDomain; private static readonly string[] COMMANDS = { "小組" }; - + private static readonly DomainType[] GROUPS = { DomainType.CellGroup, }; public string Description => "顯示小組聚會資訊"; public IEnumerable Commands => COMMANDS; - public string ReplyTextMessage => + public string ReplyTextMessage => "新生命靈糧堂 Arcadia 牧區 - 方舟小組\n" + "聚會時間 & 流程 周五晚上\n" + "07:30 PM ~ 08:30 PM - PotLuck 時光\n" + @@ -34,7 +34,8 @@ namespace WebAPI.Services.AutoReplyCommands } public bool Enabled(PastoralDomain pastoralDomain = null, string command = null) { - return COMMANDS.Any(c => c.IndexOf(command) == 0); + this.pastoralDomain = pastoralDomain; + return COMMANDS.Any(c => c.IndexOf(command, StringComparison.OrdinalIgnoreCase) == 0); } } } diff --git a/WebAPI/Services/AutoReplyCommands/ArChurchInfo.cs b/WebAPI/Services/AutoReplyCommands/ArChurchInfo.cs index d9a1561..32e4d93 100644 --- a/WebAPI/Services/AutoReplyCommands/ArChurchInfo.cs +++ b/WebAPI/Services/AutoReplyCommands/ArChurchInfo.cs @@ -12,11 +12,10 @@ namespace WebAPI.Services.AutoReplyCommands { private static readonly string[] COMMANDS = { "教會", "church" }; - private static readonly string MESSAGES = - "新生命靈糧堂 Arcadia 牧區\n聚會時間 周日 11:00 AM - 12:30PM\n聚會後有提供精緻午餐唷!\n"+ + private static readonly string MESSAGES = + "新生命靈糧堂 Arcadia 牧區\n聚會時間 周日 11:00 AM - 12:30PM\n聚會後有提供精緻午餐唷!\n" + "1881 S 1st Ave, Arcadia, CA 91006"; private static readonly DomainType[] GROUPS = { - DomainType.HappinessGroup, DomainType.CellGroup }; @@ -30,11 +29,8 @@ namespace WebAPI.Services.AutoReplyCommands public bool Enabled(PastoralDomain pastoralDomain = null, string command = null) { - return COMMANDS.Any(c => c.IndexOf(command) == 0); + return COMMANDS.Any(c => c.IndexOf(command, StringComparison.OrdinalIgnoreCase) == 0); } - public void Initialize(PastoralDomain pastoralDomain = null) - { - } } } diff --git a/WebAPI/Services/AutoReplyCommands/ArHappinessBEST.cs b/WebAPI/Services/AutoReplyCommands/ArHappinessBEST.cs new file mode 100644 index 0000000..a1daf5d --- /dev/null +++ b/WebAPI/Services/AutoReplyCommands/ArHappinessBEST.cs @@ -0,0 +1,134 @@ +using Church.Net.DAL.EF; +using Church.Net.Entity; +using Church.Net.Utility; +using LineMessaging; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WebAPI.Logics; +using WebAPI.Services.Interfaces; + +namespace WebAPI.Services.AutoReplyCommands +{ + public class ArHappinessBEST : IAutoReplyCommand + { + private PastoralDomain pastoralDomain; + public ArHappinessBEST( + PastoralDomainLogic logic) + { + this.logic = logic; + } + private static readonly string[] COMMANDS = { "BEST" }; + + private static readonly DomainType[] GROUPS = { + DomainType.HappinessGroup, + }; + private readonly PastoralDomainLogic logic; + + public string Description => "顯示幸福小組 Best 電子邀請函連結"; + public IEnumerable Commands => COMMANDS; + public IEnumerable SupportGroups => GROUPS; + public string ReplyTextMessage => null; + + public IEnumerable LineMessage + { + get + { + var random = new Random(); + + List list = new List(); + string title = $"W{weekSeq} {week.Topic} 邀請卡"; + string imageUrl = $"https://happiness.tours/assets/images/HappinessGroup/week0{weekSeq}.jpg"; + var flexMessage = new LineFlexMessage(); + flexMessage.AltText = title; + + #region Header + var headerContent = flexMessage.Contents.InitHeader(); + headerContent.Add( + new LineFlexText(title) + { + Size = FlexObjectSize.lg, + Weight = FlexObjectTextWeidht.Bold, + Align = "center" + }); + #endregion + #region Hero + flexMessage.Contents.InitHero() + .Add( + new LineFlexImage(imageUrl) + { + Size = FlexObjectSize.full, + AspectRatio = "1.5:1" + } + ); + #endregion + #region Body + + var bodyContent = flexMessage.Contents.InitBody(); + + bodyContent.Add(new LineFlexSeparator()); + #endregion + #region Footer + var footer = flexMessage.Contents.InitFooter(); + foreach (var best in pastoralDomain.Bests) + { + footer.Add( + new LineFlexButton() + { + Action = new MessageAction() + { + Text = $"親愛的 {best.Name},想邀請你來參加這周的幸福聚會唷! 這是這周的邀請函!\n\nhttps://happiness.tours/invitation/{best.Id}", + Label = best.Name, + //InputOption= "openKeyboard" + } + } + ); + + } + + #endregion + + list.Insert(0, flexMessage); + return list; + } + } + + public void Initialize(PastoralDomain pastoralDomain = null) + { + this.pastoralDomain = pastoralDomain; + } + private int weekSeq = 0; + private HappinessWeek week = null; + public bool Enabled(PastoralDomain pastoralDomain = null, string command = null) + { + + if (pastoralDomain != null && COMMANDS.Any(c => c.ToLower().IndexOf(command) == 0)) + { + + this.pastoralDomain = pastoralDomain; + logic.GetHappinessGroupInfo(pastoralDomain); + command = command.Replace("BEST", ""); + + //if (command.Length > 0) + //{ + // weekSeq = int.Parse(command); + //} + //if (weekSeq > 0) + //{ + // week = pastoralDomain.HappinessWeeks.Where(w => w.SEQ == weekSeq).FirstOrDefault(); + //} + //else + //{ + week = pastoralDomain.HappinessWeeks.Where(w => w.Date >= DateTime.UtcNow).FirstOrDefault(); + weekSeq = week.SEQ; + //} + return true; + }; + return false; + + } + } +} diff --git a/WebAPI/Services/Interfaces/IAutoReplyCommand.cs b/WebAPI/Services/Interfaces/IAutoReplyCommand.cs index 4329f9d..e678eb6 100644 --- a/WebAPI/Services/Interfaces/IAutoReplyCommand.cs +++ b/WebAPI/Services/Interfaces/IAutoReplyCommand.cs @@ -16,6 +16,5 @@ namespace WebAPI.Services.Interfaces IEnumerable SupportGroups { get; } IEnumerable LineMessage { get; } bool Enabled(PastoralDomain pastoralDomain = null, string command = null); - void Initialize(PastoralDomain pastoralDomain = null); } } diff --git a/WebAPI/Startup.cs b/WebAPI/Startup.cs index bc93d1c..f20f8ef 100644 --- a/WebAPI/Startup.cs +++ b/WebAPI/Startup.cs @@ -65,7 +65,7 @@ namespace WebAPI services.AddSingleton(); //services.AddSingleton(_ => new DatabaseOptions { ConnectionString = "Host=192.168.86.131;Port=49154;Database=Church;Username=chris;Password=1124" }); - services.AddSingleton(_ => new DatabaseOptions { ConnectionString = "Host=192.168.86.131;Port=49154;Database=ChurchSandbox;Username=chris;Password=1124" }); + services.AddSingleton(_ => new DatabaseOptions { ConnectionString = "Host=192.168.86.131;Port=49154;Database=Church;Username=chris;Password=1124" }); //services.AddSingleton(new ChurchNetContext()); services.AddDbContext(options => options.UseNpgsql( @@ -79,6 +79,7 @@ namespace WebAPI services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped();