Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "True\n",
- "type: pubmsg, source: randallatamazon!randallatamazon@randallatamazon.tmi.twitch.tv, target: #aws, arguments: [u'hello this is an example message'], tags: []\n"
- ]
- },
- {
- "ename": "KeyboardInterrupt",
- "evalue": "",
- "output_type": "error",
- "traceback": [
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
- "\u001b[0;32m<ipython-input-2-02d00fe97ae9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[0mserver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'#aws'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 27\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0mserver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_connected\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 28\u001b[0;31m \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess_forever\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
- "\u001b[0;32m/usr/local/lib/python2.7/site-packages/irc/client.pyc\u001b[0m in \u001b[0;36mprocess_forever\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 269\u001b[0m \u001b[0mlog\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdebug\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"process_forever(timeout=%s)\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 270\u001b[0m \u001b[0mone\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunctools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpartial\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess_once\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 271\u001b[0;31m \u001b[0mconsume\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minfinite_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 272\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 273\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mdisconnect_all\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmessage\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;32m/usr/local/lib/python2.7/site-packages/more_itertools/recipes.pyc\u001b[0m in \u001b[0;36mconsume\u001b[0;34m(iterator, n)\u001b[0m\n\u001b[1;32m 132\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mn\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 133\u001b[0m \u001b[0;31m# feed the entire iterator into a zero-length deque\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 134\u001b[0;31m \u001b[0mdeque\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmaxlen\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 135\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 136\u001b[0m \u001b[0;31m# advance to the empty slice starting at position n\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;32m/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/jaraco/itertools.pyc\u001b[0m in \u001b[0;36m<genexpr>\u001b[0;34m((_,))\u001b[0m\n\u001b[1;32m 384\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 385\u001b[0m \t\"\"\"\n\u001b[0;32m--> 386\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0m_\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mitertools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrepeat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 387\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 388\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;32m/usr/local/lib/python2.7/site-packages/irc/client.pyc\u001b[0m in \u001b[0;36mprocess_once\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 249\u001b[0m \u001b[0msockets\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msockets\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 250\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0msockets\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 251\u001b[0;31m \u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mo\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mselect\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mselect\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msockets\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 252\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 253\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
- ]
- }
- ],
- "source": [
- "import os\n",
- "import boto3\n",
- "import pyaudio\n",
- "import irc.client\n",
- "import irc.events\n",
- "polly = boto3.client('polly')\n",
- "p = pyaudio.PyAudio()\n",
- "\n",
- "def chat_handler(connection, event):\n",
- " print event\n",
- " if 'randallatamazon' in event.source:\n",
- " voice = 'Brian'\n",
- " else:\n",
- " voice = 'Justin'\n",
- " text = event.arguments[0]\n",
- " resp = polly.synthesize_speech(Text=text, TextType=\"text\", OutputFormat=\"pcm\", VoiceId=voice)\n",
- " stream = p.open(format=p.get_format_from_width(width=2), channels=1, rate=16000, output=True)\n",
- " stream.write(resp['AudioStream'].read())\n",
- " stream.stop_stream()\n",
- " stream.close()\n",
- "\n",
- "client = irc.client.Reactor()\n",
- "client.add_global_handler('pubmsg', chat_handler)\n",
- "server = client.server()\n",
- "server.connect(\"irc.chat.twitch.tv\", 6667, \"justinfan123\")\n",
- "server.join('#aws')\n",
- "print server.is_connected()\n",
- "client.process_forever()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "import os\n",
- "os.getenv('twitch_pass')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "help(irc.events.all)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- " buf = StringIO.StringIO()\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "True\n",
- "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotStoreColor', u'responseCard': None, u'message': u'I stored color blue for user randallatamazon', u'slots': {u'color': u'blue'}, u'sessionAttributes': {}}\n",
- "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotStoreColor', u'responseCard': None, u'message': u'I stored color kappa for user mjewl', u'slots': {u'color': u'kappa'}, u'sessionAttributes': {}}\n",
- "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotGetColor', u'responseCard': None, u'message': u\"randallatamazon's favorite color is blue\", u'slots': {}, u'sessionAttributes': {}}\n",
- "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotGetColor', u'responseCard': None, u'message': u\"yyyolk doesn't have a favorite color yet\", u'slots': {}, u'sessionAttributes': {}}\n",
- "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotGetColor', u'responseCard': None, u'message': u\"mjewl's favorite color is kappa\", u'slots': {}, u'sessionAttributes': {}}\n",
- "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotStoreColor', u'responseCard': None, u'message': u'I stored color green for user restlessnarwhal', u'slots': {u'color': u'green'}, u'sessionAttributes': {}}\n",
- "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotStoreColor', u'responseCard': None, u'message': u'I stored color yellow for user triangle_soup', u'slots': {u'color': u'yellow'}, u'sessionAttributes': {}}\n",
- "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotGetColor', u'responseCard': None, u'message': u\"restlessnarwhal's favorite color is green\", u'slots': {}, u'sessionAttributes': {}}\n",
- "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotStoreColor', u'responseCard': None, u'message': u'I stored color yellow for user yyyolk', u'slots': {u'color': u'yellow'}, u'sessionAttributes': {}}\n",
- "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotGetColor', u'responseCard': None, u'message': u\"triangle_soup's favorite color is yellow\", u'slots': {}, u'sessionAttributes': {}}\n",
- "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotStoreColor', u'responseCard': None, u'message': u'I stored color now green for user yyyolk', u'slots': {u'color': u'now green'}, u'sessionAttributes': {}}\n"
- ]
- },
- {
- "ename": "KeyboardInterrupt",
- "evalue": "",
- "output_type": "error",
- "traceback": [
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
- "\u001b[0;32m<ipython-input-7-b16ba2068e96>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0mserver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_connected\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[0mserver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprivmsg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'#aws'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"HELLO, WORLD!\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 36\u001b[0;31m \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess_forever\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
- "\u001b[0;32m/usr/local/lib/python2.7/site-packages/irc/client.pyc\u001b[0m in \u001b[0;36mprocess_forever\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 269\u001b[0m \u001b[0mlog\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdebug\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"process_forever(timeout=%s)\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 270\u001b[0m \u001b[0mone\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunctools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpartial\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess_once\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 271\u001b[0;31m \u001b[0mconsume\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minfinite_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 272\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 273\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mdisconnect_all\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmessage\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;32m/usr/local/lib/python2.7/site-packages/more_itertools/recipes.pyc\u001b[0m in \u001b[0;36mconsume\u001b[0;34m(iterator, n)\u001b[0m\n\u001b[1;32m 132\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mn\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 133\u001b[0m \u001b[0;31m# feed the entire iterator into a zero-length deque\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 134\u001b[0;31m \u001b[0mdeque\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmaxlen\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 135\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 136\u001b[0m \u001b[0;31m# advance to the empty slice starting at position n\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;32m/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/jaraco/itertools.pyc\u001b[0m in \u001b[0;36m<genexpr>\u001b[0;34m((_,))\u001b[0m\n\u001b[1;32m 384\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 385\u001b[0m \t\"\"\"\n\u001b[0;32m--> 386\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0m_\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mitertools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrepeat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 387\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 388\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;32m/usr/local/lib/python2.7/site-packages/irc/client.pyc\u001b[0m in \u001b[0;36mprocess_once\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 249\u001b[0m \u001b[0msockets\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msockets\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 250\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0msockets\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 251\u001b[0;31m \u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mo\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mselect\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mselect\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msockets\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 252\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 253\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
- ]
- }
- ],
- "source": [
- "import os\n",
- "import boto3\n",
- "import pyaudio\n",
- "import irc.client\n",
- "import irc.events\n",
- "from babylex import LexSession\n",
- "polly = boto3.client('polly')\n",
- "p = pyaudio.PyAudio()\n",
- "\n",
- "sessions = dict()\n",
- "\n",
- "def chat_handler(connection, event):\n",
- " message = event.arguments[0].split(\":\", 1)\n",
- " if len(message) > 1 and message[0].lower() == connection.get_nickname().lower():\n",
- " user = event.source.split('!')[0]\n",
- " if user not in sessions:\n",
- " sessions[user] = LexSession(\"TwitchChatBot\", \"$LATEST\", user)\n",
- " session = sessions[user]\n",
- " resp = session.text(message[1])\n",
- " print resp\n",
- " connection.privmsg(event.target, resp['message'])\n",
- "\n",
- "client = irc.client.Reactor()\n",
- "client.add_global_handler('pubmsg', chat_handler)\n",
- "server = client.server()\n",
- "server.connect(\"irc.chat.twitch.tv\", 6667, \"awslexbot\", password=os.getenv('twitch_pass'))\n",
- "server.join('#aws')\n",
- "print server.is_connected()\n",
- "server.privmsg('#aws', \"HELLO, WORLD!\")\n",
- "client.process_forever()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "True\n",
- "<Response [200]>\n",
- "<Response [200]>\n",
- "<Response [200]>\n",
- "<Response [200]>\n",
- "<Response [200]>\n",
- "<Response [200]>\n",
- "<Response [200]>\n",
- "<Response [200]>\n",
- "<Response [200]>\n"
- ]
- }
- ],
- "source": [
- "import os\n",
- "import boto3\n",
- "import pyaudio\n",
- "import irc.client\n",
- "import irc.events\n",
- "from babylex import LexSession\n",
- "polly = boto3.client('polly')\n",
- "p = pyaudio.PyAudio()\n",
- "\n",
- "sessions = dict()\n",
- "\n",
- "def chat_handler(connection, event):\n",
- " message = event.arguments[0].split(\":\", 1)\n",
- " if len(message) > 1 and message[0].lower() == connection.get_nickname().lower():\n",
- " user = event.source.split('!')[0]\n",
- " if user not in sessions:\n",
- " sessions[user] = LexSession(\"TwitchChatBot\", \"$LATEST\", user)\n",
- " session = sessions[user]\n",
- " resp = session.content(message[1], \"text/plain; charset=utf-8\", \"audio/pcm\")\n",
- " stream = p.open(format=p.get_format_from_width(width=2), channels=1, rate=16000, output=True)\n",
- " stream.write(resp.content)\n",
- " stream.stop_stream()\n",
- " stream.close()\n",
- " connection.privmsg(event.target, resp.headers['x-amz-lex-message'])\n",
- "\n",
- "client = irc.client.Reactor()\n",
- "client.add_global_handler('pubmsg', chat_handler)\n",
- "server = client.server()\n",
- "server.connect(\"irc.chat.twitch.tv\", 6667, \"awslexbot\", password=os.getenv('twitch_pass'))\n",
- "server.join('#aws')\n",
- "print server.is_connected()\n",
- "server.privmsg('#aws', \"HELLO, WORLD!\")\n",
- "client.process_forever()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 2",
- "language": "python",
- "name": "python2"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 2
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython2",
- "version": "2.7.13"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement