Пример #1
0
        internal static async Task Index(string s, SocketMessage e)
        {
            s = s.Replace("\r", "").Replace("\n", "");
            Logger.Log("Indexing " + s);

            var Result = await ResultAsync(s);

            if (Result != null)
            {
                var AllText = File.ReadAllText(SearchFile);
                var Pos     = AllText.IndexOf("\r\n" + s + "\r\n");

                if (Pos == -1)
                {
                    await Waiter.WaitAsync();

                    using (var Open = File.AppendText(SearchFile))
                    {
                        await Open.WriteAsync(s + "\r\n");
                    }
                    Waiter.Release();

                    e.Channel.SendMessageAsync(s + " will now find " + Result?.Title);
                    SpeechEngine.Invalidate();
                }
            }
        }
Пример #2
0
        internal static Task <SpeechEngine> Get(EventHandler <RecognizeCompletedEventArgs> RecognizeCompleted)
        {
            if (!Engines.TryDequeue(out SpeechEngine Engine))
            {
                Engine = new SpeechEngine
                {
                    Service = new SpeechRecognitionEngine(Culture)
                };
            }

            return(Engine.Prepare(RecognizeCompleted));
        }
Пример #3
0
        internal static async Task Deindex(string s, SocketMessage e)
        {
            s = s.Replace("\r", "").Replace("\n", "");

            Logger.Log("Deindexing " + s);
            if (await ResultAsync(s) != null)
            {
                var AllText = File.ReadAllText(SearchFile);
                var Pos     = AllText.IndexOf("\r\n" + s + "\r\n");

                if (Pos != -1)
                {
                    await Waiter.WaitAsync();

                    File.WriteAllText(SearchFile, AllText.Replace("\r\n" + s + "\r\n", "\r\n"));
                    Waiter.Release();

                    e.Channel.SendMessageAsync(s + " has been removed");
                    SpeechEngine.Invalidate();
                }
            }
        }