Пример #1
0
def alert(event):
    if event.channel in enabled_channels:
        msgtimer = timer.Timer('Dota message Timer')
        msgtimer.start()
        if event.etype == 'msg': # Meh
            mes_count = settings.trygetset('%s_notable_message_count' % event.channel, 1)
            settings.setdata('%s_notable_message_count' % event.channel, mes_count + 1, announce=False)

            try:
                if not settings.trygetset('%s_matchblurb_running' % event.channel, False):
                    settings.setdata('%s_matchblurb_running' % event.channel, True, announce=False)
                    blurb(event.channel, event.bot)
                else:
                    raise RuntimeWarning('Blurb already running')
            except RuntimeWarning as e:
                pass
            except Exception as e:
               print '[Dota-Error] Match blurb failure: %s' % e
            else:
                settings.setdata('%s_matchblurb_running' % event.channel, False, announce=False)
            msgtimer.stop()
            # print msgtimer

        if event.etype == 'timer':
            try:
                rss_update = check_for_steam_dota_rss_update(event.channel)
                if rss_update:
                    print '[Dota] RSS update found: ' + rss_update
                    event.bot.botsay(rss_update)
            except Exception, e:
                print '[Dota-Error] RSS check failure: %s (%s)' % (e,type(e))
Пример #2
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')
Пример #3
0
def check_for_steam_dota_rss_update(channel, setkey=True):
    last_rss_check = settings.trygetset('%s_last_dota_rss_check' % channel, time.time())

    if time.time() - last_rss_check < 30.0:
        return

    settings.setdata('%s_last_dota_rss_check' % channel, time.time(), announce=False)

    rs = [li for li in node.get_steam_rss() if li]
    last_feed_url = settings.trygetset('%s_dota_last_steam_rss_update_url' % channel, '0')

    for item in rs:
        if not item: continue
        if item['author'] == 'Valve' and 'Dota 2 Update' in item['title']:
            if item['guid'] != last_feed_url:
                if last_feed_url == 'derp': last_feed_url = '0'

                try:
                    bpn_old = int([x for x in last_feed_url.split('/') if x][-1])
                    bpn_new = int([x for x in item['guid'].split('/') if x][-1])

                    if bpn_old >= bpn_new:
                        break
                except Exception as e:
                    print '[Dota-RSS] Error checking steam rss:', e
                    break

                settings.setdata('%s_dota_last_steam_rss_update_url' % channel, str(item['guid']))
                settings.setdata('%s_last_dota_rss_check' % channel, last_rss_check, announce=False)

                return str("Steam News Feed: %s - %s" % (item['title'], item['guid']))
            else:
                break


    rs = [li for li in node.get_dota_rss() if li]
    last_feed_url = settings.trygetset('%s_dota_last_dota2_rss_update_url' % channel, '0')

    for item in rs:
        if not item: continue
        if item['guid'] != last_feed_url:
            if last_feed_url == 'derp': last_feed_url = '0'

            try:
                bpn_old = int(last_feed_url.split('=')[-1])
                bpn_new = int(item['guid'].split('=')[-1])

                if bpn_old >= bpn_new:
                    break
            except Exception as e:
                print '[Dota-RSS] Error checking dota rss:', e
                break

            settings.setdata('%s_dota_last_dota2_rss_update_url' % channel, str(item['guid']))

            return str("Dota 2 Blog Post: %s - %s" % (item['title'], item['link']))
        else:
            break
Пример #4
0
def enable_channel(channel, dotaid, mmr=False):
    dotaid = steamToDota(determineSteamid(dotaid))
    en_chans = settings.getdata('dota_enabled_channels')

    settings.setdata('dota_enabled_channels', list(set(en_chans + [channel])))
    settings.trygetset('%s_common_name' % channel, channel)
    settings.setdata('%s_mmr_enabled' % channel, mmr)

    settings.setdata('%s' % channel, dotaToSteam(dotaid), domain='steamids')
    settings.setdata('%s_dota_id' % channel, dotaid)

    update_channels()
Пример #5
0
def enable_channel(channel, dotaid, mmr=True, returntrueifnotnotable=False):
    en_chans = settings.getdata('dota_enabled_channels')

    settings.setdata('dota_enabled_channels', list(set(en_chans + [channel])))
    settings.trygetset('%s_common_name' % channel, channel)
    settings.setdata('%s_mmr_enabled' % channel, mmr)
    settings.setdata('%s_dota_id' % channel, dotaid)

    update_channels()
    if returntrueifnotnotable:
        if dotaid not in settings.getdata('dota_notable_players'):
            return True
Пример #6
0
def latestBlurb(channel, override=False):
    if checktimeout(channel) or override:
        dotaid = settings.getdata('%s_dota_id' % channel)
        if dotaid is None:
            print "[Dota] No ID on record for %s.  I should probably sort this out." % channel
            return

        try:
            mat = steamapi.GetMatchHistory(account_id=dotaid, matches_requested=25)
            matches = mat['result']['matches']
        except requests.exceptions.ConnectionError:
            return
        except Exception as e:
            if mat == {}:
                # print "Bad data from GetMatchHistory:", mat
                return
            else:
                print 'Error with steam api data:', e
                print mat
                print traceback.format_exc()
                return

        settings.setdata('%s_last_match_fetch' % channel, time.time(), announce=False)

        latestmatch = matches[0]
        previousnewmatch = matches[1]
        previoussavedmatch = settings.trygetset('%s_last_match' % channel, latestmatch)

        if previoussavedmatch['match_id'] != latestmatch['match_id'] or override:
            if previoussavedmatch['match_id'] != previousnewmatch['match_id']:
                # Other matches have happened.

                matchlist = [m['match_id'] for m in matches]

                # If there was a problem here it either was never a problem or doesn't exist now?

                try:
                    skippedmatches = matchlist.index(previoussavedmatch['match_id']) - 1
                except:
                    skippedmatches = 0
                print '[Dota] Skipped %s matches MAYBE PROBABLY I HOPE SO' % skippedmatches
            else:
                skippedmatches = 0

            update_channels()
            notable_check_timeout = settings.trygetset('%s_notable_check_timeout' % channel, 900.0)

            settings.setdata('%s_notable_last_check' % channel, time.time() - notable_check_timeout + 60.0, announce=False)
            settings.setdata('%s_notable_message_count' % channel, settings.trygetset('%s_notable_message_limit' % channel, 50), announce=False)

            print "[Dota] Match ID change found (%s:%s) (Lobby type %s)" % (previoussavedmatch['match_id'], latestmatch['match_id'], str(latestmatch['lobby_type']))
            return getLatestGameBlurb(channel, dotaid, latestmatch, skippedmatches=skippedmatches, getmmr = get_enabled_channels()[channel][1] and str(latestmatch['lobby_type']) == '7')
Пример #7
0
def getNotableCheckReady(channel):
    lastcheck = settings.trygetset('%s_notable_last_check' % channel, time.time())
    message_limit = settings.trygetset('%s_notable_message_limit' % channel, 50)
    notable_check_timeout = settings.trygetset('%s_notable_check_timeout' % channel, 900.0)

    if time.time() - lastcheck > notable_check_timeout:
        mes_count = settings.trygetset('%s_notable_message_count' % channel, 1)
        if mes_count <= message_limit:
            return False
        settings.setdata('%s_notable_last_check' % channel, time.time(), announce=False)
        return True
    else:
        # print notable_check_timeout - (time.time() - lastcheck)
        return False
Пример #8
0
def checktimeout(channel):
    twitchchecktimeout = settings.trygetset('%s_twitch_online_check_timeout' % channel, 15)
    lastonlinecheck = settings.trygetset('%s_twitch_online_last_check' % channel, time.time())
    laststreamingstate = settings.trygetset('%s_last_twitch_streaming_state' % channel, False)

    try:
        if time.time() - int(lastonlinecheck) > twitchchecktimeout:
            is_streaming = twitchapi.is_streaming(channel)
            settings.setdata('%s_last_twitch_streaming_state' % channel, is_streaming, announce=False)
        else:
            return laststreamingstate
    except Exception as e:
        print '[Dota] twitch api check error: ',e
        return False

    if is_streaming:
        if time.time() - int(twitchchecktimeout) > float(lastonlinecheck):
            settings.setdata('%s_twitch_online_last_check' % channel, time.time(), announce=False)
        else:
            return True
    else:
        return False

    laststreamcheck = settings.trygetset('%s_last_is_streaming_check' % channel, time.time())
    streamchecktimeout = settings.trygetset('%s_is_streaming_timeout' % channel, 30)

    if time.time() - int(streamchecktimeout) > float(laststreamcheck):
        getmatchtimeout = settings.trygetset('%s_get_online_match_timeout' % channel, 20)
        settings.setdata('%s_last_is_streaming_check' % channel, time.time(), announce=False)

    getmatchtimeout = settings.trygetset('%s_get_match_timeout' % channel, 30)
    lastmatchfetch = settings.trygetset('%s_last_match_fetch' % channel, time.time())

    return time.time() - int(getmatchtimeout) > float(lastmatchfetch)
Пример #9
0
def getNotableCheckReady(channel):
    lastcheck = settings.trygetset('%s_notable_last_check' % channel, time.time())
    message_limit = settings.trygetset('%s_notable_message_limit' % channel, 50)
    notable_check_timeout = settings.trygetset('%s_notable_check_timeout' % channel, 600.0)

    if time.time() - lastcheck > notable_check_timeout:
        mes_count = settings.trygetset('%s_notable_message_count' % channel, 1)
        if mes_count <= message_limit:
            print '%s/%s' % (mes_count, message_limit)
            return False

        return True
    else:
        print notable_check_timeout - (time.time() - lastcheck)
        return False
Пример #10
0
def latestBlurb(channel, override=False):
    # if node.get_user_status(dota.dotaToSteam(settings.getdata('%s_dota_id' % channel))) is not None:
    if checktimeout(channel) or override:
        dotaid = settings.getdata('%s_dota_id' % channel)
        if dotaid is None:
            print "[Dota] No ID on record for %s.  I should probably sort this out." % channel
            return

        try:
            matches = steamapi.GetMatchHistory(account_id=dotaid, matches_requested=25)['result']['matches']
        except:
            return

        settings.setdata('%s_last_match_fetch' % channel, time.time(), announce=False)

        latestmatch = matches[0]
        previousnewmatch = matches[1]
        previoussavedmatch = settings.trygetset('%s_last_match' % channel, latestmatch)

        if previoussavedmatch['match_id'] != latestmatch['match_id'] or override:
            if previoussavedmatch['match_id'] != previousnewmatch['match_id']:
                # Other matches have happened.

                matchlist = [m['match_id'] for m in matches]

                # TODO: Fix -1 issues for lastmatch
                # For some reason, a failed match (early abandon) was never saved as the lastest match
                try:
                    skippedmatches = matchlist.index(previoussavedmatch['match_id']) - 1
                except:
                    skippedmatches = 0
                print '[Dota] Skipped %s matches MAYBE PROBABLY I HOPE SO' % skippedmatches
            else:
                skippedmatches = 0

            update_channels()
            notable_check_timeout = settings.trygetset('%s_notable_check_timeout' % channel, 900.0)

            settings.setdata('%s_notable_last_check' % channel, time.time() - notable_check_timeout + 60.0, announce=False)
            settings.setdata('%s_notable_message_count' % channel, settings.trygetset('%s_notable_message_limit' % channel, 50), announce=False)

            print "[Dota] Match ID change found (%s:%s) (Lobby type %s)" % (previoussavedmatch['match_id'], latestmatch['match_id'], str(latestmatch['lobby_type']))
            return getLatestGameBlurb(channel, dotaid, latestmatch, skippedmatches=skippedmatches, getmmr = enabled_channels[channel][1] and str(latestmatch['lobby_type']) == '7')
Пример #11
0
def alert(event):
    # Sub alert
    if event.etype == 'twitchnotify':
        if event.channel in sub_alert_channel_list:
            sub_msg = 'ヽ༼ຈل͜ຈ༽ノ SUB HYPE! PRAISE %s' % event.data.split(
            )[0].upper()
            resub_msg = 'ヽ༼ຈل͜ຈ༽ノ RE-SUB HYPE! PRAISE %s' % event.data.split(
            )[0].upper()
            if 'just subscribed!' in event.data:
                extra = ''
                if event.channel in ['monkeys_forever', 'kizzmett']:
                    # extra = ' | If you want an invite to the sub guild use !guildinvite (Make sure you have \"Allow guild invites from -> Anyone\" enabled)'
                    extra = ''
                event.bot.botsay(sub_msg + extra)

            if 'subscribed for ' in event.data:
                event.bot.botsay(resub_msg)

    #######################################
    ## TODO:

    # Move this code over to some infoposter.py module
    # It would post titles to youtube links, twitter post text
    # steam game link info, more as I think of them

    # watch?v=n4D-N6aWIV4
    # http://youtube.com/get_video_info?video_id=n4D-N6aWIV4

    if event.etype in ['msg', 'action']:
        if settings.trygetset('%s_post_youtube_titles' % event.channel, True):
            if ('youtube.com/watch?' in event.data
                    or 'youtu.be/' in event.data) and not event.data.strip(
                    ).startswith('!'):  # and event.user != 'rime_':
                print '[ExtraEvents] Found youtube link, looking up title'

                ids = re.findall('watch\?.*?v=(\S{11})',
                                 event.data) + re.findall(
                                     'youtu.be/(.{11})', event.data)
                ids = list(set(ids))
                print '[ExtraEvents] Found ids: %s' % ids

                ytdata = {}

                for i in ids:
                    ytdata[i] = get_youtube_title(i)
                    print '[ExtraEvents] Found title for %s: %s' % (i,
                                                                    ytdata[i])

                for ytid in ytdata:
                    if ytid:
                        event.bot.botsay('Video title for ID %s: %s' %
                                         (ytid, ytdata[ytid]))
Пример #12
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')
Пример #13
0
def notablePlayerBlurb(channel, pages=33):
    playerid = settings.getdata('%s_dota_id' % channel)
    userstatus = node.get_user_status(dotaToSteam(playerid))
    if userstatus:
        # print 'Dota status for %s: %s' % (channel, userstatus)

        if userstatus in ["#DOTA_RP_HERO_SELECTION", "#DOTA_RP_PRE_GAME", "#DOTA_RP_GAME_IN_PROGRESS", "#DOTA_RP_PLAYING_AS"]:
            if getNotableCheckReady(channel):
                if twitchapi.is_streaming(channel):
                    if userstatus == '#DOTA_RP_PLAYING_AS':
                        playerheroid = node.get_user_playing_as(dotaToSteam(playerid))
                        playerheroid = getHeroIddict(False)[playerheroid[0]]
                    else:
                        playerheroid = None

                    print "[Dota-Notable] Doing search for notable players%s" % (' using hero id' if playerheroid else '')
                    players = searchForNotablePlayers(playerid, pages, playerheroid)
                    settings.setdata('%s_notable_message_count' % channel, 0, announce=False)

                    if players:
                        return "Notable players in this game: %s" % ', '.join(['%s (%s)' % (p,h) for p,h in players])
        else:
            notable_check_timeout = settings.trygetset('%s_notable_check_timeout' % channel, 600.0)
            settings.setdata('%s_notable_last_check' % channel, time.time() - notable_check_timeout + 60.0, announce=False)
Пример #14
0
# -*- coding: utf-8 -*-
import sys
sys.dont_write_bytecode = True

import time
import twitchapi
import settings

LOAD_ORDER = 40

WHITELIST = ['monkeys_forever', 'superjoe', 'imayhaveborkedit', 'mynameisamanda']

CHECK_THRESHOLD = settings.trygetset('hosting_check_threshold', 60)
OFFLINE_THRESHOLD = settings.trygetset('hosting_offline_threshold', 300)

def setup(bot):
    settings.setdata('%s_is_hosting' % bot.channel.replace('#', ''), False)
    settings.setdata('%s_hosted_channel' % bot.channel.replace('#', ''), '')

def alert(event):
    message = 'Only the channel owner and channel editors can use the /unhost command.'
    
    if event.channel:
        if event.etype == 'jtvmsg' and message in event.data:
                print "[Hosting] Not an editor, cannot unhost."
                settings.setdata('%s_auto_unhost' % event.channel, False)

        if event.etype in ['infomsg', 'jtvmsg']:  # Should only need jtvmsg
            nowhosting(event)  # This needs to be called before the check goes
            # checkifhostonline(event) # This line might need to be outside the if check
Пример #15
0
# -*- coding: utf-8 -*-
import sys
sys.dont_write_bytecode = True

import time
import twitchapi
import settings

LOAD_ORDER = 40

WHITELIST = [
    'monkeys_forever', 'superjoe', 'imayhaveborkedit', 'mynameisamanda'
]

CHECK_THRESHOLD = settings.trygetset('hosting_check_threshold', 60)
OFFLINE_THRESHOLD = settings.trygetset('hosting_offline_threshold', 300)


def setup(bot):
    settings.setdata('%s_is_hosting' % bot.channel.replace('#', ''), False)
    settings.setdata('%s_hosted_channel' % bot.channel.replace('#', ''), '')


def alert(event):
    message = 'Only the channel owner and channel editors can use the /unhost command.'

    if event.channel:
        if event.etype == 'jtvmsg' and message in event.data:
            print "[Hosting] Not an editor, cannot unhost."
            settings.setdata('%s_auto_unhost' % event.channel, False)