Skip to content
This repository was archived by the owner on Oct 12, 2025. It is now read-only.

Commit 7ce94a4

Browse files
authored
[OneBot] AutoUpdater for Lagrange.OneBot (#810)
* [OneBot]AutoUpdater for Lagrange.OneBot * [OneBot] make default enable auto update false
1 parent fc48f2b commit 7ce94a4

File tree

7 files changed

+695
-20
lines changed

7 files changed

+695
-20
lines changed

Lagrange.OneBot/Program.cs

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,71 @@ namespace Lagrange.OneBot;
88

99
internal abstract class Program
1010
{
11-
public static void Main(string[] args)
11+
public static async Task Main(string[] args)
1212
{
13-
string? version = Assembly.GetAssembly(typeof(Program))?
14-
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
15-
.InformationalVersion;
13+
string? version = Assembly
14+
.GetAssembly(typeof(Program))
15+
?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
16+
?.InformationalVersion;
1617

1718
Console.ForegroundColor = ConsoleColor.Magenta;
1819
if (Console.BufferWidth >= 45)
1920
{
20-
Console.WriteLine($$"""
21-
__
22-
/ / ___ ____ ________ ____ ___ ____
23-
/ /_/ _ `/ _ `/ __/ _ `/ _ \/ _ `/ -_)
24-
/____|_,_/\_, /_/ \_,_/_//_/\_, /\__/
25-
/___/ ____ /___/__ __
26-
/ __ \___ ___ / _ )___ / /_
27-
/ /_/ / _ \/ -_) _ / _ \/ __/
28-
\____/_//_/\__/____/\___/\__/
29-
""");
21+
Console.WriteLine(
22+
$$"""
23+
__
24+
/ / ___ ____ ________ ____ ___ ____
25+
/ /_/ _ `/ _ `/ __/ _ `/ _ \/ _ `/ -_)
26+
/____|_,_/\_, /_/ \_,_/_//_/\_, /\__/
27+
/___/ ____ /___/__ __
28+
/ __ \___ ___ / _ )___ / /_
29+
/ /_/ / _ \/ -_) _ / _ \/ __/
30+
\____/_//_/\__/____/\___/\__/
31+
"""
32+
);
3033
}
31-
else Console.WriteLine("Lagrange.OneBot");
34+
else
35+
Console.WriteLine("Lagrange.OneBot");
36+
3237
Console.ResetColor();
3338

3439
Console.WriteLine($"Version: {version?[^40..] ?? "unknown"}\n");
3540

41+
42+
// AutoUpdate
43+
var updater = new Updater.GithubUpdater();
44+
await updater.GetConfig();
45+
if (updater.Config.EnableAutoUpdate)
46+
{
47+
Console.WriteLine("Auto update enabled, Checking for updates...");
48+
try
49+
{
50+
if (await updater.CheckUpdate())
51+
{
52+
Console.WriteLine($"Update available, downloading...");
53+
await updater.Update();
54+
}
55+
else
56+
{
57+
Console.WriteLine("No updates available, continuing...");
58+
}
59+
60+
if (updater.Config.CheckInterval > 0)
61+
{
62+
Console.WriteLine(
63+
$"Interval check enabled, Next check in {updater.Config.CheckInterval} seconds."
64+
);
65+
updater.StartIntervalCheck();
66+
}
67+
}
68+
catch (Exception e)
69+
{
70+
Console.WriteLine(
71+
$"Error checking for updates: {e.Message}, please check your network connection or config file, use proxy if needed."
72+
);
73+
}
74+
}
75+
3676
Console.OutputEncoding = Encoding.UTF8;
3777
Console.InputEncoding = Encoding.UTF8;
3878

@@ -43,22 +83,26 @@ public static void Main(string[] args)
4383
Console.WriteLine("No exist config file, create it now...");
4484

4585
var assm = Assembly.GetExecutingAssembly();
46-
using var istr = assm.GetManifestResourceStream("Lagrange.OneBot.Resources.appsettings.json")!;
86+
using var istr = assm.GetManifestResourceStream(
87+
"Lagrange.OneBot.Resources.appsettings.json"
88+
)!;
4789
using var temp = File.Create("appsettings.json");
4890
istr.CopyTo(temp);
4991

5092
istr.Close();
5193
temp.Close();
5294

53-
Console.WriteLine("Please Edit the appsettings.json to set configs and press any key to continue");
95+
Console.WriteLine(
96+
"Please Edit the appsettings.json to set configs and press any key to continue"
97+
);
5498
Console.ReadKey(true);
5599
}
56100

57-
Host.CreateApplicationBuilder()
101+
await Host.CreateApplicationBuilder()
58102
.ConfigureLagrangeCore()
59103
.ConfigureOneBot()
60104
.Build()
61105
.InitializeMusicSigner() // Very ugly (
62-
.Run();
106+
.RunAsync();
63107
}
64-
}
108+
}

0 commit comments

Comments
 (0)