Beispiel #1
0
        public LinkInfoPlugin(IConnectionManager connMgr, JObject config)
        {
            ConnectionManager = connMgr;
            Config            = new LinkInfoConfig(config);
            IDNMapping        = new IdnMapping();
            Plugins           = new List <ILinkResolverPlugin>();

            LastLinkAndInfo = null;
            LinkDetector    = null;

            ConnectionManager.ChannelMessage         += HandleChannelMessage;
            ConnectionManager.OutgoingChannelMessage += HandleOutgoingChannelMessage;
            ConnectionManager.SplitToChunks          += HandleSplitToChunks;

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("ll", "lastlink"),
                    CommandUtil.NoOptions,
                    CommandUtil.NoArguments,
                    CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleLastLinkCommand
                );

            RepopulatePluginList();
        }
Beispiel #2
0
        protected virtual void PostConfigReload()
        {
            // recreate heuristic link detector at next use
            LinkDetector = null;

            RepopulatePluginList();
        }
Beispiel #3
0
        protected bool TryCreateUriHeuristically(string word, out Uri uri)
        {
            uri = null;
            if (LinkDetector == null)
            {
                if (Config.TLDListFile == null)
                {
                    return(false);
                }

                string tldListFilePath = Path.Combine(SharpIrcBotUtil.AppDirectory, Config.TLDListFile);
                if (!File.Exists(tldListFilePath))
                {
                    return(false);
                }

                var tlds = new HashSet <string>();
                using (var readStream = File.Open(tldListFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var reader = new StreamReader(readStream, StringUtil.Utf8NoBom))
                    {
                        string line;
                        while ((line = reader.ReadLine()?.Trim()) != null)
                        {
                            if (line.StartsWith("#"))
                            {
                                continue;
                            }
                            tlds.Add(line.ToLowerInvariant());
                        }
                    }

                LinkDetector = new HeuristicLinkDetector(tlds);
            }

            return(LinkDetector.TryCreateUri(word, out uri));
        }