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

Commit 7ffa89a

Browse files
author
Awbugl
committed
Update Code
1 parent de5e386 commit 7ffa89a

File tree

73 files changed

+285
-1538
lines changed

Some content is hidden

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

73 files changed

+285
-1538
lines changed

Andreal.Core/Andreal.Core.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<ProjectReference Include="..\..\..\Git\Konata.Core\Konata.Core\Konata.Core.csproj" />
11+
<ProjectReference Include="..\..\..\Git\Konata.Core\Konata.Core\Konata.Core.csproj" />
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
16-
<PackageReference Include="sqlite-net-pcl" Version="1.7.335" />
17-
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
15+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
16+
<PackageReference Include="sqlite-net-pcl" Version="1.7.335" />
17+
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
1818
</ItemGroup>
1919

2020
</Project>
Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
using System.Timers;
2-
using Andreal.Core.Data.Api;
3-
using Andreal.Core.Data.Json.Pjsk;
4-
using Andreal.Core.Model.Pjsk;
52
using Timer = System.Timers.Timer;
63

74
namespace Andreal.Core.Common;
85

9-
public static class BackgroundTask
6+
internal static class BackgroundTask
107
{
11-
private static ulong _timerCount;
12-
138
internal static void Init()
149
{
1510
Timer timer = new(240000);
16-
timer.Elapsed += PjskUpdate;
1711
timer.Elapsed += Clean;
18-
timer.Elapsed += (_, _) => ++_timerCount;
1912
timer.AutoReset = true;
2013
timer.Enabled = true;
2114
}
@@ -27,38 +20,4 @@ private static void Clean(object? source, ElapsedEventArgs e)
2720
foreach (var j in new DirectoryInfo(Path.TempImageRoot).GetFiles().Where(j => time > j.LastWriteTime))
2821
j.Delete();
2922
}
30-
31-
private static async void PjskUpdate(object? source, ElapsedEventArgs e)
32-
{
33-
try
34-
{
35-
if (_timerCount % 15 != 0) return;
36-
37-
var musics = new List<PjskMusics>();
38-
var musicMetas = new List<PjskMusicMetas>();
39-
var musicDifficulties = new List<PjskMusicDifficulties>();
40-
41-
await Task.WhenAll(Task.Run(() => musics = PjskApi.PjskMusics().Result ?? musics),
42-
Task.Run(() => musicMetas = PjskApi.PjskMusicMetas().Result ?? musicMetas),
43-
Task.Run(() => musicDifficulties
44-
= PjskApi.PjskMusicDifficulties().Result ?? musicDifficulties));
45-
46-
foreach (var item in musics)
47-
if (!SongInfo.CheckFull(item.ID))
48-
{
49-
var metas = musicMetas.Where(i => i.MusicID == item.ID).ToList();
50-
if (metas.Any())
51-
SongInfo.Insert(item, metas, null);
52-
else
53-
{
54-
var difficulties = musicDifficulties.Where(i => i.MusicID == item.ID).ToList();
55-
if (difficulties.Any()) SongInfo.Insert(item, difficulties, null);
56-
}
57-
}
58-
}
59-
catch (Exception ex)
60-
{
61-
ExceptionLogger.Log(ex);
62-
}
63-
}
6423
}

Andreal.Core/Common/ConfigJson.cs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Konata.Core;
21
using Konata.Core.Common;
3-
using Konata.Core.Interfaces;
42
using Newtonsoft.Json;
53

64
namespace Andreal.Core.Common;
@@ -15,25 +13,6 @@ public class AccountInfo
1513
{
1614
[JsonProperty("uid")] public uint Account { get; set; }
1715
[JsonProperty("password")] public string Password { get; set; } = "";
18-
19-
public Bot GenerateBotInstance(BotConfig config)
20-
{
21-
var pth = Path.BotConfig(Account);
22-
if (File.Exists(pth))
23-
{
24-
var cfg = JsonConvert.DeserializeObject<ConfigJson>(File.ReadAllText(pth))!;
25-
return BotFather.Create(config, cfg.Device, cfg.KeyStore);
26-
}
27-
else
28-
{
29-
var keystore = new BotKeyStore(Account.ToString(), Password);
30-
var device = BotDevice.Default();
31-
var bot = BotFather.Create(config, device, keystore);
32-
var cfg = new ConfigJson { Device = device, KeyStore = keystore };
33-
File.WriteAllText(pth, JsonConvert.SerializeObject(cfg));
34-
return bot;
35-
}
36-
}
3716
}
3817

3918
public class ApiConfig
@@ -46,19 +25,14 @@ public class AndrealSettings
4625
{
4726
[JsonProperty("friend_add")] public bool FriendAdd { get; set; }
4827
[JsonProperty("group_add")] public bool GroupAdd { get; set; }
49-
50-
[JsonProperty("group_inviter_whitelist")]
51-
public List<uint> GroupInviterWhitelist { get; set; } = new();
28+
[JsonProperty("group_inviter_whitelist")] public List<uint> GroupInviterWhitelist { get; set; } = new();
5229
}
5330

5431
public class AndrealConfig
5532
{
5633
[JsonProperty("master")] public uint Master { get; set; }
5734
[JsonProperty("protocol")] public OicqProtocol Protocol { get; set; }
58-
59-
[JsonProperty("enable_handle_message")]
60-
public bool EnableHandleMessage { get; set; } = true;
61-
35+
[JsonProperty("enable_handle_message")] public bool EnableHandleMessage { get; set; } = true;
6236
[JsonProperty("accounts")] public List<AccountInfo> Accounts { get; set; } = new();
6337
[JsonProperty("api")] public Dictionary<string, ApiConfig> Api { get; set; } = new();
6438
[JsonProperty("approve_settings")] public AndrealSettings Settings { get; set; } = new();

Andreal.Core/Common/GlobalConfig.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.Concurrent;
22
using Andreal.Core.Data.Json.Arcaea.PartnerPosInfoBase;
3-
using Andreal.Core.Data.Json.Pjsk;
43
using Newtonsoft.Json;
54

65
namespace Andreal.Core.Common;
@@ -11,11 +10,7 @@ internal static ConcurrentDictionary<string, List<PosInfoItem>> Locations
1110
= new(JsonConvert.DeserializeObject<Dictionary<string, List<PosInfoItem>>>(File.ReadAllText(Path.PartnerConfig))
1211
!);
1312

14-
public 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))!;
13+
public static RobotReply RobotReply = JsonConvert.DeserializeObject<RobotReply>(File.ReadAllText(Path.RobotReply))!;
1914

2015
internal static void Init(string file)
2116
{
@@ -31,10 +26,6 @@ internal static void Init(string file)
3126
case "replytemplate.json":
3227
RobotReply = JsonConvert.DeserializeObject<RobotReply>(File.ReadAllText(Path.RobotReply))!;
3328
return;
34-
35-
case "pjskalias.json":
36-
PjskAlias = JsonConvert.DeserializeObject<List<PjskAlias>>(File.ReadAllText(Path.PjskAlias))!;
37-
return;
3829
}
3930
}
4031
}

Andreal.Core/Common/MessageInfo.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ internal class MessageInfo
2323

2424
private static readonly Dictionary<(Type, MethodInfo), string[]> MethodPrefixs = GetMethodPrefixs();
2525

26-
private static readonly Dictionary<string, string> AbbreviationPairs = new()
27-
{
28-
{ "/a ", "/arc " }, { "/p ", "/pjsk " }
29-
};
30-
3126
internal Bot Bot { get; set; }
3227
internal uint FromGroup { get; private set; }
3328
internal uint FromQQ { get; private set; }
@@ -183,7 +178,8 @@ var match
183178
private static TextMessage GetErrorMessage(Exception e) =>
184179
e switch
185180
{
186-
JsonReaderException or HttpRequestException or TaskCanceledException or TimeoutException => RobotReply.OnAPIQueryFailed(e),
181+
JsonReaderException or HttpRequestException or TaskCanceledException or TimeoutException => RobotReply
182+
.OnAPIQueryFailed(e),
187183
_ => RobotReply.OnExceptionOccured(e)
188184
};
189185

@@ -200,12 +196,9 @@ private static string Replace(string rawMessage)
200196
return "/arc info";
201197
}
202198

203-
foreach (var (key, value) in
204-
AbbreviationPairs.Where(i => rawMessage.StartsWith(i.Key, StringComparison.OrdinalIgnoreCase)))
205-
rawMessage = value + rawMessage[key.Length..];
199+
if (rawMessage.StartsWith("/a ", StringComparison.OrdinalIgnoreCase)) rawMessage = "/arc " + rawMessage[3..];
206200

207-
return string.Join(" ",
208-
rawMessage.Split(new char[] { '\n', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries));
201+
return string.Join(" ", rawMessage.Split(new char[] { '\n', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries));
209202
}
210203

211204
private static Dictionary<(Type, MethodInfo), string[]> GetMethodPrefixs()

Andreal.Core/Common/ObjectPool.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

Andreal.Core/Common/Path.cs

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class Path
1212
private static readonly string ArcaeaImageRoot = BaseDirectory + "/Andreal/Arcaea/";
1313
private static readonly string ArcaeaSourceRoot = BaseDirectory + "/Andreal/Source/";
1414
private static readonly string AndreaOtherRoot = BaseDirectory + "/Andreal/Other/";
15-
private static readonly string PjskImageRoot = BaseDirectory + "/Andreal/Pjsk/";
1615
public static readonly string AndreaConfigRoot = BaseDirectory + "/Andreal/Config/";
1716
public static readonly string TempImageRoot = BaseDirectory + "/Andreal/TempImage/";
1817

@@ -24,8 +23,6 @@ public class Path
2423

2524
public static readonly Path RobotReply = new(AndreaConfigRoot + "replytemplate.json");
2625

27-
public static readonly Path PjskAlias = new(AndreaConfigRoot + "pjskalias.json");
28-
2926
public static readonly Path ArcaeaConstListBg = new(ArcaeaSourceRoot + "ConstList.jpg");
3027

3128
public static readonly Path ArcaeaDivider = new(ArcaeaSourceRoot + "Divider.png");
@@ -44,6 +41,8 @@ public class Path
4441

4542
private readonly string _rawpath;
4643

44+
private FileInfo? _fileInfo;
45+
4746
static Path()
4847
{
4948
if (!Directory.Exists(ArcaeaBackgroundRoot)) Directory.CreateDirectory(ArcaeaBackgroundRoot);
@@ -57,14 +56,6 @@ static Path()
5756
Directory.CreateDirectory(AndreaConfigRoot + "BotInfo/");
5857
}
5958

60-
if (!Directory.Exists(PjskImageRoot))
61-
{
62-
Directory.CreateDirectory(PjskImageRoot);
63-
Directory.CreateDirectory(PjskImageRoot + "Song/");
64-
Directory.CreateDirectory(PjskImageRoot + "Chart/");
65-
Directory.CreateDirectory(PjskImageRoot + "EventBg/");
66-
}
67-
6859
if (!Directory.Exists(ArcaeaImageRoot))
6960
{
7061
Directory.CreateDirectory(ArcaeaImageRoot);
@@ -77,8 +68,6 @@ static Path()
7768

7869
private Path(string rawpath) { _rawpath = rawpath; }
7970

80-
private FileInfo? _fileInfo;
81-
8271
public FileInfo FileInfo => _fileInfo ??= new(this);
8372

8473
public static Path BotConfig(uint qqid) => new(AndreaConfigRoot + $"BotInfo/{qqid}.andreal.konata.botinfo");
@@ -96,10 +85,8 @@ public static async Task<Path> ArcaeaSong(ArcaeaChart chart)
9685

9786
if (pth.FileInfo.Exists)
9887
{
99-
if (pth.FileInfo.Length > 10240)
100-
return pth;
101-
else
102-
pth.FileInfo.Delete();
88+
if (pth.FileInfo.Length > 10240) return pth;
89+
pth.FileInfo.Delete();
10390
}
10491

10592
await ArcaeaUnlimitedApi.SongAssets(chart.SongID, chart.RatingClass, pth);
@@ -142,10 +129,8 @@ public static async Task<Path> ArcaeaPartner(int partner, bool awakened)
142129

143130
if (pth.FileInfo.Exists)
144131
{
145-
if (pth.FileInfo.Length > 10240)
146-
return pth;
147-
else
148-
pth.FileInfo.Delete();
132+
if (pth.FileInfo.Length > 10240) return pth;
133+
pth.FileInfo.Delete();
149134
}
150135

151136
await ArcaeaUnlimitedApi.CharAssets(partner, awakened, pth);
@@ -159,10 +144,8 @@ public static async Task<Path> ArcaeaPartnerIcon(int partner, bool awakened)
159144

160145
if (pth.FileInfo.Exists)
161146
{
162-
if (pth.FileInfo.Length > 10240)
163-
return pth;
164-
else
165-
pth.FileInfo.Delete();
147+
if (pth.FileInfo.Length > 10240) return pth;
148+
pth.FileInfo.Delete();
166149
}
167150

168151
await ArcaeaUnlimitedApi.IconAssets(partner, awakened, pth);
@@ -176,10 +159,8 @@ public static async Task<Path> ArcaeaChartPreview(ArcaeaChart chart)
176159

177160
if (pth.FileInfo.Exists)
178161
{
179-
if (pth.FileInfo.Length > 10240)
180-
return pth;
181-
else
182-
pth.FileInfo.Delete();
162+
if (pth.FileInfo.Length > 10240) return pth;
163+
pth.FileInfo.Delete();
183164
}
184165

185166
await ArcaeaUnlimitedApi.PreviewAssets(chart.SongID, chart.RatingClass, pth);
@@ -197,13 +178,6 @@ public static async Task<Path> ArcaeaChartPreview(ArcaeaChart chart)
197178

198179
public static Path RandImageFileName() => new(TempImageRoot + $"{RandStringHelper.GetRandString()}.jpg");
199180

200-
public static Path PjskSong(string sid) => new(PjskImageRoot + $"Song/{sid}.png");
201-
202-
public static Path PjskChart(string sid, string dif) => new(PjskImageRoot + $"Chart/{sid}_{dif}.png");
203-
204-
public static Path PjskEvent(string currentEventAssetbundleName) =>
205-
new(PjskImageRoot + $"EventBg/{currentEventAssetbundleName}.png");
206-
207181
public static Path ArcaeaBg4(int difficulty, string package)
208182
{
209183
var backgroundImgV4 = difficulty == 3

Andreal.Core/Common/RobotReply.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,13 @@ namespace Andreal.Core.Common;
55

66
public class RobotReply
77
{
8-
internal TextMessage OnExceptionOccured(Exception ex) => ExceptionOccured.Replace("$exception$",ex.Message);
9-
10-
internal TextMessage OnAPIQueryFailed(Exception ex) => APIQueryFailed.Replace("$exception$",ex.Message);
11-
12-
internal TextMessage OnAPIQueryFailed(int status, string message) => APIQueryFailed.Replace("$exception$",$"{status}: {message}");
13-
14-
internal TextMessage OnJrrpResult(string value) =>JrrpResult.Replace("$jrrp$", value);
15-
16-
internal TextMessage OnBindSuccess(string value) =>BindSuccess.Replace("$info$", value);
17-
188
[JsonProperty("NotBind")] public string NotBind { get; set; } = "";
199
[JsonProperty("NotBindArc")] public string NotBindArc { get; set; } = "";
20-
[JsonProperty("NotBindPjsk")] public string NotBindPjsk { get; set; } = "";
2110
[JsonProperty("ParameterLengthError")] public string ParameterLengthError { get; set; } = "";
2211
[JsonProperty("ParameterError")] public string ParameterError { get; set; } = "";
2312
[JsonProperty("ConfigNotFound")] public string ConfigNotFound { get; set; } = "";
2413
[JsonProperty("NotPlayedTheSong")] public string NotPlayedTheSong { get; set; } = "";
2514
[JsonProperty("BestsQuerying")] public string BestsQuerying { get; set; } = "";
26-
[JsonProperty("PjskUserBindFailed")] public string PjskUserBindFailed { get; set; } = "";
2715
[JsonProperty("ArcUidNotFound")] public string ArcUidNotFound { get; set; } = "";
2816
[JsonProperty("TooManyArcUid")] public string TooManyArcUid { get; set; } = "";
2917
[JsonProperty("NoSongFound")] public string? NoSongFound { get; set; } = "";
@@ -42,4 +30,10 @@ public class RobotReply
4230
[JsonProperty("BelowTheThreshold")] public string BelowTheThreshold { get; set; } = "";
4331
[JsonProperty("NeedUpdateAUA")] public string NeedUpdateAUA { get; set; } = "";
4432
[JsonProperty("ExceptionOccured")] public string ExceptionOccured { get; set; } = "";
33+
internal TextMessage OnExceptionOccured(Exception ex) => ExceptionOccured.Replace("$exception$", ex.Message);
34+
internal TextMessage OnAPIQueryFailed(Exception ex) => APIQueryFailed.Replace("$exception$", ex.Message);
35+
internal TextMessage OnAPIQueryFailed(int status, string message) =>
36+
APIQueryFailed.Replace("$exception$", $"{status}: {message}");
37+
internal TextMessage OnJrrpResult(string value) => JrrpResult.Replace("$jrrp$", value);
38+
internal TextMessage OnBindSuccess(string value) => BindSuccess.Replace("$info$", value);
4539
}

Andreal.Core/Data/Api/ArcaeaUnlimitedApi.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private static async Task GetImage(string url, Path filename)
2525
{
2626
FileStream? fileStream = null;
2727
var message = (await _client!.GetAsync(url)).EnsureSuccessStatusCode();
28-
28+
2929
if (message.Content.Headers.ContentType?.MediaType?.StartsWith("image/") != true)
3030
throw new ArgumentException(JsonConvert.DeserializeObject<ResponseRoot>(await message.Content
3131
.ReadAsStringAsync())!
@@ -60,10 +60,7 @@ private static async Task GetImage(string url, Path filename)
6060

6161
try
6262
{
63-
if (exflag && File.Exists(filename))
64-
{
65-
File.Delete(filename);
66-
}
63+
if (exflag && File.Exists(filename)) File.Delete(filename);
6764
}
6865
catch
6966
{

0 commit comments

Comments
 (0)