Skip to content

Commit

Permalink
Merge pull request #47 from scp-cs/profile-logging
Browse files Browse the repository at this point in the history
Profile logging
  • Loading branch information
chamik authored Jun 24, 2021
2 parents eadc343 + d16a0a4 commit 0b10450
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions thorn/Config/pairs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"NEWS_CHANNEL_ID": "537063810121334784",
"LOGGING_CHANNEL_ID": "661982623085625364",
"GENERAL_CHANNEL_ID": "537064369725636611",
"CONSOLE_CHANNEL_ID": "537380917157691392",

"CLASS_C_ROLE_ID": "537322727225163776",
"INT_ROLE_ID": "537023765163409439",
Expand Down
15 changes: 14 additions & 1 deletion thorn/Modules/ProfileModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ public class ProfileModule : ModuleBase<SocketCommandContext>
private readonly UserAccountsService _userAccounts;
private readonly ILogger<ProfileModule> _logger;
private readonly PairsService _pairs;
private readonly SocketTextChannel _console;

public ProfileModule(UserAccountsService userAccounts, ILogger<ProfileModule> logger, PairsService pairs)
public ProfileModule(UserAccountsService userAccounts, ILogger<ProfileModule> logger, PairsService pairs, DiscordSocketClient client)
{
_userAccounts = userAccounts;
_logger = logger;
_pairs = pairs;
_console = client.GetChannel(ulong.Parse(_pairs.GetString("CONSOLE_CHANNEL_ID"))) as SocketTextChannel;
}

[Command]
Expand Down Expand Up @@ -64,6 +66,7 @@ public async Task SetCommand(AccountItem accountItem, [Remainder] string value)
await _userAccounts.SaveAccountsAsync();
await Context.Message.AddReactionAsync(Emote.Parse(_pairs.GetString("YES_EMOTE")));
_logger.LogInformation("{ContextUser} changed their profile setting {AccountItem} to: {Value}", Context.User, accountItem, value);
await _console.SendMessageAsync(embed: GetProfileUpdateEmbed($"**`{Context.User}`** změnil položku **{accountItem}** na: `{value}`", Context.User as IGuildUser, true));
}

[Command("remove")]
Expand All @@ -77,6 +80,7 @@ public async Task RemoveCommand(AccountItem accountItem)
await _userAccounts.SaveAccountsAsync();
await Context.Message.AddReactionAsync(Emote.Parse(_pairs.GetString("YES_EMOTE")));
_logger.LogInformation("{ContextUser} removed their profile {AccountItem}", Context.User, accountItem);
await _console.SendMessageAsync(embed: GetProfileUpdateEmbed($"**`{Context.User}`** z profilu odstranil **{accountItem}**", Context.User as IGuildUser, false));
}

private static bool IsSafe(UserAccount userAccount, AccountItem accountItem, string value)
Expand Down Expand Up @@ -118,5 +122,14 @@ private static void UpdatePrivatePage(UserAccount userAccount, string value)
if (userAccount[AccountItem.TranslatorPage] == userAccount[AccountItem.AuthorPage])
userAccount[AccountItem.PrivatePage] = value;
}

private static Embed GetProfileUpdateEmbed(string change, IGuildUser user, bool set) => new EmbedBuilder
{
Title = $"Změna profilu **{user.Nickname ?? user.Username}**",
Description = change,
Color = set ? Color.Green : Color.Red,
ThumbnailUrl = user.GetAvatarUrl(),
Timestamp = DateTimeOffset.Now.LocalDateTime
}.Build();
}
}

0 comments on commit 0b10450

Please sign in to comment.