public async Task RunBotAsync() { _client = new DiscordSocketClient(); _commands = new CommandService(); var comModule = new Coms(_userNick); _mmiComms = comModule.GetMmic(); _service = new ServiceCollection() .AddSingleton(_client) .AddSingleton(_commands) .BuildServiceProvider(); _tts = new Tts(comModule); _speechTemplates = new SpeechTemplates(); _client.Log += Log; await RegisterCommandsAsync(); _mmiComms.Message += MmiC_Message; // subscribe to the messages that come from the comMudole _mmiComms.Start(); await _client.LoginAsync(TokenType.Bot, _botToken); await _client.StartAsync(); _tts.Speak("Olá eu sou o wally, o teu bot do Discord! Se desejares podes-me perguntar o que é que eu sou capaz de fazer e que comandos estão disponíveis. So tenho um requisito, diz o meu nome antes de qualquer comando."); Thread.Sleep(2000); comModule.SendGuildInfo(_client.Guilds); await Task.Delay(-1); }
/// <summary> /// Announce the time if the current time is secBetweenAnnouncements or greater from the last time announced. /// To count down from 10 seconds, secBetweenAnnouncements = 1 and the sequence passed to AnnounceIfDelta would be 10, 9, 8...j /// To count up, secBetweenAnnouncements = 1 and the currentSec sequence would be 1, 2, ... /// AnnounceIfDelta will return after the announcement has been spoken. /// </summary> /// <param name="currentSec"> The current time. Time can be increasing or decreasing.</param> public void AnnounceIfTime(int currentSec) { // If haven't spoken the time yet or if it's time for the next announcement... if ((lastSpokenTime.HasValue == false) || ((Math.Abs(currentSec - lastSpokenTime.Value) / speechGap) >= 1.0)) { lastSpokenTime = currentSec; // Format the #seconds into the text for the words that will be spoken. string announcement = FormatMinSec(currentSec); tts.Speak(announcement); } }
private async Task AnnouceUserJoined(SocketGuildUser user) { _tts.Speak(_speechTemplates.GetGreeting(user.Username, user.Guild.Name)); }
private void SpeechRecognized2(object sender, SpeechRecognizedEventArgs e) { //gets recognized text string text = e.Result.Text; string tagCmd = e.Result.Semantics["action"].Value != null ? e.Result.Semantics["action"].Value.ToString() : ""; string tagObj = e.Result.Semantics["object"].Value != null ? e.Result.Semantics["object"].Value.ToString() : ""; double confid = e.Result.Confidence; //actualizar comando a executar if (state != 1) { if (isCommandValid(tagCmd, tagObj)) { command = tagCmd; } else { command = ""; } } if (confid < 0.33) { if (state != 1) { state = 0; } t.Speak("Não percebi, diz outra vez."); Console.WriteLine("Não percebi, diz outra vez."); } else if (confid >= 0.34 && confid < 0.66) { t.Speak("Tem a certeza que quer executar o comando " + text + "?"); Console.WriteLine("Tem a certeza que quer executar o comando " + text + "?"); state = 1; } else { if (state != 1) { state = 2; } } if (state == 2) { if (PostureVerify.getPosture() && (command == "volumeUp" || command == "volumeDown")) { execMethod(command, tagObj); PostureVerify.setPosture(false); } else { if (command != "volumeUp" && command != "volumeDown") { execMethod(command, tagObj); } PostureVerify.setPosture(false); } } else if (state == 1 && confid > 0.66) { if (text == "sim") { state = 3; if (PostureVerify.getPosture() && (command == "volumeUp" || command == "volumeDown")) { execMethod(command, tagObj); PostureVerify.setPosture(false); } else { if (command != "volumeUp" && command != "volumeDown") { execMethod(command, tagObj); } PostureVerify.setPosture(false); } } else if (text == "não") { t.Speak("Então volta a repetir o comando por favor."); state = 3; } } Console.WriteLine("Comando: " + text); }