public async Task Birthday(Context ctx, PKMember target) { if (ctx.System == null) { throw Errors.NoSystemError; } if (target.System != ctx.System.Id) { throw Errors.NotOwnMemberError; } LocalDate?date = null; var birthday = ctx.RemainderOrNull(); if (birthday != null) { date = DateUtils.ParseDate(birthday, true); if (date == null) { throw Errors.BirthdayParseError(birthday); } } target.Birthday = date; await _data.SaveMember(target); await ctx.Reply($"{Emojis.Success} Member birthdate {(date == null ? "cleared" : $"changed to {target.BirthdayString}")}.");
public async Task Birthday(Context ctx, PKMember target) { if (await ctx.MatchClear("this member's birthday")) { ctx.CheckOwnMember(target); var patch = new MemberPatch { Birthday = Partial <LocalDate?> .Null() }; await _db.Execute(conn => _repo.UpdateMember(conn, target.Id, patch)); await ctx.Reply($"{Emojis.Success} Member birthdate cleared."); } else if (!ctx.HasNext()) { if (!target.BirthdayPrivacy.CanAccess(ctx.LookupContextFor(target.System))) { throw Errors.LookupNotAllowed; } if (target.Birthday == null) { await ctx.Reply("This member does not have a birthdate set." + (ctx.System?.Id == target.System ? $" To set one, type `pk;member {target.Reference()} birthdate <birthdate>`." : "")); } else { await ctx.Reply($"This member's birthdate is **{target.BirthdayString}**." + (ctx.System?.Id == target.System ? $" To clear it, type `pk;member {target.Reference()} birthdate -clear`." : "")); } } else { ctx.CheckOwnMember(target); var birthdayStr = ctx.RemainderOrNull(); var birthday = DateUtils.ParseDate(birthdayStr, true); if (birthday == null) { throw Errors.BirthdayParseError(birthdayStr); } var patch = new MemberPatch { Birthday = Partial <LocalDate?> .Present(birthday) }; await _db.Execute(conn => _repo.UpdateMember(conn, target.Id, patch)); await ctx.Reply($"{Emojis.Success} Member birthdate changed."); } }
public async Task Birthday(Context ctx, PKMember target) { if (MatchClear(ctx)) { CheckEditMemberPermission(ctx, target); target.Birthday = null; await _data.SaveMember(target); await ctx.Reply($"{Emojis.Success} Member birthdate cleared."); } else if (!ctx.HasNext()) { if (!target.BirthdayPrivacy.CanAccess(ctx.LookupContextFor(target.System))) { throw Errors.LookupNotAllowed; } if (target.Birthday == null) { await ctx.Reply("This member does not have a birthdate set." + (ctx.System?.Id == target.System ? $" To set one, type `pk;member {target.Hid} birthdate <birthdate>`." : "")); } else { await ctx.Reply($"This member's birthdate is **{target.BirthdayString}**." + (ctx.System?.Id == target.System ? $" To clear it, type `pk;member {target.Hid} birthdate -clear`." : "")); } } else { CheckEditMemberPermission(ctx, target); var birthdayStr = ctx.RemainderOrNull(); var birthday = DateUtils.ParseDate(birthdayStr, true); if (birthday == null) { throw Errors.BirthdayParseError(birthdayStr); } target.Birthday = birthday; await _data.SaveMember(target); await ctx.Reply($"{Emojis.Success} Member birthdate changed."); } }