예제 #1
0
        public async Task InitializeReportLogger(CommandContext context)
        {
            var newReport = new Report()
            {
                UserId  = context.Message.Author.Id.ToString(),
                GuildId = context.Guild.Id.ToString(),
                Date    = DateTime.Now.ToString("dddd, dd MMMM HH:mm")
            };

            var summaryStep     = new SummaryStep("Enter summary", null);
            var timeboxStep     = new TimeboxStep("Enter timebox", summaryStep);
            var meetingTypeStep = new MeetingTypeStep("Enter meeting type", timeboxStep);

            meetingTypeStep.OnValidResult += (result) => newReport.MeetingType = result;
            summaryStep.OnValidResult     += (result) => newReport.Summary = result;
            timeboxStep.OnValidResult     += (result) => newReport.Timebox = result;

            // open dm
            // var dm = await context.Member.CreateDmChannelAsync().ConfigureAwait(false);

            var reportLogger = new ReportLoggerHandler(
                context.Client,
                context.Channel,
                context.User,
                meetingTypeStep
                );

            var succeeded = await reportLogger.ProcessReportLogger().ConfigureAwait(false);

            if (!succeeded)
            {
                return;
            }

            await _dbContext.AddAsync(newReport).ConfigureAwait(false);

            await _dbContext.SaveChangesAsync().ConfigureAwait(false);

            await context.Channel.SendMessageAsync("Report successfully saved to database").ConfigureAwait(false);
        }
        public async Task ScheduleMeeting(CommandContext context)
        {
            var newMeeting = new Meeting()
            {
                CreatorUserId = context.Message.Author.Id.ToString(),
                GuildId       = context.Guild.Id.ToString()
            };

            var dateTimeStep    = new DateTimeStep("Enter summary", null);
            var timeboxStep     = new TimeboxStep("Enter timebox", dateTimeStep);
            var meetingTypeStep = new MeetingTypeStep("Enter meeting type", timeboxStep);
            var titleStep       = new TitleStep("Enter meeting type", meetingTypeStep);

            titleStep.OnValidResult       += (result) => newMeeting.Title = result;
            meetingTypeStep.OnValidResult += (result) => newMeeting.MeetingType = result;
            timeboxStep.OnValidResult     += (result) => newMeeting.Timebox = result;
            dateTimeStep.OnValidResult    += (result) => newMeeting.DateTime = result;

            // open dm
            // var dm = await context.Member.CreateDmChannelAsync().ConfigureAwait(false);

            var meetingScheduler = new MeetingSchedulerHandler(
                context.Client,
                context.Channel,
                context.User,
                titleStep
                );

            var succeeded = await meetingScheduler.ProcessReportLogger().ConfigureAwait(false);

            if (!succeeded)
            {
                return;
            }

            await _dbContext.AddAsync(newMeeting).ConfigureAwait(false);

            await _dbContext.SaveChangesAsync().ConfigureAwait(false);

            await context.Channel.SendMessageAsync("Report successfully saved to database").ConfigureAwait(false);
        }
예제 #3
0
        public async Task InitializeConnectionToGitHub(CommandContext context, string githubToken, string username, string repoName)
        {
            var existingConnection = await _dbContext.GitHubInformations
                                     .AsNoTracking()
                                     .FirstOrDefaultAsync(g => g.GuildId == context.Guild.Id.ToString())
                                     .ConfigureAwait(false);

            if (existingConnection != default)
            {
                var embedBuilder = new DiscordEmbedBuilder
                {
                    Title = "Already connected"
                };
                embedBuilder.AddField("Connected", $"{context.User.Mention}, " +
                                      $"this server is already connected to repo '{existingConnection.RepositoryName}'");

                await context.Channel.SendMessageAsync(embed : embedBuilder).ConfigureAwait(false);

                return;
            }

            var githubInformation = new GitHubInformation
            {
                GuildId        = context.Guild.Id.ToString(),
                GitHubToken    = githubToken,
                DiscordUserId  = context.User.Id.ToString(),
                RepositoryName = repoName,
                Url            = $"https://api.github.com/repos/{username}/{repoName}"
            };

            await _dbContext.AddAsync(githubInformation);

            await _dbContext.SaveChangesAsync();

            await context.Channel.SendMessageAsync("Successfully saved github information, you're now ready to connect.");
        }