|
@@ -2,26 +2,27 @@
|
|
|
using Discord;
|
|
|
using Discord.WebSocket;
|
|
|
using Logging.Net;
|
|
|
+using Moonlight.App.Repositories;
|
|
|
using Moonlight.App.Services.DiscordBot.Commands;
|
|
|
+using Moonlight.App.Services.DiscordBot.Modules;
|
|
|
|
|
|
namespace Moonlight.App.Services.DiscordBot;
|
|
|
|
|
|
public class DiscordBotService
|
|
|
{
|
|
|
public static bool MaintenanceMode = false;
|
|
|
-
|
|
|
+
|
|
|
private readonly IServiceScopeFactory ServiceScopeFactory;
|
|
|
private readonly ConfigService ConfigService;
|
|
|
-
|
|
|
+
|
|
|
private IServiceScope ServiceScope;
|
|
|
|
|
|
private readonly DiscordSocketClient Client;
|
|
|
|
|
|
- // Add here references so e.g.
|
|
|
- // public ExampleModule ExampleModule { get; private set; }
|
|
|
- public RemoveCommandsModuels RemoveCommandsModuels { get; private set; }
|
|
|
+ // References
|
|
|
+ public ActivityStatusModule ActivityStatusModule { get; private set; }
|
|
|
|
|
|
- public DiscordBotService(
|
|
|
+public DiscordBotService(
|
|
|
IServiceScopeFactory serviceScopeFactory,
|
|
|
ConfigService configService)
|
|
|
{
|
|
@@ -39,15 +40,19 @@ public class DiscordBotService
|
|
|
var discordConfig = ConfigService
|
|
|
.GetSection("Moonlight")
|
|
|
.GetSection("DiscordBot");
|
|
|
-
|
|
|
- if(!discordConfig.GetValue<bool>("Enable"))
|
|
|
+
|
|
|
+ if (!discordConfig.GetValue<bool>("Enable"))
|
|
|
return;
|
|
|
-
|
|
|
+
|
|
|
Client.Log += Log;
|
|
|
Client.Ready += OnReady;
|
|
|
|
|
|
//Commands
|
|
|
- RemoveCommandsModuels = new(Client, ConfigService, ServiceScope);
|
|
|
+
|
|
|
+ //Module
|
|
|
+ ActivityStatusModule = new(Client, ConfigService, ServiceScope);
|
|
|
+
|
|
|
+ await ActivityStatusModule.UpdateActivityStatusList();
|
|
|
|
|
|
await Client.LoginAsync(TokenType.Bot, discordConfig.GetValue<string>("Token"));
|
|
|
await Client.StartAsync();
|
|
@@ -56,12 +61,13 @@ public class DiscordBotService
|
|
|
}
|
|
|
private async Task OnReady()
|
|
|
{
|
|
|
- //TODO: MASU Ladenachrichten jede Minute ändern.
|
|
|
- await Client.SetGameAsync("Masu ist zu lazy um das zu Implementieren.", null, ActivityType.Listening);
|
|
|
+ //await Client.SetGameAsync(name: "https://endelon-hosting.de", type: ActivityType.Watching);
|
|
|
await Client.SetStatusAsync(UserStatus.Idle);
|
|
|
-
|
|
|
+
|
|
|
Logger.Info($"Invite link: https://discord.com/api/oauth2/authorize?client_id={Client.CurrentUser.Id}&permissions=1099511696391&scope=bot%20applications.commands");
|
|
|
Logger.Info($"Login as {Client.CurrentUser.Username}#{Client.CurrentUser.DiscriminatorValue}");
|
|
|
+
|
|
|
+ Task.Run(ActivityStatusModule.ActivityStatusScheduler);
|
|
|
}
|
|
|
|
|
|
private Task Log(LogMessage message)
|
|
@@ -69,12 +75,12 @@ public class DiscordBotService
|
|
|
Logger.Debug(message.Message);
|
|
|
return Task.CompletedTask;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public async Task CreateCommands()
|
|
|
{
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
stopwatch.Start();
|
|
|
-
|
|
|
+
|
|
|
var type = this.GetType();
|
|
|
var properties = type.GetProperties();
|
|
|
Logger.Debug("Start Initializing Commands");
|
|
@@ -96,9 +102,9 @@ public class DiscordBotService
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
stopwatch.Stop();
|
|
|
Logger.Info($"Registered all commands. Done in {stopwatch.ElapsedMilliseconds}ms");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|