public async Task Info([Summary("Optional user to get info about")] SocketUser mentionedUser = null)
        {
            await Context.Channel.TriggerTypingAsync();

            if (mentionedUser == null)
            {
                mentionedUser = Context.User; //as SocketGuildUser;
            }

            _logger.LogInformation("{username}#{discriminator} executed info ({target}) on {server}/{channel}",
                                   Context.User.Username, Context.User.Discriminator, mentionedUser?.Username ?? "self", Context.Guild?.Name ?? "DM", Context.Channel.Name);

            var server = await _servers.GetServer(Context.Guild);

            var builder = new EmbedBuilder()
                          .WithThumbnailUrl(mentionedUser.GetAvatarUrl() ?? mentionedUser.GetDefaultAvatarUrl())
                          .WithDescription("User information:")
                          .WithColor(ColorHelper.GetColor(server))
                          .AddField("User ID", mentionedUser.Id, true)
                          .AddField("Discriminator", mentionedUser.Discriminator, true)
                          .AddField("Created at", mentionedUser.CreatedAt.ToString("MM/dd/yyyy"), true)
                          .WithCurrentTimestamp();

            var timezone = await _userTimeZones.GetByUserID(mentionedUser.Id);

            if (timezone != null)
            {
                builder.AddField("Timezone", timezone.TimeZone, true);
            }

            SocketGuildUser guildUser = mentionedUser as SocketGuildUser;

            if (guildUser != null)
            {
                builder
                .AddField("Joined at", guildUser.JoinedAt.Value.ToString("MM/dd/yyyy"), true)
                .AddField("Roles", string.Join(" ", guildUser.Roles.Select(x => x.Mention)));
            }

            var embed = builder.Build();

            await ReplyAsync(null, false, embed);
        }
Beispiel #2
0
        public async Task RegisterTimeZone([Summary("Your IANA or Windows timezone")][Remainder] string timeZone = null)
        {
            await Context.Channel.TriggerTypingAsync();

            _logger.LogInformation("{username}#{discriminator} executed registertimezone ({timezone}) on {server}/{channel}",
                                   Context.User.Username, Context.User.Discriminator, timeZone, Context.Guild?.Name ?? "DM", Context.Channel.Name);

            if (await ServerHelper.CheckIfContextIsDM(Context))
            {
                return;
            }

            if (timeZone == null)
            {
                await Context.Channel.SendEmbedAsync("Provide a Time Zone", "Please provide a valid windows or IANA timezone.",
                                                     ColorHelper.GetColor(await _serverService.GetServer(Context.Guild)));

                return;
            }

            if (!TryParseTimeZone(timeZone, out TimeZoneInfo timeZoneInfo))
            {
                await Context.Channel.SendEmbedAsync("Invalid Time Zone", "Please provide a valid windows or IANA timezone.",
                                                     ColorHelper.GetColor(await _serverService.GetServer(Context.Guild)));
            }
            else
            {
                var user = await _userRepository.GetByUserId(Context.User.Id);

                if (user == null)
                {
                    await _userRepository.AddAsync(new User { UserId = Context.User.Id, UserName = Context.User.Username });

                    user = await _userRepository.GetByUserId(Context.User.Id);
                }

                var userTimeZone = await _userTimeZones.GetByUserID(Context.User.Id);

                if (userTimeZone == null)
                {
                    if (user == null)
                    {
                        await _userRepository.AddAsync(new User { UserId = Context.User.Id, UserName = Context.User.Username });
                    }

                    var userTz = new UserTimeZone
                    {
                        UserId   = user.Id,
                        TimeZone = timeZone,
                    };

                    await _userTimeZones.AddAsync(userTz);

                    await Context.Channel.SendEmbedAsync("Succesfully Registered", $"Successfully registered your time zone: `{timeZoneInfo.DisplayName}`",
                                                         ColorHelper.GetColor(await _serverService.GetServer(Context.Guild)));
                }
                else
                {
                    userTimeZone.TimeZone = timeZone;
                    await _userTimeZones.EditAsync(userTimeZone);

                    await Context.Channel.SendEmbedAsync("Succesfully Updated", $"Successfully updated your time zone: `{timeZoneInfo.DisplayName}`",
                                                         ColorHelper.GetColor(await _serverService.GetServer(Context.Guild)));
                }
            }
        }