Author Topic: Knock Knock Joke  (Read 4335 times)

0 Members and 1 Guest are viewing this topic.

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Knock Knock Joke
« on: April 01, 2017, 11:29:34 PM »
Hi Ive Made this command to scrape a joke webpage and return knock knock jokes but i cant figure out how i can pause in middle of joke to say whos there and make it pick a random one, so far i put 2 pauses in but am up for suggestions as im lost on what to do next and yous know alot more than i do?any help appreciated..

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.3.5-->
<command id="270" name="Knock Knock Joke" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>https://www.jokesbykids.com/knock-knock/</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.Replace</cmdType>
    <params>
      <param>&lt;br</param>
      <param><![CDATA[ ]]></param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExReplace</cmdType>
    <params>
      <param>\d</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExReplace</cmdType>
    <params>
      <param>&amp;</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExReplace</cmdType>
    <params>
      <param>#</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExReplace</cmdType>
    <params>
      <param>;</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>&lt;p&gt;(.*?)/&gt;.*?/&gt;(.*?)/&gt;.*?&lt;div\sclass="punch_line"&gt;(.*?)&lt;/div&gt;&lt;/div&gt;</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <params>
      <param>{Match.1.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>VC.Pause</cmdType>
    <params>
      <param>3000</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <params>
      <param>{Match.1.2}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>VC.Pause</cmdType>
    <params>
      <param>3000</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <params>
      <param>{Match.1.3}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>New Joke Please</phrase>
</command>

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Knock Knock Joke
« Reply #1 on: April 02, 2017, 09:02:16 AM »
Hi Matt,

This is a fun one.

If we want to have a "call and response" knock-knock joke, we need to break the joke up. Rather than pausing, we'll ask for the punchline of the joke in a separate command. Here's one way to do it:

Command 1 (We say "knock knock"):

a. Scrape the website.
b. Capture all the jokes on the page using a regular expression.
c. Choose a random match from the jokes and respond aloud with the first part of the joke (the knock knock "name").
d. Add this name and its corresponding punchline to a payload XML file. The name is the phrase and the punchline is stored as the value.
e. Now we rebuild this command group, so that VC will be able to understand us when we say our follow-up knock knock response.

Command 2 (We say "{PF.1} who?")
a. VC just needs to read out {1} -- the punchline.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.3.5-->
<commandGroup open="True" name="Knock knock call and answer" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="291" name="Knock knock" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="60" loop="False" loopDelay="0" loopMax="0" description="Decode.HTML decodes wonky html characters. I save a random &quot;who&quot; name and its matching punchline into a payloadXML. Then we rebuild the command group, otherwise VC won't be able to listen for the new phrase we just added to the payloadXML.">
    <action>
      <cmdType>PayloadXML.Clear</cmdType>
      <params>
        <param>payloads\knockjokes.xml</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Scrape</cmdType>
      <params>
        <param>https://www.jokesbykids.com/knock-knock/page/{Rnd.1.90}/</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Tools.Decode.HTML</cmdType>
      <params>
        <param>{LastResult}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Knock knock ...</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>&lt;p&gt;.*?/&gt;.*?/&gt;(.*?).&lt;.*?&lt;div\sclass="punch_line"&gt;(.*?)&lt;/div&gt;&lt;/div&gt;</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>jokenum</param>
        <param>{Rnd.1.{#m}}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PayloadXML.AddPair</cmdType>
      <params>
        <param>payloads\knockjokes.xml</param>
        <param>{Match.{var.jokenum}.2}</param>
        <param>{Match.{var.jokenum}.1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>{Match.{var.jokenum}.1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.AddText</cmdType>
      <params>
        <param>{Match.{var.jokenum}.1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Group.Rebuild</cmdType>
      <params>
        <param>Knock knock call and answer</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Knock knock</phrase>
  </command>
  <command id="292" name="{1} who?" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>{1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>{1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\knockjokes.xml</payloadFromXML>
    <phrase>who</phrase>
  </command>
</commandGroup>

I added a few other tweaks as well.

1. The page https://www.jokesbykids.com/knock-knock/ only has 6 jokes on it, and unless kids add new jokes to it, these jokes will get stale for us quickly. But there are apparently 96 pages of knock knock jokes.

I changed the URL to this instead:
Code: [Select]
https://www.jokesbykids.com/knock-knock/page/{Rnd.1.90}/
2. You wanted to retrieve a random joke from the page. We need that random number to be the same for both {Match.#.1} and {Match.#.2}. I added an action that stores a random number between 1 and {#M} as a variable. (I called it "jokenum".) Then I use that value in order to choose a random match.

As always, there are different ways to handle the challenge. My approach is one but maybe others will have other suggestions.

Thanks for posting!

« Last Edit: April 02, 2017, 10:19:12 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Re: Knock Knock Joke
« Reply #2 on: April 02, 2017, 10:01:38 AM »
Awesome work as always Naomi and your approach much better, I have been fiddling with this for few days to try do it myself but you perfected it thnxxx and I learn more from you again cheers..  ;)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Knock Knock Joke
« Reply #3 on: April 02, 2017, 10:41:50 AM »
One really common problem that most users face is, any time we want to say something *to* VC, that signals we need a new command.

At the moment, there is no way within a single command to have a back-and-forth discussion. What we say to VC should always act as a trigger that executes a command.

---
Here's a version that provides more call-and-response. The one I posted earlier is simpler to implement, but doesn't properly follow the traditional "knock knock script". The one below does. It also has a bit of extra "chit chat" for fun.

It's a fairly different approach to the one above.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.3.5-->
<groupCollection open="True" name="comedy nest">
  <commandGroup open="True" name="Launch yuks" enabled="True" prefix="" priority="0" requiredProcess="" description="">
    <command id="341" name="Tell me a joke" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="60" loop="False" loopDelay="0" loopMax="0" description="">
      <action>
        <cmdType>PayloadXML.Clear</cmdType>
        <params>
          <param>payloads\knockjokes.xml</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.SpeakSync</cmdType>
        <params>
          <param>Okay|Sure|you bet.|Great idea.|If you like. Here's a good one.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>VC.Pause</cmdType>
        <params>
          <param>300</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>Knock knock</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>Knock knock ...</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Scrape</cmdType>
        <params>
          <param>https://www.jokesbykids.com/knock-knock/page/{Rnd.1.90}/</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Tools.Decode.HTML</cmdType>
        <params>
          <param>{LastResult}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.RegEx</cmdType>
        <params>
          <param>&lt;p&gt;.*?/&gt;.*?\&gt;(.*?)&lt;.*?&lt;div\sclass="punch_line"&gt;(.*?)&lt;/div&gt;&lt;/div&gt;</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.MatchToXML</cmdType>
        <params>
          <param>payloads\knockjokes.xml</param>
          <param>True</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Group.Rebuild</cmdType>
        <params>
          <param>Knock knock call and answer</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Group.Enable</cmdType>
        <params>
          <param>Knock knock call and answer</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <phrase>Tell me a,Tell me another, I changed my mind</phrase>
      <phrase optional="true">joke</phrase>
    </command>
    <command id="97" name="confirmation phrases" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
      <action>
        <cmdType>VC.ConfirmYes</cmdType>
        <params />
        <cmdRepeat>1</cmdRepeat>
      </action>
      <phrase>Yes please, Okay, Sounds good</phrase>
    </command>
  </commandGroup>
  <commandGroup open="True" name="Knock knock call and answer" enabled="False" prefix="" priority="0" requiredProcess="" description="">
    <command id="301" name="Who's there?" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="60" loop="False" loopDelay="0" loopMax="0" description="">
      <action>
        <cmdType>PayloadXML.GetRandomP</cmdType>
        <params>
          <param>payloads\knockjokes.xml</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>{Match.1}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>OSD.AddText</cmdType>
        <params>
          <param>{Match.1}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <phrase>Who's there, Who is there</phrase>
    </command>
    <command id="302" name="{1} who?" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
      <action>
        <cmdType>TTS.SpeakSync</cmdType>
        <params>
          <param>{1}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>{1}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>VC.Pause</cmdType>
        <params>
          <param>300</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>That was hilarious. Do you want to hear another one?|Kids today are such comedians. How about another?|A barrel of laughs that was. Want to hear another?| Would you like to hear another joke?</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>VC.TriggerEvent</cmdType>
        <params>
          <param>more jokes confirmation</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\knockjokes.xml</payloadFromXML>
      <phrase>who</phrase>
    </command>
    <command id="332" name="more jokes confirmation" enabled="true" alwaysOn="False" confirm="True" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
      <action>
        <cmdType>VC.TellVox</cmdType>
        <params>
          <param>Tell me a joke</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <event>more jokes confirmation</event>
    </command>
    <command id="333" name="Disable group on no confirm" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
      <action>
        <cmdType>TTS.SpeakSync</cmdType>
        <params>
          <param>No problem.|OK|That's fine.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>Let me know if you change your mind.|But remember that this comedy club is always open.|I'm here when you're ready for more yuks.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Group.Disable</cmdType>
        <params>
          <param>Knock knock call and answer</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <event>Confirm.Cancel.more jokes confirmation</event>
    </command>
  </commandGroup>
</groupCollection>





« Last Edit: April 03, 2017, 03:33:51 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Knock Knock Joke
« Reply #4 on: April 03, 2017, 09:33:17 AM »
A possible addition to this would be having the ability to either give the thumbs up or thumbs down on the website after hearing a joke.  I haven't looked at how the web page is set up myself, but it might be necessary to redo everything using RoboBrowser instead of just using scrape.

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Re: Knock Knock Joke
« Reply #5 on: April 16, 2017, 09:16:29 AM »
Hey Naiomi Naomi, Love the comedy nest group, ive changed url and pointed it to some adult ones for parties at my house, im into comedy lots, the regex im using works fine to export value and phrase but my regex is also picking up whos there text in some of them, been at it for 3 hours now just thought id ask if you can take a look see what i did wrong this time lol, Otherwise all good ill make do

Heres The Groups For Everyone If want

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.3.5-->
<groupCollection open="False" name="comedy nest2">
  <commandGroup open="False" name="Launch yuks2" enabled="True" prefix="" priority="0" requiredProcess="" description="">
    <command id="374" name="Tell me a joke" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="60" loop="False" loopDelay="0" loopMax="0" description="">
      <action>
        <cmdType>Scrape</cmdType>
        <params>
          <param>http://www.jokes4us.com/knockknockjokes/dirtyknockknockjokes.html</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <if ifBlockDisabled="False" ifNot="False">
        <ifType>LastActionSuccess</ifType>
        <ifParams>&amp;&amp;</ifParams>
        <then>
          <action>
            <cmdType>PayloadXML.Clear</cmdType>
            <params>
              <param>payloads\knockjokes3.xml</param>
            </params>
            <cmdRepeat>1</cmdRepeat>
          </action>
          <action>
            <cmdType>Tools.Decode.HTML</cmdType>
            <params>
              <param>{LastResult}</param>
            </params>
            <cmdRepeat>1</cmdRepeat>
          </action>
          <action>
            <cmdType>Results.RegExReplace</cmdType>
            <params>
              <param>\n&lt;br&gt;</param>
            </params>
            <cmdRepeat>1</cmdRepeat>
          </action>
          <action>
            <cmdType>RegExTool.Open</cmdType>
            <params />
            <cmdRepeat>0</cmdRepeat>
          </action>
          <action>
            <cmdType>Results.RegEx</cmdType>
            <params>
              <param>&lt;br&gt;\n.*?\n(.*?)&lt;br&gt;\n.*?\n(.*?)&lt;br&gt;</param>
            </params>
            <cmdRepeat>1</cmdRepeat>
          </action>
          <action>
            <cmdType>Results.MatchToXML</cmdType>
            <params>
              <param>payloads\knockjokes3.xml</param>
              <param>True</param>
            </params>
            <cmdRepeat>1</cmdRepeat>
          </action>
          <action>
            <cmdType>OSD.ShowText</cmdType>
            <params>
              <param>Knock knock ...</param>
            </params>
            <cmdRepeat>1</cmdRepeat>
          </action>
          <action>
            <cmdType>Group.Rebuild</cmdType>
            <params>
              <param>Knock knock call and answer 3</param>
            </params>
            <cmdRepeat>1</cmdRepeat>
          </action>
          <action>
            <cmdType>Group.Enable</cmdType>
            <params>
              <param>Knock knock call and answer 3</param>
            </params>
            <cmdRepeat>1</cmdRepeat>
          </action>
          <action>
            <cmdType>TTS.Speak</cmdType>
            <params>
              <param>Okay Knock knock|Sure Knock knock|you bet Knock knock.|Great idea Knock knock.|If you like. Here's a good one Knock knock.</param>
            </params>
            <cmdRepeat>1</cmdRepeat>
          </action>
        </then>
        <else>
          <action>
            <cmdType>TTS.Speak</cmdType>
            <params>
              <param>Sorry i cant right now try later</param>
            </params>
            <cmdRepeat>1</cmdRepeat>
          </action>
        </else>
      </if>
      <phrase>Tell me a,Tell me another, I changed my mind</phrase>
      <phrase optional="true">joke</phrase>
    </command>
    <command id="102" name="confirmation phrases" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
      <action>
        <cmdType>VC.ConfirmYes</cmdType>
        <params />
        <cmdRepeat>1</cmdRepeat>
      </action>
      <phrase>Yes please, Okay, Sounds good</phrase>
    </command>
  </commandGroup>
  <commandGroup open="True" name="Knock knock call and answer 3" enabled="False" prefix="" priority="0" requiredProcess="" description="">
    <command id="309" name="Who's there?" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="60" loop="False" loopDelay="0" loopMax="0" description="">
      <action>
        <cmdType>PayloadXML.GetRandomP</cmdType>
        <params>
          <param>payloads\knockjokes.xml</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>{Match.1}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>OSD.AddText</cmdType>
        <params>
          <param>{Match.1}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <phrase>Who's there, Who is there</phrase>
    </command>
    <command id="307" name="{1} who?" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
      <action>
        <cmdType>TTS.SpeakSync</cmdType>
        <params>
          <param>{1}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>{1}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>VC.Pause</cmdType>
        <params>
          <param>3000</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>That was hilarious. Do you want to hear another one?|Kids today are such comedians. How about another?|A barrel of laughs that was. Want to hear another?| Would you like to hear another joke?</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>VC.TriggerEvent</cmdType>
        <params>
          <param>more jokes confirmation</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\knockjokes3.xml</payloadFromXML>
      <phrase>who</phrase>
    </command>
    <command id="337" name="more jokes confirmation" enabled="true" alwaysOn="False" confirm="True" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
      <action>
        <cmdType>VC.TellVox</cmdType>
        <params>
          <param>Tell me a joke</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <event>more jokes confirmation</event>
    </command>
    <command id="393" name="Disable group on no confirm" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
      <action>
        <cmdType>TTS.SpeakSync</cmdType>
        <params>
          <param>No problem.|OK|That's fine.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>Let me know if you change your mind.|But remember that this comedy club is always open.|I'm here when you're ready for more yuks.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Group.Disable</cmdType>
        <params>
          <param>Knock knock call and answer 2</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <event>Confirm.Cancel.more jokes confirmation</event>
    </command>
  </commandGroup>
</groupCollection>



Thnxxx alot and i am learning still just stumped at this part
« Last Edit: April 16, 2017, 12:05:02 PM by nime5ter »

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Re: Knock Knock Joke
« Reply #6 on: April 16, 2017, 09:49:31 AM »
I just figured out whats happening, its capturing every 2 lines of knock knock joke in my pattern but i just found 1 thats 3 lines,when it gets to that one it starts capturing different after that, thats why my payload comes out little bit wrong i think :bonk

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Knock Knock Joke
« Reply #7 on: April 16, 2017, 09:54:24 AM »
OK then. Good luck. Glad you're having fun with it.

Since knock knock jokes have a natural pattern, it would probably be safer/cleaner to use part of the text pattern in your regular expression, rather than relying on patterns of breaks and new lines.

Naomi
« Last Edit: April 16, 2017, 12:05:21 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Knock Knock Joke
« Reply #8 on: April 16, 2017, 06:10:05 PM »
James just mentioned to me that he thinks I misunderstood your last post. I thought you were saying that you figured out how to fix your regular expression. He interpreted your follow-up message differently.

In case I misunderstood you, here's what I would probably do. In this case, I would recommend something like:

a) use Results.RegExSingle instead of Results.RegEx.

RegExSingle allows us to match patterns across multiple lines. Then  you can get rid of the Results.RegExReplace action.

b) use the fact that each Knock knock joke will include the question "who's there?" in it. You can look for the proper patterns that occur after the question "Who's there?" is posed.

This will not work 100% perfectly every time because people posting the jokes are making a lot of spelling mistakes and occasionally they don't follow the standard pattern (as you mentioned above), but it will work for most of the entries.
Try:
Code: [Select]
Results.RegexSingle --> Who.*?s.*?there.*?>(.*?)<.*?<br>(.*?)<
I tried to be a bit flexible in matching the phrase "Who's there" because I can see on the webpage that a lot of people are spelling it wrong.
« Last Edit: April 16, 2017, 06:16:04 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Re: Knock Knock Joke
« Reply #9 on: April 22, 2017, 02:45:02 AM »
Hi sorry late reply been going through some stuff,  Awesome work thnxxxxx alot

outlaw

  • Jr. Member
  • **
  • Posts: 21
  • Karma: -1
    • View Profile
Re: Knock Knock Joke
« Reply #10 on: April 15, 2021, 06:05:17 PM »
Hi, I tried to post a new topic but for some reason it wouldn't post it.
I'm trying to get VC version 2.3.1.1 to do the knock knock jokes, it does fine until after it says the punchline
than it reads off a hole bunch of junk and locks up. Thanks for your time
 
« Last Edit: April 15, 2021, 06:16:56 PM by outlaw »

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Re: Knock Knock Joke
« Reply #11 on: April 16, 2021, 01:35:27 AM »
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.3.0.8-->
<command id="369" name="Tell me a Kids joke" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="60" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>https://www.jokesbykids.com/knock-knock/page/{Rnd.1.100}/</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>LastActionSuccess</ifType>
    <ifParams>&amp;&amp;</ifParams>
    <then>
      <action>
        <cmdType>PayloadXML.Clear</cmdType>
        <params>
          <param>payloads\knockjokes.xml</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Tools.Decode.HTML</cmdType>
        <params>
          <param>{LastResult}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.RegExSingle</cmdType>
        <params>
          <param>&lt;p&gt;.*?/&gt;.*?\&gt;(.*?)&lt;.*?&lt;div\sclass="punch_line"&gt;(.*?)&lt;/div&gt;</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.MatchToXML</cmdType>
        <params>
          <param>payloads\knockjokes.xml</param>
          <param>True</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>Knock knock ...</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Group.Rebuild</cmdType>
        <params>
          <param>Knock knock call and answer </param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Group.Enable</cmdType>
        <params>
          <param>Knock knock call and answer </param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>Okay Knock knock|Sure Knock knock|you bet Knock knock.|Great idea Knock knock.|If you like. Here's a good one Knock knock.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <params>
          <param>Sorry i cant right now try later</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <phrase>Tell me a kids joke</phrase>
</command>

Hi Outlaw, This command works for me, I Use RegExSingle Instead Of Regex, Hope It Helps.