예제 #1
0
            private static async Task <bool> SetGreetDm(ulong guildId, bool?value = null)
            {
                bool enabled;

                using (var uow = DbHandler.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
            private static async Task <bool> SetBye(ulong guildId, ulong channelId, bool?value = null)
            {
                bool enabled;

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

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

                    await uow.CompleteAsync();
                }
                return(enabled);
            }
예제 #3
0
            private static async Task SetByeDel(ulong guildId, int timer)
            {
                if (timer < 0 || timer > 600)
                {
                    return;
                }

                using (var uow = DbHandler.UnitOfWork())
                {
                    var conf = uow.GuildConfigs.For(guildId, set => set);
                    conf.AutoDeleteByeMessagesTimer = timer;

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

                    await uow.CompleteAsync().ConfigureAwait(false);
                }
            }
예제 #4
0
            private static GreetSettings GetOrAddSettingsForGuild(ulong guildId)
            {
                GreetSettings settings;

                guildConfigsCache.TryGetValue(guildId, out settings);

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

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

                guildConfigsCache.TryAdd(guildId, settings);
                return(settings);
            }
예제 #5
0
            public static bool SetByeMessage(ulong guildId, ref string message)
            {
                message = message?.SanitizeMentions();

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

                bool byeMsgEnabled;

                using (var uow = DbHandler.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);
            }
예제 #6
0
            static ServerGreetCommands()
            {
                NadekoBot.Client.UserJoined += UserJoined;
                NadekoBot.Client.UserLeft   += UserLeft;
                _log = LogManager.GetCurrentClassLogger();

                GuildConfigsCache = new ConcurrentDictionary <ulong, GreetSettings>(NadekoBot.AllGuildConfigs.ToDictionary(g => g.GuildId, (g) => GreetSettings.Create(g)));
            }