示例#1
0
        public async Task ProcessChainAsync(SocketCommandContext context)
        {
            await Semaphore.WaitAsync().ConfigureAwait(false);

            try
            {
                var author  = context.Message.Author;
                var content = context.Message.Content;
                var channel = context.Channel;

                if (!LastMessages.ContainsKey(channel.Id))
                {
                    LastMessages.Add(channel.Id, new List <Tuple <ulong, string> >(ReactLimit));
                }

                if (!IsValidMessage(context))
                {
                    await CleanupAsync(channel).ConfigureAwait(false);

                    return;
                }

                if (!LastMessages[channel.Id].Any(o => o.Item1 == author.Id))
                {
                    LastMessages[channel.Id].Add(new Tuple <ulong, string>(author.Id, content));
                }

                await TryReactAsync(channel).ConfigureAwait(false);
            }
            finally
            {
                Semaphore.Release();
            }
        }
示例#2
0
 public void AddMessage(string message)
 {
     if (LastMessages.Count > 200)
     {
         LastMessages.Dequeue();
     }
     LastMessages.Enqueue(message);
 }
示例#3
0
        public void CleanupNoLockAsync(SocketGuildChannel channel)
        {
            var key = GetKey(channel);

            if (LastMessages.ContainsKey(key))
            {
                LastMessages[key].Clear();
            }
        }
示例#4
0
        public async Task CleanupAsync(ISocketMessageChannel channel, bool @lock = false)
        {
            if (@lock)
            {
                await Semaphore.WaitAsync().ConfigureAwait(false);
            }

            try
            {
                if (!LastMessages.ContainsKey(channel.Id))
                {
                    return;
                }
                LastMessages[channel.Id].Clear();
            }
            finally
            {
                if (@lock)
                {
                    Semaphore.Release();
                }
            }
        }
示例#5
0
        public async Task ProcessChainAsync(SocketCommandContext context)
        {
            if (context.Channel is not SocketTextChannel channel || ReactLimit == -1)
            {
                return;
            }

            var author  = context.Message.Author;
            var content = context.Message.Content;
            var key     = GetKey(channel);

            if (!LastMessages.ContainsKey(key))
            {
                LastMessages.Add(key, new List <Tuple <ulong, string> >(ReactLimit));
            }

            if (!IsValidMessage(context.Message, context.Guild, channel))
            {
                CleanupNoLockAsync(channel);
                return;
            }

            var group = LastMessages[key];

            if (!group.Any(o => o.Item1 == author.Id))
            {
                group.Add(new Tuple <ulong, string>(author.Id, content));
            }

            if (group.Count == ReactLimit)
            {
                await channel.SendMessageAsync(group[0].Item2);

                CleanupNoLockAsync(channel);
            }
        }
 public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel)
 {
     LastMessages.Add(message);
 }
 public void Write(string message, LogLevel logLevel)
 {
     LastMessages.Add(message);
 }
 public void Write(Exception exception, string message, LogLevel logLevel) => LastMessages.Add(message);