2024-05-02 15:24:13 -07:00

137 lines
4.6 KiB
C#

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<string> Commands => COMMANDS;
public IEnumerable<DomainType> SupportGroups => GROUPS;
public string ReplyTextMessage => null;
public string ReplyJsonMessage => null;
public IEnumerable<ILineMessage> LineMessage
{
get
{
var random = new Random();
List<ILineMessage> list = new List<ILineMessage>();
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"
},
Height = FlexObjectSize.sm,
}
);
}
#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;
}
}
}