Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Commit 50f3eb9

Browse files
author
Awbugl
committed
Initial Commit
1 parent af655b2 commit 50f3eb9

File tree

131 files changed

+5446
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+5446
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.idea
2+
*.dll
3+
*.xml
4+
*.cache
5+
*.pdb
6+
*.txt
7+
*.nupkg
8+
*.p7s
9+
*._
10+
11+
[Dd]ebug/
12+
[Dd]ebugPublic/
13+
[Rr]elease/
14+
[Rr]eleases/
15+
x64/
16+
x86/
17+
bld/
18+
[Bb]in/
19+
[Oo]bj/
20+
[Ll]og/

Andreal.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Andreal", "Andreal\Andreal.csproj", "{7F1621E9-9F21-463A-96AB-6C0F8E00095E}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{7F1621E9-9F21-463A-96AB-6C0F8E00095E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{7F1621E9-9F21-463A-96AB-6C0F8E00095E}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{7F1621E9-9F21-463A-96AB-6C0F8E00095E}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{7F1621E9-9F21-463A-96AB-6C0F8E00095E}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal

Andreal/Andreal.csproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Konata.Core" Version="1.3.1" />
12+
<PackageReference Include="Net.Codecrete.QrCodeGenerator" Version="2.0.1" />
13+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
14+
<PackageReference Include="sqlite-net-pcl" Version="1.7.335" />
15+
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<Content Include="..\README.md">
20+
<Link>README.md</Link>
21+
</Content>
22+
</ItemGroup>
23+
24+
</Project>

Andreal/ConfigJson.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Konata.Core;
2+
using Konata.Core.Common;
3+
using Konata.Core.Interfaces;
4+
using Newtonsoft.Json;
5+
using Path = Andreal.Core.Path;
6+
7+
namespace Andreal;
8+
9+
public class ConfigJson
10+
{
11+
[JsonProperty("keystore")] public BotKeyStore? KeyStore { get; set; }
12+
[JsonProperty("device")] public BotDevice? Device { get; set; }
13+
}
14+
15+
public class AccountInfo
16+
{
17+
[JsonProperty("uid")] public uint Account { get; set; }
18+
[JsonProperty("password")] public string Password { get; set; } = "";
19+
20+
internal Bot GenerateBotInstance()
21+
{
22+
var pth = Path.BotConfig(Account);
23+
if (File.Exists(pth))
24+
{
25+
var cfg = JsonConvert.DeserializeObject<ConfigJson>(File.ReadAllText(pth))!;
26+
return BotFather.Create(BotConfig.Default(), cfg.Device, cfg.KeyStore);
27+
}
28+
else
29+
{
30+
var bot = BotFather.Create(Account.ToString(), Password, out _, out var device, out var keystore);
31+
var cfg = new ConfigJson { Device = device, KeyStore = keystore };
32+
File.WriteAllText(pth, JsonConvert.SerializeObject(cfg));
33+
return bot;
34+
}
35+
}
36+
}
37+
38+
public class ApiConfig
39+
{
40+
[JsonProperty("url")] public string Url { get; set; } = "";
41+
[JsonProperty("token")] public string Token { get; set; } = "";
42+
}
43+
44+
public class AndrealSettings
45+
{
46+
[JsonProperty("friend_add")] public bool FriendAdd { get; set; }
47+
[JsonProperty("group_add")] public bool GroupAdd { get; set; }
48+
49+
[JsonProperty("group_inviter_whitelist")]
50+
public List<uint> GroupInviterWhitelist { get; set; } = new();
51+
}
52+
53+
public class AndrealConfig
54+
{
55+
[JsonProperty("master")] public uint Master { get; set; }
56+
[JsonProperty("accounts")] public List<AccountInfo> Accounts { get; set; } = new();
57+
[JsonProperty("api")] public Dictionary<string, ApiConfig> Api { get; set; } = new();
58+
[JsonProperty("approve_settings")] public AndrealSettings Settings { get; set; } = new();
59+
60+
[JsonProperty("enable_handle_message")]
61+
public bool EnableHandleMessage { get; set; } = true;
62+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Andreal.Core;
2+
3+
[Serializable]
4+
[AttributeUsage(AttributeTargets.Method)]
5+
internal class CommandPrefixAttribute : Attribute
6+
{
7+
internal CommandPrefixAttribute(params string[] prefixs) { Prefixs = prefixs; }
8+
9+
internal string[] Prefixs { get; }
10+
}

Andreal/Core/ConfigWatcher.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace Andreal.Core;
2+
3+
internal static class ConfigWatcher
4+
{
5+
private const int TimeoutMillis = 2000;
6+
private static readonly FileSystemWatcher Watcher = new(Path.AndreaConfigRoot);
7+
private static readonly List<string> TmpFiles = new();
8+
9+
internal static void Init()
10+
{
11+
Watcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.LastWrite;
12+
Watcher.Filter = "*.json";
13+
Watcher.EnableRaisingEvents = true;
14+
15+
Timer timer = new(OnTimer, null, Timeout.Infinite, Timeout.Infinite);
16+
Watcher.Changed += (_, e) =>
17+
{
18+
TmpFiles.Add(e.Name!);
19+
timer.Change(TimeoutMillis, Timeout.Infinite);
20+
};
21+
}
22+
23+
private static void OnTimer(object? _)
24+
{
25+
lock (TmpFiles)
26+
{
27+
foreach (var file in TmpFiles) GlobalConfig.Init(file);
28+
TmpFiles.Clear();
29+
}
30+
}
31+
}

Andreal/Core/External.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Andreal.Utils;
2+
using Konata.Core;
3+
using Konata.Core.Message;
4+
5+
namespace Andreal.Core;
6+
7+
[Serializable]
8+
public static class External
9+
{
10+
public static void Process(Bot bot, int type, uint fromGroup, uint fromQq, MessageStruct message) =>
11+
MessageInfo.Process(bot, type, fromGroup, fromQq, message);
12+
13+
public static void Initialize(AndrealConfig andrealConfig) => SystemHelper.Init(andrealConfig);
14+
}

Andreal/Core/GlobalConfig.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Concurrent;
2+
using Andreal.Data.Json.Arcaea.PartnerPosInfoBase;
3+
using Andreal.Data.Json.Pjsk;
4+
using Newtonsoft.Json;
5+
6+
namespace Andreal.Core;
7+
8+
internal static class GlobalConfig
9+
{
10+
internal static ConcurrentDictionary<string, List<PosInfoItem>> Locations
11+
= new(JsonConvert.DeserializeObject<Dictionary<string, List<PosInfoItem>>>(File.ReadAllText(Path.PartnerConfig))
12+
!);
13+
14+
internal static RobotReply RobotReply
15+
= JsonConvert.DeserializeObject<RobotReply>(File.ReadAllText(Path.RobotReply))!;
16+
17+
internal static List<PjskAlias> PjskAlias
18+
= JsonConvert.DeserializeObject<List<PjskAlias>>(File.ReadAllText(Path.PjskAlias))!;
19+
20+
internal static void Init(string file)
21+
{
22+
switch (file)
23+
{
24+
case "positioninfo.json":
25+
Locations
26+
= new(JsonConvert
27+
.DeserializeObject<
28+
Dictionary<string, List<PosInfoItem>>>(File.ReadAllText(Path.PartnerConfig))!);
29+
return;
30+
31+
case "replytemplate.json":
32+
RobotReply = JsonConvert.DeserializeObject<RobotReply>(File.ReadAllText(Path.RobotReply))!;
33+
return;
34+
35+
case "pjskalias.json":
36+
PjskAlias = JsonConvert.DeserializeObject<List<PjskAlias>>(File.ReadAllText(Path.PjskAlias))!;
37+
return;
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)