예제 #1
0
        public async Task DisableAsync(int zoneID, ZoneOption zoneOption)
        {
            if (!ZoneManager.Zones.Zones.ContainsKey(zoneID))
            {
                await Context.Channel.SendMessageAsync("Invalid zone id specified.");

                return;
            }

            if (await ZoneSupport.IsUserLeader(Context, zoneID, Context.User) == false)
            {
                await Context.Channel.SendMessageAsync("You are not a leader of this zone.");

                return;
            }

            var zone = ZoneManager.Zones[zoneID];

            switch (zoneOption)
            {
            case ZoneOption.Visitors:
            {
                zone.AllowVisitors = false;
            }
            break;
            }

            ZoneManager.SaveZone(zoneID);

            await Context.Channel.SendMessageAsync($"The `{zoneOption}` option is now disabled on `{zone.Name}`!");
        }
예제 #2
0
        public async Task CreateAsync(string name)
        {
            var zone = new Zone()
            {
                Name   = name,
                IsOpen = true
            };

            ZoneManager.CreateZone(zone);

            await Context.Channel.SendMessageAsync($"Zone #{zone.Num}, `{zone.Name}`, has been created!");

            var user = (SocketGuildUser)Context.User;
            await ZoneSupport.AddMember(Context, zone, user, Enums.ZoneAccess.Leader);
        }
예제 #3
0
            public async Task RemoveAsync(int zoneID, SocketGuildUser user)
            {
                if (!ZoneManager.Zones.Zones.ContainsKey(zoneID))
                {
                    await Context.Channel.SendMessageAsync("Invalid zone id specified.");

                    return;
                }

                if (await ZoneSupport.IsUserLeader(Context, zoneID, Context.User) == false)
                {
                    await Context.Channel.SendMessageAsync("You are not a leader of this zone.");

                    return;
                }

                string characterID;

                using (var dbConnection = new DatabaseConnection(DatabaseID.Players))
                {
                    characterID = PlayerDataManager.FindLinkedDiscordCharacter(dbConnection.Database, user.Id);
                }

                if (string.IsNullOrEmpty(characterID))
                {
                    await Context.Channel.SendMessageAsync("That user has not linked their Discord account with their in-game account yet. Unable to remove from the zone.");

                    return;
                }

                var zone = ZoneManager.Zones[zoneID];

                var zoneMember = zone.Members.Where(x => x.CharacterID == characterID).FirstOrDefault();

                if (zoneMember == null)
                {
                    await Context.Channel.SendMessageAsync("That user is not part of this zone.");

                    return;
                }

                zone.Members.Remove(zoneMember);
                ZoneManager.SaveZone(zoneID);

                await ZoneSupport.SyncUsersWithZoneRole(Context, zoneID);

                await Context.Channel.SendMessageAsync($"User removed from `{zone.Name}`!");
            }
예제 #4
0
            public async Task AddAsync(int zoneID, SocketGuildUser user, string access = "")
            {
                if (!ZoneManager.Zones.Zones.ContainsKey(zoneID))
                {
                    await Context.Channel.SendMessageAsync("Invalid zone id specified.");

                    return;
                }

                if (await ZoneSupport.IsUserLeader(Context, zoneID, Context.User) == false)
                {
                    await Context.Channel.SendMessageAsync("You are not a leader of this zone.");

                    return;
                }

                var zone = ZoneManager.Zones[zoneID];

                Enums.ZoneAccess accessValue;
                switch (access.ToLower())
                {
                case "viewer":
                {
                    accessValue = Enums.ZoneAccess.Viewer;
                }
                break;

                case "member":
                {
                    accessValue = Enums.ZoneAccess.Member;
                }
                break;

                case "leader":
                {
                    accessValue = Enums.ZoneAccess.Leader;
                }
                break;

                default:
                {
                    accessValue = Enums.ZoneAccess.Viewer;
                }
                break;
                }

                await ZoneSupport.AddMember(Context, zone, user, accessValue);
            }
예제 #5
0
        public async Task RenameAsync(int zoneID, string zoneName)
        {
            if (!ZoneManager.Zones.Zones.ContainsKey(zoneID))
            {
                await Context.Channel.SendMessageAsync("Invalid zone id specified.");

                return;
            }

            if (await ZoneSupport.IsUserLeader(Context, zoneID, Context.User) == false)
            {
                await Context.Channel.SendMessageAsync("You are not a leader of this zone.");

                return;
            }

            var zone = ZoneManager.Zones[zoneID];

            zone.Name = zoneName;

            ZoneManager.SaveZone(zoneID);

            await Context.Channel.SendMessageAsync($"The zone has been renamed to `{zone.Name}`!");
        }
예제 #6
0
        public async Task ReviewZoneAsync(int zoneID)
        {
            if (!ZoneManager.Zones.Zones.ContainsKey(zoneID))
            {
                await Context.Channel.SendMessageAsync("Invalid zone id specified.");

                return;
            }

            if (await ZoneSupport.IsUserLeader(Context, zoneID, Context.User) == false)
            {
                await Context.Channel.SendMessageAsync("You are not a leader of this zone.");

                return;
            }

            var reviewer = new Reviewer();

            var review = reviewer.ReviewZone(zoneID);

            var response = new StringBuilder();

            foreach (var group in review.Items.GroupBy(x => x.Group))
            {
                if (!string.IsNullOrEmpty(group.Key))
                {
                    response.AppendLine($"**Items - {group.Key}**");
                }
                else
                {
                    response.AppendLine("**Items**");
                }

                foreach (var item in group)
                {
                    var itemName = Items.ItemManager.Items[item.Number].Name;

                    response.AppendLine($"[{item.Number}] `{itemName}` x{item.Amount} ({item.AppearanceRate}%) on {item.Location.GetDescription()}");
                }

                response.AppendLine();
            }

            foreach (var group in review.NPCs.GroupBy(x => x.Group))
            {
                if (!string.IsNullOrEmpty(group.Key))
                {
                    response.AppendLine($"**NPCs - {group.Key}**");
                }
                else
                {
                    response.AppendLine("**NPCs**");
                }

                foreach (var groupItem in group)
                {
                    var npc     = Npcs.NpcManager.Npcs[groupItem.Number];
                    var pokemon = Pokedex.Pokedex.GetPokemon(npc.Species);

                    response.AppendLine($"[{groupItem.Number}] `{npc.Name}` ({pokemon.Name}) {npc.Behavior.ToString()}, RR: {npc.RecruitRate}");
                }

                response.AppendLine();
            }

            await Context.Channel.SendSplitMessageAsync(response.ToString());
        }
예제 #7
0
        public async Task ChannelAsync(int zoneID, string command)
        {
            if (!ZoneManager.Zones.Zones.ContainsKey(zoneID))
            {
                await Context.Channel.SendMessageAsync("Invalid zone id specified.");

                return;
            }

            if (await ZoneSupport.IsUserLeader(Context, zoneID, Context.User) == false)
            {
                await Context.Channel.SendMessageAsync("You are not a leader of this zone.");

                return;
            }

            var zone = ZoneManager.Zones[zoneID];

            var channelName = $"{zoneID}-{zone.Name.Substring(0, System.Math.Min(zone.Name.Length, 17))}";

            channelName = channelName.ToLower().Replace(' ', '-');

            var roleName = $"zone-{zoneID}";

            switch (command.ToLower())
            {
            case "open":
            {
                var category = Context.Guild.CategoryChannels.Where(x => x.Name.ToLower() == "zones").FirstOrDefault();

                if (category == null)
                {
                    await Context.Channel.SendMessageAsync("Category not found.");

                    return;
                }

                var channel = await Context.Guild.CreateTextChannelAsync(channelName);

                await channel.ModifyAsync(o =>
                    {
                        o.CategoryId = category.Id;
                        o.Topic      = $"Discussion for Zone {zoneID} - {zone.Name}.";
                    });

                global::Discord.IRole role = Context.Guild.Roles.Where(x => x.Name == roleName).FirstOrDefault();
                if (role == null)
                {
                    role = await Context.Guild.CreateRoleAsync(roleName);
                }

                var botRole = Context.Guild.Roles.Where(x => x.Name == "Bot").FirstOrDefault();
                if (botRole != null)
                {
                    await channel.AddPermissionOverwriteAsync(botRole, new global::Discord.OverwritePermissions(readMessages: global::Discord.PermValue.Allow, sendMessages: global::Discord.PermValue.Allow));
                }

                await channel.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, new global::Discord.OverwritePermissions(readMessages: global::Discord.PermValue.Deny, sendMessages: global::Discord.PermValue.Deny));

                await channel.AddPermissionOverwriteAsync(role, new global::Discord.OverwritePermissions(readMessages: global::Discord.PermValue.Allow, sendMessages: global::Discord.PermValue.Allow));

                await ZoneSupport.SyncUsersWithZoneRole(Context, zoneID, role);
            }
            break;

            case "close":
            {
                var channel = Context.Guild.Channels.Where(x => x.Name == channelName).FirstOrDefault();

                if (channel != null)
                {
                    await channel.DeleteAsync();

                    await Context.Channel.SendMessageAsync("Channel closed!");
                }
                else
                {
                    await Context.Channel.SendMessageAsync("Channel not found.");
                }

                var role = Context.Guild.Roles.Where(x => x.Name == roleName).FirstOrDefault();
                if (role != null)
                {
                    await role.DeleteAsync();
                }
            }
            break;
            }
        }