Beispiel #1
0
        public async Task <RuntimeResult> CancelDateAsync(
            [Summary("The date on which the session will take place.")] string date)
        {
            var campaign = await _campaignService.GetByTextChannelId(Context.Channel.Id);

            if (campaign == null)
            {
                return(GameMasterResult.ErrorResult("you are not in a campaign text channel."));
            }

            if (!DateTime.TryParseExact(date, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedDate))
            {
                return(GameMasterResult.ErrorResult("the date you entered was invalid."));
            }

            // Check to make sure that this user is the game master of the campaign
            var commandIssuer = Context.Guild.GetUser(Context.User.Id);

            if (campaign.GameMaster.User.DiscordId != Context.User.Id && !commandIssuer.GuildPermissions.Administrator)
            {
                return(GameMasterResult.ErrorResult("you do not have permission to cancel a session for this campaign. You must either be the Game Master of this campaign or a Server Administrator."));
            }

            try
            {
                await _sessionService.CancelForDate(campaign.Id, parsedDate);
                await ReplyAsync($"Session planned for {parsedDate.ToShortDateString()} cancelled successfully.");

                return(GameMasterResult.SuccessResult());
            }
            catch (Exception e)
            {
                return(GameMasterResult.ErrorResult(e.Message));
            }
        }
Beispiel #2
0
        public async Task <RuntimeResult> CancelNextAsync()
        {
            var campaign = await _campaignService.GetByTextChannelId(Context.Channel.Id);

            if (campaign == null)
            {
                return(GameMasterResult.ErrorResult("you are not in a campaign text channel."));
            }

            var commandIssuer = Context.Guild.GetUser(Context.User.Id);

            if (campaign.GameMaster.User.DiscordId != Context.User.Id && !commandIssuer.GuildPermissions.Administrator)
            {
                return(GameMasterResult.ErrorResult("you do not have permission to cancel a session for this campaign. You must either be the Game Master of this campaign or a Server Administrator."));
            }

            try
            {
                await _sessionService.CancelNext(campaign.Id);
                await ReplyAsync("Next session cancelled successfully.");

                return(GameMasterResult.SuccessResult());
            }
            catch (Exception e)
            {
                return(GameMasterResult.ErrorResult(e.Message));
            }
        }
Beispiel #3
0
        public async Task <RuntimeResult> UpcomingAsync()
        {
            var campaign = await _campaignService.GetByTextChannelId(Context.Channel.Id);

            if (campaign == null)
            {
                return(GameMasterResult.ErrorResult("you are not in a campaign text channel."));
            }

            try
            {
                var sessions = await _sessionService.GetUpcoming(campaign.Id);

                if (!sessions.Any())
                {
                    return(GameMasterResult.ErrorResult("the next session for this campaign has not been scheduled yet."));
                }

                await ReplyAsync(embed : EmbedBuilder.SessionList($"Upcoming Sessions for {campaign}", sessions));

                return(GameMasterResult.SuccessResult());
            }
            catch (Exception e)
            {
                return(GameMasterResult.ErrorResult(e.Message));
            }
        }
Beispiel #4
0
        public async Task <RuntimeResult> AddAsync(
            [Summary("The date on which the session will take place.")] string date,
            [Summary("The time at which the session will take place.")] string time)
        {
            var campaign = await _campaignService.GetByTextChannelId(Context.Channel.Id);

            if (campaign == null)
            {
                return(GameMasterResult.ErrorResult("you are not in a campaign text channel."));
            }

            var commandIssuer = Context.Guild.GetUser(Context.User.Id);

            if (campaign.GameMaster.User.DiscordId != Context.User.Id && !commandIssuer.GuildPermissions.Administrator)
            {
                return(GameMasterResult.ErrorResult("you do not have permission to add a session to this campaign. You must either be the Game Master of this campaign or a Server Administrator."));
            }

            if (!DateTime.TryParseExact($"{date} {time}", "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedDate))
            {
                return(GameMasterResult.ErrorResult("you entered an invalid date. Dates must be in the form 'dd/MM/yyyy hh:mm'"));
            }

            var user = await _userService.GetByDiscordUser(Context.User);

            var timeZoneId = user.TimeZoneId;

            if (timeZoneId == null)
            {
                await ReplyAsync("You do not have your timezone set, so I will just assume you wrote that date in UTC. If you want me to account for your timezone, set it using the '!timezone' command.");

                timeZoneId = "UTC";
            }
            if (!TZConvert.TryGetTimeZoneInfo(timeZoneId, out var tzInfo))
            {
                return(GameMasterResult.ErrorResult("your timezone was not found."));
            }

            var utcTime = TimeZoneInfo.ConvertTimeToUtc(parsedDate, tzInfo);

            if (utcTime <= DateTime.UtcNow)
            {
                return(GameMasterResult.ErrorResult("you cannot schedule a session in the past!"));
            }

            try
            {
                var session = await _sessionService.Create(campaign.Id, Schedule.AdHoc, utcTime);
                await ReplyAsync(embed : EmbedBuilder.SessionInfo($"Session successfully added for this campaign.", session));

                return(GameMasterResult.SuccessResult());
            }
            catch (Exception e)
            {
                return(GameMasterResult.ErrorResult(e.Message));
            }
        }
Beispiel #5
0
        public async Task <RuntimeResult> ScheduleAsync(
            [Summary("The date on which the session will take place.")] string date,
            [Summary("The time at which the session will take place.")] string time,
            [Summary("The schedule type for the session.")] string schedule)
        {
            var campaign = await _campaignService.GetByTextChannelId(Context.Channel.Id);

            if (campaign == null)
            {
                return(GameMasterResult.ErrorResult("you are not in a campaign text channel."));
            }

            // Check to make sure that this user is the game master of the campaign
            var commandIssuer = Context.Guild.GetUser(Context.User.Id);

            if (campaign.GameMaster.User.DiscordId != Context.User.Id && !commandIssuer.GuildPermissions.Administrator)
            {
                return(GameMasterResult.ErrorResult("you do not have permission to schedule a session for this campaign. You must either be the Game Master of this campaign or a Server Administrator."));
            }

            if (!DateTime.TryParseExact($"{date} {time}", "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedDate))
            {
                return(GameMasterResult.ErrorResult("you entered an invalid date. Dates must be in the form 'dd/MM/yyyy hh:mm'"));
            }

            var user = await _userService.GetByDiscordUser(Context.User);

            var timeZoneId = user.TimeZoneId;

            if (timeZoneId == null)
            {
                await ReplyAsync("You do not have your timezone set, so I will just assume you wrote that date in UTC. If you want me to account for your timezone, set it using the '!set-timezone' command.");

                timeZoneId = "UTC";
            }
            if (!TZConvert.TryGetTimeZoneInfo(timeZoneId, out var tzInfo))
            {
                return(GameMasterResult.ErrorResult("your timezone was not found."));
            }
            var utcTime = TimeZoneInfo.ConvertTimeToUtc(parsedDate, tzInfo);

            if (utcTime <= DateTime.UtcNow)
            {
                return(GameMasterResult.ErrorResult("you cannot schedule a session in the past!"));
            }

            var      scheduleLower = schedule.ToLower();
            Schedule scheduleValue;

            switch (scheduleLower)
            {
            case "weekly":
                scheduleValue = Schedule.Weekly;
                break;

            case "fortnightly":
                scheduleValue = Schedule.Fortnightly;
                break;

            case "monthly":
                scheduleValue = Schedule.Monthly;
                break;

            default:
                return(GameMasterResult.ErrorResult("you chose an invalid schedule type. Choose from 'Weekly', 'Fortnightly', or 'Monthly'."));
            }

            try
            {
                var session = await _sessionService.Create(campaign.Id, scheduleValue, utcTime);
                await ReplyAsync(embed : EmbedBuilder.SessionInfo($"Session scheduled for this campaign.", session));

                return(GameMasterResult.SuccessResult());
            }
            catch (Exception e)
            {
                return(GameMasterResult.ErrorResult(e.Message));
            }
        }