2020-03-04 17:13:36 +00:00
using System.Text.RegularExpressions ;
2020-02-01 12:03:02 +00:00
using System.Threading.Tasks ;
2020-06-17 19:31:39 +00:00
using System ;
2020-06-13 14:03:57 +00:00
using DSharpPlus.Entities ;
2020-02-01 12:03:02 +00:00
2020-06-29 11:57:48 +00:00
using NodaTime ;
2020-02-01 12:03:02 +00:00
using PluralKit.Core ;
2020-02-12 14:16:19 +00:00
namespace PluralKit.Bot
2020-02-01 12:03:02 +00:00
{
public class MemberEdit
{
2020-06-13 17:36:43 +00:00
private readonly IDatabase _db ;
2020-08-29 11:46:27 +00:00
private readonly ModelRepository _repo ;
2020-02-01 12:03:02 +00:00
2020-08-29 11:46:27 +00:00
public MemberEdit ( IDatabase db , ModelRepository repo )
2020-02-01 12:03:02 +00:00
{
2020-06-13 14:03:57 +00:00
_db = db ;
2020-08-29 11:46:27 +00:00
_repo = repo ;
2020-02-01 12:03:02 +00:00
}
2020-11-22 21:15:26 +00:00
public async Task Name ( Context ctx , PKMember target )
{
ctx . CheckSystem ( ) . CheckOwnMember ( target ) ;
2020-02-01 12:03:02 +00:00
var newName = ctx . RemainderOrNull ( ) ? ? throw new PKSyntaxError ( "You must pass a new name for the member." ) ;
// Hard name length cap
if ( newName . Length > Limits . MaxMemberNameLength ) throw Errors . MemberNameTooLongError ( newName . Length ) ;
// Warn if there's already a member by this name
2020-08-29 11:46:27 +00:00
var existingMember = await _db . Execute ( conn = > _repo . GetMemberByName ( conn , ctx . System . Id , newName ) ) ;
2020-07-28 17:52:57 +00:00
if ( existingMember ! = null & & existingMember . Id ! = target . Id )
{
2020-07-21 00:10:26 +00:00
var msg = $"{Emojis.Warn} You already have a member in your system with the name \" { existingMember . NameFor ( ctx ) } \ " (`{existingMember.Hid}`). Do you want to rename this member to that name too?" ;
2020-02-01 12:03:02 +00:00
if ( ! await ctx . PromptYesNo ( msg ) ) throw new PKError ( "Member renaming cancelled." ) ;
}
// Rename the member
2020-06-29 11:57:48 +00:00
var patch = new MemberPatch { Name = Partial < string > . Present ( newName ) } ;
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
2020-02-01 12:03:02 +00:00
await ctx . Reply ( $"{Emojis.Success} Member renamed." ) ;
if ( newName . Contains ( " " ) ) await ctx . Reply ( $"{Emojis.Note} Note that this member's name now contains spaces. You will need to surround it with \" double quotes \ " when using commands referring to it." ) ;
2020-06-20 15:36:03 +00:00
if ( target . DisplayName ! = null ) await ctx . Reply ( $"{Emojis.Note} Note that this member has a display name set ({target.DisplayName}), and will be proxied using that name instead." ) ;
2020-02-01 12:03:02 +00:00
2020-12-22 15:55:13 +00:00
if ( ctx . GuildNew ! = null )
2020-02-01 12:03:02 +00:00
{
2020-12-22 15:55:13 +00:00
var memberGuildConfig = await _db . Execute ( c = > _repo . GetMemberGuild ( c , ctx . GuildNew . Id , target . Id ) ) ;
2020-02-01 12:03:02 +00:00
if ( memberGuildConfig . DisplayName ! = null )
2020-12-22 15:55:13 +00:00
await ctx . Reply ( $"{Emojis.Note} Note that this member has a server name set ({memberGuildConfig.DisplayName}) in this server ({ctx.GuildNew.Name}), and will be proxied using that name here." ) ;
2020-02-01 12:03:02 +00:00
}
}
2020-03-04 17:13:36 +00:00
public async Task Description ( Context ctx , PKMember target ) {
2020-10-04 08:53:07 +00:00
if ( await ctx . MatchClear ( "this member's description" ) )
2020-02-27 23:23:54 +00:00
{
2020-11-22 21:15:26 +00:00
ctx . CheckOwnMember ( target ) ;
2020-06-29 11:57:48 +00:00
var patch = new MemberPatch { Description = Partial < string > . Null ( ) } ;
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
2020-03-04 17:13:36 +00:00
await ctx . Reply ( $"{Emojis.Success} Member description cleared." ) ;
}
else if ( ! ctx . HasNext ( ) )
{
2020-06-17 19:31:39 +00:00
if ( ! target . DescriptionPrivacy . CanAccess ( ctx . LookupContextFor ( target . System ) ) )
throw Errors . LookupNotAllowed ;
2020-02-27 23:23:54 +00:00
if ( target . Description = = null )
2020-03-04 17:13:36 +00:00
if ( ctx . System ? . Id = = target . System )
2020-08-25 20:33:04 +00:00
await ctx . Reply ( $"This member does not have a description set. To set one, type `pk;member {target.Reference()} description <description>`." ) ;
2020-02-27 23:23:54 +00:00
else
await ctx . Reply ( "This member does not have a description set." ) ;
else if ( ctx . MatchFlag ( "r" , "raw" ) )
2020-06-20 15:36:03 +00:00
await ctx . Reply ( $"```\n{target.Description}\n```" ) ;
2020-02-27 23:23:54 +00:00
else
2020-04-24 19:50:28 +00:00
await ctx . Reply ( embed : new DiscordEmbedBuilder ( )
2020-02-27 23:23:54 +00:00
. WithTitle ( "Member description" )
. WithDescription ( target . Description )
2020-08-25 20:33:04 +00:00
. AddField ( "\u200B" , $"To print the description with formatting, type `pk;member {target.Reference()} description -raw`."
+ ( ctx . System ? . Id = = target . System ? $" To clear it, type `pk;member {target.Reference()} description -clear`." : "" ) )
2020-02-27 23:23:54 +00:00
. Build ( ) ) ;
}
2020-03-04 17:13:36 +00:00
else
{
2020-11-22 21:15:26 +00:00
ctx . CheckOwnMember ( target ) ;
2020-02-27 23:23:54 +00:00
2020-03-04 17:13:36 +00:00
var description = ctx . RemainderOrNull ( ) . NormalizeLineEndSpacing ( ) ;
if ( description . IsLongerThan ( Limits . MaxDescriptionLength ) )
throw Errors . DescriptionTooLongError ( description . Length ) ;
2020-06-29 11:57:48 +00:00
var patch = new MemberPatch { Description = Partial < string > . Present ( description ) } ;
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
2020-06-29 12:15:30 +00:00
2020-03-04 17:13:36 +00:00
await ctx . Reply ( $"{Emojis.Success} Member description changed." ) ;
}
2020-02-01 12:03:02 +00:00
}
public async Task Pronouns ( Context ctx , PKMember target ) {
2020-10-04 08:53:07 +00:00
if ( await ctx . MatchClear ( "this member's pronouns" ) )
2020-03-04 17:13:36 +00:00
{
2020-11-22 21:15:26 +00:00
ctx . CheckOwnMember ( target ) ;
2020-06-29 11:57:48 +00:00
var patch = new MemberPatch { Pronouns = Partial < string > . Null ( ) } ;
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
2020-03-04 17:13:36 +00:00
await ctx . Reply ( $"{Emojis.Success} Member pronouns cleared." ) ;
}
else if ( ! ctx . HasNext ( ) )
{
2020-06-17 19:31:39 +00:00
if ( ! target . PronounPrivacy . CanAccess ( ctx . LookupContextFor ( target . System ) ) )
throw Errors . LookupNotAllowed ;
2020-03-04 17:13:36 +00:00
if ( target . Pronouns = = null )
if ( ctx . System ? . Id = = target . System )
2020-08-25 20:33:04 +00:00
await ctx . Reply ( $"This member does not have pronouns set. To set some, type `pk;member {target.Reference()} pronouns <pronouns>`." ) ;
2020-03-04 17:13:36 +00:00
else
await ctx . Reply ( "This member does not have pronouns set." ) ;
else
2020-06-20 15:36:03 +00:00
await ctx . Reply ( $"**{target.NameFor(ctx)}**'s pronouns are **{target.Pronouns}**."
2020-08-25 20:33:04 +00:00
+ ( ctx . System ? . Id = = target . System ? $" To clear them, type `pk;member {target.Reference()} pronouns -clear`." : "" ) ) ;
2020-03-04 17:13:36 +00:00
}
else
{
2020-11-22 21:15:26 +00:00
ctx . CheckOwnMember ( target ) ;
2020-02-01 12:03:02 +00:00
2020-03-04 17:13:36 +00:00
var pronouns = ctx . RemainderOrNull ( ) . NormalizeLineEndSpacing ( ) ;
if ( pronouns . IsLongerThan ( Limits . MaxPronounsLength ) )
throw Errors . MemberPronounsTooLongError ( pronouns . Length ) ;
2020-06-29 11:57:48 +00:00
var patch = new MemberPatch { Pronouns = Partial < string > . Present ( pronouns ) } ;
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
2020-06-29 11:57:48 +00:00
2020-03-04 17:13:36 +00:00
await ctx . Reply ( $"{Emojis.Success} Member pronouns changed." ) ;
}
2020-02-01 12:03:02 +00:00
}
public async Task Color ( Context ctx , PKMember target )
{
var color = ctx . RemainderOrNull ( ) ;
2020-10-04 08:53:07 +00:00
if ( await ctx . MatchClear ( ) )
2020-02-01 12:03:02 +00:00
{
2020-11-22 21:15:26 +00:00
ctx . CheckOwnMember ( target ) ;
2020-06-29 11:57:48 +00:00
var patch = new MemberPatch { Color = Partial < string > . Null ( ) } ;
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
2020-06-29 11:57:48 +00:00
2020-03-04 17:13:36 +00:00
await ctx . Reply ( $"{Emojis.Success} Member color cleared." ) ;
2020-02-01 12:03:02 +00:00
}
2020-03-04 17:13:36 +00:00
else if ( ! ctx . HasNext ( ) )
{
2020-06-17 19:51:40 +00:00
// if (!target.ColorPrivacy.CanAccess(ctx.LookupContextFor(target.System)))
// throw Errors.LookupNotAllowed;
2020-02-01 12:03:02 +00:00
2020-03-04 17:13:36 +00:00
if ( target . Color = = null )
if ( ctx . System ? . Id = = target . System )
await ctx . Reply (
2020-08-25 20:33:04 +00:00
$"This member does not have a color set. To set one, type `pk;member {target.Reference()} color <color>`." ) ;
2020-03-04 17:13:36 +00:00
else
await ctx . Reply ( "This member does not have a color set." ) ;
else
2020-04-24 19:50:28 +00:00
await ctx . Reply ( embed : new DiscordEmbedBuilder ( )
2020-03-04 17:13:36 +00:00
. WithTitle ( "Member color" )
. WithColor ( target . Color . ToDiscordColor ( ) . Value )
2020-06-21 13:34:32 +00:00
. WithThumbnail ( $"https://fakeimg.pl/256x256/{target.Color}/?text=%20" )
2020-03-04 17:13:36 +00:00
. WithDescription ( $"This member's color is **#{target.Color}**."
2020-08-25 20:33:04 +00:00
+ ( ctx . System ? . Id = = target . System ? $" To clear it, type `pk;member {target.Reference()} color -clear`." : "" ) )
2020-03-04 17:13:36 +00:00
. Build ( ) ) ;
}
else
{
2020-11-22 21:15:26 +00:00
ctx . CheckOwnMember ( target ) ;
2020-02-01 12:03:02 +00:00
2020-03-04 17:13:36 +00:00
if ( color . StartsWith ( "#" ) ) color = color . Substring ( 1 ) ;
if ( ! Regex . IsMatch ( color , "^[0-9a-fA-F]{6}$" ) ) throw Errors . InvalidColorError ( color ) ;
2020-06-29 11:57:48 +00:00
var patch = new MemberPatch { Color = Partial < string > . Present ( color . ToLowerInvariant ( ) ) } ;
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
2020-03-04 17:13:36 +00:00
2020-04-24 19:50:28 +00:00
await ctx . Reply ( embed : new DiscordEmbedBuilder ( )
2020-03-04 17:13:36 +00:00
. WithTitle ( $"{Emojis.Success} Member color changed." )
2020-06-29 11:57:48 +00:00
. WithColor ( color . ToDiscordColor ( ) . Value )
2020-08-05 18:20:11 +00:00
. WithThumbnail ( $"https://fakeimg.pl/256x256/{color}/?text=%20" )
2020-03-04 17:13:36 +00:00
. Build ( ) ) ;
}
2020-02-01 12:03:02 +00:00
}
public async Task Birthday ( Context ctx , PKMember target )
{
2020-10-04 08:53:07 +00:00
if ( await ctx . MatchClear ( "this member's birthday" ) )
2020-03-04 17:13:36 +00:00
{
2020-11-22 21:15:26 +00:00
ctx . CheckOwnMember ( target ) ;
2020-06-29 11:57:48 +00:00
var patch = new MemberPatch { Birthday = Partial < LocalDate ? > . Null ( ) } ;
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
2020-06-29 11:57:48 +00:00
2020-03-04 17:13:36 +00:00
await ctx . Reply ( $"{Emojis.Success} Member birthdate cleared." ) ;
}
else if ( ! ctx . HasNext ( ) )
2020-02-01 12:03:02 +00:00
{
2020-06-17 19:31:39 +00:00
if ( ! target . BirthdayPrivacy . CanAccess ( ctx . LookupContextFor ( target . System ) ) )
throw Errors . LookupNotAllowed ;
2020-03-04 17:13:36 +00:00
if ( target . Birthday = = null )
await ctx . Reply ( "This member does not have a birthdate set."
2020-08-25 20:33:04 +00:00
+ ( ctx . System ? . Id = = target . System ? $" To set one, type `pk;member {target.Reference()} birthdate <birthdate>`." : "" ) ) ;
2020-03-04 17:13:36 +00:00
else
await ctx . Reply ( $"This member's birthdate is **{target.BirthdayString}**."
2020-08-25 20:33:04 +00:00
+ ( ctx . System ? . Id = = target . System ? $" To clear it, type `pk;member {target.Reference()} birthdate -clear`." : "" ) ) ;
2020-03-04 17:13:36 +00:00
}
else
{
2020-11-22 21:15:26 +00:00
ctx . CheckOwnMember ( target ) ;
2020-03-04 17:13:36 +00:00
var birthdayStr = ctx . RemainderOrNull ( ) ;
var birthday = DateUtils . ParseDate ( birthdayStr , true ) ;
if ( birthday = = null ) throw Errors . BirthdayParseError ( birthdayStr ) ;
2020-06-29 11:57:48 +00:00
var patch = new MemberPatch { Birthday = Partial < LocalDate ? > . Present ( birthday ) } ;
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
2020-06-29 11:57:48 +00:00
2020-03-04 17:13:36 +00:00
await ctx . Reply ( $"{Emojis.Success} Member birthdate changed." ) ;
2020-02-01 12:03:02 +00:00
}
}
2020-03-04 17:13:36 +00:00
2020-04-24 19:50:28 +00:00
private async Task < DiscordEmbedBuilder > CreateMemberNameInfoEmbed ( Context ctx , PKMember target )
2020-03-04 17:13:36 +00:00
{
2020-06-18 15:08:36 +00:00
var lcx = ctx . LookupContextFor ( target ) ;
2020-03-04 17:13:36 +00:00
MemberGuildSettings memberGuildConfig = null ;
2020-12-22 15:55:13 +00:00
if ( ctx . GuildNew ! = null )
memberGuildConfig = await _db . Execute ( c = > _repo . GetMemberGuild ( c , ctx . GuildNew . Id , target . Id ) ) ;
2020-02-01 12:03:02 +00:00
2020-04-24 19:50:28 +00:00
var eb = new DiscordEmbedBuilder ( ) . WithTitle ( $"Member names" )
2020-03-04 17:13:36 +00:00
. WithFooter ( $"Member ID: {target.Hid} | Active name in bold. Server name overrides display name, which overrides base name." ) ;
2020-02-01 12:03:02 +00:00
2020-03-04 17:13:36 +00:00
if ( target . DisplayName = = null & & memberGuildConfig ? . DisplayName = = null )
2020-06-18 15:08:36 +00:00
eb . AddField ( "Name" , $"**{target.NameFor(ctx)}**" ) ;
2020-03-04 17:13:36 +00:00
else
2020-06-18 15:08:36 +00:00
eb . AddField ( "Name" , target . NameFor ( ctx ) ) ;
if ( target . NamePrivacy . CanAccess ( lcx ) )
{
if ( target . DisplayName ! = null & & memberGuildConfig ? . DisplayName = = null )
eb . AddField ( "Display Name" , $"**{target.DisplayName}**" ) ;
else
eb . AddField ( "Display Name" , target . DisplayName ? ? "*(none)*" ) ;
}
2020-02-01 12:03:02 +00:00
2020-12-22 15:55:13 +00:00
if ( ctx . GuildNew ! = null )
2020-02-01 12:03:02 +00:00
{
2020-03-04 17:13:36 +00:00
if ( memberGuildConfig ? . DisplayName ! = null )
2020-12-22 15:55:13 +00:00
eb . AddField ( $"Server Name (in {ctx.GuildNew.Name})" , $"**{memberGuildConfig.DisplayName}**" ) ;
2020-03-04 17:13:36 +00:00
else
2020-12-22 15:55:13 +00:00
eb . AddField ( $"Server Name (in {ctx.GuildNew.Name})" , memberGuildConfig ? . DisplayName ? ? "*(none)*" ) ;
2020-02-01 12:03:02 +00:00
}
2020-03-04 17:13:36 +00:00
return eb ;
2020-02-01 12:03:02 +00:00
}
2020-03-04 17:13:36 +00:00
public async Task DisplayName ( Context ctx , PKMember target )
2020-02-01 12:03:02 +00:00
{
2020-03-04 17:13:36 +00:00
async Task PrintSuccess ( string text )
{
var successStr = text ;
2020-12-22 15:55:13 +00:00
if ( ctx . GuildNew ! = null )
2020-03-04 17:13:36 +00:00
{
2020-12-22 15:55:13 +00:00
var memberGuildConfig = await _db . Execute ( c = > _repo . GetMemberGuild ( c , ctx . GuildNew . Id , target . Id ) ) ;
2020-03-04 17:13:36 +00:00
if ( memberGuildConfig . DisplayName ! = null )
2020-12-22 15:55:13 +00:00
successStr + = $" However, this member has a server name set in this server ({ctx.GuildNew.Name}), and will be proxied using that name, \" { memberGuildConfig . DisplayName } \ ", here." ;
2020-03-04 17:13:36 +00:00
}
await ctx . Reply ( successStr ) ;
}
2020-02-01 12:03:02 +00:00
2020-10-04 08:53:07 +00:00
if ( await ctx . MatchClear ( "this member's display name" ) )
2020-03-04 17:13:36 +00:00
{
2020-11-22 21:15:26 +00:00
ctx . CheckOwnMember ( target ) ;
2020-03-04 17:13:36 +00:00
2020-06-29 11:57:48 +00:00
var patch = new MemberPatch { DisplayName = Partial < string > . Null ( ) } ;
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
2020-06-29 11:57:48 +00:00
2020-06-20 15:36:03 +00:00
await PrintSuccess ( $"{Emojis.Success} Member display name cleared. This member will now be proxied using their member name \" { target . NameFor ( ctx ) } \ "." ) ;
2020-03-04 17:13:36 +00:00
}
else if ( ! ctx . HasNext ( ) )
{
// No perms check, display name isn't covered by member privacy
var eb = await CreateMemberNameInfoEmbed ( ctx , target ) ;
if ( ctx . System ? . Id = = target . System )
2020-08-25 20:33:04 +00:00
eb . WithDescription ( $"To change display name, type `pk;member {target.Reference()} displayname <display name>`.\nTo clear it, type `pk;member {target.Reference()} displayname -clear`." ) ;
2020-03-04 17:13:36 +00:00
await ctx . Reply ( embed : eb . Build ( ) ) ;
}
else
{
2020-11-22 21:15:26 +00:00
ctx . CheckOwnMember ( target ) ;
2020-03-04 17:13:36 +00:00
var newDisplayName = ctx . RemainderOrNull ( ) ;
2020-06-29 11:57:48 +00:00
var patch = new MemberPatch { DisplayName = Partial < string > . Present ( newDisplayName ) } ;
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
2020-03-04 17:13:36 +00:00
2020-06-20 15:36:03 +00:00
await PrintSuccess ( $"{Emojis.Success} Member display name changed. This member will now be proxied using the name \" { newDisplayName } \ "." ) ;
2020-03-04 17:13:36 +00:00
}
}
public async Task ServerName ( Context ctx , PKMember target )
{
2020-02-01 12:03:02 +00:00
ctx . CheckGuildContext ( ) ;
2020-10-04 08:53:07 +00:00
if ( await ctx . MatchClear ( "this member's server name" ) )
2020-03-04 17:13:36 +00:00
{
2020-11-22 21:15:26 +00:00
ctx . CheckOwnMember ( target ) ;
2020-06-13 14:03:57 +00:00
2020-06-29 13:20:28 +00:00
var patch = new MemberGuildPatch { DisplayName = null } ;
2020-12-22 15:55:13 +00:00
await _db . Execute ( conn = > _repo . UpsertMemberGuild ( conn , target . Id , ctx . GuildNew . Id , patch ) ) ;
2020-02-01 12:03:02 +00:00
2020-03-04 17:13:36 +00:00
if ( target . DisplayName ! = null )
2020-12-22 15:55:13 +00:00
await ctx . Reply ( $"{Emojis.Success} Member server name cleared. This member will now be proxied using their global display name \" { target . DisplayName } \ " in this server ({ctx.GuildNew.Name})." ) ;
2020-03-04 17:13:36 +00:00
else
2020-12-22 15:55:13 +00:00
await ctx . Reply ( $"{Emojis.Success} Member server name cleared. This member will now be proxied using their member name \" { target . NameFor ( ctx ) } \ " in this server ({ctx.GuildNew.Name})." ) ;
2020-03-04 17:13:36 +00:00
}
else if ( ! ctx . HasNext ( ) )
{
// No perms check, server name isn't covered by member privacy
var eb = await CreateMemberNameInfoEmbed ( ctx , target ) ;
if ( ctx . System ? . Id = = target . System )
2020-08-25 20:33:04 +00:00
eb . WithDescription ( $"To change server name, type `pk;member {target.Reference()} servername <server name>`.\nTo clear it, type `pk;member {target.Reference()} servername -clear`." ) ;
2020-03-04 17:13:36 +00:00
await ctx . Reply ( embed : eb . Build ( ) ) ;
}
2020-02-01 12:03:02 +00:00
else
2020-03-04 17:13:36 +00:00
{
2020-11-22 21:15:26 +00:00
ctx . CheckOwnMember ( target ) ;
2020-03-04 17:13:36 +00:00
var newServerName = ctx . RemainderOrNull ( ) ;
2020-06-29 13:20:28 +00:00
var patch = new MemberGuildPatch { DisplayName = newServerName } ;
2020-12-22 15:55:13 +00:00
await _db . Execute ( conn = > _repo . UpsertMemberGuild ( conn , target . Id , ctx . GuildNew . Id , patch ) ) ;
2020-02-01 12:03:02 +00:00
2020-12-22 15:55:13 +00:00
await ctx . Reply ( $"{Emojis.Success} Member server name changed. This member will now be proxied using the name \" { newServerName } \ " in this server ({ctx.GuildNew.Name})." ) ;
2020-03-04 17:13:36 +00:00
}
2020-02-01 12:03:02 +00:00
}
public async Task KeepProxy ( Context ctx , PKMember target )
{
2020-11-22 21:15:26 +00:00
ctx . CheckSystem ( ) . CheckOwnMember ( target ) ;
2020-02-01 12:03:02 +00:00
bool newValue ;
if ( ctx . Match ( "on" , "enabled" , "true" , "yes" ) ) newValue = true ;
else if ( ctx . Match ( "off" , "disabled" , "false" , "no" ) ) newValue = false ;
else if ( ctx . HasNext ( ) ) throw new PKSyntaxError ( "You must pass either \"on\" or \"off\"." ) ;
2020-03-04 17:13:36 +00:00
else
{
if ( target . KeepProxy )
await ctx . Reply ( "This member has keepproxy **enabled**, which means proxy tags will be **included** in the resulting message when proxying." ) ;
else
await ctx . Reply ( "This member has keepproxy **disabled**, which means proxy tags will **not** be included in the resulting message when proxying." ) ;
return ;
} ;
2020-02-01 12:03:02 +00:00
2020-06-29 11:57:48 +00:00
var patch = new MemberPatch { KeepProxy = Partial < bool > . Present ( newValue ) } ;
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
2020-02-01 12:03:02 +00:00
if ( newValue )
await ctx . Reply ( $"{Emojis.Success} Member proxy tags will now be included in the resulting message when proxying." ) ;
else
await ctx . Reply ( $"{Emojis.Success} Member proxy tags will now not be included in the resulting message when proxying." ) ;
}
2020-11-20 21:40:36 +00:00
public async Task MemberAutoproxy ( Context ctx , PKMember target )
{
if ( ctx . System = = null ) throw Errors . NoSystemError ;
if ( target . System ! = ctx . System . Id ) throw Errors . NotOwnMemberError ;
bool newValue ;
if ( ctx . Match ( "on" , "enabled" , "true" , "yes" ) | | ctx . MatchFlag ( "on" , "enabled" , "true" , "yes" ) ) newValue = true ;
else if ( ctx . Match ( "off" , "disabled" , "false" , "no" ) | | ctx . MatchFlag ( "off" , "disabled" , "false" , "no" ) ) newValue = false ;
else if ( ctx . HasNext ( ) ) throw new PKSyntaxError ( "You must pass either \"on\" or \"off\"." ) ;
else
{
if ( target . AllowAutoproxy )
await ctx . Reply ( "Latch/front autoproxy are **enabled** for this member. This member will be automatically proxied when autoproxy is set to latch or front mode." ) ;
else
await ctx . Reply ( "Latch/front autoproxy are **disabled** for this member. This member will not be automatically proxied when autoproxy is set to latch or front mode." ) ;
return ;
} ;
var patch = new MemberPatch { AllowAutoproxy = Partial < bool > . Present ( newValue ) } ;
await _db . Execute ( conn = > _repo . UpdateMember ( conn , target . Id , patch ) ) ;
if ( newValue )
await ctx . Reply ( $"{Emojis.Success} Latch / front autoproxy have been **enabled** for this member." ) ;
else
await ctx . Reply ( $"{Emojis.Success} Latch / front autoproxy have been **disabled** for this member." ) ;
}
2020-02-07 21:20:40 +00:00
public async Task Privacy ( Context ctx , PKMember target , PrivacyLevel ? newValueFromCommand )
2020-02-01 12:03:02 +00:00
{
2020-11-22 21:15:26 +00:00
ctx . CheckSystem ( ) . CheckOwnMember ( target ) ;
2020-02-01 12:03:02 +00:00
2020-06-17 19:31:39 +00:00
// Display privacy settings
if ( ! ctx . HasNext ( ) & & newValueFromCommand = = null )
2020-03-04 17:13:36 +00:00
{
2020-07-07 22:46:58 +00:00
await ctx . Reply ( embed : new DiscordEmbedBuilder ( )
. WithTitle ( $"Current privacy settings for {target.NameFor(ctx)}" )
. AddField ( "Name (replaces name with display name if member has one)" , target . NamePrivacy . Explanation ( ) )
. AddField ( "Description" , target . DescriptionPrivacy . Explanation ( ) )
. AddField ( "Avatar" , target . AvatarPrivacy . Explanation ( ) )
. AddField ( "Birthday" , target . BirthdayPrivacy . Explanation ( ) )
. AddField ( "Pronouns" , target . PronounPrivacy . Explanation ( ) )
. AddField ( "Meta (message count, last front, last message)" , target . MetadataPrivacy . Explanation ( ) )
. AddField ( "Visibility" , target . MemberVisibility . Explanation ( ) )
. WithDescription ( "To edit privacy settings, use the command:\n`pk;member <member> privacy <subject> <level>`\n\n- `subject` is one of `name`, `description`, `avatar`, `birthday`, `pronouns`, `created`, `messages`, `visibility`, or `all`\n- `level` is either `public` or `private`." )
. Build ( ) ) ;
2020-03-04 17:13:36 +00:00
return ;
}
2020-06-20 14:10:36 +00:00
// Get guild settings (mostly for warnings and such)
MemberGuildSettings guildSettings = null ;
2020-12-22 15:55:13 +00:00
if ( ctx . GuildNew ! = null )
guildSettings = await _db . Execute ( c = > _repo . GetMemberGuild ( c , ctx . GuildNew . Id , target . Id ) ) ;
2020-02-01 12:03:02 +00:00
2020-07-07 22:46:58 +00:00
async Task SetAll ( PrivacyLevel level )
2020-06-17 19:31:39 +00:00
{
2020-08-29 11:46:27 +00:00
await _db . Execute ( c = > _repo . UpdateMember ( c , target . Id , new MemberPatch ( ) . WithAllPrivacy ( level ) ) ) ;
2020-07-07 22:46:58 +00:00
if ( level = = PrivacyLevel . Private )
await ctx . Reply ( $"{Emojis.Success} All {target.NameFor(ctx)}'s privacy settings have been set to **{level.LevelName()}**. Other accounts will now see nothing on the member card." ) ;
else
await ctx . Reply ( $"{Emojis.Success} All {target.NameFor(ctx)}'s privacy settings have been set to **{level.LevelName()}**. Other accounts will now see everything on the member card." ) ;
2020-06-17 19:31:39 +00:00
}
2020-07-07 22:46:58 +00:00
async Task SetLevel ( MemberPrivacySubject subject , PrivacyLevel level )
2020-06-17 19:31:39 +00:00
{
2020-08-29 11:46:27 +00:00
await _db . Execute ( c = > _repo . UpdateMember ( c , target . Id , new MemberPatch ( ) . WithPrivacy ( subject , level ) ) ) ;
2020-06-17 21:06:49 +00:00
2020-07-07 22:46:58 +00:00
var subjectName = subject switch
{
MemberPrivacySubject . Name = > "name privacy" ,
MemberPrivacySubject . Description = > "description privacy" ,
MemberPrivacySubject . Avatar = > "avatar privacy" ,
MemberPrivacySubject . Pronouns = > "pronoun privacy" ,
MemberPrivacySubject . Birthday = > "birthday privacy" ,
MemberPrivacySubject . Metadata = > "metadata privacy" ,
MemberPrivacySubject . Visibility = > "visibility" ,
_ = > throw new ArgumentOutOfRangeException ( $"Unknown privacy subject {subject}" )
} ;
2020-06-17 21:06:49 +00:00
2020-07-07 22:46:58 +00:00
var explanation = ( subject , level ) switch
2020-06-17 21:06:49 +00:00
{
( MemberPrivacySubject . Name , PrivacyLevel . Private ) = > "This member's name is now hidden from other systems, and will be replaced by the member's display name." ,
( MemberPrivacySubject . Description , PrivacyLevel . Private ) = > "This member's description is now hidden from other systems." ,
2020-06-20 14:00:50 +00:00
( MemberPrivacySubject . Avatar , PrivacyLevel . Private ) = > "This member's avatar is now hidden from other systems." ,
2020-06-17 21:06:49 +00:00
( MemberPrivacySubject . Birthday , PrivacyLevel . Private ) = > "This member's birthday is now hidden from other systems." ,
( MemberPrivacySubject . Pronouns , PrivacyLevel . Private ) = > "This member's pronouns are now hidden from other systems." ,
( MemberPrivacySubject . Metadata , PrivacyLevel . Private ) = > "This member's metadata (eg. created timestamp, message count, etc) is now hidden from other systems." ,
( MemberPrivacySubject . Visibility , PrivacyLevel . Private ) = > "This member is now hidden from member lists." ,
( MemberPrivacySubject . Name , PrivacyLevel . Public ) = > "This member's name is no longer hidden from other systems." ,
( MemberPrivacySubject . Description , PrivacyLevel . Public ) = > "This member's description is no longer hidden from other systems." ,
2020-06-20 14:00:50 +00:00
( MemberPrivacySubject . Avatar , PrivacyLevel . Public ) = > "This member's avatar is no longer hidden from other systems." ,
2020-06-17 21:06:49 +00:00
( MemberPrivacySubject . Birthday , PrivacyLevel . Public ) = > "This member's birthday is no longer hidden from other systems." ,
( MemberPrivacySubject . Pronouns , PrivacyLevel . Public ) = > "This member's pronouns are no longer hidden other systems." ,
( MemberPrivacySubject . Metadata , PrivacyLevel . Public ) = > "This member's metadata (eg. created timestamp, message count, etc) is no longer hidden from other systems." ,
( MemberPrivacySubject . Visibility , PrivacyLevel . Public ) = > "This member is no longer hidden from member lists." ,
2020-06-18 15:34:03 +00:00
2020-07-07 22:46:58 +00:00
_ = > throw new InvalidOperationException ( $"Invalid subject/level tuple ({subject}, {level})" )
2020-06-17 21:06:49 +00:00
} ;
2020-07-07 22:46:58 +00:00
await ctx . Reply ( $"{Emojis.Success} {target.NameFor(ctx)}'s **{subjectName}** has been set to **{level.LevelName()}**. {explanation}" ) ;
2020-06-29 11:57:48 +00:00
2020-07-07 22:46:58 +00:00
// Name privacy only works given a display name
if ( subject = = MemberPrivacySubject . Name & & level = = PrivacyLevel . Private & & target . DisplayName = = null )
await ctx . Reply ( $"{Emojis.Warn} This member does not have a display name set, and name privacy **will not take effect**." ) ;
2020-06-17 21:06:49 +00:00
2020-07-07 22:46:58 +00:00
// Avatar privacy doesn't apply when proxying if no server avatar is set
if ( subject = = MemberPrivacySubject . Avatar & & level = = PrivacyLevel . Private & & guildSettings ? . AvatarUrl = = null )
2020-08-25 20:33:04 +00:00
await ctx . Reply ( $"{Emojis.Warn} This member does not have a server avatar set, so *proxying* will **still show the member avatar**. If you want to hide your avatar when proxying here, set a server avatar: `pk;member {target.Reference()} serveravatar`" ) ;
2020-06-17 19:31:39 +00:00
}
2020-07-07 22:46:58 +00:00
if ( ctx . Match ( "all" ) | | newValueFromCommand ! = null )
await SetAll ( newValueFromCommand ? ? ctx . PopPrivacyLevel ( ) ) ;
2020-02-01 12:03:02 +00:00
else
2020-07-07 22:46:58 +00:00
await SetLevel ( ctx . PopMemberPrivacySubject ( ) , ctx . PopPrivacyLevel ( ) ) ;
2020-02-01 12:03:02 +00:00
}
public async Task Delete ( Context ctx , PKMember target )
{
2020-11-22 21:15:26 +00:00
ctx . CheckSystem ( ) . CheckOwnMember ( target ) ;
2020-02-01 12:03:02 +00:00
2020-06-20 15:36:03 +00:00
await ctx . Reply ( $"{Emojis.Warn} Are you sure you want to delete \" { target . NameFor ( ctx ) } \ "? If so, reply to this message with the member's ID (`{target.Hid}`). __***This cannot be undone!***__" ) ;
2020-02-01 12:03:02 +00:00
if ( ! await ctx . ConfirmWithReply ( target . Hid ) ) throw Errors . MemberDeleteCancelled ;
2020-06-29 11:57:48 +00:00
2020-08-29 11:46:27 +00:00
await _db . Execute ( conn = > _repo . DeleteMember ( conn , target . Id ) ) ;
2020-06-29 11:57:48 +00:00
2020-02-01 12:03:02 +00:00
await ctx . Reply ( $"{Emojis.Success} Member deleted." ) ;
}
}
2020-07-22 14:27:53 +00:00
}