Пример #1
0
        public async Task <bool> SetGreetDm(ulong guildId, bool?value = null)
        {
            bool enabled;

            using (var uow = _db.UnitOfWork)
            {
                var conf = uow.GuildConfigs.For(guildId, set => set);
                enabled = conf.SendDmGreetMessage = value ?? !conf.SendDmGreetMessage;

                var toAdd = GreetSettings.Create(conf);
                GuildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd);

                await uow.CompleteAsync().ConfigureAwait(false);
            }
            return(enabled);
        }
Пример #2
0
        public async Task <bool> SetBye(ulong guildId, ulong channelId, bool?value = null)
        {
            bool enabled;

            using (var uow = _db.UnitOfWork)
            {
                var conf = uow.GuildConfigs.For(guildId, set => set);
                enabled = conf.SendChannelByeMessage = value ?? !conf.SendChannelByeMessage;
                conf.ByeMessageChannelId = channelId;

                var toAdd = GreetSettings.Create(conf);
                GuildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd);

                await uow.CompleteAsync();
            }
            return(enabled);
        }
Пример #3
0
        public async Task SetGreetDel(ulong id, int timer)
        {
            if (timer < 0 || timer > 600)
            {
                return;
            }

            using (var uow = _db.UnitOfWork)
            {
                var conf = uow.GuildConfigs.For(id, set => set);
                conf.AutoDeleteGreetMessagesTimer = timer;

                var toAdd = GreetSettings.Create(conf);
                GuildConfigsCache.AddOrUpdate(id, toAdd, (key, old) => toAdd);

                await uow.CompleteAsync().ConfigureAwait(false);
            }
        }
Пример #4
0
        public GreetSettings GetOrAddSettingsForGuild(ulong guildId)
        {
            GuildConfigsCache.TryGetValue(guildId, out var settings);

            if (settings != null)
            {
                return(settings);
            }

            using (var uow = _db.UnitOfWork)
            {
                var gc = uow.GuildConfigs.For(guildId, set => set);
                settings = GreetSettings.Create(gc);
            }

            GuildConfigsCache.TryAdd(guildId, settings);
            return(settings);
        }
Пример #5
0
        public async Task <bool> SetSettings(ulong guildId, GreetSettings settings)
        {
            if (settings.AutoDeleteByeMessagesTimer > 600 ||
                settings.AutoDeleteByeMessagesTimer < 0 ||
                settings.AutoDeleteGreetMessagesTimer > 600 ||
                settings.AutoDeleteGreetMessagesTimer < 0)
            {
                return(false);
            }

            using (var uow = _db.UnitOfWork)
            {
                var conf = uow.GuildConfigs.For(guildId, set => set);
                conf.DmGreetMessageText      = settings.DmGreetMessageText?.SanitizeMentions();
                conf.ChannelGreetMessageText = settings.ChannelGreetMessageText?.SanitizeMentions();
                conf.ChannelByeMessageText   = settings.ChannelByeMessageText?.SanitizeMentions();

                conf.AutoDeleteGreetMessagesTimer = settings.AutoDeleteGreetMessagesTimer;
                conf.AutoDeleteGreetMessages      = settings.AutoDeleteGreetMessagesTimer > 0;

                conf.AutoDeleteByeMessagesTimer = settings.AutoDeleteByeMessagesTimer;
                conf.AutoDeleteByeMessages      = settings.AutoDeleteByeMessagesTimer > 0;

                conf.GreetMessageChannelId = settings.GreetMessageChannelId;
                conf.ByeMessageChannelId   = settings.ByeMessageChannelId;

                conf.SendChannelGreetMessage = settings.SendChannelGreetMessage;
                conf.SendChannelByeMessage   = settings.SendChannelByeMessage;

                await uow.CompleteAsync().ConfigureAwait(false);

                var toAdd = GreetSettings.Create(conf);
                GuildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd);
            }

            return(true);
        }
Пример #6
0
        public bool SetByeMessage(ulong guildId, ref string message)
        {
            message = message?.SanitizeMentions();

            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException(nameof(message));
            }

            bool byeMsgEnabled;

            using (var uow = _db.UnitOfWork)
            {
                var conf = uow.GuildConfigs.For(guildId, set => set);
                conf.ChannelByeMessageText = message;
                byeMsgEnabled = conf.SendChannelByeMessage;

                var toAdd = GreetSettings.Create(conf);
                GuildConfigsCache.AddOrUpdate(guildId, toAdd, (key, old) => toAdd);

                uow.Complete();
            }
            return(byeMsgEnabled);
        }