public async Task ExecuteAsync() { QueueLog($"============== STARTUP =============="); QueueLog("`MASZ` started!"); QueueLog("System time: " + DateTime.Now.ToString()); QueueLog("System time (UTC): " + DateTime.UtcNow.ToString()); QueueLog($"Language: `{_config.GetDefaultLanguage()}`"); QueueLog($"Hostname: `{_config.GetHostName()}`"); QueueLog($"URL: `{_config.GetBaseUrl()}`"); QueueLog($"Domain: `{_config.GetServiceDomain()}`"); QueueLog($"ClientID: `{_config.GetClientId()}`"); if (_config.IsCorsEnabled()) { QueueLog("CORS support: \u26A0 `ENABLED`"); } else { QueueLog("CORS support: `DISABLED`"); } if (_config.IsCustomPluginModeEnabled()) { QueueLog("Plugin support: \u26A0 `ENABLED`"); } else { QueueLog("Plugin support: `DISABLED`"); } if (_config.IsDemoModeEnabled()) { QueueLog("Demo mode: \u26A0 `ENABLED`"); } else { QueueLog("Demo mode: `DISABLED`"); } if (_config.IsPublicFileEnabled()) { QueueLog("Public file mode: \u26A0 `ENABLED`"); } else { QueueLog("Public file mode: `DISABLED`"); } QueueLog($"============== /STARTUP ============="); await ExecuteWebhook(); }
public async Task ExecuteAsync() { using var scope = _serviceProvider.CreateScope(); try { await _interactions.AddModulesAsync(Assembly.GetEntryAssembly(), scope.ServiceProvider); } catch (Exception ex) { _logger.LogError(ex, "Modules could not initialize!"); return; } await _client.LoginAsync(TokenType.Bot, _internalConfiguration.GetBotToken()); await _client.StartAsync(); await _client.SetGameAsync(_internalConfiguration.GetBaseUrl(), type : ActivityType.Watching); }
private async Task AnnounceModCase(ModCase modCase, IUser actor, bool announcePublic, bool announceDm, RestAction action) { using var scope = _serviceProvider.CreateScope(); _logger.LogInformation($"Announcing modcase {modCase.Id} in guild {modCase.GuildId}."); var translator = scope.ServiceProvider.GetRequiredService <Translator>(); IUser caseUser = await _discordAPI.FetchUserInfo(modCase.UserId, CacheBehavior.Default); GuildConfig guildConfig = await GuildConfigRepository.CreateDefault(scope.ServiceProvider).GetGuildConfig(modCase.GuildId); translator.SetContext(guildConfig); if (announceDm && action != RestAction.Deleted) { _logger.LogInformation($"Sending dm notification to {modCase.UserId} for case {modCase.GuildId}/{modCase.CaseId}"); try { IGuild guild = _discordAPI.FetchGuildInfo(modCase.GuildId, CacheBehavior.Default); string message = string.Empty; switch (modCase.PunishmentType) { case PunishmentType.Mute: if (modCase.PunishedUntil.HasValue) { message = translator.T().NotificationModcaseDMMuteTemp(modCase, guild, _config.GetBaseUrl()); } else { message = translator.T().NotificationModcaseDMMutePerm(guild, _config.GetBaseUrl()); } break; case PunishmentType.Kick: message = translator.T().NotificationModcaseDMKick(guild, _config.GetBaseUrl()); break; case PunishmentType.Ban: if (modCase.PunishedUntil.HasValue) { message = translator.T().NotificationModcaseDMBanTemp(modCase, guild, _config.GetBaseUrl()); } else { message = translator.T().NotificationModcaseDMBanPerm(guild, _config.GetBaseUrl()); } break; default: message = translator.T().NotificationModcaseDMWarn(guild, _config.GetBaseUrl()); break; } await _discordAPI.SendDmMessage(modCase.UserId, message); } catch (Exception e) { _logger.LogError(e, $"Error while announcing modcase {modCase.GuildId}/{modCase.CaseId} in DMs to {modCase.UserId}."); } } if (!string.IsNullOrEmpty(guildConfig.ModPublicNotificationWebhook) && announcePublic) { _logger.LogInformation($"Sending public webhook for modcase {modCase.GuildId}/{modCase.CaseId} to {guildConfig.ModPublicNotificationWebhook}."); try { EmbedBuilder embed = await modCase.CreateModcaseEmbed(action, actor, scope.ServiceProvider, caseUser, false); await _discordAPI.ExecuteWebhook(guildConfig.ModPublicNotificationWebhook, embed.Build(), $"<@{modCase.UserId}>"); } catch (Exception e) { _logger.LogError(e, $"Error while announcing modcase {modCase.GuildId}/{modCase.CaseId} public to {guildConfig.ModPublicNotificationWebhook}."); } } if (!string.IsNullOrEmpty(guildConfig.ModInternalNotificationWebhook)) { _logger.LogInformation($"Sending internal webhook for modcase {modCase.GuildId}/{modCase.CaseId} to {guildConfig.ModInternalNotificationWebhook}."); try { EmbedBuilder embed = await modCase.CreateModcaseEmbed(action, actor, scope.ServiceProvider, caseUser, true); await _discordAPI.ExecuteWebhook(guildConfig.ModInternalNotificationWebhook, embed.Build(), $"<@{modCase.UserId}>"); } catch (Exception e) { _logger.LogError(e, $"Error while announcing modcase {modCase.GuildId}/{modCase.CaseId} internal to {guildConfig.ModInternalNotificationWebhook}."); } } }