Example #1
0
        public async Task AddChannel(ITextChannel channel)
        {
            ulong id      = Check.NotNull(channel).Id;
            bool  success = !_channels.ContainsKey(id);

            if (success)
            {
                _channels[id] = new ChannelLog(channel);
            }
            await _channels[id].Initialize();
        }
Example #2
0
        public async Task <string> SearchDirectory(CommandContext context,
                                                   Func <string, bool> pred,
                                                   string directory)
        {
            if (!Directory.Exists(directory))
            {
                return(string.Empty);
            }
            var guild       = Check.NotNull(context.Guild);
            var guildConfig = Database.GetGuild(guild);
            var res         =
                from file in Directory.EnumerateFiles(directory, "*.*", SearchOption.AllDirectories).AsParallel()
                from line in File.ReadLines(file)
                where pred(line)
                group line by Directory.GetParent(file).Name into g
                orderby g.Key
                select g;

            var builder = new StringBuilder();

            foreach (var re in res)
            {
                if (!re.Any())
                {
                    continue;
                }
                var name = re.Key;
                Log.Info(name);
                ulong id;
                if (ulong.TryParse(name, out id))
                {
                    var channel = await guild.GetChannelAsync(id);

                    if (channel != null)
                    {
                        var config = Database.GetChannel(channel);
                        if (channel.Id != context.Channel.Id && config.SearchIgnored)
                        {
                            continue;
                        }
                        name = channel.Name;
                    }
                }
                builder.AppendLine($"Match results in { name }: ".Bold());
                builder.AppendLine(re.OrderBy(s => s).Join("\n"));
            }
            return(ChannelLog.LogToMessage(builder.ToString()));
        }