示例#1
0
        public static void WriteExample(string file)
        {
            var Ex = new Broadcast();
            Ex.Name = "Example Broadcast";
            Ex.Enabled = false;
            Ex.Messages = new string[]
            {
                "This is an example broadcast",
                "It will broadcast every 5 minutes",
                "Broadcasts can also execute commands",
                "/time noon"
            };
            Ex.ColorRGB = new float[] { 255f, 0f, 0f };
            Ex.Interval = 300;
            Ex.StartDelay = 60;

            var Conf = new ABConfig();
            Conf.Broadcasts = new Broadcast[] { Ex };

            Conf.Write(file);
        }
示例#2
0
        public static void Enable(CommandArgs args)
        {
            if (args.Parameters.Count < 1)
            {
                throw new CommandException("Invalid usage! Usage: /autobc enable <broadcast name>");
            }
            string broadcastName = args.Parameters[0];

            if (!Utils.BroadcastExists(broadcastName))
            {
                throw new CommandException("A Broadcast with that name does not exist! Type /autobc list, for a list of Broadcasts.");
            }

            Broadcast broadcast = Utils.GetBroadcastByName(broadcastName);

            if (!Database.UpdateBroadcast(broadcast.Name, !broadcast.Enabled, broadcast.Messages, string.Join(", ", broadcast.Color), broadcast.Interval, broadcast.StartDelay, broadcast.TriggerRegions,
                                          broadcast.RegionTriggerTo, broadcast.Groups, broadcast.TriggerWords, broadcast.TriggerToWholeGroup ? true : false))
            {
                throw new CommandException($"Failed turn {(broadcast.Enabled ? "on" : "off")} of Broadcast \"{broadcast.Name}\" due to a database error.");
            }

            broadcast.Enabled = !broadcast.Enabled;
            args.Player.SendSuccessMessage($"Successfully turned {(broadcast.Enabled ? "on" : "off")} Broadcast \"{broadcast.Name}\"!");
        }
示例#3
0
        public static void WriteExample(string file)
        {
            var Ex = new Broadcast()
            {
                Name     = "Example Broadcast",
                Enabled  = false,
                Messages = new string[]
                {
                    "This is an example broadcast",
                    "It will broadcast every 5 minutes",
                    "Broadcasts can also execute commands",
                    "/time noon"
                },
                ColorRGB   = new float[] { 255f, 0f, 0f },
                Interval   = 300,
                StartDelay = 60
            };
            var Conf = new ABConfig()
            {
                Broadcasts = new Broadcast[] { Ex }
            };

            Conf.Write(file);
        }
示例#4
0
        public static void Set(CommandArgs args)
        {
            if (args.Parameters.Count < 1)
            {
                throw new CommandException("Invalid usage! Usage: /autobc set <broadcast name> [flags] \nType /autobc listflags for a list of flags.");
            }
            string broadcastName = args.Parameters[0];

            if (!Utils.BroadcastExists(broadcastName))
            {
                throw new CommandException("A Broadcast with that name does not exist! Type /autobc list, for a list of Broadcasts.");
            }

            Broadcast broadcast = Utils.GetBroadcastByName(broadcastName);

            int    interval = -1, startDelay = -1;
            string color = "", triggerRegions = "", regionTriggerTo = "", groups = "", triggerWords = "", triggertowholegroup = "";

            OptionSet o = new OptionSet
            {
                { "c|color=", v => color = v },
                { "i|interval=", v => Int32.TryParse(v, out interval) },
                { "sd|startdelay=", v => Int32.TryParse(v, out startDelay) },
                { "tregions|triggerregions=", v => triggerRegions = v },
                { "regionto|regiontriggerto=", v => regionTriggerTo = v },
                { "g|groups=", v => groups = v },
                { "twords|triggerwords=", v => triggerWords = v },
                { "ttwg|triggertowholegroup=", v => triggertowholegroup = String.IsNullOrWhiteSpace(v) ? "true" : v }
            };

            List <string> parsed = o.Parse(args.Parameters);

            if (!String.IsNullOrWhiteSpace(color))
            {
                broadcast.Color = color.FloatFromRGB();
            }

            if (interval != -1)
            {
                broadcast.Interval = interval;
            }

            if (startDelay != -1)
            {
                broadcast.StartDelay = startDelay;
            }

            if (!String.IsNullOrWhiteSpace(triggerRegions))
            {
                broadcast.TriggerRegions = triggerRegions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            }

            if (!String.IsNullOrWhiteSpace(regionTriggerTo) && new string[] { "all", "region", "self" }.Contains(regionTriggerTo))
            {
                broadcast.RegionTriggerTo = regionTriggerTo;
            }

            if (!String.IsNullOrWhiteSpace(groups))
            {
                broadcast.Groups = groups.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            }

            if (!String.IsNullOrWhiteSpace(triggerWords))
            {
                broadcast.TriggerWords = triggerWords.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            }

            if (!String.IsNullOrWhiteSpace(triggertowholegroup))
            {
                broadcast.TriggerToWholeGroup = triggertowholegroup == "true" ? true : false;
            }



            if (!Database.UpdateBroadcast(broadcast.Name, broadcast.Enabled, broadcast.Messages, broadcast.Color.ToColorString(), broadcast.Interval, broadcast.StartDelay, broadcast.TriggerRegions,
                                          broadcast.RegionTriggerTo, broadcast.Groups, broadcast.TriggerWords, broadcast.TriggerToWholeGroup ? true : false))
            {
                throw new CommandException($"Failed set parameters of Broadcast \"{broadcast.Name}\" due to a database error.");
            }

            args.Player.SendSuccessMessage($"Successfully set variables for Broadcast \"{broadcast.Name}\"!");
        }
示例#5
0
        public static void BroadcastInfo(CommandArgs args)
        {
            int pageParamIndex = 1;
            int pageNumber;

            if (args.Parameters.Count < 1)
            {
                throw new CommandException("Invalid usage! Usage: /autobc info <broadcast name>");
            }

            string broadcastName = args.Parameters[0];

            if (!Utils.BroadcastExists(broadcastName))
            {
                throw new CommandException("A Broadcast with that name does not exist! Type /autobc list, for a list of Broadcasts.");
            }

            Broadcast broadcast = Utils.GetBroadcastByName(broadcastName);

            string messages = string.Join("; ", broadcast.Messages);

            if (broadcast.Messages.Count > 1)
            {
                messages = $"Enter /autobc listmessages \"{broadcastName}\" for the messages of this broadcast.";
            }
            string triggerRegions = string.Join("; ", broadcast.TriggerRegions);

            /*if (broadcast.TriggerRegions.Count > 4)
             *      triggerRegions = $"Enter /autobc listregions \"{broadcastName}\" for the triggerRegions of this broadcast.";*/
            string groups = string.Join("; ", broadcast.Groups);

            /*	if (broadcast.TriggerRegions.Count > 5)
             *              groups = $"Enter /autobc listregions \"{broadcastName}\" for the triggerRegions of this broadcast.";*/
            string triggerWords = string.Join("; ", broadcast.TriggerWords);

            /*	if (broadcast.TriggerRegions.Count > 5)
             *              triggerRegions = $"Enter /autobc listregions \"{broadcastName}\" for the triggerRegions of this broadcast.";*/


            string[] broadcastInfo = new[]
            {
                $"Enabled: {(broadcast.Enabled ? "true" : "false")}",
                $"Interval: {broadcast.Interval}",
                $"StartDelay: {broadcast.StartDelay}",
                $"Color: {string.Join(", ", broadcast.Color)}",
                $"Message: {messages}",
                $"TriggerRegion: {triggerRegions}",
                $"RegionTriggerTo: {broadcast.RegionTriggerTo}",
                $"Groups: {groups}",
                $"triggerWords: {triggerWords}",
                $"TriggerToWholeGroup: {(broadcast.TriggerToWholeGroup ? "true" : "false")}",
            };


            if (!PaginationTools.TryParsePageNumber(args.Parameters, pageParamIndex, args.Player, out pageNumber))
            {
                return;
            }

            PaginationTools.SendPage(args.Player, pageNumber, broadcastInfo,
                                     new PaginationTools.Settings
            {
                HeaderFormat    = $"\"{broadcastName}\" Info ({{0}}/{{1}}):",
                FooterFormat    = $"Type /autobc info \"{broadcastName}\" {{0}} for more.",
                MaxLinesPerPage = 5,
            });
        }