示例#1
0
def checkifhostonline(event):
    HOSTED_CHANNEL = settings.getdata('%s_hosted_channel' % event.channel)

    IS_HOSTING = settings.trygetset('%s_is_hosting' % event.channel, True)
    AUTO_UNHOST = settings.trygetset('%s_auto_unhost' % event.channel, True)
    WHITELIST = settings.trygetset('hosting_whitelist', ['monkeys_forever', 'superjoe', 'imayhaveborkedit']) # This should only be temp

    if IS_HOSTING and AUTO_UNHOST and event.channel in WHITELIST:

        LAST_CHECK = settings.trygetset('%s_last_hosting_check' % event.channel, time.time())

        if LAST_CHECK is None:
            settings.setdata('%s_last_hosting_check' % event.channel, time.time())

        elif check_check_threshold(event.channel):
            print '[Hosting] Checking if host is online'
            try:
                streamdata = twitchapi.get('streams/%s' % HOSTED_CHANNEL, 'stream')
            except:
                print "[Hosting] Error grabbing stream data, probably a bad stream."
                event.bot.botsay("%s, I don't think that's a real stream.  If it is, the twitch api is kaput." % event.channel)
            else:
                if streamdata:
                    settings.setdata('%s_last_hosting_check' % event.channel, time.time())

                elif check_offline_threshold(event.channel):
                    print "[Hosting] %s has been offline for long enough, attempting to unhost" % HOSTED_CHANNEL
                    event.bot.botsay('/unhost')
示例#2
0
def nowhosting(event):
    if event.data.startswith('HOSTTARGET') and event.data.split()[1] != '-':
        HOSTED_CHANNEL = event.data.split()[1]

        print event.etype, event.channel, event.data

        settings.setdata('%s_is_hosting' % event.channel, True)
        settings.setdata('%s_hosted_channel' % event.channel, event.data.split()[1])

        streamdata = twitchapi.get('streams/%s' % HOSTED_CHANNEL, 'stream')

        print '[Hosting] WE ARE NOW HOSTING %s' % HOSTED_CHANNEL

        if streamdata:
            if event.data.split()[2] == '-':
                return
            try:
                viewers = str(int(event.data.split()[2]))
            except:
                viewers = event.data.split()[2].split('=')[1].split(')')[0]

            event.bot.botsay("Now hosting %s, playing %s.  All %s of you, go check it out! %s" %
                (HOSTED_CHANNEL, str(streamdata['game']), viewers, 'http://twitch.tv/%s' % HOSTED_CHANNEL))
        else:
            print "[Hosting] %s is not streaming." % HOSTED_CHANNEL
    elif event.data.startswith('HOSTTARGET') and event.data.split()[1] == '-':
        print "[Hosting] Unhosting %s " % settings.getdata('%s_hosted_channel' % event.channel)

        settings.setdata('%s_is_hosting' % event.channel, False)
        settings.setdata('%s_hosted_channel' % event.channel, '')
示例#3
0
def nowhosting(event):
    if event.data.startswith('HOSTTARGET') and event.data.split()[1] != '-':
        HOSTED_CHANNEL = event.data.split()[1]

        print event.etype, event.channel, event.data

        settings.setdata('%s_is_hosting' % event.channel, True)
        settings.setdata('%s_hosted_channel' % event.channel,
                         event.data.split()[1])

        streamdata = twitchapi.get('streams/%s' % HOSTED_CHANNEL, 'stream')

        print '[Hosting] WE ARE NOW HOSTING %s' % HOSTED_CHANNEL

        if streamdata:
            if event.data.split()[2] == '-':
                return
            try:
                viewers = str(int(event.data.split()[2]))
            except:
                viewers = event.data.split()[2].split('=')[1].split(')')[0]

            event.bot.botsay(
                "Now hosting %s, playing %s.  All %s of you, go check it out! %s"
                % (HOSTED_CHANNEL, str(streamdata['game']), viewers,
                   'http://twitch.tv/%s' % HOSTED_CHANNEL))
        else:
            print "[Hosting] %s is not streaming." % HOSTED_CHANNEL
    elif event.data.startswith('HOSTTARGET') and event.data.split()[1] == '-':
        print "[Hosting] Unhosting %s " % settings.getdata(
            '%s_hosted_channel' % event.channel)

        settings.setdata('%s_is_hosting' % event.channel, False)
        settings.setdata('%s_hosted_channel' % event.channel, '')
示例#4
0
def checkifhostonline(event):
    HOSTED_CHANNEL = settings.getdata('%s_hosted_channel' % event.channel)

    IS_HOSTING = settings.trygetset('%s_is_hosting' % event.channel, True)
    AUTO_UNHOST = settings.trygetset('%s_auto_unhost' % event.channel, True)
    WHITELIST = settings.trygetset(
        'hosting_whitelist',
        ['monkeys_forever', 'superjoe', 'imayhaveborkedit'
         ])  # This should only be temp

    if IS_HOSTING and AUTO_UNHOST and event.channel in WHITELIST:

        LAST_CHECK = settings.trygetset(
            '%s_last_hosting_check' % event.channel, time.time())

        if LAST_CHECK is None:
            settings.setdata('%s_last_hosting_check' % event.channel,
                             time.time())

        elif check_check_threshold(event.channel):
            print '[Hosting] Checking if host is online'
            try:
                streamdata = twitchapi.get('streams/%s' % HOSTED_CHANNEL,
                                           'stream')
            except:
                print "[Hosting] Error grabbing stream data, probably a bad stream."
                event.bot.botsay(
                    "%s, I don't think that's a real stream.  If it is, the twitch api is kaput."
                    % event.channel)
            else:
                if streamdata:
                    settings.setdata('%s_last_hosting_check' % event.channel,
                                     time.time())

                elif check_offline_threshold(event.channel):
                    print "[Hosting] %s has been offline for long enough, attempting to unhost" % HOSTED_CHANNEL
                    event.bot.botsay('/unhost')