public static int GetAge(this IBirthDate person)
        {
            Counter++;
            var age   = DateTime.Now - person.BirthDate;
            var years = age.TotalDays / YearDays;

            return(Convert.ToInt32(Math.Floor(years)));
        }
        public void SetBirthDate(ulong userid, IBirthDate bd)
        {
            var bdm = GetUserBirthDate(userid);

            if (bdm == null)
            {
                _set.Add(new BirthDateModel(userid, bd));
            }
            else
            {
                bdm.Update(bd);
            }
        }
Example #3
0
        public async Task BirthdaySet(IBirthDate bd, IUser user)
        {
            uow.BirthDates.SetBirthDate(user.Id, bd);
            await uow.SaveChangesAsync(false).ConfigureAwait(false);

            if (user == Context.User)
            {
                await ConfirmLocalized("birthdayset_set", bd.ToString()).ConfigureAwait(false);
            }
            else
            {
                await ConfirmLocalized("birthdayset_set_owner", user.ToString(), bd.ToString()).ConfigureAwait(false);
            }
        }
Example #4
0
        public async Task BirthdaySet(IBirthDate bd)
        {
            var bdm = uow.BirthDates.GetUserBirthDate(Context.User.Id);

            if (_botCreds.IsOwner(Context.User) || (bdm?.Year) == null && (bdm == null || bdm.Year != null || bdm.Day == bd.Day && bdm.Month == bd.Month))
            {
                uow.BirthDates.SetBirthDate(Context.User.Id, bd);
                await uow.SaveChangesAsync(false).ConfigureAwait(false);

                await ReplyConfirmLocalized("birthdayset_set", bd.ToString()).ConfigureAwait(false);

                if (bd.IsBirthday(DateTime.Now) && (bdm == null || !bdm.IsBirthday(DateTime.Now)))
                {
                    var gc = uow.GuildConfigs.For(Context.Guild.Id);

                    if (gc.BirthdaysEnabled)
                    {
                        var bdmChId = gc.BirthdayMessageChannelId;

                        if (bdmChId != null)
                        {
                            var bdmCh = await Context.Guild.GetTextChannelAsync(bdmChId.Value).ConfigureAwait(false);

                            if (bdmCh != null)
                            {
                                await bdmCh.SendMessageAsync(string.Format(gc.BirthdayMessage, Context.User.Mention)).ConfigureAwait(false);
                            }
                        }

                        var roleId = gc.BirthdayRoleId;

                        if (roleId != null)
                        {
                            var role = Context.Guild.GetRole(roleId.Value);

                            if (role != null)
                            {
                                await((SocketGuildUser)Context.User).AddRoleAsync(role).ConfigureAwait(false);
                            }
                        }
                    }
                }
            }
            else
            {
                await ReplyErrorLocalized("birthdayset_set_before").ConfigureAwait(false);
            }
        }
Example #5
0
        public async Task Birthdays(IBirthDate bd = null)
        {
            bd ??= BirthDate.TodayWithoutYear;
            var birthdates = uow.BirthDates.GetBirthdays(bd, bd.Year.HasValue).ToList();

            if (!birthdates.Any())
            {
                await ConfirmLocalized("birthdays_none_date", bd.ToString()).ConfigureAwait(false);
            }
            else
            {
                var eb = new EmbedBuilder()
                         .WithOkColor()
                         .WithTitle(GetText("birthdays_list_title", bd.ToString()))
                         .WithDescription(string.Join("\n", birthdates.Select(bdm => $"- {Context.Client.GetUserAsync(bdm.UserId).GetAwaiter().GetResult()?.ToString() ?? bdm.UserId.ToString()}{(bdm.Year.HasValue && !bd.Year.HasValue ? $"{BirthDate.Today.Year - bdm.Year}" : "")}")));
                await Context.Channel.EmbedAsync(eb).ConfigureAwait(false);
            }
        }
 public IQueryable <BirthDateModel> GetBirthdays(IBirthDate bd, bool checkYear = false)
 => _set.AsQueryable().Where(b => b.Day == bd.Day && b.Month == bd.Month && (!checkYear || !bd.Year.HasValue || b.Year.HasValue && bd.Year.HasValue && b.Year == bd.Year));
 public bool IsBirthday(IBirthDate bd)
 => bd.Day == Day && bd.Month == Month;
 public void Update(IBirthDate bd)
 {
     Day   = bd.Day;
     Month = bd.Month;
     Year  = bd.Year;
 }
 public BirthDateModel(ulong userid, IBirthDate bd)
 {
     UserId = userid;
     Update(bd);
 }