Skip to content

Commit

Permalink
[All -> All] Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogFeelings committed Nov 25, 2024
1 parent b64699d commit 5fef0d2
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 34 deletions.
1 change: 0 additions & 1 deletion Source/SammBot.Library/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#endregion

using Discord;
using System.Diagnostics;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand Down
4 changes: 3 additions & 1 deletion Source/SammBot.Tests/Extensions/ObjectExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ public void ToQueryStringTest()
}
}

// ReSharper disable UnusedMember.Local
file class TestClass
{
[UglyName("testString")]
public string TestString { get; } = "hello!";

[UglyName("testInt")]
public int TestInt { get; } = 2;
}
}
// ReSharper restore UnusedMember.Local
16 changes: 8 additions & 8 deletions Source/SammBot/Modules/FunModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public async Task<RuntimeResult> HugUserAsync
SocketGuildUser targetUser
)
{
string chosenKaomoji = _settingsService.Settings.HugKaomojis.PickRandom();
string chosenKaomoji = _settingsService.Settings!.HugKaomojis.PickRandom();

SocketGuildUser authorGuildUser = (Context.Interaction.User as SocketGuildUser)!;

Expand Down Expand Up @@ -195,7 +195,7 @@ SocketGuildUser targetUser
{
SocketGuildUser authorUser = (Context.Interaction.User as SocketGuildUser)!;

string chosenMessage = _settingsService.Settings.KillMessages.PickRandom();
string chosenMessage = _settingsService.Settings!.KillMessages.PickRandom();
Dictionary<string, object?> template = new Dictionary<string, object?>()
{
["murderer"] = Format.Bold(authorUser.DisplayName),
Expand Down Expand Up @@ -316,20 +316,20 @@ public async Task<RuntimeResult> ShipUsersAsync
if (percentage < _shipSegments[i])
{
if (i == 0)
progressBar += _settingsService.Settings.ShipBarStartEmpty;
progressBar += _settingsService.Settings!.ShipBarStartEmpty;
else if (i == _shipSegments.Length - 1)
progressBar += _settingsService.Settings.ShipBarEndEmpty;
progressBar += _settingsService.Settings!.ShipBarEndEmpty;
else
progressBar += _settingsService.Settings.ShipBarHalfEmpty;
progressBar += _settingsService.Settings!.ShipBarHalfEmpty;
}
else
{
if (i == 0)
progressBar += _settingsService.Settings.ShipBarStartFull;
progressBar += _settingsService.Settings!.ShipBarStartFull;
else if (i == _shipSegments.Length - 1)
progressBar += _settingsService.Settings.ShipBarEndFull;
progressBar += _settingsService.Settings!.ShipBarEndFull;
else
progressBar += _settingsService.Settings.ShipBarHalfFull;
progressBar += _settingsService.Settings!.ShipBarHalfFull;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/SammBot/Modules/UserTagsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task<RuntimeResult> SearchTagsAsync
using (DatabaseService databaseService = new DatabaseService())
{
List<UserTag> allTags = await databaseService.UserTags.Where(x => x.GuildId == Context.Guild.Id).ToListAsync();
List<UserTag> filteredTags = allTags.Where(x => searchTerm.DamerauDistance(x.Name, _settingsService.Settings.TagDistance) < int.MaxValue).Take(25).ToList();
List<UserTag> filteredTags = allTags.Where(x => searchTerm.DamerauDistance(x.Name, _settingsService.Settings!.TagDistance) < int.MaxValue).Take(25).ToList();

if (!filteredTags.Any())
return ExecutionResult.FromError($"No tags found with a name similar to \"{searchTerm}\".");
Expand Down
12 changes: 0 additions & 12 deletions Source/SammBot/Modules/UtilsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
using Discord;
using Discord.Interactions;
using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection;
using SammBot.Library;
using SammBot.Library.Attributes;
using SammBot.Library.Extensions;
using SammBot.Library.Models;
using SammBot.Library.Preconditions;
using SkiaSharp;
using System;
using System.IO;
using System.Threading.Tasks;
using SammBot.Services;

namespace SammBot.Modules;

Expand All @@ -38,15 +35,6 @@ namespace SammBot.Modules;
[ModuleEmoji("\U0001f527")]
public class UtilsModule : InteractionModuleBase<ShardedInteractionContext>
{
private readonly HttpService _httpService;
private readonly SettingsService _settingsService;

public UtilsModule(IServiceProvider provider)
{
_httpService = provider.GetRequiredService<HttpService>();
_settingsService = provider.GetRequiredService<SettingsService>();
}

[SlashCommand("viewhex", "Displays a HEX color, and converts it in other formats.")]
[DetailedDescription("Sends an image with the provided color as background, and a piece of text with the color written in the middle. " +
"Also converts it to RGB, CMYK, HSV and HSL.")]
Expand Down
4 changes: 2 additions & 2 deletions Source/SammBot/Services/CommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private async Task HandleInteractionAsync(SocketInteraction interaction)
{
ShardedInteractionContext context = new ShardedInteractionContext(_shardedClient, interaction);

if (_settingsService.Settings.OnlyOwnerMode)
if (_settingsService.Settings!.OnlyOwnerMode)
{
IApplication botApplication = await _shardedClient.GetApplicationInfoAsync();

Expand All @@ -137,7 +137,7 @@ private async Task HandleInteractionAsync(SocketInteraction interaction)
["username"] = interaction.User.GetFullUsername(),
["channelname"] = interaction.Channel.Name
};
string formattedLog = _settingsService.Settings.CommandLogFormat.TemplateReplace(template);
string formattedLog = _settingsService.Settings!.CommandLogFormat.TemplateReplace(template);

await _logger.LogAsync(LogSeverity.Debug, formattedLog);
#endif
Expand Down
4 changes: 2 additions & 2 deletions Source/SammBot/Services/HttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public HttpService(IServiceProvider services)

SettingsService settingsService = services.GetRequiredService<SettingsService>();

_client.DefaultRequestHeaders.Add("User-Agent", settingsService.Settings.HttpUserAgent);
_client.DefaultRequestHeaders.Add("User-Agent", settingsService.Settings!.HttpUserAgent);
}

/// <summary>
Expand Down Expand Up @@ -118,7 +118,7 @@ public void UnregisterDomainQueue(string domain)
}

// This domain has a queue.
if (_queueDictionary.TryGetValue(uriBuilder.Host, out TaskQueue? queue) && queue != default)
if (_queueDictionary.TryGetValue(uriBuilder.Host, out TaskQueue? queue))
return await queue.Enqueue(GetJsonRemote, CancellationToken.None);

return await GetJsonRemote();
Expand Down
4 changes: 2 additions & 2 deletions Source/SammBot/Services/RandomService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public RandomService(IServiceProvider services)
{
SettingsService settingsService = services.GetRequiredService<SettingsService>();

CatRequester = new SharpCatRequester(settingsService.Settings.CatKey);
DogRequester = new SharpDogRequester(settingsService.Settings.DogKey);
CatRequester = new SharpCatRequester(settingsService.Settings!.CatKey);
DogRequester = new SharpDogRequester(settingsService.Settings!.DogKey);
}
}
1 change: 0 additions & 1 deletion Source/SammBot/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#endregion

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text.Json;
using SammBot.Library;
Expand Down
8 changes: 4 additions & 4 deletions Source/SammBot/Services/StartupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public StartupService(IServiceProvider services)
public async Task StartAsync()
{
await _logger.LogAsync(LogSeverity.Information, "Logging in as a bot...");
await _shardedClient.LoginAsync(TokenType.Bot, _settingsService.Settings.BotToken);
await _shardedClient.LoginAsync(TokenType.Bot, _settingsService.Settings!.BotToken);
await _shardedClient.StartAsync();
await _logger.LogAsync(LogSeverity.Success, "Succesfully connected to web socket.");

Expand Down Expand Up @@ -175,7 +175,7 @@ private async Task OnShardReady(DiscordSocketClient shardClient)

if (_shardsReady == _shardedClient.Shards.Count)
{
if (_settingsService.Settings.StatusList.Count > 0 && _settingsService.Settings.RotatingStatus)
if (_settingsService.Settings!.StatusList.Count > 0 && _settingsService.Settings.RotatingStatus)
_statusTimer = new Timer(RotateStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(20));

await _interactionService.RegisterCommandsGloballyAsync();
Expand Down Expand Up @@ -213,9 +213,9 @@ private async void RotateStatus(object? state)
{
try
{
BotStatus chosenStatus = _settingsService.Settings.StatusList.PickRandom();
BotStatus chosenStatus = _settingsService.Settings!.StatusList.PickRandom();
ActivityType gameType = chosenStatus.Type;
string? gameUrl = gameType == ActivityType.Streaming ? _settingsService.Settings.TwitchUrl : null;
string? gameUrl = gameType == ActivityType.Streaming ? _settingsService.Settings!.TwitchUrl : null;

if (gameType == ActivityType.CustomStatus)
await _shardedClient.SetCustomStatusAsync(chosenStatus.Content);
Expand Down

0 comments on commit 5fef0d2

Please sign in to comment.