public async Task SetDelMsgOnCmdState(ulong guildId, ulong chId, Administration.State s)
        {
            using (var uow = _db.UnitOfWork)
            {
                var conf = uow.GuildConfigs.ForId(guildId,
                                                  set => set.Include(x => x.DelMsgOnCmdChannels));

                var obj = new DelMsgOnCmdChannel()
                {
                    ChannelId = chId,
                    State     = s == Administration.State.Enable,
                };
                conf.DelMsgOnCmdChannels.Remove(obj);
                if (s != Administration.State.Inherit)
                {
                    conf.DelMsgOnCmdChannels.Add(obj);
                }

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

            if (s == Administration.State.Disable)
            {
                DeleteMessagesOnCommandChannels.AddOrUpdate(chId, false, delegate { return(false); });
            }
            else if (s == Administration.State.Enable)
            {
                DeleteMessagesOnCommandChannels.AddOrUpdate(chId, true, delegate { return(true); });
            }
            else
            {
                DeleteMessagesOnCommandChannels.TryRemove(chId, out var _);
            }
        }
Esempio n. 2
0
        public async Task SetDelMsgOnCmdState(ulong guildId, ulong chId, Administration.State newState)
        {
            using (var uow = _db.GetDbContext())
            {
                var conf = uow.GuildConfigs.ForId(guildId,
                                                  set => set.Include(x => x.DelMsgOnCmdChannels));

                var old = conf.DelMsgOnCmdChannels.FirstOrDefault(x => x.ChannelId == chId);
                if (newState == Administration.State.Inherit)
                {
                    if (!(old is null))
                    {
                        conf.DelMsgOnCmdChannels.Remove(old);
                        uow._context.Remove(old);
                    }
                }
                else
                {
                    if (old is null)
                    {
                        old = new DelMsgOnCmdChannel {
                            ChannelId = chId
                        };
                        conf.DelMsgOnCmdChannels.Add(old);
                    }

                    old.State = newState == Administration.State.Enable;
                    DeleteMessagesOnCommandChannels[chId] = newState == Administration.State.Enable;
                }

                await uow.SaveChangesAsync();
            }

            if (newState == Administration.State.Disable)
            {
            }
            else if (newState == Administration.State.Enable)
            {
                DeleteMessagesOnCommandChannels[chId] = true;
            }
            else
            {
                DeleteMessagesOnCommandChannels.TryRemove(chId, out var _);
            }
        }
Esempio n. 3
0
        public async Task Delmsgoncmd(Channel _, State s, ulong?chId = null)
        {
            chId = chId ?? Context.Channel.Id;
            using (var uow = _db.UnitOfWork)
            {
                var conf = uow.GuildConfigs.ForId(Context.Guild.Id,
                                                  set => set.Include(x => x.DelMsgOnCmdChannels));

                var obj = new DelMsgOnCmdChannel()
                {
                    ChannelId = chId.Value,
                    State     = s == State.Enable,
                };
                var del = conf.DelMsgOnCmdChannels.FirstOrDefault(x => x == obj);
                if (s != State.Inherit)
                {
                    conf.DelMsgOnCmdChannels.Add(obj);
                }
                else
                {
                    if (del != null)
                    {
                        uow._context.Remove(del);
                    }
                }

                await uow.CompleteAsync().ConfigureAwait(false);
            }
            if (s == State.Disable)
            {
                _service.DeleteMessagesOnCommandChannels.AddOrUpdate(chId.Value, false, delegate { return(false); });
                await ReplyConfirmLocalizedAsync("delmsg_channel_off").ConfigureAwait(false);
            }
            else if (s == State.Enable)
            {
                _service.DeleteMessagesOnCommandChannels.AddOrUpdate(chId.Value, true, delegate { return(true); });
                await ReplyConfirmLocalizedAsync("delmsg_channel_on").ConfigureAwait(false);
            }
            else
            {
                _service.DeleteMessagesOnCommandChannels.TryRemove(chId.Value, out var _);
                await ReplyConfirmLocalizedAsync("delmsg_channel_inherit").ConfigureAwait(false);
            }
        }
        public async Task SetDelMsgOnCmdState(ulong guildId, ulong chId, Administration.State s)
        {
            using (var uow = _db.GetDbContext())
            {
                var conf = uow.GuildConfigs.ForId(guildId,
                                                  set => set.Include(x => x.DelMsgOnCmdChannels));

                var obj = new DelMsgOnCmdChannel()
                {
                    ChannelId = chId,
                    State     = s == Administration.State.Enable,
                };
                var del = conf.DelMsgOnCmdChannels.FirstOrDefault(x => x.Equals(obj));
                if (s != Administration.State.Inherit)
                {
                    conf.DelMsgOnCmdChannels.Add(obj);
                }
                else
                {
                    if (del != null)
                    {
                        uow._context.Remove(del);
                    }
                }

                await uow.SaveChangesAsync();
            }

            if (s == Administration.State.Disable)
            {
                DeleteMessagesOnCommandChannels.AddOrUpdate(chId, false, delegate { return(false); });
            }
            else if (s == Administration.State.Enable)
            {
                DeleteMessagesOnCommandChannels.AddOrUpdate(chId, true, delegate { return(true); });
            }
            else
            {
                DeleteMessagesOnCommandChannels.TryRemove(chId, out var _);
            }
        }