Ejemplo n.º 1
0
        /// <summary>
        /// Mod command. Sets the rules applying to a privileges group.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="core">The core.</param>
        public static void SetRules(Command command, Core core = null)
        {
            if (Tools.IsNotModThenSendWarning(command))
            {
                return;
            }

            string[] arguements = command.SplitArguements(count: 7);
            if (arguements.Length < 7)
            {
                Entites.Message.SendMessage(Message.Answer(command.Message,
                                                           "Incorect syntax. Please use the following one: /setrules privileges messageDelayInSeconds extensionBlocked? domainBlocked? messageTypeBlocked? blockedWordsEnabled? r9kEnabled?. Note that the fields ending by ? must be either 'y' or 'n'."));
                return;
            }
            for (int i = 2; i < arguements.Length; ++i)
            {
                if (!arguements[i].Equals("y", StringComparison.InvariantCultureIgnoreCase) && !arguements[i].Equals("n", StringComparison.InvariantCultureIgnoreCase))
                {
                    Entites.Message.SendMessage(Message.Answer(command.Message,
                                                               "Incorect syntax. Please use the following one: /setrules privileges messageDelayInSeconds extensionBlocked? domainBlocked? messageTypeBlocked? blockedWordsEnabled? r9kEnabled?. Note that the fields ending by ? must be either 'y' or 'n'."));
                    return;
                }
            }

            if (!int.TryParse(arguements[1], out int messageDelay))
            {
                Entites.Message.SendMessage(Message.Answer(command.Message,
                                                           $"Please write a time in seconds rather than {arguements[1]}"));
                return;
            }

            Entites.Privileges privileges = Privileges.GetPrivileges(command.Message.UserToChannel.Channel, arguements[0]);
            if (privileges == null)
            {
                Entites.Message.SendMessage(Message.Answer(command.Message,
                                                           $"No privileges group nammed {arguements[0]} was found."));
                return;
            }
            DAL.Privileges.LoadRules(privileges);

            privileges.Rules.SpamDelay           = messageDelay <= 0 ? null : (TimeSpan?)TimeSpan.FromSeconds(messageDelay);
            privileges.Rules.ExtensionBlocked    = "y".Equals(arguements[2], StringComparison.InvariantCultureIgnoreCase);
            privileges.Rules.DomainBlocked       = "y".Equals(arguements[3], StringComparison.InvariantCultureIgnoreCase);
            privileges.Rules.MessageTypeBlocked  = "y".Equals(arguements[4], StringComparison.InvariantCultureIgnoreCase);
            privileges.Rules.BlockedWordsEnabled = "y".Equals(arguements[5], StringComparison.InvariantCultureIgnoreCase);
            privileges.Rules.R9KEnabled          = "y".Equals(arguements[6], StringComparison.InvariantCultureIgnoreCase);
            DAL.Rules.Update(privileges.Rules);
            Entites.Message.SendMessage(Message.Answer(command.Message, $"The rules of {arguements[0]} were successfully updated."));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the specified channel.
        /// </summary>
        /// <param name="iChannel">The ichannel.</param>
        /// <returns>The newly created channel.</returns>
        public static Entites.Channel Create(IChannel iChannel)
        {
            Entites.Channel channel =
                DAL.Channel.Create(new Entites.Channel(Application.GetOrCreate(iChannel.Application),
                                                       iChannel.ApplicationId, iChannel.IsSolo));

            channel.UserNames = new List <Entites.UserName>
            {
                DAL.UserName.Create(UserName.ExtractUserName(iChannel, channel))
            };

            if (!channel.Private)
            {
                channel.AdSystem    = AdSystem.Create(channel);
                channel.PointSystem = PointSystem.Create(channel);
                channel.Privileges  = Privileges.Create(channel);
            }

            return(channel);
        }
Ejemplo n.º 3
0
        private static string SetPrivilegesAnalyzes(Command command)
        {
            if (!Tools.IsMod(command.Message.UserToChannel))
            {
                return("This command is reserved for moderators.");
            }

            string[] arguements = command.Arguement.Split(new[] { ' ' }, 2);
            string   user;
            string   privilegesName;

            if (arguements.Length > 1)
            {
                user           = arguements[0].Substring(1);
                privilegesName = arguements[1];
            }
            else
            {
                user           = command.Message.UserToChannel.User.CurrentUserName.Username;
                privilegesName = arguements[0];
            }

            Entites.UserToChannel userToChannel =
                Get(DAL.UserName.LoadOwnedBy(DAL.UserName.GetFromUsername(user, command.Message.ApplicationName))
                    .OwnedBy as Entites.User, command.Message.UserToChannel.Channel);
            if (userToChannel == null)
            {
                return($"No one nammed @{user} was found.");
            }

            Entites.Privileges privileges = Privileges.GetPrivileges(command.Message.UserToChannel.Channel, privilegesName);
            if (privileges == null)
            {
                return($"No privileges group nammed {privilegesName} was found.");
            }

            userToChannel.PrivilegesId = privileges.PrivilegesId;
            Update(userToChannel);
            return($"Your privileges group is now set to {privilegesName}.");
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates the specified user to channel.
 /// </summary>
 /// <param name="iApplication">The application.</param>
 /// <param name="iUser">The user.</param>
 /// <param name="iChannel">The channel.</param>
 /// <returns>The newly created uesr to channel.</returns>
 public static Entites.UserToChannel Create(IApplication iApplication, IUser iUser, IChannel iChannel)
 {
     Entites.Channel channel = Channel.UpdateOrCreate(iChannel);
     return(DAL.UserToChannel.Create(new Entites.UserToChannel(Application.GetOrCreate(iApplication),
                                                               User.UpdateOrCreate(iUser),
                                                               channel, DateTime.UtcNow, Privileges.GetDefaultUser(channel))));
 }