{"id":"remhnk","deleted":false,"future_paste":false,"expired":false,"language":"python3","created_at":"2018-02-21 22:34:00","expires_at":null,"content":"import listen\r\nimport discord\r\nfrom discord.ext import commands\r\nimport websockets\r\nimport json\r\nimport time\r\nimport asyncio\r\nb = \"\"\r\n\r\nclass listen:\r\n        \"\"\"Beta. Please don't run yet.\"\"\"\r\n\r\n        def __init__(self, bot):\r\n                self.bot = bot\r\n\r\n        async def whiile(websocket, ctx, timee):\r\n                        time.sleep(timee\/1000)\r\n                        await websocket.send('{ \"op\": 9 }')\r\n                        c = json.loads(await websocket.recv())\r\n                        c = json.loads(await websocket.recv())\r\n                        if c[\"op\"] == 1:\r\n                                await ctx.send(\"Currently playing: \" + c[\"d\"][\"song\"][\"title\"])\r\n\r\n        @commands.command()\r\n        async def listen_moe(self, ctx):\r\n#               if ctx.message.author.voice.is_connected() == True:\r\n#                       await ctx.message.author.voice.disconnect()\r\n                if ctx.message.author.voice == None:\r\n                        await ctx.send(\"I'm only going to play listen.moe if you're there to listen with me. ;-;\")\r\n                else:\r\n                        a = await ctx.message.author.voice.channel.connect()\r\n                        a.play(discord.FFmpegPCMAudio(\"https:\/\/listen.moe\/stream\"))\r\n                        async with websockets.connect(\"wss:\/\/listen.moe\/gateway\") as web:\r\n                                await web.send('{ \"op\": 0, \"d\": {\"auth\": \"\" } }')\r\n                                b = json.loads(await web.recv())\r\n                                c = json.loads(await web.recv())\r\n                                await ctx.send(\"Joined Listen.moe! Currently playing: \" + c[\"d\"][\"song\"][\"title\"])\r\n                                lsock =  listen.whiile(web, ctx, b[\"d\"][\"heartbeat\"])\r\n                                asyncio.get_event_loop().run_until_complete(lsock)\r\n                                asyncio.get_event_loop().run_forever()\r\n        @commands.command()\r\n        async def stop(self, ctx):\r\n                if ctx.voice_client:\r\n                        ctx.voice_client.source.cleanup()\r\n                        await ctx.voice_client.disconnect()\r\n\r\n\r\ndef setup(bot):\r\n        bot.add_cog(listen(bot))"}