コード例 #1
0
        public async Task UpdateTimeZone(CommandContext context)
        {
            using IBotAccessProvider accessProvider = this.providerBuilder.Build();

            if (accessProvider.GetUsersTimeZone(context.User.Id) == null)
            {
                await context.RespondAsync(
                    $"{context.User.Mention}, you don't have a timezone set up. To initialize your timezone please type `time init`.");

                return;
            }
            await context.RespondAsync(
                "Please navigate to https://kevinnovak.github.io/Time-Zone-Picker/ and select your timezone. After you do please hit the copy button and paste the contents into the chat.");

            InteractivityExtension interactivity        = context.Client.GetInteractivity();
            InteractivityResult <DiscordMessage> result = await interactivity.WaitForMessageAsync(msg => msg.Author.Equals(context.Message.Author));

            if (!result.TimedOut)
            {
                DateTimeZone test = this.timeZoneProvider.GetZoneOrNull(result.Result.Content);
                if (test != null)
                {
                    UserTimeZone updatedUserTimeZone = accessProvider.GetUsersTimeZone(context.Message.Author.Id);
                    updatedUserTimeZone.TimeZoneId = result.Result.Content;
                    accessProvider.UpdateUserTimeZone(updatedUserTimeZone);
                    await context.RespondAsync(
                        $"I updated your timezone to {result.Result.Content} in all guilds I am a member of.");
                }
                else
                {
                    await context.RespondAsync("You provided me with an invalid timezone. Try again by typing `time update`.");
                }
            }
            else
            {
                await context.RespondAsync(
                    "You either waited too long to respond. Try again by typing `time update`.");
            }
        }