Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
1.4: optimize algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
TURX committed Mar 17, 2020
1 parent 4912db5 commit 87ea45c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 44 deletions.
1 change: 1 addition & 0 deletions QQCourseBot/GroupInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class GroupInfo
{
public int MessageCount = 1;
public string LastMessage = string.Empty;
public int RepeatCount = 10;
public bool Sent = false;
}
}
84 changes: 40 additions & 44 deletions QQCourseBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace QQCourseBot
{
public class Program
{
public static int RepeatCount = 5;
public static bool WhiteListEnabled;
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.";
public static Dictionary<long, GroupInfo> Groups = new Dictionary<long, GroupInfo>();
Expand All @@ -28,7 +27,6 @@ public class Program

public static void Init()
{
RepeatCount = random.Next(1, 10);
client = new CQHTTPClient(
access_url: "http://127.0.0.1:5700",
listen_port: 8080
Expand Down Expand Up @@ -125,130 +123,128 @@ public static void Main()
}
if (!inWhiteList) return new EmptyResponse();
}
string ThisMessage = me.message.ToString().ToLower();
string ThisMessageNormal = me.message.ToString();
string ThisMessage = me.message.ToString();
if (!Groups.ContainsKey(me.group_id))
{
Groups.Add(me.group_id, new GroupInfo());
}
if (ThisMessage == Groups[me.group_id].LastMessage && !ThisMessage.Contains(' '))
if (ThisMessage.ToLower() == Groups[me.group_id].LastMessage && !ThisMessage.Contains(' '))
{
Groups[me.group_id].MessageCount++;
}
else
{
Groups[me.group_id].MessageCount = 1;
Groups[me.group_id].Sent = false;
Groups[me.group_id].RepeatCount = random.Next(2, 11);
}
Groups[me.group_id].LastMessage = me.message.ToString().ToLower();
Console.WriteLine("[INFO] Time: " + DateTime.Now + "; Count: " + Groups[me.group_id].MessageCount + "; GroupID: " + me.group_id + "; Message: " + ThisMessageNormal);
if (ThisMessage.Contains(Personal.Name) || ThisMessage.Contains("[cq:at,qq=" + Personal.QQ + "]"))
Console.WriteLine("[INFO] Time: " + DateTime.Now + "; Count: " + Groups[me.group_id].MessageCount + "; GroupID: " + me.group_id + "; Message: " + ThisMessage);
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())));
}
if (ThisMessageNormal.Contains("https://meeting.tencent.com"))
if (ThisMessage.Contains("https://meeting.tencent.com"))
{
ThisMessageNormal = ThisMessageNormal.Replace("会议时间:", "会议时间:");
if (ThisMessageNormal.Contains("会议时间:") && ThisMessageNormal.Contains("预定的会议"))
ThisMessage = ThisMessage.Replace("会议时间:", "会议时间:");
if (ThisMessage.Contains("会议时间:") && ThisMessage.Contains("预定的会议"))
{
TencentScheduledMeeting meeting = new TencentScheduledMeeting();
int start = ThisMessageNormal.IndexOf("会议时间:");
int end = ThisMessageNormal.IndexOf(' ', start);
string date = ThisMessageNormal.Substring(start + 5, end - start - 5);
int start = ThisMessage.IndexOf("会议时间:");
int end = ThisMessage.IndexOf(' ', start);
string date = ThisMessage.Substring(start + 5, end - start - 5);
Console.WriteLine("[WEMEET] Date: " + date);
start = end;
end = ThisMessageNormal.IndexOf("-", start);
string startTime = ThisMessageNormal.Substring(start + 1, end - start - 1);
end = ThisMessage.IndexOf("-", start);
string startTime = ThisMessage.Substring(start + 1, end - start - 1);
Console.WriteLine("[WEMEET] StartTime: " + startTime);
meeting.StartTime = DateTime.Parse(date + " " + startTime);
meeting.StartTime = meeting.StartTime.AddMinutes(-random.Next(5, 20));
Console.WriteLine("[WEMEET] JoinTime: " + meeting.StartTime.ToString());
start = end;
end = ThisMessageNormal.IndexOf("", start);
if (end == -1) end = ThisMessageNormal.IndexOf("\r\n", start);
if (end == -1) end = ThisMessageNormal.IndexOf("\n", start);
if (end == -1) end = ThisMessageNormal.IndexOf("\r", start);
string endTime = ThisMessageNormal.Substring(start + 1, end - start - 1);
end = ThisMessage.IndexOf("", start);
if (end == -1) end = ThisMessage.IndexOf("\r\n", start);
if (end == -1) end = ThisMessage.IndexOf("\n", start);
if (end == -1) end = ThisMessage.IndexOf("\r", start);
string endTime = ThisMessage.Substring(start + 1, end - start - 1);
Console.WriteLine("[WEMEET] EndTime: " + endTime);
meeting.EndTime = DateTime.Parse(date + " " + endTime);
start = ThisMessageNormal.IndexOf("https://meeting.tencent.com");
end = ThisMessageNormal.Length;
for (int i = start; i < ThisMessageNormal.Length; i++)
start = ThisMessage.IndexOf("https://meeting.tencent.com");
end = ThisMessage.Length;
for (int i = start; i < ThisMessage.Length; i++)
{
if (ThisMessageNormal[i] == ' ' || ThisMessageNormal[i] == '\n' || ThisMessageNormal[i] == '\r' || ThisMessageNormal[i] == ']' || ThisMessageNormal[i] == ',')
if (ThisMessage[i] == ' ' || ThisMessage[i] == '\n' || ThisMessage[i] == '\r' || ThisMessage[i] == ']' || ThisMessage[i] == ',')
{
end = i;
break;
}
}
meeting.Url = ThisMessageNormal.Substring(start, end - start);
meeting.Url = ThisMessage.Substring(start, end - start);
ScheduledMeetings.Add(meeting);
File.WriteAllText("meetings.config.json", JsonConvert.SerializeObject(ScheduledMeetings));
Console.WriteLine("[WEMEET] Scheduled");
}
else {
int start = ThisMessageNormal.IndexOf("https://meeting.tencent.com");
int end = ThisMessageNormal.Length;
for (int i = start; i < ThisMessageNormal.Length; i++)
int start = ThisMessage.IndexOf("https://meeting.tencent.com");
int end = ThisMessage.Length;
for (int i = start; i < ThisMessage.Length; i++)
{
if (ThisMessageNormal[i] == ' ' || ThisMessageNormal[i] == '\n' || ThisMessageNormal[i] == '\r' || ThisMessageNormal[i] == ']' || ThisMessageNormal[i] == ',')
if (ThisMessage[i] == ' ' || ThisMessage[i] == '\n' || ThisMessage[i] == '\r' || ThisMessage[i] == ']' || ThisMessage[i] == ',')
{
end = i;
break;
}
}
TencentMeeting.InvokeWemeet(ThisMessageNormal.Substring(start, end - start));
TencentMeeting.InvokeWemeet(ThisMessage.Substring(start, end - start));
}
}
if (ThisMessage.Contains("please send"))
if (ThisMessage.ToLower().Contains("please send"))
{
int addLen;
int start = ThisMessage.IndexOf("please send me the");
int start = ThisMessage.ToLower().IndexOf("please send me the");
addLen = 18;
if (start == -1)
{
start = ThisMessage.IndexOf("please send me one");
start = ThisMessage.ToLower().IndexOf("please send me one");
addLen = 18;
}
if (start == -1)
{
start = ThisMessage.IndexOf("please send me an");
start = ThisMessage.ToLower().IndexOf("please send me an");
addLen = 17;
}
if (start == -1)
{
start = ThisMessage.IndexOf("please send me a");
start = ThisMessage.ToLower().IndexOf("please send me a");
addLen = 16;
}
if (start == -1)
{
start = ThisMessage.IndexOf("please send me");
start = ThisMessage.ToLower().IndexOf("please send me");
addLen = 14;
}
if (start == -1)
{
start = ThisMessage.IndexOf("please send");
start = ThisMessage.ToLower().IndexOf("please send");
addLen = 11;
}
start += addLen;
int end = ThisMessage.IndexOf(' ', start + 1);
int end = ThisMessage.ToLower().IndexOf(' ', start + 1);
if (end == -1)
{
Send(me.group_id, new Message(new ElementText(ThisMessageNormal.Substring(start, ThisMessageNormal.Length - start))));
Send(me.group_id, new Message(new ElementText(ThisMessage.Substring(start, ThisMessage.Length - start))));
}
else
{
Send(me.group_id, new Message(new ElementText(ThisMessageNormal.Substring(start, end - start))));
Send(me.group_id, new Message(new ElementText(ThisMessage.Substring(start, end - start))));
}
Groups[me.group_id].Sent = true;
}
if (Groups[me.group_id].MessageCount > RepeatCount && !Groups[me.group_id].Sent)
if (Groups[me.group_id].MessageCount == Groups[me.group_id].RepeatCount && !Groups[me.group_id].Sent)
{
Send(me.group_id, new Message(new ElementText(ThisMessageNormal)));
RepeatCount = random.Next(1, 10);
Groups[me.group_id].Sent = true;
Send(me.group_id, new Message(new ElementText(ThisMessage)));
}
}
return new EmptyResponse();
Expand Down

0 comments on commit 87ea45c

Please sign in to comment.