From acd0ff324f1b5824caf1366aa9cacc3832680d2d Mon Sep 17 00:00:00 2001 From: TURX Date: Tue, 31 Mar 2020 14:13:44 +0800 Subject: [PATCH] 1.5.5: ignore repetition in 5 minutes --- QQCourseBot/GroupInfo.cs | 5 ++++- QQCourseBot/Program.cs | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/QQCourseBot/GroupInfo.cs b/QQCourseBot/GroupInfo.cs index 579f2f1..e39cb52 100644 --- a/QQCourseBot/GroupInfo.cs +++ b/QQCourseBot/GroupInfo.cs @@ -1,4 +1,6 @@ -namespace QQCourseBot +using System; + +namespace QQCourseBot { public class GroupInfo { @@ -6,5 +8,6 @@ public class GroupInfo public string LastMessage = string.Empty; public int RepeatCount = 10; public bool Sent = false; + public DateTime LastRepeatTime = new DateTime(); } } diff --git a/QQCourseBot/Program.cs b/QQCourseBot/Program.cs index a6ca2d3..f49736e 100644 --- a/QQCourseBot/Program.cs +++ b/QQCourseBot/Program.cs @@ -101,6 +101,7 @@ public static void Main() if (e is GroupMessageEvent) { var me = (e as GroupMessageEvent); + #region WhiteList foreach (TencentScheduledMeeting i in ScheduledMeetings) { if (DateTime.Now < EndTime) break; @@ -123,6 +124,8 @@ public static void Main() } if (!inWhiteList) return new EmptyResponse(); } + #endregion + #region Preparation string ThisMessage = me.message.ToString(); if (!Groups.ContainsKey(me.group_id)) { @@ -140,12 +143,16 @@ public static void Main() } Groups[me.group_id].LastMessage = ThisMessage; Console.WriteLine("[INFO] Time: " + DateTime.Now + "; Count: " + Groups[me.group_id].MessageCount + "; GroupID: " + me.group_id + "; Message: " + ThisMessage); + #endregion + #region Mention if (ThisMessage.ToLower().Contains(Personal.Name) || ThisMessage.Contains("[CQ:at,qq=" + Personal.QQ + "]")) { Console.WriteLine("[WARNING] You have been mentioned!!!"); Thread.Sleep(random.Next(3000, 6000)); Send(me.group_id, new Message(new ElementText(Mentioned()))); } + #endregion + #region Tencent Meeting if (ThisMessage.Contains("https://meeting.tencent.com")) { ThisMessage = ThisMessage.Replace("会议时间:", "会议时间:"); @@ -219,6 +226,8 @@ public static void Main() Console.WriteLine("[WEMEET] Launched"); } } + #endregion + #region Please send if (ThisMessage.ToLower().Contains("please send")) { int addLen; @@ -261,10 +270,15 @@ public static void Main() } Groups[me.group_id].Sent = true; } - if (Groups[me.group_id].MessageCount == Groups[me.group_id].RepeatCount && !Groups[me.group_id].Sent) + #endregion + #region Repeat + if (Groups[me.group_id].MessageCount == Groups[me.group_id].RepeatCount && !Groups[me.group_id].Sent && DateTime.Compare(DateTime.Now.AddMinutes(-5), Groups[me.group_id].LastRepeatTime) > 0) { Send(me.group_id, new Message(new ElementText(ThisMessage))); + Groups[me.group_id].LastRepeatTime = DateTime.Now; + Console.WriteLine("[REPEAT] Updated LastRepeatTime: " + Groups[me.group_id].LastRepeatTime); } + #endregion } return new EmptyResponse(); };