Skip to content

Commit

Permalink
Added log to update roles
Browse files Browse the repository at this point in the history
  • Loading branch information
FeroxFoxxo committed Jun 19, 2024
1 parent cc6026f commit 3613e08
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 37 deletions.
4 changes: 3 additions & 1 deletion backend/Bot/Abstractions/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public abstract class Command<T> : InteractionModuleBase<SocketInteractionContex
public override async Task BeforeExecuteAsync(ICommandInfo command)
{
Logger.LogInformation(
$"{Context.User.Id} used {command.Name} in {Context.Channel.Id} | {Context.Guild.Id} {Context.Guild.Name}");
"{Username} used {CommandName} in {ChannelName} | {GuildName} ({GuildId})",
Context.User.Username, command.Name, Context.Channel.Name, Context.Guild.Name, Context.Guild.Id
);

GuildConfig = await GuildConfigRepository.GetGuildConfig(Context.Guild.Id);

Expand Down
14 changes: 7 additions & 7 deletions backend/Bot/Bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.15.0" />
<PackageReference Include="Discord.Net" Version="3.15.2" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.5">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -23,11 +23,11 @@

<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />

<PackageReference Include="AspNet.Security.OAuth.Discord" Version="8.0.0" />
<PackageReference Include="AspNet.Security.OAuth.Discord" Version="8.1.0" />

<PackageReference Include="RestSharp" Version="110.2.1-alpha.0.16" />
<PackageReference Include="RestSharp" Version="111.3.0" />

<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>

</Project>
21 changes: 12 additions & 9 deletions backend/Bot/Services/DiscordBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private async Task HandleInteraction(SocketInteraction arg)
}
catch (Exception)
{
_logger.LogInformation($"Unable to execute {arg.Type} in channel {arg.Channel}");
_logger.LogInformation("Unable to execute {ArgType} in channel {ArgChannel}", arg.Type, arg.Channel);

if (arg.Type is InteractionType.ApplicationCommand)
await arg.GetOriginalResponseAsync().ContinueWith(async msg => await msg.Result.DeleteAsync());
Expand Down Expand Up @@ -145,7 +145,7 @@ private async Task ReadyHandler()
}
catch (Exception ex)
{
_logger.LogError(ex, $"Something went wrong while handling guild join for {guild.Id}.");
_logger.LogError(ex, "Something went wrong while handling guild join for {GuildId}.", guild.Id);
}
}

Expand All @@ -171,9 +171,9 @@ private static Task Log(LogMessage logMessage, ILogger logger)
};

if (logMessage.Exception is null)
logger.Log(level, logMessage.Message);
logger.Log(level, "{Message}", logMessage.Message);
else
logger.LogError(logMessage.Exception, logMessage.Message);
logger.LogError(logMessage.Exception, "{Message}", logMessage.Message);

return Task.CompletedTask;
}
Expand All @@ -184,7 +184,7 @@ await _interactions.RegisterCommandsToGuildAsync(
guild.Id
);

_logger.LogInformation($"Initialized guild commands for guild {guild.Name}.");
_logger.LogInformation("Initialized guild commands for guild {GuildName}.", guild.Name);
}

private Task GuildBanRemoved(SocketUser user, SocketGuild guild)
Expand Down Expand Up @@ -248,7 +248,7 @@ private Task GuildUserUpdatedHandler(Cacheable<SocketGuildUser, ulong> oldUsrCac

private Task GuildCreatedHandler(SocketGuild guild)
{
_logger.LogInformation($"Joined guild '{guild.Name}' with ID: '{guild.Id}'");
_logger.LogInformation("Joined guild {GuildName} ({GuildId})", guild.Name, guild.Id);
return Task.CompletedTask;
}

Expand Down Expand Up @@ -288,7 +288,7 @@ private async Task CmdErrorHandler(SlashCommandInfo info, IInteractionContext co
{
await SendError(info, translation, context, $"{result.ErrorReason}\n{exception.Message}", result.Error.Value.ToString());

_logger.LogError($"Command '{info.Name}' invoked by '{context.User.Username}' failed: " +
_logger.LogError("Command '{Name}' invoked by '{Username}' failed: {Message}", info.Name, context.User.Username,
exception.Message + "\n" + exception.StackTrace);
}

Expand All @@ -301,7 +301,8 @@ private async Task CmdErrorHandler(SlashCommandInfo info, IInteractionContext co
await SendError(info, translation, context, result.ErrorReason, result.Error.Value.ToString());

_logger.LogError(
$"Command '{info.Name}' ({result.GetType()}) invoked by '{context.User.Username}' failed due to {result.Error}: {result.ErrorReason}.");
"Command '{Name}' ({Result}) invoked by '{Username}' failed due to {Error}: {ErrorReason}.",
info.Name, result.GetType(), context.User.Username, result.Error, result.ErrorReason);

_eventHandler.CommandErroredEvent.Invoke(
new Exception($"{result.ErrorReason}\nResult Type: {result.GetType()}"));
Expand All @@ -323,7 +324,9 @@ private async Task SendError(ICommandInfo info, Translation translation, IIntera
string errorReason, string code)
{
_logger.LogError(
$"Command '{info.Name}' invoked by '{context.User.Username}' failed: {errorReason}");
"Command '{Name}' invoked by '{Username}' failed: {ErrorReason}",
info.Name, context.User.Username, errorReason
);

var builder = new EmbedBuilder()
.WithTitle(translation.Get<BotTranslator>().SomethingWentWrong())
Expand Down
34 changes: 17 additions & 17 deletions backend/Bot/Services/DiscordRest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ public async Task<List<IBan>> GetGuildBans(ulong guildId, CacheBehavior cacheBeh
.Select(x => x as IBan)
.Where(x => x is not null)
.ToListAsync();
_logger.LogInformation(string.Join(", ", bans));
_logger.LogInformation("{Bans}", string.Join(", ", bans));
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to fetch guild bans for guild '{guildId}' from API.");
_logger.LogError(e, "Failed to fetch guild bans for guild '{GuildId}' from API.", guildId);
return FallBackToCache<List<IBan>>(cacheKey, cacheBehavior);
}

Expand Down Expand Up @@ -233,7 +233,7 @@ public async Task<IBan> GetGuildUserBan(ulong guildId, ulong userId, CacheBehavi
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to fetch guild ban for guild '{guildId}' and user '{userId}' from API.");
_logger.LogError(e, "Failed to fetch guild ban for guild '{GuildId}' and user '{UserId}' from API.", guildId, userId);
return FallBackToCache<IBan>(cacheKey, cacheBehavior);
}

Expand Down Expand Up @@ -316,7 +316,7 @@ public async Task<IUser> FetchUserInfo(ulong userId, bool onlyUseCachedUsers)
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to fetch user '{userId}' from API.");
_logger.LogError(e, "Failed to fetch user '{UserId}' from API.", userId);

user = FallBackToCache<IUser>(cacheKey, cachingType);

Expand All @@ -341,7 +341,7 @@ public IUser FetchMemCachedUserInfo(ulong userId)

private async Task<bool> IsImageAvailable(string imageUrl)
{
_logger.LogInformation($"Fetching {imageUrl} from API for user download.");
_logger.LogInformation("Fetching {ImageUrl} from API for user download.", imageUrl);

using var client = new HttpClient();

Expand Down Expand Up @@ -375,7 +375,7 @@ public async Task<List<IGuildUser>> FetchGuildUsers(ulong guildId, CacheBehavior
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to fetch users for guild '{guildId}' from API.");
_logger.LogError(e, "Failed to fetch users for guild '{GuildId}' from API.", guildId);
return FallBackToCache<List<IGuildUser>>(cacheKey, cacheBehavior);
}

Expand Down Expand Up @@ -413,7 +413,7 @@ public async Task<ISelfUser> FetchCurrentUserInfo(string token, CacheBehavior ca
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to fetch current user for token '{token}' from API.");
_logger.LogError(e, "Failed to fetch current user for token '{Token}' from API.", token);
return FallBackToCache<ISelfUser>(cacheKey, cacheBehavior);
}

Expand Down Expand Up @@ -448,7 +448,7 @@ public List<IGuildChannel> FetchGuildChannels(ulong guildId, CacheBehavior cache
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to fetch guild channels for guild '{guildId}' from API.");
_logger.LogError(e, "Failed to fetch guild channels for guild '{GuildId}' from API.", guildId);
return FallBackToCache<List<IGuildChannel>>(cacheKey, cacheBehavior);
}

Expand Down Expand Up @@ -480,7 +480,7 @@ public IGuild FetchGuildInfo(ulong guildId, CacheBehavior cacheBehavior)
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to fetch guild '{guildId}' from API.");
_logger.LogError(e, "Failed to fetch guild '{GuildId}' from API.", guildId);
return FallBackToCache<SocketGuild>(cacheKey, cacheBehavior);
}

Expand Down Expand Up @@ -515,7 +515,7 @@ public async Task<List<UserGuild>> FetchGuildsOfCurrentUser(string token, CacheB
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to fetch guilds of current user for token '{token}' from API.");
_logger.LogError(e, "Failed to fetch guilds of current user for token '{Token}' from API.", token);
return FallBackToCache<List<UserGuild>>(cacheKey, cacheBehavior);
}

Expand Down Expand Up @@ -547,7 +547,7 @@ public IGuildUser FetchGuildUserInfo(ulong guildId, ulong userId, CacheBehavior
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to fetch guild '{guildId}' user '{userId}' from API.");
_logger.LogError(e, "Failed to fetch guild '{GuildId}' user '{UserId}' from API.", guildId, userId);
return FallBackToCache<IGuildUser>(cacheKey, cacheBehavior);
}

Expand All @@ -572,7 +572,7 @@ public async Task<bool> BanUser(ulong guildId, ulong userId, string reason = nul
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to ban user '{userId}' from guild '{guildId}'.");
_logger.LogError(e, "Failed to ban user '{UserId}' from guild '{GuildId}'.", userId, guildId);
return false;
}

Expand All @@ -594,7 +594,7 @@ public async Task<bool> UnBanUser(ulong guildId, ulong userId, string reason = n
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to unban user '{userId}' from guild '{guildId}'.");
_logger.LogError(e, "Failed to unban user '{UserId}' from guild '{GuildId}'.", userId, guildId);
return false;
}

Expand All @@ -621,7 +621,7 @@ public async Task<bool> TimeoutGuildUser(ulong guildId, ulong userId, TimeSpan t
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to grant user '{userId}' from guild '{guildId}' timeout '{timeOutDuration}'.");
_logger.LogError(e, "Failed to grant user '{UserId}' from guild '{GuildId}' timeout '{TimeOutDuration}'.", userId, guildId, timeOutDuration);
return false;
}

Expand All @@ -647,7 +647,7 @@ public async Task<bool> RemoveTimeoutFromGuildUser(ulong guildId, ulong userId,
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to revoke user '{userId}' from guild '{guildId}' timeout.");
_logger.LogError(e, "Failed to revoke user '{UserId}' from guild '{GuildId}' timeout.", userId, guildId);
return false;
}

Expand All @@ -672,7 +672,7 @@ public async Task<bool> KickGuildUser(ulong guildId, ulong userId, string reason
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to kick user '{userId}' from guild '{guildId}'.");
_logger.LogError(e, "Failed to kick user '{UserId}' from guild '{GuildId}'.", userId, guildId);
return false;
}

Expand Down Expand Up @@ -702,7 +702,7 @@ public async Task<RestDMChannel> CreateDmChannel(ulong userId)
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to create dm with user '{userId}'.");
_logger.LogError(e, "Failed to create dm with user '{UserId}'.", userId);
return FallBackToCache<RestDMChannel>(cacheKey, CacheBehavior.Default);
}

Expand Down
6 changes: 5 additions & 1 deletion backend/Levels/Commands/UpdateRoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Levels.Data;
using Levels.Models;
using Levels.Services;
using Microsoft.Extensions.Logging;
using Color = Discord.Color;

namespace Levels.Commands;
Expand All @@ -25,7 +26,7 @@ public override async Task BeforeCommandExecute() =>
[SlashCommand("updateroles", "Update a user's roles to match their level.", runMode: RunMode.Async)]
public async Task RankCommand(
[Summary("user", "User to update roles for. Defaults to oneself.")]
IGuildUser user = null
IGuildUser user = null
)
{
user ??= Context.Guild.GetUser(Context.User.Id);
Expand All @@ -44,6 +45,9 @@ public async Task RankCommand(

var result = await LevelingService.HandleLevelRoles(level, totalLevel, user, GuildLevelConfigRepository);

Logger.LogInformation("{RunAgent} used the update roles command on {Affected} in {GuildName} ({GuildId})",
Context.User.Username, user.Username, Context.Guild.Name, Context.Guild.Id);

var embed = new EmbedBuilder()
.WithTitle("Role update")
.WithCurrentTimestamp();
Expand Down
1 change: 0 additions & 1 deletion backend/Music/Commands/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Discord.Interactions;
using Discord.WebSocket;
using Lavalink4NET.Players;
using Lavalink4NET.Rest.Entities.Tracks;
using Lavalink4NET.Tracks;
using Music.Abstractions;
using Music.Enums;
Expand Down
2 changes: 1 addition & 1 deletion backend/Music/Music.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Fergun.Interactive" Version="1.7.6" />
<PackageReference Include="Fergun.Interactive" Version="1.7.7" />
<PackageReference Include="Lavalink4NET" Version="4.0.18" />
<PackageReference Include="Lavalink4NET.Artwork" Version="4.0.18" />
<PackageReference Include="Lavalink4NET.Discord.NET" Version="4.0.18" />
Expand Down

0 comments on commit 3613e08

Please sign in to comment.