diff --git a/QQCourseBot/GroupInfo.cs b/QQCourseBot/GroupInfo.cs new file mode 100644 index 0000000..a85ef9d --- /dev/null +++ b/QQCourseBot/GroupInfo.cs @@ -0,0 +1,9 @@ +using System; +namespace QQCourseBot +{ + public class GroupInfo + { + public int MessageCount = 1; + public string LastMessage = string.Empty; + } +} diff --git a/QQCourseBot/Program.cs b/QQCourseBot/Program.cs index 3fd427e..2caee07 100644 --- a/QQCourseBot/Program.cs +++ b/QQCourseBot/Program.cs @@ -5,14 +5,14 @@ using cqhttp.Cyan.Enums; using cqhttp.Cyan.Messages; using cqhttp.Cyan.Messages.CQElements; +using System.Collections.Generic; namespace QQCourseBot { public class Program { public static string[] response; - public static string LastMessage = string.Empty; - public static int MessageCount = 1; + public static Dictionary Groups = new Dictionary(); public static int RepeatCount = 5; public static Random random = new Random(); public static string License = "Copyright (C) 2020 Ruixuan Tu\nThis program comes with ABSOLUTELY NO WARRANTY with GNU GPL v3 license. This is free software, and you are welcome to redistribute it under certain conditions; go to https://www.gnu.org/licenses/gpl-3.0.html for details."; @@ -26,10 +26,12 @@ public static void Init() }; RepeatCount = random.Next(1, 10); } + public static string Mentioned() { return response[random.Next(0, response.Length)]; } + public static void Main() { Console.WriteLine("QQ Course Bot"); @@ -49,19 +51,23 @@ public static void Main() { var me = (e as GroupMessageEvent); string ThisMessage = me.message.ToString().ToLower(); - if (ThisMessage == LastMessage && !ThisMessage.Contains(' ')) + if (!Groups.ContainsKey(me.group_id)) + { + Groups.Add(me.group_id, new GroupInfo()); + } + if (ThisMessage == Groups[me.group_id].LastMessage && !ThisMessage.Contains(' ')) { - MessageCount++; + Groups[me.group_id].MessageCount++; } else { - MessageCount = 1; + Groups[me.group_id].MessageCount = 1; } - LastMessage = me.message.ToString().ToLower(); - Console.WriteLine("MessageCount: " + MessageCount); + Groups[me.group_id].LastMessage = me.message.ToString().ToLower(); + Console.WriteLine("[INFO] MessageCount: " + Groups[me.group_id].MessageCount + "; GroupID: " + me.group_id + "; Message: " + ThisMessage); if (ThisMessage.Contains(PersonalInfo.name) || ThisMessage.Contains("@" + PersonalInfo.nickname)) { - Console.WriteLine("You have been mentioned!!!"); + Console.WriteLine("[WARNING] You have been mentioned!!!"); await client.SendMessageAsync( MessageType.group_, me.group_id, @@ -80,7 +86,7 @@ await client.SendMessageAsync( { if (ThisMessage[end] == ' ') { - Console.WriteLine("Send: " + ThisMessage.Substring(start, end - start)); + Console.WriteLine("[RESPOND] Send: " + ThisMessage.Substring(start, end - start)); await client.SendMessageAsync( MessageType.group_, me.group_id, @@ -94,7 +100,7 @@ await client.SendMessageAsync( } if (flagSent == false) { - Console.WriteLine("Send: " + ThisMessage.Substring(start, ThisMessage.Length - start)); + Console.WriteLine("[RESPOND] Send: " + ThisMessage.Substring(start, ThisMessage.Length - start)); await client.SendMessageAsync( MessageType.group_, me.group_id, @@ -104,9 +110,9 @@ await client.SendMessageAsync( ); } } - if (MessageCount == RepeatCount) + if (Groups[me.group_id].MessageCount > RepeatCount) { - Console.WriteLine("Repeat: " + ThisMessage); + Console.WriteLine("[RESPOND] Repeat: " + ThisMessage); await client.SendMessageAsync( MessageType.group_, me.group_id,