Skip to content

Commit

Permalink
Merge branch 'release/5.8.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Sep 30, 2023
2 parents 7eeaec6 + 1db9e14 commit b9b4ea9
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.8.0] - 2023-09-30

### Added
- Added `/userinfo` command and "User Information" context menu.

## [5.7.0] - 2023-09-06

### Added
Expand Down Expand Up @@ -438,6 +443,7 @@ No substantial changes. Commit 3b8259a6cfb82ec0f5f51804c1ac7f1f5880d014 fixed an

- Hammer is released.

[5.8.0]: https://github.com/BrackeysBot/Hammer/releases/tag/v5.8.0
[5.7.0]: https://github.com/BrackeysBot/Hammer/releases/tag/v5.7.0
[5.6.1]: https://github.com/BrackeysBot/Hammer/releases/tag/v5.6.1
[5.6.0]: https://github.com/BrackeysBot/Hammer/releases/tag/v5.6.0
Expand Down
117 changes: 117 additions & 0 deletions Hammer/Commands/UserInfoCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes;
using Hammer.Configuration;
using Hammer.Extensions;
using Hammer.Services;
using X10D.DSharpPlus;

namespace Hammer.Commands;

/// <summary>
/// Represents a class which implements the <c>userinfo</c> command.
/// </summary>
internal sealed class UserInfoCommand : ApplicationCommandModule
{
private readonly ConfigurationService _configurationService;
private readonly AltAccountService _altAccountService;
private readonly InfractionService _infractionService;

/// <summary>
/// Initializes a new instance of the <see cref="UserInfoCommand" /> class.
/// </summary>
/// <param name="configurationService">The configuration service.</param>
/// <param name="altAccountService">The alt account service.</param>
/// <param name="infractionService">The infraction service.</param>
public UserInfoCommand(ConfigurationService configurationService, AltAccountService altAccountService,
InfractionService infractionService)
{
_configurationService = configurationService;
_altAccountService = altAccountService;
_infractionService = infractionService;
}

[SlashCommand("userinfo", "Displays information about a user.")]
[SlashRequireGuild]
public async Task UserInfoAsync(InteractionContext context,
[Option("user", "The user whose information to view.", true)]
DiscordUser user)
{
DiscordGuild guild = context.Guild;
GuildConfiguration? configuration = _configurationService.GetGuildConfiguration(guild);
if (configuration is null)
{
await context.CreateResponseAsync("This guild is not configured.", true).ConfigureAwait(false);
return;
}

bool staffRequested = context.Member.IsStaffMember(configuration);
DiscordMember? member = await user.GetAsMemberOfAsync(guild);
DiscordEmbed embed = CreateUserInfoEmbed(user, member, staffRequested, guild);

await context.CreateResponseAsync(embed).ConfigureAwait(false);
}

[ContextMenu(ApplicationCommandType.UserContextMenu, "User Information")]
[SlashRequireGuild]
public async Task UserInfoAsync(ContextMenuContext context)
{
DiscordGuild guild = context.Guild;
GuildConfiguration? configuration = _configurationService.GetGuildConfiguration(guild);
if (configuration is null)
{
await context.CreateResponseAsync("This guild is not configured.", true).ConfigureAwait(false);
return;
}

bool staffRequested = context.Member.IsStaffMember(configuration);
DiscordEmbed embed = CreateUserInfoEmbed(context.TargetUser, context.TargetMember, staffRequested, guild);
await context.CreateResponseAsync(embed, true).ConfigureAwait(false);
}

private DiscordEmbed CreateUserInfoEmbed(DiscordUser user, DiscordMember? member, bool staffRequested, DiscordGuild guild)
{
var embed = new DiscordEmbedBuilder();
GuildConfiguration? configuration = _configurationService.GetGuildConfiguration(guild);

if (member is null && !staffRequested)
{
embed.WithColor(DiscordColor.Red);
embed.WithTitle("User not found");
embed.WithDescription("The specified user is not a member of this guild.");
return embed;
}

// ReSharper disable ConditionIsAlwaysTrueOrFalse
embed.WithAuthor(user.GetUsernameWithDiscriminator(), iconUrl: user.GetAvatarUrl(ImageFormat.Png));
embed.WithColor(member?.Color ?? DiscordColor.Gray);
embed.WithTitle("User Information");
embed.WithThumbnail(user.AvatarUrl);

embed.AddField("Username", user.GetUsernameWithDiscriminator(), true);
embed.AddField("ID", user.Id, true);
embed.AddFieldIf(!string.IsNullOrWhiteSpace(member?.Nickname), "Nickname", () => member!.Nickname, true);
embed.AddField("Created", Formatter.Timestamp(user.CreationTimestamp), true);

embed.AddFieldIf(member is not null, "Joined", () => Formatter.Timestamp(member!.JoinedAt), true);
embed.AddFieldIf(member is not null, "Permission Level", () => member!.GetPermissionLevel(configuration), true);

if (staffRequested)
{
int infractionCount = _infractionService.GetInfractionCount(user, guild);
int altCount = _altAccountService.GetAltsFor(user.Id).Count;

embed.AddFieldIf(infractionCount > 0, "Infractions", infractionCount, true);
embed.AddFieldIf(altCount > 0, "Alt Accounts", altCount, true);
}

if (member is null)
{
embed.WithFooter("⚠️ This user is not currently in the server.");
}
// ReSharper restore ConditionIsAlwaysTrueOrFalse

return embed;
}
}
2 changes: 1 addition & 1 deletion Hammer/Hammer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<VersionPrefix>5.7.0</VersionPrefix>
<VersionPrefix>5.8.0</VersionPrefix>
</PropertyGroup>

<PropertyGroup Condition="'$(VersionSuffix)' != '' And '$(BuildNumber)' == ''">
Expand Down
1 change: 1 addition & 0 deletions Hammer/Services/BotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
slashCommands.RegisterCommands<StaffHistoryCommand>();
slashCommands.RegisterCommands<UnbanCommand>();
slashCommands.RegisterCommands<UnmuteCommand>();
slashCommands.RegisterCommands<UserInfoCommand>();
slashCommands.RegisterCommands<ViewMessageCommand>();
slashCommands.RegisterCommands<WarnCommand>();
RegisterEvents();
Expand Down
17 changes: 16 additions & 1 deletion USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ The default reaction equivalent is the 🔇️emoji (`:mute:`). The config key i
The default reaction equivalent is the 🕓 emoji (`:clock4:`). The config key is `GUILD_ID.reactions.historyReaction`.k4: ). When
this reaction is used, the history is instead sent as a DM to the staff member.

### 👤 User > Apps > User Information

**Public action.** Displays information about a user. This is identical to the `/userinfo` command, except that the response **is ephemeral**.

There is no reaction equivalent for this action.

# Slash Commands

Below is an outline of every slash command currently implemented in Hammer, along with their descriptions and parameters.
Expand Down Expand Up @@ -69,7 +75,7 @@ Unblocks a user, so that their message reports are acknowledged.
|:----------|:---------|:-------------------|:-----------------------------------|
| user | ✅ Yes | User mention or ID | The user whose reports to unblock. |

## Alt account management
## User management

### `/alt add`

Expand Down Expand Up @@ -97,6 +103,14 @@ Views a user's alt accounts.
|:----------|:---------|:-------------------|:-----------------------------------|
| user | ✅ Yes | User mention or ID | The user whose alts to view. |

### `/userinfo`

**Public command.** Displays information about a user.

| Parameter | Required | Type | Description |
|:----------|:---------|:-------------------|:-----------------------------------|
| user | ✅ Yes | User mention or ID | The user whose info to view. |

## Issuing and revoking infractions

### `/ban`
Expand Down Expand Up @@ -387,5 +401,6 @@ Below is a table outlining all the commands and whether or not they have ephemer
| `/unmute` | ✅ Yes |
| `/unban` | ✅ Yes |
| `/unblockreports` | ✅ Yes |
| `/userinfo` | ❌ No |
| `/viewmessage` | ❌ No |
| `/warn` | ✅ Yes |
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"version": "7.0.0",
"rollForward": "latestMajor",
"allowPrerelease": true
"rollForward": "latestMinor",
"allowPrerelease": false
}
}

0 comments on commit b9b4ea9

Please sign in to comment.