コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
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);
            }
        }