コード例 #1
0
ファイル: stupid.py プロジェクト: unnes/aetherbot
def citation(db, chan, nick, reason):
    fine = random.randint(1, 500)
    try:
        totalfines = int(database.get(db, 'users', 'fines', 'nick',
                                      nick)) + fine
    except:
        totalfines = 0 + fine
    database.set(db, 'users', 'fines', totalfines, 'nick', nick)
    return "PRIVMSG {} :\x01ACTION fines {} \x02${}\x02 {}. You owe: \x0304${}\x02\x01".format(
        chan, nick, fine, reason, totalfines)
コード例 #2
0
def waifu(text, nick=None, conn=None, chan=None,db=None, notice=None):
    "waifu <waifu | @ person> -- Shows a users Waifu or Husbando."

    if not text or '@' in text:
        if '@' in text: nick = text.split('@')[1].strip()
        result = database.get(db,'users','waifu','nick',nick)
        if result:
            return '{}'.format(result)
        else:
            if not '@' in text: notice(waifu.__doc__)
            return 'No waifu saved for {}.'.format(nick)
    elif 'del' in text:
        database.set(db,'users','waifu','','nick',nick)
        notice("Deleted your waifu.")
    else:
        database.set(db,'users','waifu','{} '.format(text.strip()),'nick',nick)
        notice("Saved your waifu.")
    return
コード例 #3
0
def steam(text, nick=None, conn=None, chan=None,db=None, notice=None):
    "steam <steam | @ person> -- Shows a users steam information."

    if not text or '@' in text:
        if '@' in text: nick = text.split('@')[1].strip()
        result = database.get(db,'users','steam','nick',nick)
        if result:
            return '{}'.format(result)
        else:
            if not '@' in text: notice(steam.__doc__)
            return 'No steam information saved for {}.'.format(nick)
    elif 'del' in text:
        database.set(db,'users','steam','','nick',nick)
        notice("Deleted your steam information.")
    else:
        database.set(db,'users','steam','{} '.format(text.strip()),'nick',nick)
        notice("Saved your steam information.")
    return
コード例 #4
0
def mymanga(text, nick=None, conn=None, chan=None,db=None, notice=None):
    "mymanga <mal name | @ person> -- Shows a users myanimelist profile."

    if not text or '@' in text:
        if '@' in text: nick = text.split('@')[1].strip()
        result = database.get(db,'users','mal','nick',nick)
        if result:
            return '{}: http://myanimelist.net/mangalist/{}'.format(nick,result)
        else:
            if not '@' in text: notice(mal.__doc__)
            return 'No mal saved for {}.'.format(nick)
    elif 'del' in text:
        database.set(db,'users','mal','','nick',nick)
        notice("Deleted your mal.")
    else:
        database.set(db,'users','mal','{} '.format(text.strip()),'nick',nick)
        notice("Saved your mal.")
    return
コード例 #5
0
def socialmedia(text, nick=None, conn=None, chan=None,db=None, notice=None):
    "socialmedia <socialmedianames | @ person> -- Shows a users social medias names."

    if not text or '@' in text:
        if '@' in text: nick = text.split('@')[1].strip()
        result = database.get(db,'users','socialmedias','nick',nick)
        if result:
            return '{}'.format(result)
        else:
            if not '@' in text: notice(snapchat.__doc__)
            return 'No social medias saved for {}.'.format(nick)
    elif 'del' in text:
        database.set(db,'users','socialmedias','','nick',nick)
        notice("Deleted your social medias.")
    else:
        database.set(db,'users','socialmedias','{} '.format(text.strip()),'nick',nick)
        notice("Saved your social medias.")
    return
コード例 #6
0
def birthday(text, nick=None, conn=None, chan=None,db=None, notice=None):
    "birthday <01/01/2001> | <@ person> -- Shows a users Birthday."

    if not text or '@' in text:
        if '@' in text: nick = text.split('@')[1].strip()
        result = database.get(db,'users','birthday','nick',nick)
        if result:
            return '{}'.format(result)
        else:
            if not '@' in text: notice(birthday.__doc__)
            return 'No birthday saved for {}.'.format(nick)
    elif 'del' in text:
        database.set(db,'users','birthday','','nick',nick)
        notice("Deleted your birthday.")
    else:
        database.set(db,'users','birthday','{} '.format(text.strip()),'nick',nick)
        notice("Saved your birthday.")
    return
コード例 #7
0
def daughteru(text, nick=None, conn=None, chan=None,db=None, notice=None):
    "daughteru <daughteru | @ person> -- Shows a users daughteru."

    if not text or '@' in text:
        if '@' in text: nick = text.split('@')[1].strip()
        result = database.get(db,'users','daughteru','nick',nick)
        if result:
            return '{}'.format(result)
        else:
            if not '@' in text: notice(imouto.__doc__)
            return 'No daughteru saved for {}.'.format(nick)
    elif 'del' in text:
        database.set(db,'users','daughteru','','nick',nick)
        notice("Deleted your daughteru.")
    else:
        database.set(db,'users','daughteru','{} '.format(text.strip()),'nick',nick)
        notice("Saved your daughteru.")
    return
コード例 #8
0
def imouto(text, nick=None, conn=None, chan=None,db=None, notice=None):
    "imouto <imouto | @ person> -- Shows a users imouto or Husbando."

    if not text or '@' in text:
        if '@' in text: nick = text.split('@')[1].strip()
        result = database.get(db,'users','imouto','nick',nick)
        if result:
            return '{}'.format(result)
        else:
            if not '@' in text: notice(imouto.__doc__)
            return 'No imouto saved for {}.'.format(nick)
    elif 'del' in text:
        database.set(db,'users','imouto','','nick',nick)
        notice("Deleted your imouto.")
    else:
        database.set(db,'users','imouto','{} '.format(text.strip()),'nick',nick)
        notice("Saved your imouto.")
    return
コード例 #9
0
def desktop(text, nick=None, conn=None, chan=None,db=None, notice=None):
    "desktop http://url.to/desktop | @ nick -- Shows a users Desktop."
    if text:
        if  "http" in text:
            database.set(db,'users','desktop',text.strip(),'nick',nick)
            notice("Saved your desktop.")
            return
        elif 'del' in text:
            database.set(db,'users','desktop','','nick',nick)
            notice("Deleted your desktop.")
            return
        else:
            if '@' in text: nick = text.split('@')[1].strip()
            else: nick = text.strip()

    result = database.get(db,'users','desktop','nick',nick)
    if result:
        return '{}'.format(result)
    else:
        if not '@' in text: notice(desktop.__doc__)
        return 'No desktop saved for {}.'.format(nick)
コード例 #10
0
def selfie(text, nick=None, conn=None, chan=None,db=None, notice=None):
    "selfie <url | @ person> -- Shows a users selfie."
    if text:
        if  "http" in text:
            database.set(db,'users','selfie',text.strip(),'nick',nick)
            notice("Saved your selfie.")
            return
        elif 'del' in text:
            database.set(db,'users','selfie','','nick',nick)
            notice("Deleted your selfie.")
            return
        else:
            if '@' in text: nick = text.split('@')[1].strip()
            else: nick = text.strip()

    result = database.get(db,'users','selfie','nick',nick)
    if result:
        return '{}'.format(result)
    else:
        if not '@' in text: notice(selfie.__doc__)
        return 'No selfie saved for {}.'.format(nick)
コード例 #11
0
def battlestation(text, nick=None, conn=None, chan=None,db=None, notice=None):
    "battlestation <url | @ person> -- Shows a users Battlestation."
    if text:
        if  "http" in text:
            database.set(db,'users','battlestation',text.strip(),'nick',nick)
            notice("Saved your battlestation.")
            return
        elif 'del' in text:
            database.set(db,'users','battlestation','','nick',nick)
            notice("Deleted your battlestation.")
            return
        else:
            if '@' in text: nick = text.split('@')[1].strip()
            else: nick = text.strip()

    result = database.get(db,'users','battlestation','nick',nick)
    if result:
        return '{}'.format(result)
    else:
        if not '@' in text: notice(battlestation.__doc__)
        return 'No battlestation saved for {}.'.format(nick)
コード例 #12
0
def homescreen(text, nick=None, conn=None, chan=None,db=None, notice=None):
    "homescreen <url | @ person> -- Shows a users homescreen."
    if "http" in text:
        database.set(db,'users','homescreen',text.strip(),'nick',nick)
        notice("Saved your homescreen.")
        return
    elif 'del' in text:
        database.set(db,'users','homescreen','','nick',nick)
        notice("Deleted your homescreen.")
        return
    elif not text:
        homescreen = database.get(db,'users','homescreen','nick',nick)
    else:
        if '@' in text: nick = text.split('@')[1].strip()
        else: nick = text.strip()

    homescreen = database.get(db,'users','homescreen','nick',nick)
    if homescreen:
        return '{}: {}'.format(nick,homescreen)
    else:
        # notice(homescreen.__doc__)
        return 'No homescreen saved for {}.'.format(nick)
コード例 #13
0
def time_command(text, nick, db, reply, notice):
    """<location> -- Gets the current time in <location>."""
    if not dev_key:
        return "This command requires a Google Developers Console API key."
    # If no input try the db
    save = True
    if not text:
        location = database.get(db,'users','location','nick',nick)
        print (location)
        if not location:
            notice("I have no location stored for you.")
            return
    elif '@' in text:
        save = False
        nick = text.split('@')[1].strip()
        location = database.get(db,'users','location','nick',nick)
        if not location:
            notice("No location stored for user")
            return
    else:
        location = text
        loc = location
    if text.lower().startswith("utc") or text.lower().startswith("gmt"):
        timezone = text.strip()
        pattern = re.compile(r"utc|gmt|[:+]")
        utcoffset = [x for x in pattern.split(text.lower()) if x]
        if len(utcoffset) > 2:
           return "Please specify a valid UTC/GMT format Example: UTC-4, UTC+7 GMT7"
        if len(utcoffset) == 1:
           utcoffset.append('0')
        if len(utcoffset) == 2:
           try:
               offset = datetime.timedelta(hours=int(utcoffset[0]), minutes=int(utcoffset[1]))
           except:
               return "Sorry I could not parse the UTC format you entered. Example UTC7 or UTC-4"
           curtime = datetime.datetime.utcnow()
           tztime = curtime + offset
           formatted_time = datetime.datetime.strftime(tztime, '%I:%M %p, %A, %B %d, %Y')
           return "\x02{}\x02 ({})".format(formatted_time, timezone)
           
    # Use the Geocoding API to get co-ordinates from the input
    params = {"address": location, "key": dev_key}
    if bias:
        params['region'] = bias

    json = requests.get(geocode_api, params=params).json()

    error = check_status(json['status'], "geocoding")
    if error:
        return error

    result = json['results'][0]

    location_name = result['formatted_address']
    location = result['geometry']['location']

    # Now we have the co-ordinates, we use the Timezone API to get the timezone
    formatted_location = "{lat},{lng}".format(**location)

    epoch = time.time()

    params = {"location": formatted_location, "timestamp": epoch, "key": dev_key}
    json = requests.get(timezone_api, params=params).json()

    error = check_status(json['status'], "timezone")
    if error:
        return error

    # Work out the current time
    offset = json['rawOffset'] + json['dstOffset']

    # I'm telling the time module to parse the data as GMT, but whatever, it doesn't matter
    # what the time module thinks the timezone is. I just need dumb time formatting here.
    raw_time = time.gmtime(epoch + offset)
    formatted_time = time.strftime('%I:%M %p, %A, %B %d, %Y', raw_time)

    timezone = json['timeZoneName']
    if text and save:
        database.set(db,'users','location',loc,'nick',nick)
    return "\x02{}\x02 - {} ({})".format(formatted_time, location_name, timezone)
コード例 #14
0
ファイル: stupid.py プロジェクト: ihatevim/aetherbot
def citation(db,chan,nick,reason):
    fine = random.randint(1, 500)
    try: totalfines = int(database.get(db,'users','fines','nick',nick)) + fine
    except: totalfines = 0 + fine
    database.set(db,'users','fines',totalfines,'nick',nick)
    return "PRIVMSG {} :\x01ACTION fines {} \x02${}\x02 {}. You owe: \x0304${}\x02\x01".format(chan, nick, fine, reason, totalfines)
コード例 #15
0
ファイル: weather.py プロジェクト: unnes/aetherbot
def weather(text, reply, db, nick, notice):
    """weather <location> -- Gets weather data for <location>."""
    if not wunder_key:
        return "This command requires a Weather Underground API key."
    if not dev_key:
        return "This command requires a Google Developers Console API key."
    save = True
    location = ""
    # If no input try the db
    if not text:
        location = database.get(db,'users','location','nick',nick)
        if not location:
            notice(weather.__doc__)
            return
    elif '@' in text:
        save = False
        nick = text.split('@')[1].strip()
        location = database.get(db,'users','location','nick',nick)
        if not location:
            notice("No location stored for user")
            return
    else:
        location = text
    # use find_location to get location data from the user input
    try:
        location_data = find_location(location)
    except APIError as e:
        return e

    formatted_location = "{lat},{lng}".format(**location_data)

    url = wunder_api.format(wunder_key, formatted_location)
    response = requests.get(url).json()

    if response['response'].get('error'):
        return "{}".format(response['response']['error']['description'])

    forecast_today = response["forecast"]["simpleforecast"]["forecastday"][0]
    forecast_tomorrow = response["forecast"]["simpleforecast"]["forecastday"][1]

    # put all the stuff we want to use in a dictionary for easy formatting of the output
    weather_data = {
        "place": response['current_observation']['display_location']['full'],
        "conditions": response['current_observation']['weather'],
        "temp_f": response['current_observation']['temp_f'],
        "temp_c": response['current_observation']['temp_c'],
        "humidity": response['current_observation']['relative_humidity'],
        "wind_kph": response['current_observation']['wind_kph'],
        "wind_mph": response['current_observation']['wind_mph'],
        "wind_direction": response['current_observation']['wind_dir'],
        "today_conditions": forecast_today['conditions'],
        "today_high_f": forecast_today['high']['fahrenheit'],
        "today_high_c": forecast_today['high']['celsius'],
        "today_low_f": forecast_today['low']['fahrenheit'],
        "today_low_c": forecast_today['low']['celsius'],
        "tomorrow_conditions": forecast_tomorrow['conditions'],
        "tomorrow_high_f": forecast_tomorrow['high']['fahrenheit'],
        "tomorrow_high_c": forecast_tomorrow['high']['celsius'],
        "tomorrow_low_f": forecast_tomorrow['low']['fahrenheit'],
        "tomorrow_low_c": forecast_tomorrow['low']['celsius']
    }

    # Get the more accurate URL if available, if not, get the generic one.
    if "?query=," in response["current_observation"]['ob_url']:
        try:
            weather_data['url'] = web.try_shorten(response["current_observation"]['forecast_url'])
        except:
            weather_data['url'] = response["current_observation"]["forcast_url"]
            pass
    else:
        try:
            weather_data['url'] = web.try_shorten(response["current_observation"]['ob_url'])
        except:
            weather_data['url'] = response["current_observation"]["ob_url"]
            pass

    reply("{place} - \x02Current:\x02 {conditions}, {temp_f}F/{temp_c}C, {humidity}, "
          "Wind: {wind_mph}MPH/{wind_kph}KPH {wind_direction}, \x02Today:\x02 {today_conditions}, "
          "High: {today_high_f}F/{today_high_c}C, Low: {today_low_f}F/{today_low_c}C. "
          "\x02Tomorrow:\x02 {tomorrow_conditions}, High: {tomorrow_high_f}F/{tomorrow_high_c}C, "
          "Low: {tomorrow_low_f}F/{tomorrow_low_c}C - {url}".format(**weather_data))
    if text and save:
        database.set(db,'users','location',text,'nick',nick)