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

Commit

Permalink
1.1: support multiple groups
Browse files Browse the repository at this point in the history
  • Loading branch information
TURX committed Mar 12, 2020
1 parent 698ff94 commit 5dde8a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
9 changes: 9 additions & 0 deletions QQCourseBot/GroupInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
namespace QQCourseBot
{
public class GroupInfo
{
public int MessageCount = 1;
public string LastMessage = string.Empty;
}
}
30 changes: 18 additions & 12 deletions QQCourseBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<long, GroupInfo> Groups = new Dictionary<long, GroupInfo>();
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.";
Expand All @@ -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");
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 5dde8a9

Please sign in to comment.