2022-10-02 09:50:42 -07:00

257 lines
11 KiB
C#

using Church.Net.DAL.EF;
using Church.Net.Entity;
using Church.Net.Utility;
using Esprima;
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 ArArkCellGroupPrayer : IAutoReplyCommand
{
PastoralDomain pastoralDomain;
public ArArkCellGroupPrayer(
PastoralDomainLogic logic
)
{
this.logic = logic;
this.bibleReferrences = new List<BibleReferrence>();
bibleReferrences.Add(new BibleReferrence(
"腓立比書 4:6-7",
"應當一無掛慮,只要凡事藉著禱告、祈求和感謝,將你們所要的告訴神。神所賜出人意外的平安必在基督耶穌裡保守你們的心懷意念。"
));
bibleReferrences.Add(new BibleReferrence(
"馬太福音 7:7-8",
"你們祈求,就給你們;尋找,就尋見;叩門,就給你們開門。因為凡祈求的,就得著;尋找的,就尋見;叩門的,就給他開門。"
));
bibleReferrences.Add(new BibleReferrence(
"耶利米書 29:12",
"你們要呼求我,禱告我,我就應允你們。"
));
bibleReferrences.Add(new BibleReferrence(
"馬太福音 18:19-20",
"我又告訴你們,若是你們中間有兩個人在地上同心合意地求什麼事,我在天上的父必為他們成全。因為無論在哪裡,有兩三個人奉我的名聚會,那裡就有我在他們中間。"
));
bibleReferrences.Add(new BibleReferrence(
"路加福音 11:2-4",
"耶穌說:「你們禱告的時候,要說:『我們在天上的父(有古卷只作:父啊):願人都尊你的名為聖。願你的國降臨;願你的旨意行在地上,如同行在天上(有古卷無願你的旨意云云)。我們日用的飲食,天天賜給我們。赦免我們的罪,因為我們也赦免凡虧欠我們的人。不叫我們遇見試探;救我們脫離凶惡(有古卷無末句)。』」"
));
bibleReferrences.Add(new BibleReferrence(
"馬太福音 21:22",
"主耶穌說:「你們禱告,無論求什麼,只要信,就必得著。」"
));
bibleReferrences.Add(new BibleReferrence(
"馬太福音 6:5",
"你們禱告的時候,不可像那假冒為善的人,愛站在會堂裡和十字路口上禱告,故意叫人看見。我實在告訴你們,他們已經得了他們的賞賜。"
));
bibleReferrences.Add(new BibleReferrence(
"馬太福音 6:6-7",
"你禱告的時候,要進你的內屋,關上門,禱告你在暗中的父;你父在暗中察看,必然報答你。你們禱告,不可像外邦人,用許多重複話,他們以為話多了必蒙垂聽。"
));
bibleReferrences.Add(new BibleReferrence(
"馬太福音 26:41",
"總要儆醒禱告,免得入了迷惑。你們心靈固然願意,肉體卻軟弱了。"
));
bibleReferrences.Add(new BibleReferrence(
"雅各書 5:16",
"所以你們要彼此認罪,互相代求,使你們可以得醫治。義人祈禱所發的力量是大有功效的。"
));
}
private static readonly string[] COMMANDS = { "禱告", "代禱", "letspray", "pray" };
private static readonly DomainType[] GROUPS = {
DomainType.CellGroup,
};
private readonly PastoralDomainLogic logic;
public string Description => "顯示代禱事項";
public IEnumerable<string> Commands => COMMANDS;
public IEnumerable<DomainType> SupportGroups => GROUPS;
public string ReplyTextMessage => null;
public IEnumerable<ILineMessage> LineMessage
{
get
{
var random = new Random();
int index = random.Next(bibleReferrences.Count);
var bibleSentence = bibleReferrences[index];
List<ILineMessage> list = new List<ILineMessage>();
var _event = logic.GetLastEvent(this.pastoralDomain.Id);
string title = "禱告中心 普壘森特";
string imageUrl = "https://dailyverses.net/images/tc/cuv/matthew-21-22-3.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,
}
);
#endregion
#region Body
var bodyContent = flexMessage.Contents.InitBody();
bodyContent.Add(
new LineFlexText("代禱項目")
{
Size = FlexObjectSize.md,
Weight = FlexObjectTextWeidht.Bold,
OffsetBottom = FlexObjectSize.md
});
//$"目前暫無禱告事項唷, 趕快來新增代禱事項吧!!"
List<LineFlexBox> comments = new List<LineFlexBox>();
if (_event == null || _event.Prayers.Count == 0)
{
bodyContent.Add(
new LineFlexText("目前暫無禱告事項唷, 趕快來新增代禱事項吧!!")
{
Size = FlexObjectSize.md,
Color = "#666666",
});
}
else
{
foreach (var a in _event.Prayers)
{
var name = logic.GetMemberFirstNameById(a.MemberId);
var baseLineBox = new LineFlexBox()
{
Layout = FlexObjectBoxLayout.Baseline,
};
baseLineBox.Contents.Add(
new LineFlexText(name)
{
Size = FlexObjectSize.sm,
Color = "#aaaaaa",
Flex = 1
});
baseLineBox.Contents.Add(
new LineFlexText(
string.Join(", ", a.Prayer.Split('|')
.Where(s => !String.IsNullOrWhiteSpace(s))
)
)
{
Size = FlexObjectSize.sm,
Color = "#666666",
Flex = 5,
Wrap = true
});
if (!string.IsNullOrWhiteSpace(a.Comment))
{
var commentLineBox = new LineFlexBox()
{
Layout = FlexObjectBoxLayout.Baseline,
};
commentLineBox.Contents.Add(
new LineFlexText(name)
{
Size = FlexObjectSize.sm,
Color = "#aaaaaa",
Flex = 1
});
commentLineBox.Contents.Add(
new LineFlexText(a.Comment)
{
Size = FlexObjectSize.sm,
Color = "#666666",
Flex = 5,
Wrap = true
});
comments.Add(commentLineBox);
}
bodyContent.Add(baseLineBox);
}
if (comments.Count > 0)
{
bodyContent.Add(
new LineFlexText("備註")
{
Size = FlexObjectSize.md,
Weight = FlexObjectTextWeidht.Bold,
//Style = "Italic"
});
foreach (var item in comments)
{
bodyContent.Add(item);
}
}
}
bodyContent.Add(new LineFlexSeparator());
#endregion
#region Footer
flexMessage.Contents.InitFooter()
.Add(
new LineFlexButton()
{
Action = new UriAction()
{
Uri = "https://happiness.tours/CellGroup/prayer?openExternalBrowser=1",
Label = "我的代禱事項"
}
}
);
#endregion
list.Insert(0, flexMessage);
return list;
}
}
private List<BibleReferrence> bibleReferrences;
public void Initialize(PastoralDomain pastoralDomain = null)
{
this.pastoralDomain = pastoralDomain;
}
public bool Enabled(PastoralDomain pastoralDomain = null, string command = null)
{
return COMMANDS.Any(c => c.IndexOf(command) == 0);
}
}
class BibleReferrence
{
public BibleReferrence(string from, string content)
{
From = from;
Content = content;
}
public string From { get; set; }
public string Content { get; set; }
}
}