Exemplo n.º 1
0
        public async Task <ModuleResult> AddPokemon(string raidName, string raidBoss, IGuildUser user)
        {
            var    result = new ModuleResult();
            int    raidBossId;
            string raidBossName;
            string raidBossSpriteUrl;

            try {
                (raidBossId, raidBossName, raidBossSpriteUrl) = await Mons.GetMonInfo(raidBoss);
            }
            catch (Exception e) {
                result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Cannot recognise raid boss. Check your spelling!");
                return(result);
            }

            var raids = _raidFileService.GetRaidsFromFile().Where(a => a.Name.Equals(raidName, StringComparison.CurrentCultureIgnoreCase));

            if (raids.Count() == 1)
            {
                var raid = raids.Single();
                if (raid.RaidBossId == raidBossId)
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder($"That raid already has a raidboss of: {raidBossName}");
                    return(result);
                }
                if (user.GuildPermissions.Has(GuildPermission.ManageMessages) || raid.Users.FirstOrDefault().Equals(User.FromIUser(user)))
                {
                    result.Users = raid.Users;
                    var allRaids      = _raidFileService.GetRaidsFromFile();
                    var oldRaidBossId = allRaids.Single(a => a.Equals(raid)).RaidBossId;
                    allRaids.Single(a => a.Equals(raid)).RaidBossId        = raidBossId;
                    allRaids.Single(a => a.Equals(raid)).RaidBossName      = raidBossName;
                    allRaids.Single(a => a.Equals(raid)).RaidBossSpriteUrl = raidBossSpriteUrl;
                    _raidFileService.PushRaidsToFile(allRaids);

                    string raidBossMessage = oldRaidBossId == 0 ? $"Raidboss has been changed to {raidBossName}" : $"Raidboss has been changed from {raid.RaidBossName} to {raidBossName}";

                    result.Success = true;
                    result.RequesterUserBuilder = EmbedBuilderHelper.GreenBuilder();
                    result.RequesterUserBuilder
                    .WithTitle($"Raid: {raidName}")
                    .WithDescription(raidBossMessage)
                    .WithThumbnailUrl(raidBossSpriteUrl);
                }
                else
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Only the leader can change the raidboss");
                }
            }
            else if (raids.Count() == 0)
            {
                result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Cannot find raid");
            }
            else
            {
                result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Unknown Error");
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <ModuleResult> CreateRaid(string raidName, string raidTime, string raidBoss, IUser user, int guests)
        {
            ModuleResult result = new ModuleResult();
            int          raidBossId;
            string       raidBossName;
            string       raidBossSpriteUrl;

            try {
                (raidBossId, raidBossName, raidBossSpriteUrl) = await Mons.GetMonInfo(raidBoss);
            }
            catch (Exception e) {
                result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Cannot recognise raid boss. Check your spelling!");
                return(result);
            }

            var now = DateTime.Now;

            raidTime = raidTime.Replace(".", ":").Replace(",", ":").Replace(";", ":");
            DateTime time;

            if (DateTime.TryParseExact(raidTime, "H:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out time))
            {
                Raid raid = new Raid()
                {
                    Name              = raidName,
                    Time              = time,
                    Users             = new List <User>(),
                    CreateDateTime    = now,
                    ExpireStart       = now,
                    Expire            = TimeSpan.FromMinutes(_permissions.AutoExpireMins),
                    RaidBossId        = raidBossId,
                    RaidBossName      = raidBossName,
                    RaidBossSpriteUrl = raidBossSpriteUrl
                };
                if (_permissions.JoinRaidOnCreate)
                {
                    raid.Users.Add(User.FromIUser(user, guests));
                }
                bool success = AddRaids(raid);
                if (success)
                {
                    result.Success = true;
                    result.RequesterUserBuilder = EmbedBuilderHelper.GreenBuilder();
                    result.RequesterUserBuilder
                    .WithTitle("Raid succesfully created:")
                    .WithDescription(raid.ToString())
                    .WithThumbnailUrl(raidBossSpriteUrl);
                }
                else
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Raid already exists. Please join or create a different raid.");
                }
            }
            else
            {
                result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("I do not understand that time. Try using a format of Hours:Mins e.g. `11:30`");
            }
            return(result);
        }
Exemplo n.º 3
0
        public ModuleResult CreateRaid(string raidName, string raidTime, string raidBoss, IUser user, int guests)
        {
            ModuleResult result = new ModuleResult();
            var          now    = DateTime.Now;
            int          id     = 0;

            if (int.TryParse(raidBoss, out id))
            {
                if (!Mons.IsValidId(id))
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Invalid raid boss Id");
                    return(result);
                }
            }
            else
            {
                id = Mons.GetIdByName(raidBoss);
                if (id == 0)
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Cannot recognise raid boss. Check your spelling!");
                    return(result);
                }
            }

            raidTime = raidTime.Replace(".", ":").Replace(",", ":").Replace(";", ":");
            DateTime time;

            if (DateTime.TryParseExact(raidTime, "H:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out time))
            {
                Raid raid = new Raid()
                {
                    Name           = raidName,
                    Time           = time,
                    Users          = new List <User>(),
                    CreateDateTime = now,
                    ExpireStart    = now,
                    Expire         = TimeSpan.FromMinutes(_permissions.AutoExpireMins),
                    RaidBossId     = id
                };
                if (_permissions.JoinRaidOnCreate)
                {
                    raid.Users.Add(User.FromIUser(user, guests));
                }
                bool success = AddRaids(raid);
                if (success)
                {
                    result.Success = true;
                    result.RequesterUserBuilder = EmbedBuilderHelper.GreenBuilder();
                    result.RequesterUserBuilder.AddField(x => {
                        x.Name     = "Raid succesfully created:";
                        x.Value    = raid.ToString();
                        x.IsInline = false;
                    });
                    result.RequesterUserBuilder.WithThumbnailUrl(string.Format(ConfigVariables.PokemonIconURL, id));
                }
                else
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Raid already exists. Please join or create a different raid.");
                }
            }
            else
            {
                result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("I do not understand that time. Try using a format of Hours:Mins e.g. `11:30`");
            }
            return(result);
        }
Exemplo n.º 4
0
        public ModuleResult AddPokemon(string raidName, string raidBoss, IGuildUser user)
        {
            var    result = new ModuleResult();
            string newRaidBossName;

            int raidBossId = 0;

            if (int.TryParse(raidBoss, out raidBossId))
            {
                if (!Mons.IsValidId(raidBossId))
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Invalid raid boss Id");
                    return(result);
                }
                newRaidBossName = Mons.GetNameById(raidBossId);
            }
            else
            {
                raidBossId = Mons.GetIdByName(raidBoss);
                if (raidBossId == 0)
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Cannot recognise raid boss. Check your spelling!");
                    return(result);
                }
                newRaidBossName = raidBoss;
            }

            var raids = _raidFileService.GetRaidsFromFile().Where(a => a.Name.Equals(raidName, StringComparison.CurrentCultureIgnoreCase));

            if (raids.Count() == 1)
            {
                var raid = raids.Single();
                if (raid.RaidBossId == raidBossId)
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder($"That raid already has a raidboss of: { Mons.GetNameById(raidBossId)}");
                    return(result);
                }
                if (user.GuildPermissions.Has(GuildPermission.ManageMessages) || raid.Users.FirstOrDefault().Equals(User.FromIUser(user)))
                {
                    result.Users = raid.Users;
                    var allRaids      = _raidFileService.GetRaidsFromFile();
                    var oldRaidBossId = allRaids.Single(a => a.Equals(raid)).RaidBossId;
                    allRaids.Single(a => a.Equals(raid)).RaidBossId = raidBossId;
                    _raidFileService.PushRaidsToFile(allRaids);

                    string raidBossMessage = oldRaidBossId == 0 ? $"Raidboss has been changed to {newRaidBossName}" : $"Raidboss has been changed from {Mons.GetNameById(oldRaidBossId)} to {newRaidBossName}";

                    result.Success = true;
                    result.RequesterUserBuilder = EmbedBuilderHelper.GreenBuilder();
                    result.RequesterUserBuilder.WithThumbnailUrl(string.Format(ConfigVariables.PokemonIconURL, raidBossId));
                    result.RequesterUserBuilder.AddField(x => {
                        x.Name     = $"Raid: {raidName}";
                        x.Value    = raidBossMessage;
                        x.IsInline = false;
                    });
                }
                else
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Only the leader can change the raidboss");
                }
            }
            else if (raids.Count() == 0)
            {
                result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Cannot find raid");
            }
            else
            {
                result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Unknown Error");
            }

            return(result);
        }
Exemplo n.º 5
0
        public ModuleResult CreateRaid(string raidName, string raidTime, string raidBoss, IUser user, int guests)
        {
            ModuleResult result = new ModuleResult();

            int id = 0;

            if (int.TryParse(raidBoss, out id))
            {
                if (!Mons.IsValidId(id))
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Invalid raid boss Id");
                    return(result);
                }
            }
            else
            {
                id = Mons.GetIdByName(raidBoss);
                if (id == 0)
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Cannot recognise raid boss. Check your spelling!");
                    return(result);
                }
            }

            raidTime = raidTime.Replace(".", ":").Replace(",", ":").Replace(";", ":");
            DateTime time;

            if (DateTime.TryParseExact(raidTime, "H:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out time))
            {
                if (time > DateTime.Now.AddHours(_permissions.TimeZone))
                {
                    Raid raid = new Raid()
                    {
                        Name           = raidName,
                        Time           = time,
                        Users          = new List <User>(),
                        CreateDateTime = DateTime.Now,
                        RaidBossId     = id
                    };
                    if (_permissions.JoinRaidOnCreate)
                    {
                        raid.Users.Add(User.FromIUser(user, guests));
                    }
                    bool success = AddRaids(raid);
                    if (success)
                    {
                        result.Success = true;
                        result.RequesterUserBuilder = EmbedBuilderHelper.GreenBuilder();
                        result.RequesterUserBuilder.AddField(x => {
                            x.Name     = "Raid succesfully created:";
                            x.Value    = raid.ToString();
                            x.IsInline = false;
                        });
                        result.RequesterUserBuilder.WithThumbnailUrl($"https://raw.githubusercontent.com/kvangent/PokeAlarm/master/icons/{id}.png");
                    }
                    else
                    {
                        result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("Raid already exists. Please join or create a different raid.");
                    }
                }
                else
                {
                    result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("That time has already passed. Please choose a different time.");
                }
            }
            else
            {
                result.RequesterUserBuilder = EmbedBuilderHelper.ErrorBuilder("I do not understand that time. Try using a format of Hours:Mins e.g. `11:30`");
            }
            return(result);
        }