Skip to content

Commit

Permalink
feat: add avatar deletion command (#5)
Browse files Browse the repository at this point in the history
* bump: update GL.NET to 0.4.14

* add avatar deletion command

* fix: remove uppercase letter in avatar deletion command

* fix: remove extra $ response message
  • Loading branch information
bryanpth authored Feb 27, 2025
1 parent 8e66885 commit a1f25ce
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AdvancedBot.Core/AdvancedBot.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.16.0" />
<PackageReference Include="GL.Net" Version="0.4.13" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="GL.Net" Version="0.4.14" />
<PackageReference Include="LiteDB" Version="5.0.21" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
Expand Down
7 changes: 7 additions & 0 deletions src/AdvancedBot.Core/Commands/Modules/ModerationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -646,4 +646,11 @@ Context.Channel is IGuildChannel
await SendPaginatedMessageAsync(null, displayTexts, embed);

}

[SlashCommand("deleteavatar", "Deletes the targeted user's avatar")]
public async Task DeleteAvatarAsync(uint userId)
{
var result = await ModService.DeleteAvatarAsync(Context.User.Id, userId);
await SendResponseMessage(result.Message, false);
}
}
1 change: 1 addition & 0 deletions src/AdvancedBot.Core/Entities/Enums/LogAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ public enum LogAction
GetAccounts = 27,
GetChipsSpent = 28,
Compensate = 29,
AvatarDeleted = 30,
}
1 change: 1 addition & 0 deletions src/AdvancedBot.Core/Services/LogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public static Embed GetEmbedForLog(Log log, User target)
case LogAction.AddEmulate:
case LogAction.RemoveEmulate:
case LogAction.GetAccounts:
case LogAction.AvatarDeleted:
default:
break;
}
Expand Down
29 changes: 29 additions & 0 deletions src/AdvancedBot.Core/Services/ModerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,35 @@ public async Task<ModResult> GiveRoleAsync(ulong discordId, uint userId, Phoenix
return new ModResult(ModResultType.Success, message, user);
}

public async Task<ModResult> DeleteAvatarAsync(ulong discordId, uint userId)
{
var user = await _gl.Phoenix.GetPhoenixUserAsync(userId);

if (user == null)
{
return new ModResult(ModResultType.NotFound, new ResponseMessage($"Could not find any user with id **{userId}**."));
}

if (!await _gl.Phoenix.DeleteAvatarAsync(userId))
{
return new ModResult(ModResultType.BackendError, new ResponseMessage($"Failed to remove {user.UserName}'s avatar."));
}

await _logs.LogGameActionAsync(LogAction.AvatarDeleted, discordId, userId);

var embed = new EmbedBuilder()
.WithTitle($"Avatar successfully removed")
.WithDescription($"**{user.UserName}** ({user.UserId})'s avatar has been removed.")
.WithColor(Color.Green)
.WithFooter(footer => footer
.WithText($"Avatar removed by moderator with id {discordId}"))
.WithCurrentTimestamp()
.Build();

var message = new ResponseMessage(embeds: [embed]);
return new ModResult(ModResultType.Success, message);
}

public async Task<ModResult> GetChipsBoughtAsync(ulong discordId, uint userId)
{
var user = await _gl.Api.GetUserById(userId.ToString());
Expand Down

0 comments on commit a1f25ce

Please sign in to comment.