import discord
import asyncio
from twitch.api import v3 as twitch
from twitch.exceptions import ResourceUnavailableException
from random import randint
import argparse
import requests
import json



client = discord.Client()


async def my_background_task():
    await client.wait_until_ready()
    channel = discord.Object(id='292869746293211146')
    while not client.is_closed:
        streamer_html = requests.get('https://api.twitch.tv/kraken/streams/sing_sing?client_id=vpmzqjo3ab8dyeslvz2ia3r3yehif3').json()
        print(streamer_html)
        streamer = json.loads(json.dumps(streamer_html))
        stream_data  = streamer['stream']
        if(stream_data == None):
            reply_message = 'Master Sing is offline'
        else:
            reply_message = 'Master Sing is live'
        print(reply_message)
        await client.change_presence(game=discord.Game(name=reply_message))
        await asyncio.sleep(60) # task runs every 60 seconds

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')

@client.event
async def on_message(message):
    if message.author != 'BEANBot#8947':
        if message.content.startswith('!info'):
            streamer_html = requests.get('https://api.twitch.tv/kraken/streams/sing_sing?client_id=vpmzqjo3ab8dyeslvz2ia3r3yehif3').json()
            print(streamer_html)
            streamer = json.loads(json.dumps(streamer_html))
            stream_data  = streamer['stream']
            if(stream_data == None):
                reply_message = 'Master Sing is offline. FeelsBadMan'
            else:
                reply_message = 'Master Sing is live - http://www.twitch.tv/sing_sing ' + str(stream_data)
            await client.send_message(message.channel, reply_message)

            
        elif message.content.startswith('!mymmr'):
            mmr = randint(0,9999)
            reply_message = 'Hey ' + str(message.author).split('#', 1)[0]
            reply_message = reply_message + ', your MMR is ' + str(mmr)
            if  mmr > 5999:
                reply_message = reply_message + ' PogChamp'
            else:
                reply_message = reply_message + ' LUL'
            await client.send_message(message.channel, reply_message)

            
        elif message.content.startswith('!mydong'):
            mmr = randint(0,25)
            reply_message = 'Hey ' + str(message.author).split('#', 1)[0]
            reply_message = reply_message + ', your dong hangs '
            reply_message = reply_message + str(mmr)
            reply_message = reply_message + ' cms low Jebaited'
            await client.send_message(message.channel, reply_message)

            
        elif message.content.startswith('!bean'):
            await client.send_message(message.channel, "http://i0.kym-cdn.com/photos/images/facebook/001/166/993/284.png")
        
        
client.loop.create_task(my_background_task())

client.run('Mjk2NzI2MjExODE0NjIxMTg2.C72dJw.qgiXa_FvhGX9DY-8pK3ZbzV1FwY')

@@ -374,16 +374,173 @@
 closed:%0A
+        headers = %7B'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'%7D%0A
         
@@ -661,44 +661,32 @@
 if3'
-).json()%0A        print(streamer_html
+, headers=headers).json(
 )%0A  
@@ -936,37 +936,8 @@
 ve'%0A
-        print(reply_message)%0A
     
@@ -1038,16 +1038,17 @@
 sleep(60
+0
 ) # task
@@ -1338,24 +1338,185 @@
 h('!info'):%0A
+            headers = %7B'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'%7D%0A
             
@@ -1637,48 +1637,32 @@
 if3'
-).json()%0A            print(streamer_html
+, headers=headers).json(
 )%0A  
@@ -1883,32 +1883,32 @@
           else:%0A
-
                 
@@ -1998,16 +1998,53 @@
 m_data)%0A
+                print(reply_message)%0A
         

fix again?