/// <summary>
        ///     Get the settings for dynamic channels.
        ///     Will reset corrupted values to default.
        /// </summary>
        /// <param name="serverId">The id of the server.</param>
        /// <param name="type">The type of the dynamic settings.</param>
        /// <returns>The dynamic channel settings.</returns>
        public async Task <DynamicChannel> Load(ulong serverId, AutomationType type)
        {
            var channels = await _dbDynamic.List(serverId);

            var settings = channels.FirstOrDefault(x => x.Type == type);

            if (settings == null)
            {
                settings = new DynamicChannel(type)
                {
                    ServerId = serverId
                };
                await _dbDynamic.Add(settings);

                return(settings);
            }

            var update = false;

            if (string.IsNullOrWhiteSpace(settings.Prefix))
            {
                switch (type)
                {
                case AutomationType.Temporary:
                    settings.Prefix = "➕";
                    break;

                case AutomationType.Permanent:
                    settings.Prefix = "👥";
                    break;
                }
                update = true;
            }

            if (string.IsNullOrWhiteSpace(settings.Name))
            {
                switch (type)
                {
                case AutomationType.Temporary:
                    settings.Name = "--channel";
                    break;

                case AutomationType.Permanent:
                    settings.Name = "{0} channel";
                    break;
                }
                update = true;
            }

            if (update)
            {
                await _dbDynamic.Update(settings);
            }

            return(settings);
        }
        /// <summary>
        ///     Save the new settings for dynamic channels.
        /// </summary>
        /// <param name="settings">The new settings for dynamic channels.</param>
        /// <exception cref="InvalidPrefixException">Thrown if the prefix is null or empty.</exception>
        /// <exception cref="InvalidNameException">Thrown if the name is null or empty.</exception>
        /// <exception cref="PrefixExistsException">Thrown if the prefix is already in use by perma channels.</exception>
        public async Task Save(DynamicChannel settings)
        {
            if (string.IsNullOrWhiteSpace(settings.Prefix))
            {
                throw new InvalidPrefixException("The prefix cannot be null or empty.");
            }

            if (string.IsNullOrWhiteSpace(settings.Name))
            {
                throw new InvalidNameException("The name cannot be null or empty.");
            }

            var channels = await _dbDynamic.List(settings.ServerId);

            if (channels.Any(x =>
                             x.Prefix.Equals(settings.Prefix, StringComparison.OrdinalIgnoreCase) &&
                             x.Id != settings.Id))
            {
                throw new PrefixExistsException("The prefix for auto channels cannot be the same as the prefix for perma channels.");
            }

            await _dbDynamic.Update(settings);
        }
Exemple #3
0
            private async Task Prepare()
            {
                await _localization.Load(await _language.GetLanguage(Context.Guild.Id));

                _data = await _channel.Load(Context.Guild.Id, AutomationType.Temporary);
            }
Exemple #4
0
 public Task Remove(DynamicChannel value)
 {
     Context.DynamicChannels.Remove(value);
     return(Context.SaveChangesAsync());
 }
Exemple #5
0
 public Task Add(DynamicChannel value)
 {
     Context.DynamicChannels.Add(value);
     return(Context.SaveChangesAsync());
 }