Skip to content

Commit

Permalink
米游社订阅,分步处理优化
Browse files Browse the repository at this point in the history
  • Loading branch information
GardenHamster committed May 25, 2022
1 parent 8c88c08 commit 7bd6563
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 123 deletions.
335 changes: 218 additions & 117 deletions Theresa3rd-Bot/Business/MYSBusiness.cs

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Theresa3rd-Bot/Dao/SubscribeDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public List<SubscribeInfo> getSubscribeInfo()

public SubscribePO getSubscribe(string subscribeCode, SubscribeType subscribeType)
{
string sql = Db.Queryable<SubscribePO>().Where(o => o.SubscribeCode == subscribeCode && o.SubscribeType == subscribeType).ToSqlString();
return Db.Queryable<SubscribePO>().Where(o => o.SubscribeCode == subscribeCode && o.SubscribeType == subscribeType).First();
}

Expand All @@ -29,6 +28,10 @@ public SubscribePO getSubscribe(string subscribeCode, SubscribeType subscribeTyp
return Db.Queryable<SubscribePO>().Where(o => o.SubscribeCode == subscribeCode && o.SubscribeType == subscribeType && o.SubscribeSubType == subscribeSubType).First();
}

public List<SubscribePO> getSubscribes(string subscribeCode, SubscribeType subscribeType)
{
return Db.Queryable<SubscribePO>().Where(o => o.SubscribeCode == subscribeCode && o.SubscribeType == subscribeType).OrderBy(o => o.SubscribeSubType).ToList();
}

}
}
14 changes: 13 additions & 1 deletion Theresa3rd-Bot/Model/Cache/StepDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@ public class StepDetail

public Func<IMiraiHttpSession, IGroupMessageEventArgs, string, Task<bool>> CheckInput { get; set; }

public Func<IMiraiHttpSession, IGroupMessageEventArgs, StepInfo, StepDetail, Task<string>> StepQuestion { get; set; }

public StepDetail(int waitSecond, string question, Func<IMiraiHttpSession, IGroupMessageEventArgs, string, Task<bool>> checkInput = null)
{
this.WaitSecond = waitSecond;
this.Question = question;
this.CheckInput = checkInput;
}

public StepDetail(
int waitSecond,
Func<IMiraiHttpSession, IGroupMessageEventArgs, StepInfo, StepDetail, Task<string>> stepQuestion,
Func<IMiraiHttpSession, IGroupMessageEventArgs, string, Task<bool>> checkInput = null)
{
this.WaitSecond = waitSecond;
this.StepQuestion = stepQuestion;
this.CheckInput = checkInput;
}

public bool IsTimeout()
{
if (StartTime == null) return false;
Expand All @@ -44,7 +56,7 @@ public void StartStep()
public void FinishStep(IGroupMessageEventArgs args, string answer)
{
this.Args = args;
this.Answer = answer;
this.Answer = answer?.Trim();
this.IsFinish = true;
}

Expand Down
7 changes: 7 additions & 0 deletions Theresa3rd-Bot/Model/Cache/StepInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ public Task<bool> StartStep(IMiraiHttpSession session, IGroupMessageEventArgs ar
StepDetail stepDetail = StepDetails[i];
if (stepDetail.IsFinish) continue;
if (stepDetail.StartTime == null) stepDetail.StartStep();
if (stepDetail.StepQuestion != null)
{
stepDetail.Question = await stepDetail.StepQuestion(session, args, this, stepDetail);
if (string.IsNullOrEmpty(stepDetail.Question)) return false;
}

await session.SendMessageWithAtAsync(args, new PlainMessage(stepDetail.Question));

while (true)
{
if (stepDetail.IsFinish) break;
Expand Down
13 changes: 12 additions & 1 deletion Theresa3rd-Bot/Timer/MysUserTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,18 @@ private static async Task sendGroupSubscribeAsync(MYSBusiness mysBusiness, Subsc
List<IChatMessage> chailList = await mysBusiness.getSubscribeInfoAsync(mysSubscribe, BotConfig.SubscribeConfig.Mihoyo.Template);
foreach (long groupId in subscribeTask.GroupIdList)
{
await MiraiHelper.Session.SendGroupMessageAsync(groupId, chailList.ToArray());
try
{
await MiraiHelper.Session.SendGroupMessageAsync(groupId, chailList.ToArray());
}
catch (Exception ex)
{
LogHelper.Error(ex, "米游社订阅消息发送失败");
}
finally
{
await Task.Delay(1000);
}
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion Theresa3rd-Bot/Timer/PixivTagTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,18 @@ private static async Task sendGroupSubscribeAsync(SubscribeTask subscribeTask, L
}
foreach (long groupId in subscribeTask.GroupIdList)
{
await MiraiHelper.Session.SendGroupMessageAsync(groupId, chailList.ToArray());
try
{
await MiraiHelper.Session.SendGroupMessageAsync(groupId, chailList.ToArray());
}
catch (Exception ex)
{
LogHelper.Error(ex, "pixiv标签订阅消息发送失败");
}
finally
{
await Task.Delay(1000);
}
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion Theresa3rd-Bot/Timer/PixivUserTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,18 @@ private static async Task sendGroupSubscribeAsync(SubscribeTask subscribeTask, L
}
foreach (long groupId in subscribeTask.GroupIdList)
{
await MiraiHelper.Session.SendGroupMessageAsync(groupId, chailList.ToArray());
try
{
await MiraiHelper.Session.SendGroupMessageAsync(groupId, chailList.ToArray());
}
catch (Exception ex)
{
LogHelper.Error(ex, "pixiv画师订阅消息发送失败");
}
finally
{
await Task.Delay(1000);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Theresa3rd-Bot/Type/MysSectionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public enum MysSectionType
{
其他 = 0,
全部 = 0,
崩坏3 = 1,
原神 = 2,
崩坏2 = 3,
Expand Down
1 change: 1 addition & 0 deletions Theresa3rd-Bot/Util/EnumHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class EnumHelper
public static string MysSectionOption()
{
StringBuilder optionBuilder=new StringBuilder();
optionBuilder.AppendLine($"{(int)MysSectionType.全部}{Enum.GetName(typeof(MysSectionType), MysSectionType.全部)}");
optionBuilder.AppendLine($"{(int)MysSectionType.崩坏3}{Enum.GetName(typeof(MysSectionType), MysSectionType.崩坏3)}");
optionBuilder.AppendLine($"{(int)MysSectionType.原神}{Enum.GetName(typeof(MysSectionType), MysSectionType.原神)}");
optionBuilder.AppendLine($"{(int)MysSectionType.崩坏2}{Enum.GetName(typeof(MysSectionType), MysSectionType.崩坏2)}");
Expand Down

0 comments on commit 7bd6563

Please sign in to comment.