Exemple #1
0
async def status_changer():
    cshtype = 1
    url = 'https://cricket.yahoo.net/sifeeds/multisport/?methodtype=3&client=24&sport=1&league=0&timezone=0530&language=en&gamestate='+str(cshtype)
    sh = cb.schedule(40, cb.fetch(url))
    t,preid,ie = '', '', True
    for i in sh:
        if 'India' in i[4]:
            preid = i[9]
            break
    if preid == '':
        try:
            preid = sh[0][9]
        except IndexError:
            preid = 'abcd'
            ie=False
    url = 'https://cricket.yahoo.net/sifeeds/cricket/live/json/' + preid + '.json'
    data = cb.fetch(url)
    c=0
    while ie:
        try: 
            s=cb.miniscore(c,data)
            c+=1
        except IndexError:break
        except KeyError: 
            s='No live matches currently'
            break
    try:
        if ie==False:
            raise IndexError
        score = '{0}-{1} ({2})'.format(s[4], s[5], s[6])
        t = '{0} vs {1}'.format(s[7], s[8])
        string = '{0} | {1}'.format(t, score)
    except IndexError: string = 'No matches live currently.'
    await bot.change_presence(activity=discord.Game(name=string))
Exemple #2
0
def leaderboard_embed(mf, dtype, count):
    data=cb.fetch(cb.urlprov('', 2, '', 0, mf, dtype))
    rawlb=cb.leaderboard(data, count)[-10:]
    embed = discord.Embed(title='Leaderboard [{0}] [{1}]'.format(mf,dtype), color=0x03f8fc)
    for i in rawlb:
        embed.add_field(name='{0}. {1} Team: {2} Point: {3}'.format(i[0],i[1],i[2],i[3]), value='+'+i[4], inline=False)
    return embed
Exemple #3
0
async def powerplay(ctx, match_index: int):
    channel_id = ctx.message.channel.id    
    global ids_con, curr_teams
    m_id = ids_con[channel_id][match_index]
    raw_data = cb.fetch(cb.urlprov(m_id, 0, '', 0, '', ''))
    message = await ctx.send(embed=powerplay_embed_f(raw_data, match_index))
    await message.add_reaction(num_emojis[1])
    await message.add_reaction(num_emojis[2])
Exemple #4
0
async def partnership_current(ctx, match_index: int):
    channel_id = ctx.message.channel.id
    global ids_con, curr_teams
    m_id = ids_con[channel_id][match_index]
    url = cb.urlprov(m_id, 0, '', 0, '', '')
    raw_data = cb.fetch(url)
    message=await ctx.send(embed=pshipc_embed_f(match_index, raw_data))
    await message.add_reaction(num_emojis[1])
    await message.add_reaction(num_emojis[2])
Exemple #5
0
async def schedule(ctx, shtype='live'):
    channel_id = ctx.message.channel.id
    cshtype = {'ended': 4, 'upcoming': 2, 'live': 1, 'all': 3}[shtype]
    url = 'https://cricket.yahoo.net/sifeeds/multisport/?methodtype=3&client=24&sport=1&league=0&timezone=0530&language=en&gamestate='+str(cshtype)
    e=schedule_embed(5, cb.fetch(url), channel_id)
    e.set_footer(text='sessionid:SCD-{0}-{1}'.format(str(cshtype), str(5)))
    message=await ctx.send(embed=e)
    await message.add_reaction(arrows_emojis[0])
    await message.add_reaction(arrows_emojis[1])
Exemple #6
0
async def shots(ctx, match_index: int):
    channel_id = ctx.message.channel.id    
    global ids_con, curr_teams
    m_id = ids_con[channel_id][match_index]
    raw_data = cb.fetch(cb.urlprov(m_id, 0, '', 0, '', ''))
    e=shotsfig_embed_f(raw_data)
    e.set_footer(text='sessionid:SFG-{0}-{1}'.format(match_index, str(1)))
    message = await ctx.send(embed=e)
    await message.add_reaction(num_emojis[1])
    await message.add_reaction(num_emojis[2])
Exemple #7
0
async def againstcard(ctx, match_index: int):
    channel_id = ctx.message.channel.id    
    global ids_con, curr_teams
    m_id = ids_con[channel_id][match_index]
    url = cb.urlprov(m_id, 0, '', 0, '', '')
    raw_data = cb.fetch(url)
    e=player_againstcard_embed_f(raw_data, 0)
    e.set_footer(text='sessionid:PAC-{0}'.format(match_index))
    message=await ctx.send(embed=e)
    await message.add_reaction(num_emojis[1])
    await message.add_reaction(num_emojis[2])
Exemple #8
0
async def fantasy_insight(ctx, match_index: int):
    channel_id = ctx.message.channel.id
    global ids_con
    m_id = ids_con[channel_id][match_index]
    url='https://cricket.yahoo.net/sifeeds/cricket/live/json/{}_fantasy_picks.json'.format(m_id)
    raw_data = cb.fetch(url)
    c=fantasy_insight_embed(raw_data, 'd11')
    embed=c[1]
    embed.set_footer(text='sessionid:FI-{0}-{1}'.format(str(match_index), 'd11'))
    message=await ctx.message.channel.send(file=c[0], embed=embed)
    await message.add_reaction(num_emojis[1])
    await message.add_reaction(num_emojis[2])
Exemple #9
0
async def score(ctx, match_index: int):
    channel_id = ctx.message.channel.id
    global ids_con
    m_id = ids_con[channel_id][match_index]
    msg=await ctx.send(embed=score_embed(cb.fetch(cb.urlprov(m_id,0,'',0,'','')), match_index))
    await msg.add_reaction('🔄')
Exemple #10
0
async def on_reaction_add(reaction, user):
    message = reaction.message
    if not user.bot and message.author == bot.user:
        global ids_con, botid
        channel = message.channel
        channel_id = channel.id
        msg=await channel.fetch_message(message.id)
        try:
            session_id=str(msg.embeds[0].footer.text).split('sessionid:')[1].split('`')[0]
            await message.remove_reaction(reaction, user)
        except IndexError:pass
        sess_args=session_id.split('-')
        if 'SCD' in sess_args[0]:
            cshtype = int(sess_args[1])
            curr_count = int(sess_args[2])
            if str(reaction) == arrows_emojis[1]:
                curr_count+=5
            if str(reaction) == arrows_emojis[0]:
                curr_count-=5
            if curr_count < 5:
                curr_count=5
            url = 'https://cricket.yahoo.net/sifeeds/multisport/?methodtype=3&client=24&sport=1&league=0&timezone=0530&language=en&gamestate='+str(cshtype)
            e=schedule_embed(curr_count, cb.fetch(url), channel_id)            
            e.set_footer(text='sessionid:SCD-{0}-{1}'.format(str(cshtype), str(curr_count)))
            await message.edit(embed=e)

        if 'TEF' in sess_args[0]:
            m_id = ids_con[channel_id][int(sess_args[1])]
            e=team_embed(cb.fetch(cb.urlprov(m_id, 0, '', 0, '', '')),sess_args[num_emojis.index(str(reaction))+1])
            e.set_footer(text='sessionid:TEF-{0}-{1}-{2}'.format(sess_args[1],sess_args[2],sess_args[3]))
            await message.edit(embed=e)
        if 'PEF' in sess_args[0]:
            inning_index=num_emojis.index(str(reaction))
            m_id = ids_con[channel_id][int(sess_args[1])]
            url=cb.urlprov(m_id, 0, '', 0, '', '')
            d=partnership_embed(cb.fetch(url), inning_index)
            await channel.send(embed=d[0], file=d[1])
        
        if 'MSC' in sess_args[0]:
            m_id = ids_con[channel_id][int(sess_args[1])]
            await message.edit(embed=score_embed(cb.fetch(cb.urlprov(m_id, 0, '', 0, '', '')), sess_args[1]))
        if 'SFG' == sess_args[0]:
            m_id = ids_con[channel_id][int(sess_args[1])]
            inning_id=num_emojis.index(str(reaction))
            url=cb.urlprov(m_id, 1, 'batsman', inning_id, '', '')
            curr_plindex=int(sess_args[2])
            data=cb.fetch(url)
            file = shotsfig_embed(curr_plindex, data)
            content='sessionid:SFGL-{0}-{1}-{2}'.format(sess_args[1],(str(curr_plindex)),inning_id)
            embed = file[0]
            embed.set_footer(text=content)
            await message.delete()
            nm = await channel.send(embed=embed, file=file[1])
            await nm.add_reaction(arrows_emojis[3])
            await nm.add_reaction(arrows_emojis[2])

        if 'SFGL' == sess_args[0]:
            m_id = ids_con[channel_id][int(sess_args[1])]
            inning_id = int(sess_args[3])
            curr_plindex= int(sess_args[2])
            url=cb.urlprov(m_id, 1, 'batsman', inning_id, '', '')
            data = cb.fetch(url)
            if str(reaction) == arrows_emojis[2]:
                curr_plindex += 1
            if str(reaction) == arrows_emojis[3]:
                curr_plindex -= 1
            if curr_plindex <0:
                curr_plindex=0
            content='sessionid:SFGL-{0}-{1}-{2}'.format(sess_args[1],str(curr_plindex), str(inning_id))
            try:
                f = shotsfig_embed(curr_plindex, data)
                embed = f[0]
                embed.set_footer(text=content)
                nm=await channel.send(file=f[1], embed=embed)
            except (IndexError,UnboundLocalError,JSONDecodeError): pass
            await message.delete()
            await nm.add_reaction(arrows_emojis[3])
            await nm.add_reaction(arrows_emojis[2])

        if 'HFG' == sess_args[0]:
            embed = discord.Embed(title='Heatmap', color=0x03f8fc)
            m_id = ids_con[channel_id][int(sess_args[1])]
            url=cb.urlprov(m_id, 1, 'bowler', num_emojis.index(str(reaction)), '', '')
            data=cb.fetch(url)
            f=cb.shotsfig_bl(int(sess_args[2]), data)
            file = discord.File(fp=f[1], filename='img{}.png'.format(m_id))
            embed.add_field(name='Name:', value=f[0], inline=False)
            embed.set_image(url='attachment://img{}.png'.format(m_id))
            embed.set_footer(text='sessionid:HFGL-{0}-{1}-{2}'.format(
                sess_args[1],sess_args[2], num_emojis.index(str(reaction))))
            nm = await channel.send(file=file, embed=embed)
            await message.delete()
            await nm.add_reaction(arrows_emojis[3])
            await nm.add_reaction(arrows_emojis[2])

        if 'HFGL' == sess_args[0]:
            m_id = ids_con[channel_id][int(sess_args[1])]
            url=cb.urlprov(m_id, 1, 'bowler', 1, '', '')
            data = cb.fetch(url)
            content=''
            if str(reaction) == arrows_emojis[2]:
                curr_plindex = int(sess_args[2])+1
            if str(reaction) == arrows_emojis[3]:
                curr_plindex = int(sess_args[2])-1
            if curr_plindex <0:
                curr_plindex=0
            try:
                embed = discord.Embed(title='Heatmap', color=0x03f8fc)
                f=cb.shotsfig_bl(curr_plindex, data)
                file = discord.File(fp=f[1], filename='img{}.png'.format(m_id))
                embed.add_field(name='Name:', value=f[0], inline=False)
                embed.set_image(url='attachment://img{}.png'.format(m_id))
                embed.set_footer(text='sessionid:HFGL-{0}-{1}-{2}'.format(
                    sess_args[1], str(curr_plindex), sess_args[3]))
                if file != None:
                    nm=await channel.send(file=file, embed=embed)
                else: raise IndexError
            except IndexError:pass
            await message.delete()
            await nm.add_reaction(arrows_emojis[3])
            await nm.add_reaction(arrows_emojis[2])
        if 'LB' in sess_args[0]:
            curr_count = int(sess_args[3])
            mf=sess_args[1]
            dtype = sess_args[2]
            if str(reaction) == arrows_emojis[1]:
                curr_count+=10
            if str(reaction) == arrows_emojis[0]:
                curr_count-=10
            if curr_count < 10:
                curr_count = 10
            e=leaderboard_embed(mf, dtype, curr_count)
            e.set_footer(text='sessionid:LB-{}-{}-{}'.format(mf,dtype, curr_count))
            await message.edit(embed=e)

        if 'FOW' in sess_args[0]:
            m_id = ids_con[channel_id][int(sess_args[1])]
            f=fow_embed(cb.fetch(cb.urlprov(m_id, 0, '', 0, '', '')), num_emojis.index(str(reaction)))
            await channel.send(file=f[1], embed=f[0])

        if 'PSP' in sess_args[0]:
            m_id = ids_con[channel_id][int(sess_args[1])]
            e=powerplay_embed(cb.fetch(cb.urlprov(m_id, 0, '', 0, '', '')), num_emojis.index(str(reaction)))
            e.set_footer(text='sessionid:PSP-{0}-{1}-{2}'.format(sess_args[1],sess_args[2],sess_args[3]))
            await message.edit(embed=e)
        if 'PRC' == sess_args[0]:
            await message.remove_reaction(str(num_emojis[1]), await bot.fetch_user(botid))
            await message.remove_reaction(str(num_emojis[2]), await bot.fetch_user(botid))
            global plids, prctid
            plids.clear()
            m_id = ids_con[channel_id][int(sess_args[1])]
            data = cb.fetch(cb.urlprov(m_id, 0, '', 0, '', ''))
            teams = list(data['Teams'])
            team_id = num_emojis.index(str(reaction))
            prctid = team_id
            plids = list(data['Teams'][teams[team_id-1]]['Players'])
            player_id = plids[int(sess_args[4])]
            e = playercard_embed(data, player_id, teams[team_id-1])
            e.set_footer(text='sessionid:PRCI={0}={1}={2}={3}'.format(
                sess_args[1],sess_args[2],sess_args[3], sess_args[4]))
            await message.edit(embed=e)
            await message.add_reaction(arrows_emojis[3])
            await message.add_reaction(arrows_emojis[2])
        
        #split pattern changed as spliting and parsing '-' to string to int 
        #results into considering the minus as hyphen;
        # '=' replace here '-' to avoid this bug.
        sess_args=session_id.split('=')
        if 'PRCI' in sess_args[0]:
            m_id = ids_con[channel_id][int(sess_args[1])]
            data = cb.fetch(cb.urlprov(m_id, 0, '', 0, '', ''))
            teams = list(data['Teams'])
            team_id = prctid
            if str(reaction) == arrows_emojis[2]:
                curr_plindex = int(sess_args[4])+1
            if str(reaction) == arrows_emojis[3]:
                curr_plindex = int(sess_args[4])-1
            if curr_plindex <0:
                curr_plindex=0
            try:
                player_id = plids[curr_plindex]
                e = playercard_embed(data, player_id, teams[team_id-1])
                e.set_footer(text='sessionid:PRCI={0}={1}={2}={3}'.format(
                    sess_args[1], sess_args[2], sess_args[3], str(curr_plindex)))
            except IndexError: pass
            await message.edit(embed=e)
        #resetting splition back to normal '-'
        sess_args = session_id.split('-')
        if 'SCR' == sess_args[0]:
            await message.remove_reaction(str(num_emojis[1]), await bot.fetch_user(botid))
            await message.remove_reaction(str(num_emojis[2]), await bot.fetch_user(botid))
            m_id = ids_con[channel_id][int(sess_args[1])]
            url = cb.urlprov(m_id, 0, '', 0, '', '')
            raw_data = cb.fetch(url)
            try:
                in_id = num_emojis.index(str(reaction))
            except ValueError:
                in_id = sess_args[2]
            sessid='sessionid:SCR-{0}-{1}'.format(sess_args[1], in_id)
            embed=scorecard_embed(raw_data, int(in_id)-1)
            embed.set_footer(text=sessid)
            await message.edit(embed=embed)
            await message.add_reaction(arrows_emojis[4])

        if 'PAC' == sess_args[0]:
            m_id = ids_con[channel_id][int(sess_args[1])]
            data = cb.fetch(cb.urlprov(m_id, 0, '', 0, '', ''))
            e = player_againstcard_embed_f(data, 1)
            e.set_footer(text='sessionid:PACF-{0}-{1}-{2}'.format(sess_args[1], num_emojis.index(str(reaction)), str(0)))
            await message.edit(embed=e)
            
        if 'PACF' in sess_args[0]:
            m_id = ids_con[channel_id][int(sess_args[1])]
            inning_index = int(sess_args[2])
            a = ['batsman', 'bowler']
            b = [True, False]
            player_type = num_emojis.index(str(reaction))-1
            curr_plindex = int(sess_args[3])
            url = cb.urlprov(m_id, 1, a[player_type], inning_index, '', '')
            try:data = cb.fetch(url)
            except JSONDecodeError: pass
            try:
                embed = player_againstcard_embed(curr_plindex, data, b[player_type])
                embed.set_footer(text='sessionid:PACR-{0}-{1}-{2}-{3}'.format(
                    sess_args[1], sess_args[2], str(curr_plindex), str(player_type)))
            except IndexError: pass
            nm=await channel.send(embed=embed)
            await nm.add_reaction(arrows_emojis[3])
            await nm.add_reaction(arrows_emojis[2])

        if 'PACR' in sess_args[0]:
            m_id = ids_con[channel_id][int(sess_args[1])]
            inning_index = int(sess_args[2])
            a = ['batsman', 'bowler']
            b = [True, False]
            player_type = int(sess_args[4])
            curr_plindex = int(sess_args[3])
            url = cb.urlprov(m_id, 1, a[player_type], inning_index, '', '')
            try:data = cb.fetch(url)
            except JSONDecodeError: pass
    
            if str(reaction) == arrows_emojis[2]:
                curr_plindex = int(sess_args[3])+1
            if str(reaction) == arrows_emojis[3]:
                curr_plindex = int(sess_args[3])-1
            if curr_plindex <0:
                curr_plindex=0
            try:
                embed = player_againstcard_embed(curr_plindex, data, b[player_type])
                embed.set_footer(text='sessionid:PACR-{0}-{1}-{2}-{3}'.format(sess_args[1], sess_args[2], str(curr_plindex), str(player_type)))
            except IndexError: pass
            await message.edit(embed=embed)

        if 'LO' in sess_args[0]:
            await message.remove_reaction(str(num_emojis[1]), await bot.fetch_user(botid))
            await message.remove_reaction(str(num_emojis[2]), await bot.fetch_user(botid))
            m_id = ids_con[channel_id][int(sess_args[1])]
            inning_index = num_emojis.index(str(reaction))
            url = cb.urlprov(m_id, 0, '', inning_index, '', '')
            raw_data = cb.fetch(url)
            e=lastover_embed(raw_data, inning_index-1)
            await message.edit(embed=e)

        if 'PPC' in sess_args[0]:
            await message.remove_reaction(str(num_emojis[1]), await bot.fetch_user(botid))
            await message.remove_reaction(str(num_emojis[2]), await bot.fetch_user(botid))
            m_id = ids_con[channel_id][int(sess_args[1])]
            inning_index = num_emojis.index(str(reaction))
            url = cb.urlprov(m_id, 0, '', inning_index, '', '')
            raw_data = cb.fetch(url)
            e=pshipc_embed(raw_data, inning_index-1)
            await message.edit(embed=e)

        if 'FI' in sess_args[0]:
            d={1:'d11', 2:'my11'}
            m_id = ids_con[channel_id][int(sess_args[1])]
            ftype = d[num_emojis.index(str(reaction))]
            url='https://cricket.yahoo.net/sifeeds/cricket/live/json/{}_fantasy_picks.json'.format(m_id)
            data= cb.fetch(url)
            c=fantasy_insight_embed(data, ftype)
            embed=c[1]
            embed.set_footer(text='sessionid:FI-{0}-{1}'.format(str(sess_args[1]), ftype))
            await message.delete()
            msg=await channel.send(file=c[0], embed=embed)
            await msg.add_reaction(num_emojis[1])
            await msg.add_reaction(num_emojis[2])
        '''