Пример #1
0
def command_fullweather(bot, user, channel, args):
    """.fullweather (location) - Gets more weather info from Weather Underground (wind speed and barometric pressure)"""
    global defaults, defaultsLower
    nick = getnick.get(user)
    
    if not args:
        if nick in defaults:
            parsed = get_weather(bot, nick, channel, defaults[nick], True)
        else:
            return bot.say(channel,"No location specified, and no default found! Use '.weather set [LOC]' to set a default.")
    elif args in defaultsLower:
        parsed = get_weather(bot, nick, channel, defaultsLower[args], True)
    else:
        parsed = get_weather(bot, nick, channel, args, True)
        
    info = parsed['current_observation']
    
    wind = info['wind_mph']
    direction = info['wind_dir']
    pressure = info['pressure_mb']
    
    if info['pressure_trend'] == "-":
        pressuretext = "downward"
    else:
        pressuretext = "upward"
    
    bot.say(channel, "Wind: %smph from the %s | Pressure: %smb, trending %s" % (wind, direction, pressure, pressuretext))
    
    history = info['history_url']
    
    bot.say(channel, "Station history at: %s" % history)
Пример #2
0
def command_forecast(bot, user, channel, args):
    """.forecast (location) - Gets next two forecast periods from Weather Underground"""
    global defaults, defaultsLower
    nick = getnick.get(user)
    
    if not args:
        if nick in defaults:
            parsed = get_weather(bot, nick, channel, defaults[nick], False)
        else:
            return bot.say(channel,"No location specified, and no default found! Use '.weather set [LOC]' to set a default.")
    elif args in defaultsLower:
        parsed = get_weather(bot, nick, channel, defaultsLower[args], False)
    else:
        parsed = get_weather(bot, nick, channel, args, False)
    
    time = parsed['current_observation']['local_time_rfc822']
    hour = int(time[17:19])

    if hour > 20: #After 8pm, start with tomorrow day
        start = 2
    elif hour > 14: #After 2pm, before 8pm, show tonight and tomorrow day
        start = 1
    else: #Before 2pm, show today and tonight
        start = 0
    
    forecast = parsed['forecast']['txt_forecast']['forecastday']
    
    firstName = forecast[start]['title']
    firstFcast = forecast[start]['fcttext']
    
    nextName = forecast[start + 1]['title']
    nextFcast = forecast[start + 1]['fcttext']
    
    bot.say(channel, "Forecast for %s: %s" % (firstName, firstFcast))
    bot.say(channel, "For %s: %s" % (nextName, nextFcast))
Пример #3
0
def command_time(bot, user, channel, args):
    """.time (location) - Gets the current time and time zone of a location"""
    global defaults, defaultsLower
    nick = getnick.get(user)

    if not args:
        if nick in defaults:
            parsed = get_weather(bot, nick, channel, defaults[nick], False)
        else:
            return bot.say(channel,"No location specified! I hope you already know what time it is where you are.")
    elif args.lower() in defaultsLower:
        parsed = get_weather(bot, nick, channel, defaultsLower[args], False)
    else:
        parsed = get_weather(bot, nick, channel, args, False)
        
    try:
        info = parsed['current_observation']
        
        location = info['display_location']['full']
        time = info['local_time_rfc822']
        zone = info['local_tz_long']
        bot.say(channel, "In %s, it is currently %s (%s)" % (location, time, zone))
    except KeyError:
        error = parsed['response']['error']['description']
        bot.say(channel, "ERROR: %s [for query '%s']" % (error, location))
        pass
Пример #4
0
def command_records(bot, user, channel, args):
    """.records (location) - Gets the average and record temps for a location from Weather Underground"""
    global defaults, defaultsLower
    nick = getnick.get(user)

    if not args:
        if nick in defaults:
            parsed = get_weather(bot, nick, channel, defaults[nick], False)
        else:
            return bot.say(
                channel,
                "No location specified, and no default found! Use '.weather set [LOC]' to set a default."
            )
    elif args in defaultsLower:
        parsed = get_weather(bot, nick, channel, defaultsLower[args], False)
    else:
        parsed = get_weather(bot, nick, channel, args, False)

    airport = parsed['almanac']['airport_code']
    highInfo = parsed['almanac']['temp_high']
    lowInfo = parsed['almanac']['temp_low']

    highTemp = highInfo['record']['F']
    lowTemp = lowInfo['record']['F']
    highYear = highInfo['recordyear']
    lowYear = lowInfo['recordyear']

    degree_sign = u'\N{DEGREE SIGN}'
    bot.say(
        channel, "Today at %s: Highest %s (%s), Lowest %s (%s)" %
        (airport, str(highTemp) + degree_sign + 'F', highYear,
         str(lowTemp) + degree_sign + 'F', lowYear))
Пример #5
0
def command_tell(bot, user, channel, args):
    """.tell [nick] [message] - Instructs the bot to relay a message to a user when they next join the channel"""
    global tells
    splut = args.split(' ', 1)

    if len(splut) < 2:
        bot.say(channel, "You must provide both a username and a message!")
        return

    nick = splut[0]
    fnick = getnick.get(user)

    tells.append({
        'to': nick,
        'from': fnick,
        'channel': channel,
        'message': splut[1]
    })

    bot.say(channel,
            "%s: I will tell that to %s next time I see him!" % (fnick, nick))

    with open(
            os.path.join(sys.path[0], 'modules', 'module_tell_messages.json'),
            'w') as tellfile:
        json.dump(tells, tellfile, indent=2)
Пример #6
0
def update_user(user, action, msg=None):
    global users
    users[getnick.get(user).lower()] = {
        'time': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        'action': action,
        'msg': msg
    }
Пример #7
0
def command_weather(bot, user, channel, args):
    """.weather [set] (location) - Gets weather from Weather Underground (Can store per-user defaults). Also
    .fullweather, .forecast, .records"""
    global defaults, defaultsLower
    nick = getnick.get(user)

    if not args:
        if nick == "ashandarei":
            return bot.say(
                channel, "ashandarei: I dunno, probably like a perfect 72" +
                degree_sign + "F, you jerk")
        if nick in defaults:
            return get_weather(bot, nick, channel, defaults[nick], True)
        else:
            return bot.say(
                channel,
                "No location specified, and no default found! Use '.weather set [LOC]' to set a default."
            )

    splut = args.split(' ', 1)
    cmd = splut[0].lower()
    if cmd == "set":
        set_weather_default(bot, nick, channel, splut[1])
    elif cmd in defaultsLower:
        return get_weather(bot, nick, channel, defaultsLower[cmd], True)
    else:
        return get_weather(bot, nick, channel, args, True)
Пример #8
0
def command_time(bot, user, channel, args):
    """.time (location) - Gets the current time and time zone of a location"""
    global defaults, defaultsLower
    nick = getnick.get(user)

    if not args:
        if nick in defaults:
            parsed = get_weather(bot, nick, channel, defaults[nick], False)
        else:
            return bot.say(
                channel,
                "No location specified! I hope you already know what time it is where you are."
            )
    elif args.lower() in defaultsLower:
        parsed = get_weather(bot, nick, channel, defaultsLower[args], False)
    else:
        parsed = get_weather(bot, nick, channel, args, False)

    try:
        info = parsed['current_observation']

        location = info['display_location']['full']
        time = info['local_time_rfc822']
        zone = info['local_tz_long']
        bot.say(channel,
                "In %s, it is currently %s (%s)" % (location, time, zone))
    except KeyError:
        error = parsed['response']['error']['description']
        bot.say(channel, "ERROR: %s [for query '%s']" % (error, location))
        pass
Пример #9
0
def command_records(bot, user, channel, args):
    """.records (location) - Gets the average and record temps for a location from Weather Underground"""
    global defaults, defaultsLower
    nick = getnick.get(user)
    
    if not args:
        if nick in defaults:
            parsed = get_weather(bot, nick, channel, defaults[nick], False)
        else:
            return bot.say(channel,"No location specified, and no default found! Use '.weather set [LOC]' to set a default.")
    elif args in defaultsLower:
        parsed = get_weather(bot, nick, channel, defaultsLower[args], False)
    else:
        parsed = get_weather(bot, nick, channel, args, False)
    
    airport = parsed['almanac']['airport_code']
    highInfo = parsed['almanac']['temp_high']
    lowInfo = parsed['almanac']['temp_low']
    
    highTemp = highInfo['record']['F']
    lowTemp = lowInfo['record']['F']
    highYear = highInfo['recordyear']
    lowYear = lowInfo['recordyear']
    
    degree_sign = u'\N{DEGREE SIGN}'
    bot.say(channel, "Today at %s: Highest %s (%s), Lowest %s (%s)" % (airport, str(highTemp) + degree_sign + 'F', highYear, str(lowTemp) + degree_sign + 'F', lowYear))
Пример #10
0
def check_messages(bot, user):
    global tells
    nick = getnick.get(user).lower()

    found = False
    for tell in tells:
        if tell["to"].lower() == nick:
            bot.say(str(tell["channel"]), "%s: Hey, %s says: %s" % (tell["to"], tell["from"], tell["message"]))
            tells.remove(tell)
            found = True

    if found:
        with open(os.path.join(sys.path[0], 'modules', 'module_tell_messages.json'), 'w') as tellfile:
            json.dump(tells, tellfile, indent=2)
Пример #11
0
def command_assess(bot, user, channel, args):
    """.assess [topic] - WhatDoesTheInternetThink.net about whatever topic"""
    url = "http://www.whatdoestheinternetthink.net/core/getdata.php?query=%s&searchtype=1" % args
    headers = {
        "Host": "www.whatdoestheinternetthink.net",
        "User-Agent":
        "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0",
        "Accept": "application/json, text/javascript, */*",
        "Content-Type": "application/x-www-form-urlencoded",
        "Accept-Encoding": "gzip, deflate",
        "X-Requested-With": "XMLHttpRequest",
        "Referer": "http://www.whatdoestheinternetthink.net/"
    }

    data = requests.get(url, headers=headers)
    parsed = json.loads(data.content)

    try:
        pos = float(parsed[1]['positive'])
    except Exception:
        return bot.say(
            channel,
            "{0}: The internet has no opinion on that insignificant topic!".
            format(getnick.get(user)))

    neg = float(parsed[1]['negative'])
    neu = float(parsed[1]['indifferent'])

    total = pos + neg + neu
    posperc = int((pos / total) * 100)
    negperc = int((neg / total) * 100)
    neuperc = int((neu / total) * 100)

    return bot.say(
        channel,
        "{0}: The internet is {1}% positive, {2}% negative, and {3}% neutral about that!"
        .format(getnick.get(user), posperc, negperc, neuperc))
Пример #12
0
def command_store(bot, user, channel, args):
    """.store [key] [value] - Store arbitrary text under a given key for later reference (key is one word)"""
    global data
    nick = getnick.get(user)

    input = str(args).split()
    if len(input) < 2:
        log.info("Failed to store data with args: %s" % args)
        bot.say(channel, "Could not store data; must provide both key and string data.")
    else:
        newkey = input[0]
        for key in data.keys():
            if newkey.lower() == key.lower():
                return bot.say(channel, "Could not store data; that key is already in use.")
        data[newkey] = args[args.find(' ')+1:]
        bot.say(channel, "Data succesfully added for key: %s" % newkey)
        with open(os.path.join(sys.path[0], 'modules', 'module_store_conf.json'),'w') as datafile:
            json.dump(data, datafile, indent=2)
Пример #13
0
def check_messages(bot, user):
    global tells
    nick = getnick.get(user).lower()

    found = False
    for tell in tells:
        if tell["to"].lower() == nick:
            bot.say(
                str(tell["channel"]), "%s: Hey, %s says: %s" %
                (tell["to"], tell["from"], tell["message"]))
            tells.remove(tell)
            found = True

    if found:
        with open(
                os.path.join(sys.path[0], 'modules',
                             'module_tell_messages.json'), 'w') as tellfile:
            json.dump(tells, tellfile, indent=2)
Пример #14
0
def command_weather(bot, user, channel, args):
    """.weather [set] (location) - Gets weather from Weather Underground (Can store per-user defaults). Also .fullweather, .forecast"""
    global defaults, defaultsLower
    nick = getnick.get(user)
    
    if not args:
        if nick in defaults:
            return get_weather(bot, nick, channel, defaults[nick], True)
        else:
            return bot.say(channel,"No location specified, and no default found! Use '.weather set [LOC]' to set a default.")
    
    splut = args.split(' ', 1)
    cmd = splut[0].lower();
    if cmd == "set":
        set_weather_default(bot, nick, channel, splut[1])
    elif cmd in defaultsLower:
        return get_weather(bot, nick, channel, defaultsLower[cmd], True)
    else:
        return get_weather(bot, nick, channel, args, True)
Пример #15
0
def command_tell(bot, user, channel, args):
    """.tell [nick] [message] - Instructs the bot to relay a message to a user when they next join the channel"""
    global tells
    splut = args.split(' ', 1)

    if len(splut) < 2:
        bot.say(channel, "You must provide both a username and a message!")
        return

    nick = splut[0]
    fnick = getnick.get(user)

    tells.append({'to': nick,
                  'from': fnick,
                  'channel': channel,
                  'message': splut[1]})

    bot.say(channel, "%s: I will tell that to %s next time I see him!" % (fnick, nick))

    with open(os.path.join(sys.path[0], 'modules', 'module_tell_messages.json'), 'w') as tellfile:
        json.dump(tells, tellfile, indent=2)
Пример #16
0
def command_forecast(bot, user, channel, args):
    """.forecast (location) - Gets next two forecast periods from Weather Underground"""
    global defaults, defaultsLower
    nick = getnick.get(user)

    if not args:
        if nick in defaults:
            parsed = get_weather(bot, nick, channel, defaults[nick], False)
        else:
            return bot.say(
                channel,
                "No location specified, and no default found! Use '.weather set [LOC]' to set a default."
            )
    elif args in defaultsLower:
        parsed = get_weather(bot, nick, channel, defaultsLower[args], False)
    else:
        parsed = get_weather(bot, nick, channel, args, False)

    time = parsed['current_observation']['local_time_rfc822']
    hour = int(time[17:19])

    if hour > 20:  #After 8pm, start with tomorrow day
        start = 2
    elif hour > 14:  #After 2pm, before 8pm, show tonight and tomorrow day
        start = 1
    else:  #Before 2pm, show today and tonight
        start = 0

    forecast = parsed['forecast']['txt_forecast']['forecastday']

    firstName = forecast[start]['title']
    firstFcast = forecast[start]['fcttext']

    nextName = forecast[start + 1]['title']
    nextFcast = forecast[start + 1]['fcttext']

    bot.say(channel, "Forecast for %s: %s" % (firstName, firstFcast))
    bot.say(channel, "For %s: %s" % (nextName, nextFcast))
Пример #17
0
def command_assess(bot, user, channel, args):
    """.assess [topic] - WhatDoesTheInternetThink.net about whatever topic"""
    url = "http://www.whatdoestheinternetthink.net/core/getdata.php?query=%s&searchtype=1" % args
    headers = {
        "Host": "www.whatdoestheinternetthink.net",
        "User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0",
        "Accept": "application/json, text/javascript, */*",
        "Content-Type": "application/x-www-form-urlencoded",
        "Accept-Encoding": "gzip, deflate",
        "X-Requested-With": "XMLHttpRequest",
        "Referer": "http://www.whatdoestheinternetthink.net/",
    }

    data = requests.get(url, headers=headers)
    parsed = json.loads(data.content)

    try:
        pos = float(parsed[1]["positive"])
    except Exception:
        return bot.say(
            channel, "{0}: The internet has no opinion on that insignificant topic!".format(getnick.get(user))
        )

    neg = float(parsed[1]["negative"])
    neu = float(parsed[1]["indifferent"])

    total = pos + neg + neu
    posperc = int((pos / total) * 100)
    negperc = int((neg / total) * 100)
    neuperc = int((neu / total) * 100)

    return bot.say(
        channel,
        "{0}: The internet is {1}% positive, {2}% negative, and {3}% neutral about that!".format(
            getnick.get(user), posperc, negperc, neuperc
        ),
    )
Пример #18
0
def command_fullweather(bot, user, channel, args):
    """.fullweather (location) - Gets more weather info from Weather Underground (wind speed and barometric pressure)"""
    global defaults, defaultsLower
    nick = getnick.get(user)

    if not args:
        if nick in defaults:
            parsed = get_weather(bot, nick, channel, defaults[nick], True)
        else:
            return bot.say(
                channel,
                "No location specified, and no default found! Use '.weather set [LOC]' to set a default."
            )
    elif args in defaultsLower:
        parsed = get_weather(bot, nick, channel, defaultsLower[args], True)
    else:
        parsed = get_weather(bot, nick, channel, args, True)

    info = parsed['current_observation']

    wind = info['wind_mph']
    direction = info['wind_dir']
    pressure = info['pressure_mb']

    if info['pressure_trend'] == "-":
        pressuretext = "downward"
    else:
        pressuretext = "upward"

    bot.say(
        channel, "Wind: %smph from the %s | Pressure: %smb, trending %s" %
        (wind, direction, pressure, pressuretext))

    history = info['history_url']

    bot.say(channel, "Station history at: %s" % history)
Пример #19
0
def command_rname(bot, user, channel, args):
    """.rname [gender] [type] - Generates a random name of the specified type from BehindTheName.com"""
    inputs = args.split()
    
    gender = ""
    usage = ""
    
    for arg in inputs:
        if arg.lower() in genders:
            gender = arg
        else:
            usage += ' ' + arg
            
    usage = usage.strip()
            
    usage_codes = {
        "African": "afr",
        "Akan": "aka",
        "Albanian": "alb",
        "Algonquin": "alg",
        "Native American": "ame",
        "Amharic": "amh",
        "Ancient": "anci",
        "Apache": "apa",
        "Arabic": "ara",
        "Armenian": "arm",
        "Astronomy": "astr",
        "Indigenous Australian": "aus",
        "Aymara": "aym",
        "Azerbaijani": "aze",
        "Basque": "bas",
        "Bengali": "ben",
        "Berber": "ber",
        "Biblical": "bibl",
        "Bosnian": "bos",
        "Breton": "bre",
        "Bulgarian": "bul",
        "Catalan": "cat",
        "Ancient Celtic": "cela",
        "Celtic Mythology": "celm",
        "Chinese": "chi",
        "Choctaw": "cht",
        "Comanche": "com",
        "Coptic": "cop",
        "Cornish": "cor",
        "Cree": "cre",
        "Croatian": "cro",
        "Corsican": "crs",
        "Czech": "cze",
        "Danish": "dan",
        "Dutch": "dut",
        "English": "eng",
        "Esperanto": "esp",
        "Estonian": "est",
        "Ewe": "ewe",
        "Fairy": "fairy",
        "Filipino": "fil",
        "Finnish": "fin",
        "Flemish": "fle",
        "French": "fre",
        "Frisian": "fri",
        "Galician": "gal",
        "Ganda": "gan",
        "Georgian": "geo",
        "German": "ger",
        "Goth": "goth",
        "Greek": "gre",
        "Ancient Greek": "grea",
        "Greek Mythology": "grem",
        "Greenlandic": "grn",
        "Hawaiian": "haw",
        "Hillbilly": "hb",
        "Hippy": "hippy",
        "History": "hist",
        "Hungarian": "hun",
        "Ibibio": "ibi",
        "Icelandic": "ice",
        "Igbo": "igb",
        "Indian": "ind",
        "Indian Mythology": "indm",
        "Indonesian": "ins",
        "Inuit": "inu",
        "Iranian": "ira",
        "Irish": "iri",
        "Iroquois": "iro",
        "Italian": "ita",
        "Japanese": "jap",
        "Jewish": "jew",
        "Kazakh": "kaz",
        "Khmer": "khm",
        "Kikuyu": "kik",
        "Kreatyve": "kk",
        "Korean": "kor",
        "Kurdish": "kur",
        "Kyrgyz": "kyr",
        "Latvian": "lat",
        "Limburgish": "lim",
        "Literature": "lite",
        "Lithuanian": "lth",
        "Luhya": "luh",
        "Luo": "luo",
        "Macedonian": "mac",
        "Maltese": "mal",
        "Manx": "man",
        "Maori": "mao",
        "Mapuche": "map",
        "Mayan": "may",
        "Medieval": "medi",
        "Mongolian": "mon",
        "Mormon": "morm",
        "Mwera": "mwe",
        "Mythology": "myth",
        "Nahuatl": "nah",
        "Navajo": "nav",
        "Ndebele": "nde",
        "Norwegian": "nor",
        "Nuu-chah-nulth": "nuu",
        "Occitan": "occ",
        "Ojibwe": "oji",
        "Pacific/Polynesian": "pac",
        "Pakistani": "pak",
        "Pet": "pets",
        "Polish": "pol",
        "Popular Culture": "popu",
        "Portuguese": "por",
        "Punjabi": "pun",
        "Quechua": "que",
        "Rapper": "rap",
        "Romanian": "rmn",
        "Ancient Roman": "roma",
        "Roman Mythology": "romm",
        "Russian": "rus",
        "Sami": "sam",
        "Norse Mythology": "scam",
        "Scottish": "sco",
        "Serbian": "ser",
        "Shawnee": "sha",
        "Shona": "sho",
        "Sioux": "sio",
        "Norse Mythology": "slam",
        "Slovak": "slk",
        "Slovene": "sln",
        "Sotho": "sot",
        "Spanish": "spa",
        "Swahili": "swa",
        "Swedish": "swe",
        "Tagalog": "tag",
        "Tamil": "tam",
        "Telugu": "tel",
        "Ancient Germanic": "teua",
        "Thai": "tha",
        "Theology": "theo",
        "Tibetan": "tib",
        "Transformer": "trans",
        "Tswana": "tsw",
        "Tumbuka": "tum",
        "Turkish": "tur",
        "Ukrainian": "ukr",
        "?": "unkn",
        "Urdu": "urd",
        "American": "usa",
        "Various": "vari",
        "Vietnamese": "vie",
        "Welsh": "wel",
        "Witch": "witch",
        "Wrestler": "wrest",
        "Xhosa": "xho",
        "Yao": "yao",
        "Yoruba": "yor",
        "Zapotec": "zap",
        "Zulu": "zul",
    }
    
    matched = False
    for full, code in usage_codes.items():
        if usage.lower() == full.lower() or usage.lower() == code.lower():
            usage = code
            utext = full
            matched = True
            break
            
    if matched is False:
        return bot.say(channel, "No code found for '%s.' (http://www.behindthename.com/api/appendix2.php)" % usage)

    if gender.lower() == 'm':
        gtext = "a man"
    elif gender.lower() == 'f':
        gtext = "a woman"
    else:
        gender = 'both'
        gtext = "any gender"

    data = urllib.urlopen(api % (usage, gender))
    parsed = bs4(data,'xml')
    
    nick = getnick.get(user)

    return bot.say(channel, "%s: Random %s name for %s: %s" % (nick, utext, gtext, parsed.get_text().encode('utf8').strip()))
Пример #20
0
def update_user(user, action, msg=None):
    global users
    users[getnick.get(user).lower()] = {'time': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
                                        'action': action,
                                        'msg': msg}
Пример #21
0
def command_why(bot, user, channel, args):
    """.why - Gives a random excuse from http://developerexcuses.com/"""
    page = bot.get_url("http://developerexcuses.com/")
    text = BeautifulSoup(page.text).find("a", {"href": "/"}).text

    bot.say(channel, "%s: %s" % (getnick.get(user), text))
Пример #22
0
def command_rname(bot, user, channel, args):
    """.rname [gender] [type] - Generates a random name of the specified type from BehindTheName.com"""
    inputs = args.split()

    gender = ""
    usage = ""

    for arg in inputs:
        if arg.lower() in genders:
            gender = arg
        else:
            usage += ' ' + arg

    usage = usage.strip()

    usage_codes = {
        "African": "afr",
        "Akan": "aka",
        "Albanian": "alb",
        "Algonquin": "alg",
        "Native American": "ame",
        "Amharic": "amh",
        "Ancient": "anci",
        "Apache": "apa",
        "Arabic": "ara",
        "Armenian": "arm",
        "Astronomy": "astr",
        "Indigenous Australian": "aus",
        "Aymara": "aym",
        "Azerbaijani": "aze",
        "Basque": "bas",
        "Bengali": "ben",
        "Berber": "ber",
        "Biblical": "bibl",
        "Bosnian": "bos",
        "Breton": "bre",
        "Bulgarian": "bul",
        "Catalan": "cat",
        "Ancient Celtic": "cela",
        "Celtic Mythology": "celm",
        "Chinese": "chi",
        "Choctaw": "cht",
        "Comanche": "com",
        "Coptic": "cop",
        "Cornish": "cor",
        "Cree": "cre",
        "Croatian": "cro",
        "Corsican": "crs",
        "Czech": "cze",
        "Danish": "dan",
        "Dutch": "dut",
        "English": "eng",
        "Esperanto": "esp",
        "Estonian": "est",
        "Ewe": "ewe",
        "Fairy": "fairy",
        "Filipino": "fil",
        "Finnish": "fin",
        "Flemish": "fle",
        "French": "fre",
        "Frisian": "fri",
        "Galician": "gal",
        "Ganda": "gan",
        "Georgian": "geo",
        "German": "ger",
        "Goth": "goth",
        "Greek": "gre",
        "Ancient Greek": "grea",
        "Greek Mythology": "grem",
        "Greenlandic": "grn",
        "Hawaiian": "haw",
        "Hillbilly": "hb",
        "Hippy": "hippy",
        "History": "hist",
        "Hungarian": "hun",
        "Ibibio": "ibi",
        "Icelandic": "ice",
        "Igbo": "igb",
        "Indian": "ind",
        "Indian Mythology": "indm",
        "Indonesian": "ins",
        "Inuit": "inu",
        "Iranian": "ira",
        "Irish": "iri",
        "Iroquois": "iro",
        "Italian": "ita",
        "Japanese": "jap",
        "Jewish": "jew",
        "Kazakh": "kaz",
        "Khmer": "khm",
        "Kikuyu": "kik",
        "Kreatyve": "kk",
        "Korean": "kor",
        "Kurdish": "kur",
        "Kyrgyz": "kyr",
        "Latvian": "lat",
        "Limburgish": "lim",
        "Literature": "lite",
        "Lithuanian": "lth",
        "Luhya": "luh",
        "Luo": "luo",
        "Macedonian": "mac",
        "Maltese": "mal",
        "Manx": "man",
        "Maori": "mao",
        "Mapuche": "map",
        "Mayan": "may",
        "Medieval": "medi",
        "Mongolian": "mon",
        "Mormon": "morm",
        "Mwera": "mwe",
        "Mythology": "myth",
        "Nahuatl": "nah",
        "Navajo": "nav",
        "Ndebele": "nde",
        "Norwegian": "nor",
        "Nuu-chah-nulth": "nuu",
        "Occitan": "occ",
        "Ojibwe": "oji",
        "Pacific/Polynesian": "pac",
        "Pakistani": "pak",
        "Pet": "pets",
        "Polish": "pol",
        "Popular Culture": "popu",
        "Portuguese": "por",
        "Punjabi": "pun",
        "Quechua": "que",
        "Rapper": "rap",
        "Romanian": "rmn",
        "Ancient Roman": "roma",
        "Roman Mythology": "romm",
        "Russian": "rus",
        "Sami": "sam",
        "Norse Mythology": "scam",
        "Scottish": "sco",
        "Serbian": "ser",
        "Shawnee": "sha",
        "Shona": "sho",
        "Sioux": "sio",
        "Norse Mythology": "slam",
        "Slovak": "slk",
        "Slovene": "sln",
        "Sotho": "sot",
        "Spanish": "spa",
        "Swahili": "swa",
        "Swedish": "swe",
        "Tagalog": "tag",
        "Tamil": "tam",
        "Telugu": "tel",
        "Ancient Germanic": "teua",
        "Thai": "tha",
        "Theology": "theo",
        "Tibetan": "tib",
        "Transformer": "trans",
        "Tswana": "tsw",
        "Tumbuka": "tum",
        "Turkish": "tur",
        "Ukrainian": "ukr",
        "?": "unkn",
        "Urdu": "urd",
        "American": "usa",
        "Various": "vari",
        "Vietnamese": "vie",
        "Welsh": "wel",
        "Witch": "witch",
        "Wrestler": "wrest",
        "Xhosa": "xho",
        "Yao": "yao",
        "Yoruba": "yor",
        "Zapotec": "zap",
        "Zulu": "zul",
    }

    matched = False
    for full, code in usage_codes.items():
        if usage.lower() == full.lower() or usage.lower() == code.lower():
            usage = code
            utext = full
            matched = True
            break

    if matched is False:
        return bot.say(
            channel,
            "No code found for '%s.' (http://www.behindthename.com/api/appendix2.php)"
            % usage)

    if gender.lower() == 'm':
        gtext = "a man"
    elif gender.lower() == 'f':
        gtext = "a woman"
    else:
        gender = 'both'
        gtext = "any gender"

    data = urllib.urlopen(api % (usage, gender))
    parsed = bs4(data, 'xml')

    nick = getnick.get(user)

    return bot.say(
        channel, "%s: Random %s name for %s: %s" %
        (nick, utext, gtext, parsed.get_text().encode('utf8').strip()))