Skip to content

Commit dd8c01e

Browse files
committed
move the config stuff & add the ability to ignore specific debug log messagess to the config
1 parent fa8d78b commit dd8c01e

File tree

6 files changed

+105
-83
lines changed

6 files changed

+105
-83
lines changed

src/Bot/Helpers/Logger.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ public static event Action<VolteLogEventArgs> Event
1717

1818
public static void Log(VolteLogEventArgs eventArgs)
1919
{
20-
if (eventArgs.Severity is LogSeverity.Debug && !IsDebugLoggingEnabled)
21-
return;
22-
20+
switch (eventArgs.Severity)
21+
{
22+
case LogSeverity.Debug when !IsDebugLoggingEnabled:
23+
case LogSeverity.Debug
24+
when Config.IgnoredDebugLines.Length > 0
25+
&& eventArgs.Message is not null
26+
&& eventArgs.Message.ContainsAnyIgnoreCase(Config.IgnoredDebugLines):
27+
return;
28+
}
29+
2330
try
2431
{
2532
LogEventHandler.Call(eventArgs);
Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Text.Json.Serialization;
22

3-
namespace Volte;
3+
namespace Volte.Systems.Configuration;
44

55
public static class Config
66
{
@@ -142,6 +142,8 @@ public static bool IsValidToken()
142142
public static string Streamer => _configuration.Streamer;
143143

144144
public static bool DebugEnabled => _configuration?.EnableDebug ?? false;
145+
146+
public static string[] IgnoredDebugLines => _configuration?.IgnoredDebugMessages ?? [];
145147

146148
public static string FormattedStreamUrl => $"https://twitch.tv/{Streamer}";
147149

@@ -154,82 +156,4 @@ public static bool IsValidToken()
154156
public static HashSet<ulong> BlacklistedOwners => _configuration.BlacklistedGuildOwners;
155157

156158
public static EnabledFeatures EnabledFeatures => _configuration?.EnabledFeatures;
157-
}
158-
159-
public struct HeadlessBotConfig : IVolteConfig
160-
{
161-
[JsonPropertyName("discord_token")]
162-
public string Token { get; set; }
163-
164-
[JsonPropertyName("sentry_dsn")]
165-
public string SentryDsn { get; set; }
166-
167-
[JsonPropertyName("command_prefix")]
168-
public string CommandPrefix { get; set; }
169-
170-
[JsonPropertyName("bot_owner")]
171-
public ulong Owner { get; set; }
172-
173-
[JsonPropertyName("status_game")]
174-
public string Game { get; set; }
175-
176-
[JsonPropertyName("status_twitch_streamer")]
177-
public string Streamer { get; set; }
178-
179-
[JsonPropertyName("enable_debug_logging")]
180-
public bool EnableDebug { get; set; }
181-
182-
[JsonPropertyName("color_success")]
183-
public uint SuccessEmbedColor { get; set; }
184-
185-
[JsonPropertyName("color_error")]
186-
public uint ErrorEmbedColor { get; set; }
187-
188-
[JsonPropertyName("log_all_commands")]
189-
public bool LogAllCommands { get; set; }
190-
191-
[JsonPropertyName("blacklisted_guild_owners")]
192-
public HashSet<ulong> BlacklistedGuildOwners { get; set; }
193-
194-
[JsonPropertyName("enabled_features")]
195-
public EnabledFeatures EnabledFeatures { get; set; }
196-
}
197-
198-
public interface IVolteConfig
199-
{
200-
[JsonPropertyName("discord_token")]
201-
public string Token { get; set; }
202-
203-
[JsonPropertyName("sentry_dsn")]
204-
public string SentryDsn { get; set; }
205-
206-
[JsonPropertyName("command_prefix")]
207-
public string CommandPrefix { get; set; }
208-
209-
[JsonPropertyName("bot_owner")]
210-
public ulong Owner { get; set; }
211-
212-
[JsonPropertyName("status_game")]
213-
public string Game { get; set; }
214-
215-
[JsonPropertyName("status_twitch_streamer")]
216-
public string Streamer { get; set; }
217-
218-
[JsonPropertyName("enable_debug_logging")]
219-
public bool EnableDebug { get; set; }
220-
221-
[JsonPropertyName("color_success")]
222-
public uint SuccessEmbedColor { get; set; }
223-
224-
[JsonPropertyName("color_error")]
225-
public uint ErrorEmbedColor { get; set; }
226-
227-
[JsonPropertyName("log_all_commands")]
228-
public bool LogAllCommands { get; set; }
229-
230-
[JsonPropertyName("blacklisted_guild_owners")]
231-
public HashSet<ulong> BlacklistedGuildOwners { get; set; }
232-
233-
[JsonPropertyName("enabled_features")]
234-
public EnabledFeatures EnabledFeatures { get; set; }
235159
}

src/Bot/Entities/Config/EnabledFeatures.cs renamed to src/Bot/Systems/Configuration/Types/EnabledFeatures.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Text.Json.Serialization;
22

3-
namespace Volte.Entities;
3+
namespace Volte.Systems.Configuration;
44

55
/// <summary>
66
/// Model that represents enabled/disabled features as defined in your config.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace Volte.Systems.Configuration;
4+
5+
public struct HeadlessBotConfig : IVolteConfig
6+
{
7+
[JsonPropertyName("discord_token")]
8+
public string Token { get; set; }
9+
10+
[JsonPropertyName("sentry_dsn")]
11+
public string SentryDsn { get; set; }
12+
13+
[JsonPropertyName("command_prefix")]
14+
public string CommandPrefix { get; set; }
15+
16+
[JsonPropertyName("bot_owner")]
17+
public ulong Owner { get; set; }
18+
19+
[JsonPropertyName("status_game")]
20+
public string Game { get; set; }
21+
22+
[JsonPropertyName("status_twitch_streamer")]
23+
public string Streamer { get; set; }
24+
25+
[JsonPropertyName("enable_debug_logging")]
26+
public bool EnableDebug { get; set; }
27+
28+
[JsonPropertyName("ignored_debug_log_messages")]
29+
public string[] IgnoredDebugMessages { get; set; }
30+
31+
[JsonPropertyName("color_success")]
32+
public uint SuccessEmbedColor { get; set; }
33+
34+
[JsonPropertyName("color_error")]
35+
public uint ErrorEmbedColor { get; set; }
36+
37+
[JsonPropertyName("log_all_commands")]
38+
public bool LogAllCommands { get; set; }
39+
40+
[JsonPropertyName("blacklisted_guild_owners")]
41+
public HashSet<ulong> BlacklistedGuildOwners { get; set; }
42+
43+
[JsonPropertyName("enabled_features")]
44+
public EnabledFeatures EnabledFeatures { get; set; }
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace Volte.Systems.Configuration;
4+
5+
public interface IVolteConfig
6+
{
7+
[JsonPropertyName("discord_token")]
8+
public string Token { get; set; }
9+
10+
[JsonPropertyName("sentry_dsn")]
11+
public string SentryDsn { get; set; }
12+
13+
[JsonPropertyName("command_prefix")]
14+
public string CommandPrefix { get; set; }
15+
16+
[JsonPropertyName("bot_owner")]
17+
public ulong Owner { get; set; }
18+
19+
[JsonPropertyName("status_game")]
20+
public string Game { get; set; }
21+
22+
[JsonPropertyName("status_twitch_streamer")]
23+
public string Streamer { get; set; }
24+
25+
[JsonPropertyName("enable_debug_logging")]
26+
public bool EnableDebug { get; set; }
27+
28+
[JsonPropertyName("ignored_debug_log_messages")]
29+
public string[] IgnoredDebugMessages { get; set; }
30+
31+
[JsonPropertyName("color_success")]
32+
public uint SuccessEmbedColor { get; set; }
33+
34+
[JsonPropertyName("color_error")]
35+
public uint ErrorEmbedColor { get; set; }
36+
37+
[JsonPropertyName("log_all_commands")]
38+
public bool LogAllCommands { get; set; }
39+
40+
[JsonPropertyName("blacklisted_guild_owners")]
41+
public HashSet<ulong> BlacklistedGuildOwners { get; set; }
42+
43+
[JsonPropertyName("enabled_features")]
44+
public EnabledFeatures EnabledFeatures { get; set; }
45+
}

src/Bot/globalusings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
global using Discord;
1919
global using Humanizer;
2020
global using Volte.Systems.Commands.Text;
21+
global using Volte.Systems.Configuration;
2122
global using Volte.Entities;
2223
global using Volte.Services;
2324
global using System.Net.Http;

0 commit comments

Comments
 (0)