Esempio n. 1
0
        public static void DelMessage(CommandArgs args)
        {
            if (args.Parameters.Count < 3)
            {
                throw new CommandException("Invalid usage! Usage: /autobc messages delete <broadcast name> <message ID>");
            }

            string broadcastName = args.Parameters[1];

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

            if (!int.TryParse(args.Parameters[2], out int messageID))
            {
                throw new CommandException("Invalid message ID! Enter a numeric ID. Example usage: /autobc messages delete announcment 2");
            }

            Broadcast broadcast = Utils.GetBroadcastByName(broadcastName);

            if (broadcast.Messages.Count < messageID)
            {
                throw new CommandException("Broadcast does not contain a message with that ID. Type /autobc messages list <broadcast name> for the list!");
            }

            List <string> messageList = new List <string>();

            messageList.AddRange(broadcast.Messages);
            string messageRemoved = messageList.ElementAt(messageID);

            messageList.RemoveAt(messageID);
            if (!Database.UpdateBroadcast(broadcast.Name, broadcast.Enabled, messageList, Extensions.ToColorString(broadcast.Color), broadcast.Interval, broadcast.StartDelay, broadcast.TriggerRegions,
                                          broadcast.RegionTriggerTo, broadcast.Groups, broadcast.TriggerWords, broadcast.TriggerToWholeGroup))
            {
                throw new CommandException($"Failed remove message from Broadcast \"{broadcast.Name}\" due to a database error.");
            }

            args.Player.SendSuccessMessage($"Successfully removed message: [{messageID}] {messageRemoved}");
            broadcast.Messages.RemoveAt(messageID);
        }
Esempio n. 2
0
        public static void EditMessage(CommandArgs args)
        {
            if (args.Parameters.Count < 4)
            {
                throw new CommandException("Invalid usage! Usage: /autobc messages edit <broadcast name> <messageID> <new message>");
            }
            string broadcastName = args.Parameters[1];
            string message       = string.Join(" ", args.Parameters.Skip(3));

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

            if (!int.TryParse(args.Parameters[2], out int messageID))
            {
                throw new CommandException("Invalid message ID! Enter a numeric ID. Example usage: /autobc messages edit testbroadcast 2 new message");
            }

            Broadcast     broadcast = Utils.GetBroadcastByName(broadcastName);
            List <string> messages  = new List <string>();

            messages.AddRange(broadcast.Messages);
            messages[messageID] = message;

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

            broadcast.Messages[messageID] = message;
            args.Player.SendSuccessMessage($"Successfully edited message of Broadcast \"{broadcast.Name}\"!");
        }
Esempio n. 3
0
        public static void AddMessage(CommandArgs args)
        {
            if (args.Parameters.Count < 3)
            {
                throw new CommandException("Invalid usage! Usage: /autobc messages add <broadcast name> <message>");
            }
            string broadcastName = args.Parameters[1];
            string message       = string.Join(" ", args.Parameters.Skip(2));

            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);
            List <string> messages  = new List <string>();

            messages.AddRange(broadcast.Messages);
            messages.Add(message);

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

            broadcast.Messages.Add(message);
            args.Player.SendSuccessMessage($"Successfully added message to Broadcast \"{broadcast.Name}\"!");
        }