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

Commit

Permalink
1.3: auto join Tencent Meeting
Browse files Browse the repository at this point in the history
  • Loading branch information
TURX committed Mar 16, 2020
1 parent ac9d9a2 commit 4912db5
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 28 deletions.
3 changes: 1 addition & 2 deletions QQCourseBot/GroupInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
namespace QQCourseBot
namespace QQCourseBot
{
public class GroupInfo
{
Expand Down
118 changes: 94 additions & 24 deletions QQCourseBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
using cqhttp.Cyan.Messages;
using cqhttp.Cyan.Messages.CQElements;
using System.Collections.Generic;
using System.Text.Json;
using System.IO;
using System.Threading;
using Newtonsoft.Json;

namespace QQCourseBot
{
public class Program
{
public static List<string> ResponseMentioned;
public static Dictionary<long, GroupInfo> Groups = new Dictionary<long, GroupInfo>();
public static int RepeatCount = 5;
public static Random random = new Random();
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>();
public static CQHTTPClient client;
public static List<long> WhiteList;
public static List<string> ResponseMentioned;
public static List<TencentScheduledMeeting> ScheduledMeetings;
public static PersonalInfo Personal;
public static bool WhiteListEnabled;
public static Random random = new Random();
public static DateTime EndTime = new DateTime();

public static void Init()
{
Expand All @@ -36,29 +38,38 @@ public static void Init()
PersonalInfo personal = new PersonalInfo();
personal.Name = "testname";
personal.QQ = "123456789";
File.WriteAllText("personal.config.json", JsonSerializer.Serialize(personal));
File.WriteAllText("personal.config.json", JsonConvert.SerializeObject(personal));
} else
{
Personal = JsonSerializer.Deserialize<PersonalInfo>(File.ReadAllText("personal.config.json"));
Personal = JsonConvert.DeserializeObject<PersonalInfo>(File.ReadAllText("personal.config.json"));
}
if (!File.Exists("whitelist.config.json"))
{
WhiteList = new List<long>();
File.WriteAllText("whitelist.config.json", JsonSerializer.Serialize(WhiteList));
File.WriteAllText("whitelist.config.json", JsonConvert.SerializeObject(WhiteList));
} else
{
WhiteList = JsonSerializer.Deserialize<List<long>>(File.ReadAllText("whitelist.config.json"));
WhiteList = JsonConvert.DeserializeObject<List<long>>(File.ReadAllText("whitelist.config.json"));
}
if(!File.Exists("response.config.json"))
{
ResponseMentioned = new List<string>();
ResponseMentioned.Add("My internet is poor.");
ResponseMentioned.Add("I am restarting my router.");
ResponseMentioned.Add("My device has no battery now.");
File.WriteAllText("response.config.json", JsonSerializer.Serialize(ResponseMentioned));
File.WriteAllText("response.config.json", JsonConvert.SerializeObject(ResponseMentioned));
} else
{
ResponseMentioned = JsonSerializer.Deserialize<List<string>>(File.ReadAllText("response.config.json"));
ResponseMentioned = JsonConvert.DeserializeObject<List<string>>(File.ReadAllText("response.config.json"));
}
if (!File.Exists("meetings.config.json"))
{
ScheduledMeetings = new List<TencentScheduledMeeting>();
File.WriteAllText("meetings.config.json", JsonConvert.SerializeObject(ScheduledMeetings));
}
else
{
ScheduledMeetings = JsonConvert.DeserializeObject<List<TencentScheduledMeeting>>(File.ReadAllText("meetings.config.json"));
}
WhiteListEnabled = WhiteList.Count > 0;
}
Expand Down Expand Up @@ -92,6 +103,16 @@ public static void Main()
if (e is GroupMessageEvent)
{
var me = (e as GroupMessageEvent);
foreach (TencentScheduledMeeting i in ScheduledMeetings)
{
if (DateTime.Now < EndTime) break;
if (i.StartTime < DateTime.Now && i.EndTime > DateTime.Now)
{
TencentMeeting.InvokeWemeet(i.Url);
EndTime = i.EndTime;
break;
}
}
if (WhiteListEnabled)
{
bool inWhiteList = false;
Expand All @@ -105,6 +126,7 @@ public static void Main()
if (!inWhiteList) return new EmptyResponse();
}
string ThisMessage = me.message.ToString().ToLower();
string ThisMessageNormal = me.message.ToString();
if (!Groups.ContainsKey(me.group_id))
{
Groups.Add(me.group_id, new GroupInfo());
Expand All @@ -119,16 +141,69 @@ public static void Main()
Groups[me.group_id].Sent = false;
}
Groups[me.group_id].LastMessage = me.message.ToString().ToLower();
Console.WriteLine("[INFO] MessageCount: " + Groups[me.group_id].MessageCount + "; GroupID: " + me.group_id + "; Message: " + ThisMessage);
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("[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"))
{
ThisMessageNormal = ThisMessageNormal.Replace("会议时间:", "会议时间:");
if (ThisMessageNormal.Contains("会议时间:") && ThisMessageNormal.Contains("预定的会议"))
{
TencentScheduledMeeting meeting = new TencentScheduledMeeting();
int start = ThisMessageNormal.IndexOf("会议时间:");
int end = ThisMessageNormal.IndexOf(' ', start);
string date = ThisMessageNormal.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);
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);
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++)
{
if (ThisMessageNormal[i] == ' ' || ThisMessageNormal[i] == '\n' || ThisMessageNormal[i] == '\r' || ThisMessageNormal[i] == ']' || ThisMessageNormal[i] == ',')
{
end = i;
break;
}
}
meeting.Url = ThisMessageNormal.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++)
{
if (ThisMessageNormal[i] == ' ' || ThisMessageNormal[i] == '\n' || ThisMessageNormal[i] == '\r' || ThisMessageNormal[i] == ']' || ThisMessageNormal[i] == ',')
{
end = i;
break;
}
}
TencentMeeting.InvokeWemeet(ThisMessageNormal.Substring(start, end - start));
}
}
if (ThisMessage.Contains("please send"))
{
bool flagSent = false;
int addLen;
int start = ThisMessage.IndexOf("please send me the");
addLen = 18;
Expand Down Expand Up @@ -158,25 +233,20 @@ public static void Main()
addLen = 11;
}
start += addLen;
int end;
for (end = start + 1; end < ThisMessage.Length; end++)
int end = ThisMessage.IndexOf(' ', start + 1);
if (end == -1)
{
if (ThisMessage[end] == ' ')
{
Send(me.group_id, new Message(new ElementText(ThisMessage.Substring(start, end - start))));
flagSent = true;
break;
}
Send(me.group_id, new Message(new ElementText(ThisMessageNormal.Substring(start, ThisMessageNormal.Length - start))));
}
if (flagSent == false)
else
{
Send(me.group_id, new Message(new ElementText(ThisMessage.Substring(start, ThisMessage.Length - start))));
Send(me.group_id, new Message(new ElementText(ThisMessageNormal.Substring(start, end - start))));
}
Groups[me.group_id].Sent = true;
}
if (Groups[me.group_id].MessageCount > RepeatCount && !Groups[me.group_id].Sent)
{
Send(me.group_id, new Message(new ElementText(ThisMessage)));
Send(me.group_id, new Message(new ElementText(ThisMessageNormal)));
RepeatCount = random.Next(1, 10);
Groups[me.group_id].Sent = true;
}
Expand Down
3 changes: 2 additions & 1 deletion QQCourseBot/QQCourseBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="cqhttp.Cyan" Version="2.1.3" />
<PackageReference Include="cqhttp.Cyan" Version="2.1.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
</Project>
47 changes: 47 additions & 0 deletions QQCourseBot/TencentMeeting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Threading;

namespace QQCourseBot
{
public class TencentMeeting
{
private static string GetWemeet(string Url)
{
var client = new HttpClient();
var result = client.GetAsync(Url);
result.Wait();
return "wemeet://page/inmeeting" + result.Result.RequestMessage.RequestUri.Query.Replace("meetingcode", "meeting_code");
}

public static void InvokeWemeet(string Url)
{
Console.WriteLine("[WEMEET] Meeting URL: " + GetWemeet(Url));
Process process = new Process();
process.StartInfo.UseShellExecute = true;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
process.StartInfo.FileName = GetWemeet(Url);
process.Start();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
process.StartInfo.FileName = "xdg-open";
process.StartInfo.Arguments = GetWemeet(Url);
process.Start();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
process.StartInfo.FileName = "open";
process.StartInfo.Arguments = GetWemeet(Url);
process.Start();
}
else
{
Console.WriteLine("[WEMEET] Your OS does not support Tencent Meeting.");
}
}
}
}
10 changes: 10 additions & 0 deletions QQCourseBot/TencentScheduledMeeting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
namespace QQCourseBot
{
public class TencentScheduledMeeting
{
public DateTime StartTime;
public DateTime EndTime;
public string Url;
}
}
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ copyright by &copy; TURX, licensed by GPL v3.
- Support multiple groups. (1.1)
- Support JSON configuration. (1.2)
- Support QQ group whitelist. (1.2)
- Auto join Tencent Meeting (support both quick meeting and scheduled meeting and multiple sharing methods) (1.3)

## Screenshots

Expand All @@ -33,12 +34,21 @@ Console Warning:

![Console](img/5.png)

Auto Joining of Tencent Meetings (app scheduled and text quick):

![Meeting](img/6.png)

Auto Joining of Tencent Meetings (link only and text scheduled):

![Meeting](img/7.png)

## Dependencies

- .NET Core
- CoolQ
- cqhttp.Cyan (a C# wrapper for cqhttp)
- Docker (for non-Windows systems)
- Docker (optional, for non-Windows systems)
- Newtonsoft.Json

## Usage

Expand Down Expand Up @@ -111,3 +121,9 @@ Use the following configuration (with whitelisted QQ group IDs) to enable the wh
345678912
]
```

- meetings.config.json

This file would be auto-written by sending invitation of Tencent Meeting to whitelisted (if enabled, if not, any) groups.

You can also do some cleanups, removing unnecessary items from this file, to enhance the performance of the robot.
Binary file added img/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4912db5

Please sign in to comment.