Пример #1
0
def waifu(gender, args="", otp=False, DISCORD=False, user_id=False):
    if gender == 0:
        list_name = "Waifu"
        end_tag = "1girl+solo"
    else:
        list_name = "Husbando"
        end_tag = "-1girl+-female"
    result = ""
    lines = utils.file_to_list(
        os.path.join(settings['list_loc'],
                     list_name + " List.txt"))
    args = ' '.join(args.split()).lower()
    matched = []
    ignore = ["high-school-dxd", "love-live",
              "aoki-hagane-no-arpeggio", "kantai-collection",
              "aikatsu", "akb0048", "idolmaster",
              "idolmaster-cinderella-girls"]
    if len(args) > 4:
        for entry in lines:
            if slugify(entry[1], word_boundary=True) in ignore:
                continue
            if slugify(args, word_boundary=True) ==\
               slugify(entry[1], word_boundary=True):
                matched.append(entry)
        # It's not really that random if there isn't that many people matched.
        if len(matched) > 4:
            result = random.choice(matched)
    if not result:
        result = random.choice(lines)

    name, show, otp_img = result
    if otp:
        return name, show, otp_img
    path_name = slugify(name,
                        word_boundary=True, separator="_")
    path = os.path.join(list_name, path_name)
    tweet_image = utils.get_image(path)
    if not tweet_image and not DISCORD:
        tags = [name.replace(" ", "_"), "solo", "-genderswap", end_tag]
        tweet_image = utils.get_image_online(tags, 0, 1,
                                             "", path)
    name = re.sub(r' \([^)]*\)', '', name)
    m = "Your {0} is {1} ({2})".format(list_name.title(),
                                       name, show)
    if user_id:
        st = "{} ({})".format(name, show)
        count_command(list_name, st,
                      os.path.join(settings['user_count_loc'], user_id))
    count_command(list_name, "{} ({})".format(name, show),
                  settings['count_file'])

    return m, tweet_image
Пример #2
0
def mywaifu(user_id, gender):
    if gender == 0:
        gender = "Waifu"
        filename = "users_waifus.json"
    else:
        gender = "Husbando"
        filename = "users_husbandos.json"
    user_waifus_file = open(
        os.path.join(settings['list_loc'], filename), 'r',
        encoding='utf-8')
    user_waifus = json.load(user_waifus_file)
    user_waifus_file.close()
    for user in user_waifus['users']:
        if int(user['twitter_id']) == user_id:
            break
    if int(user['twitter_id']) != user_id:
        count_trigger("mywaifu")
        m = ("I don't know who your {0} is!\n"
             "Use {1}Register!\n"
             "Help: {2}").format(gender, gender,
                                 config_get('Help URLs', 'include_name'))
        return m, False
    tags = user['name'] + user['tags']
    if user.get('max_page'):
        max_page = user['max_page']
    else:
        max_page = 20
    path_name = slugify(user['name'],
                        word_boundary=True, separator="_")
    path = os.path.join(settings['image_loc'],
                        gender.lower(), path_name)
    ignore_list = "user_ignore/{0}".format(user['twitter_id'])
    tweet_image = utils.get_image_online(tags, user['web_index'],
                                         max_page, ignore_list)
    if not tweet_image:
        tweet_image = utils.get_image(path, ignore_list)
    if not tweet_image:
        m = ("Failed to get an image (website could be offline).\n"
             "Help: {0}").format(config_get('Help URLs', 'website_offline'))
        remove_one_limit(user_id, "my" + gender.lower())
        return m, False
    if datetime.datetime.now().isoweekday() == 3:
        m = "#{0}Wednesday".format(gender)
    else:
        m = "#{0}AnyDay".format(gender)
    return m, tweet_image
Пример #3
0
def mywaifu(user_id, gender):
    if gender == 0:
        gender = "Waifu"
        filename = "users_waifus.json"
    else:
        gender = "Husbando"
        filename = "users_husbandos.json"
    user_waifus_file = open(os.path.join(settings['list_loc'], filename),
                            'r',
                            encoding='utf-8')
    user_waifus = json.load(user_waifus_file)
    user_waifus_file.close()
    for user in user_waifus['users']:
        if int(user['twitter_id']) == user_id:
            break
    if int(user['twitter_id']) != user_id:
        count_trigger("mywaifu")
        m = ("I don't know who your {0} is!\n"
             "Use {1}Register!\n"
             "Help: {2}").format(gender, gender,
                                 config_get('Help URLs', 'include_name'))
        return m, False
    tags = user['name'] + user['tags']
    if user.get('max_page'):
        max_page = user['max_page']
    else:
        max_page = 20
    path_name = slugify(user['name'], word_boundary=True, separator="_")
    path = os.path.join(settings['image_loc'], gender.lower(), path_name)
    ignore_list = "user_ignore/{0}".format(user['twitter_id'])
    tweet_image = utils.get_image_online(tags, user['web_index'], max_page,
                                         ignore_list)
    if not tweet_image:
        tweet_image = utils.get_image(path, ignore_list)
    if not tweet_image:
        m = ("Failed to get an image (website could be offline).\n"
             "Help: {0}").format(config_get('Help URLs', 'website_offline'))
        remove_one_limit(user_id, "my" + gender.lower())
        return m, False
    if datetime.datetime.now().isoweekday() == 3:
        m = "#{0}Wednesday".format(gender)
    else:
        m = "#{0}AnyDay".format(gender)
    return m, tweet_image
Пример #4
0
def pictag(tags="", repeat_for=1, DISCORD=False):
    """ Search Safebooru and return random result.
    For Patreon supporters only.
    """
    tags = tags.split(" ")
    tags = [tag.strip() for tag in tags]
    if len(tags) > 5:
        return ("Sorry, can't search more than 5 tags!\n"
                "Example of using tags correctly: "
                "http://safebooru.org/index.php?"
                "page=post&s=list&tags=blake_belladonna+solo+bow", False)
    tweet_image_list = []
    for x in range(0, repeat_for):
        if not DISCORD:
            tweet_image_list.append(
                utils.get_image_online('+'.join(tags), site=2, high_page=10))
        else:
            # Discord
            try:
                url = r"http://safebooru.org/index.php?page=dapi&s=post&q=index&tags=" + '+'.join(tags)
                import urllib.request
                from bs4 import BeautifulSoup
                xml_data = urllib.request.urlopen(url).read()
                soup = BeautifulSoup(xml_data, 'xml')
                posts = [str(i).strip() for i in list(soup.posts)]
                posts = list(filter(None, posts))
                post = BeautifulSoup(random.choice(posts), 'xml')
                return "Result for the tags: {} {}".format(', '.join(tags), post.post['file_url']), False
            except:
                pass
        if not tweet_image_list[0]:
            message = "Sorry failed to get an image! Try different tags!"
            return message, False
        else:
            message = "Result for the tags: {}".format(', '.join(tags))
    return message, tweet_image_list
Пример #5
0
def run_tests():
    print("Login Test:")
    api = functions.login()
    print(api)
    print("\nTest Tweet")
    msg = "@AceStatusBot Running Tests..."
    api.update_status(status=msg)
    print("\nGet Level Test:")
    print(functions.get_level(123))
    print("\nRandom Waifu Test:")
    print(functions.waifu(0))
    print("\nRandom Husbando Test:")
    print(functions.waifu(1))
    # Name should be flipped
    print("\nWaifuRegister Test:")
    print(functions.waifuregister(123, "Test Username", "rin shibuya", 0))
    # Name should return "not enough images"
    print("\nHusbandoReigster Paste Test:")
    print(functions.waifuregister(123, "Test Username", "admiral", 1))
    # Name should work
    print("\nHusbandoReigster Test:")
    print(
        functions.waifuregister(123, "Test Username",
                                "admiral (kantai collection)", 1))
    print("\nMyWaifu Test:")
    print(functions.mywaifu(123, 0))
    print("\nMyHusbando Test:")
    print(functions.mywaifu(123, 1))
    print("\nRemoveWaifu Test:")
    print(functions.waifuremove(123, 0))
    print("\nRemoveHusbando Test:")
    print(functions.waifuremove(123, 1))
    print("\nRandom OTP Test:")
    print(functions.otp(""))
    print("\nRandom List Shipgirl Test:")
    m, i = functions.random_list("Shipgirl", "")
    print(m, i)
    print("\nRandom List Imouto Test:")
    m, ii = functions.random_list("Imouto", "")
    if not i:
        i = ii
    print(m, ii)
    print("\nRandom List Shota Test:")
    print(functions.random_list("Shota", ""))
    print("Sleeping for 10 seconds...")
    time.sleep(10)
    print("\nRandom List Sensei Test:")
    print(functions.random_list("Sensei", ""))
    print("\nRandom List Senpai Test:")
    m, ii = functions.random_list("Senpai", "")
    if not i:
        i = ii
    print(m, ii)
    print("\nRandom List Kouhai Test:")
    print(functions.random_list("Kouhai", ""))
    print("\nRandom List Kouhai Male Test:")
    print(functions.random_list("Kouhai", "male"))
    print("\nAiring Test:")
    print(functions.airing("One Piece"))
    print("\nTest Tweet (with Image)")
    msg = "@AceStatusBot Test Tweet with Image..."
    api.update_with_media(i, status=msg)
    print("\nTest Tweet (with Video)")
    tags = [
        "rating:safe", "webm", "-extremely_large_filesize", "-large_filesize",
        "-no_audio"
    ]
    i = get_image_online(tags, 0, 1, "")
    msg = "@AceStatusBot Test Tweet with Video..."
    api.update_with_media(i, status=msg)
    print("\nFinished all Tests!")
Пример #6
0
def random_list(list_name, args="", DISCORD=False):
    gender = "waifu"
    hashtag = ""
    search_for = ""
    m = False
    lines = False
    show_series = False
    scrape_images = True
    if list_name == "Shipgirl":
        if "aoki" in args:
            lines = utils.file_to_list('Shipgirl Aoki.txt')
        elif "all" in args:
            if "otp" in args:
                list_name += " OTP"
                lines = utils.file_to_list('Shipgirl All OTP.txt')
            else:
                lines = utils.file_to_list('Shipgirl Aoki.txt')
                lines += utils.file_to_list('Shipgirl.txt')
        else:
            hashtag = "#Kancolle"
            if "otp" in args:
                list_name += " OTP"
                lines = utils.file_to_list('Shipgirl OTP.txt')
            else:
                lines = utils.file_to_list('Shipgirl.txt')
    elif list_name == "Touhou":
        hashtag = "#Touhou"
        if "otp" in args:
            list_name += " OTP"
            lines = utils.file_to_list('Touhou OTP.txt')
        else:
            lines = utils.file_to_list('Touhou.txt')
    elif list_name == "Vocaloid":
        hashtag = "#Vocaloids"
        if "otp" in args:
            list_name += " OTP"
            lines = utils.file_to_list('Vocaloid OTP.txt')
        else:
            lines = utils.file_to_list('Vocaloid.txt')
    elif list_name == "Imouto":
        list_name = "Imouto"
        show_series = True
        lines = utils.file_to_list('Imouto.txt')
    elif list_name == "Idol":
        show_series = True
        if "love live" in args or "lovelive" in args:
            search_for = "Love Live!"
            hashtag = "#LoveLive"
            if "otp" in args:
                list_name = "Love Live! OTP"
                show_series = False
                lines = utils.file_to_list('Idol Love Live OTP.txt')
        elif "cinderella" in args or "cinderella" in args:
            search_for = "Idolmaster Cinderella Girls"
            hashtag = "#Idolmaster"
        elif "idolmaster" in args or "idolm@ster" in args:
            search_for = "Idolmaster"
            hashtag = "#Idolmaster"
        elif "akb0048" in args:
            search_for = "AKB0048"
            hashtag = "#akb0048"
        elif "wake" in args:
            search_for = "Wake Up Girls!"
            hashtag = "#WUG_JP"
        elif "aikatsu" in args:
            search_for = "Aikatsu!"
            hashtag = "#Aikatsu"
        if "male" in args:
            list_name = "Male Idol"
            lines = utils.file_to_list('Idol Males.txt')
        else:
            if not lines:
                lines = utils.file_to_list('Idol.txt')
                if search_for:
                    temp_lines = []
                    for line in lines:
                        if line[1] == search_for:
                            temp_lines.append(line)
                    lines = temp_lines
                    del temp_lines
    elif list_name == "Shota":
        show_series = True
        gender = "husbando"
        lines = utils.file_to_list('Shota.txt')
    elif list_name == "Onii":
        list_name = "Onii-chan"
        show_series = True
        gender = "husbando"
        lines = utils.file_to_list('Onii-chan.txt')
    elif list_name == "Onee":
        list_name = "Onee-chan"
        show_series = True
        lines = utils.file_to_list('Onee-chan.txt')
    elif list_name == "Sensei":
        show_series = True
        if "female" in args:
            lines = utils.file_to_list('Sensei Female.txt')
        elif "male" in args:
            gender = "husbando"
            lines = utils.file_to_list('Sensei Male.txt')
        else:
            lines = utils.file_to_list('Sensei Male.txt')
            lines += utils.file_to_list('Sensei Female.txt')
    elif list_name == "Senpai":
        show_series = True
        if "female" in args:
            lines = utils.file_to_list('Senpai Female.txt')
        elif "male" in args:
            gender = "husbando"
            lines = utils.file_to_list('Senpai Male.txt')
        else:
            lines = utils.file_to_list('Senpai Male.txt')
            lines += utils.file_to_list('Senpai Female.txt')
    elif list_name == "Kouhai":
        show_series = True
        if "female" in args:
            lines = utils.file_to_list('Kouhai Female.txt')
        elif "male" in args:
            gender = "husbando"
            lines = utils.file_to_list('Kouhai Male.txt')
        else:
            lines = utils.file_to_list('Kouhai Male.txt')
            lines += utils.file_to_list('Kouhai Female.txt')
    elif list_name == "Monstergirl":
        show_series = True
        scrape_images = True
        lines = utils.file_to_list('Monstergirl.txt')
    elif list_name == "Witchgirl":
        hashtag = "#s_witch"
        show_series = False
        scrape_images = True
        lines = utils.file_to_list('Witchgirl.txt')
    elif list_name == "Tankgirl":
        hashtag = "#garupan"
        show_series = False
        scrape_images = True
        lines = utils.file_to_list('Tankgirl.txt')

    # Under heavy stuff random.choice can be very weak
    # so just a quick way to make sure it's 'random random'
    random.shuffle(lines)
    entry = random.choice(lines)
    if list_name.endswith("OTP"):
        names = entry.split("(x)")
        if list_name == "Touhou":
            tags = "{0}+{1}+2girls+yuri+touhou+-asai_genji+-comic".format(
                names[0].replace(" ", "_"),
                names[1].replace(" ", "_"))
        if "love live" in list_name.lower():
            tags = "{0}+{1}+2girls+yuri+-comic".format(
                names[0].replace(" ", "_"),
                names[1].replace(" ", "_"))
        else:
            tags = "{0}+{1}+yuri+2girls+-comic".format(
                names[0].replace(" ", "_"),
                names[1].replace(" ", "_"))
        name = "{0}(x){1}".format(names[0], names[1])
    else:
        if isinstance(entry, list):
            name = entry[0]
            show = entry[1]
        else:
            name = entry
        if scrape_images:
            tags = "{0}+solo".format(name.replace(" ", "_"))
    path_name = slugify(name,
                        word_boundary=True, separator="_")
    path = "{0}/{1}".format(gender.lower(), path_name)
    tweet_image = utils.get_image(path)
    if scrape_images and not DISCORD or not tweet_image and not DISCORD:
        tweet_image_temp = utils.get_image_online(tags, 0, 1, "", path)
        if tweet_image_temp is not False:
            tweet_image = tweet_image_temp

    name = re.sub(r' \([^)]*\)', '', name)
    hashtag = ""  # TODO: Temp (testing with twitter)
    if show_series:
        m = "Your {0} is {1} ({2}) {3}".format(list_name, name,
                                               show, hashtag)
    elif list_name.endswith("OTP"):
        name_one = re.sub(r' \([^)]*\)', '', names[0])
        name_two = re.sub(r' \([^)]*\)', '', names[1])
        name = "{0} x {1}".format(name_one, name_two)
    if not m:
        m = "Your {0} is {1} {2}".format(list_name, name, hashtag)
        if not list_name.endswith("OTP"):
            count_trigger(name, gender)
    return m, tweet_image
Пример #7
0
def mywaifu(user_id, gender, DISCORD=False, SKIP_DUP_CHECK=False):
    tweet_image = False
    if gender == 0:
        gender = "Waifu"
        filename = "users_waifus.json"
    else:
        gender = "Husbando"
        filename = "users_husbandos.json"
    user_waifus_file = open(
        os.path.join(settings['list_loc'], filename), 'r',
        encoding='utf-8')
    user_waifus = json.load(user_waifus_file)
    user_waifus_file.close()
    for user in user_waifus['users']:
        if int(user['twitter_id']) == int(user_id):
            break
    if int(user['twitter_id']) != int(user_id):
        count_trigger("mywaifu")
        m = ("I don't know who your {0} is!\n"
             "Use {1}Register!\n"
             "Help: {2}").format(gender, gender,
                                 config_get('Help URLs', 'include_name'))
        return m, False
    tags = user['name'] + user['tags']
    if user.get('max_page'):
        max_page = user['max_page']
    else:
        max_page = 20
    path_name = slugify(user['name'],
                        word_boundary=True, separator="_")
    path = os.path.join(settings['image_loc'],
                        gender.lower(), path_name)
    if DISCORD:
        ignore_list = "user_ignore/discord_{0}".format(user['twitter_id'])
        tweet_image = utils.get_image(path, ignore_list)
    else:
        ignore_list = "user_ignore/{0}".format(user['twitter_id'])

    if not DISCORD:
        tweet_image = utils.get_image_online(tags, user['web_index'],
                                             max_page, ignore_list,
                                             path=path)
    if not tweet_image:
        tweet_image = utils.get_image(path, ignore_list)

    if not tweet_image and SKIP_DUP_CHECK:
        tweet_image = utils.get_image(path)

    if not tweet_image:
        m = ("Failed to grab a new image!\nThe main image website could be offline.\n"
             "Help: {0}").format(config_get('Help URLs', 'website_offline'))
        remove_one_limit(user_id, "my" + gender.lower())
        return m, False
    if datetime.datetime.now().isoweekday() == 3:
        # TODO: Remember hashtags here
        m = "{0}Wednesday".format(gender)
    else:
        m = "{0}AnyDay".format(gender)
    if DISCORD:
        # @user's x is x
        m = " {gender} is {name}!".format(
            gender=gender, name=user['name'].replace("_", " ").title())
    return m, tweet_image
Пример #8
0
            if img_count <= 0:
                # Has enough images
                if img_count < -3:
                    # Too many images
                    while img_count < 0:
                        files = os.listdir(path_name)
                        os.remove(os.path.join(path_name, files[0]))
                        img_count += 1
                continue
        else:
            os.makedirs(path_name)

        false_count = 0
        print(path_name)
        for x in range(0, img_count):
            tweet_image = get_image_online(tags, 0, 0, "", path_name)
            if false_count == 2:
                break
            if not tweet_image:
                false_count += 1
                print("$ Possible no images for:")
                print(path_name)
                print("$")
                continue
            else:
                img_count -= 1
        SLEEP_COUNT += 1
        if SLEEP_COUNT == 5:
            SLEEP_COUNT = 0
            time.sleep(120)
        else:
Пример #9
0
def random_list(list_name, args="", DISCORD=False, user_id=False):
    gender = "waifu"
    hashtag = ""
    search_for = ""
    m = False
    lines = False
    end_tags = False
    show_series = False
    scrape_images = True
    message_layout = False
    if list_name == "Shipgirl":
        if "aoki" in args:
            lines = utils.file_to_list('Shipgirl Aoki.txt')
        elif "all" in args:
            if "otp" in args:
                list_name += " OTP"
                lines = utils.file_to_list('Shipgirl All OTP.txt')
            else:
                lines = utils.file_to_list('Shipgirl Aoki.txt')
                lines += utils.file_to_list('Shipgirl.txt')
        else:
            hashtag = "#Kancolle"
            if "otp" in args:
                list_name += " OTP"
                lines = utils.file_to_list('Shipgirl OTP.txt')
            else:
                lines = utils.file_to_list('Shipgirl.txt')
    elif list_name == "Touhou":
        hashtag = "#Touhou"
        if "otp" in args:
            list_name += " OTP"
            lines = utils.file_to_list('Touhou OTP.txt')
        else:
            lines = utils.file_to_list('Touhou.txt')
    elif list_name == "Vocaloid":
        hashtag = "#Vocaloids"
        if "otp" in args:
            list_name += " OTP"
            lines = utils.file_to_list('Vocaloid OTP.txt')
        else:
            lines = utils.file_to_list('Vocaloid.txt')
    elif list_name == "Imouto":
        list_name = "Imouto"
        show_series = True
        lines = utils.file_to_list('Imouto.txt')
    elif list_name == "Idol":
        show_series = True
        if "love live" in args or "lovelive" in args:
            search_for = "Love Live!"
            hashtag = "#LoveLive"
            if "otp" in args:
                list_name = "Love Live! OTP"
                show_series = False
                lines = utils.file_to_list('Idol Love Live OTP.txt')
        elif "cinderella" in args or "cinderella" in args:
            search_for = "Idolmaster Cinderella Girls"
            hashtag = "#Idolmaster"
        elif "idolmaster" in args or "idolm@ster" in args:
            search_for = "Idolmaster"
            hashtag = "#Idolmaster"
        elif "akb0048" in args:
            search_for = "AKB0048"
            hashtag = "#akb0048"
        elif "wake" in args:
            search_for = "Wake Up Girls!"
            hashtag = "#WUG_JP"
        elif "aikatsu" in args:
            search_for = "Aikatsu!"
            hashtag = "#Aikatsu"
        if "male" in args:
            list_name = "Male Idol"
            lines = utils.file_to_list('Idol Males.txt')
        else:
            if not lines:
                lines = utils.file_to_list('Idol.txt')
                if search_for:
                    temp_lines = []
                    for line in lines:
                        if line[1] == search_for:
                            temp_lines.append(line)
                    lines = temp_lines
                    del temp_lines
    elif list_name == "Shota":
        show_series = True
        gender = "husbando"
        lines = utils.file_to_list('Shota.txt')
    elif list_name == "Onii":
        list_name = "Onii-chan"
        show_series = True
        gender = "husbando"
        lines = utils.file_to_list('Onii-chan.txt')
    elif list_name == "Onee":
        list_name = "Onee-chan"
        show_series = True
        lines = utils.file_to_list('Onee-chan.txt')
    elif list_name == "Sensei":
        show_series = True
        if "female" in args:
            lines = utils.file_to_list('Sensei Female.txt')
        elif "male" in args:
            gender = "husbando"
            lines = utils.file_to_list('Sensei Male.txt')
        else:
            if random.randint(0, 10) < 3:
                gender = "husbando"
                lines = utils.file_to_list('Sensei Male.txt')
            else:
                lines = utils.file_to_list('Sensei Female.txt')
    elif list_name == "Senpai":
        show_series = True
        if "female" in args:
            lines = utils.file_to_list('Senpai Female.txt')
        elif "male" in args:
            gender = "husbando"
            lines = utils.file_to_list('Senpai Male.txt')
        else:
            if random.randint(0, 10) < 3:
                gender = "husbando"
                lines = utils.file_to_list('Senpai Male.txt')
            else:
                lines = utils.file_to_list('Senpai Female.txt')
    elif list_name == "Kouhai":
        show_series = True
        if "female" in args:
            lines = utils.file_to_list('Kouhai Female.txt')
        elif "male" in args:
            gender = "husbando"
            lines = utils.file_to_list('Kouhai Male.txt')
        else:
            if random.randint(0, 10) < 3:
                gender = "husbando"
                lines = utils.file_to_list('Kouhai Male.txt')
            else:
                lines = utils.file_to_list('Kouhai Female.txt')
    elif list_name == "Monstergirl":
        show_series = True
        scrape_images = True
        lines = utils.file_to_list('Monstergirl.txt')
    elif list_name == "Witchgirl":
        hashtag = "#s_witch"
        show_series = False
        scrape_images = True
        lines = utils.file_to_list('Witchgirl.txt')
    elif list_name == "Tankgirl":
        hashtag = "#garupan"
        show_series = False
        scrape_images = True
        lines = utils.file_to_list('Tankgirl.txt')
    elif list_name == "Granblue":
        hashtag = ""
        show_series = False
        scrape_images = True
        lines = utils.file_to_list('Granblue.txt')
        message_layout = "{name} has joined your party!"
        end_tags = "+granblue_fantasy"

    # Under heavy stuff random.choice can be very weak
    # so just a quick way to make sure it's 'random random'
    random.shuffle(lines)
    entry = random.choice(lines)
    if list_name.endswith("OTP"):
        names = entry.split("(x)")
        if list_name == "Touhou":
            tags = "{0}+{1}+2girls+yuri+touhou+-asai_genji+-comic".format(
                names[0].replace(" ", "_"),
                names[1].replace(" ", "_"))
        if "love live" in list_name.lower():
            tags = "{0}+{1}+2girls+yuri+-comic".format(
                names[0].replace(" ", "_"),
                names[1].replace(" ", "_"))
        else:
            tags = "{0}+{1}+yuri+2girls+-comic".format(
                names[0].replace(" ", "_"),
                names[1].replace(" ", "_"))
        name = "{0}(x){1}".format(names[0], names[1])
    else:
        if isinstance(entry, list):
            name = entry[0]
            show = entry[1]
        else:
            name = entry
        if scrape_images:
            tags = "{0}+solo+-genderswap".format(name.replace(" ", "_"))
    path_name = slugify(name,
                        word_boundary=True, separator="_")
    path = "{0}/{1}".format(gender.lower(), path_name)
    tweet_image = utils.get_image(path)
    if end_tags:
        tags = tags + end_tags
    if scrape_images and not DISCORD or not tweet_image and not DISCORD:
        tweet_image_temp = utils.get_image_online(tags, 0, 1, "", path)
        if tweet_image_temp is not False:
            tweet_image = tweet_image_temp

    name = re.sub(r' \([^)]*\)', '', name)
    hashtag = ""  # TODO: Temp (testing with twitter)
    if show_series:
        m = "Your {0} is {1} ({2}) {3}".format(list_name, name,
                                               show, hashtag)
    elif list_name.endswith("OTP"):
        name_one = re.sub(r' \([^)]*\)', '', names[0])
        name_two = re.sub(r' \([^)]*\)', '', names[1])
        name = "{0} x {1}".format(name_one, name_two)
    if not m:
        if message_layout:
            m = message_layout.format(name=name)
        else:
            m = "Your {0} is {1} {2}".format(list_name, name, hashtag)

    if not list_name.endswith("OTP"):
        if user_id:
            if show_series:
                st = "{} ({})".format(list_name, name, show)
            else:
                st = "{}".format(name)
            count_command(list_name, st,
                          os.path.join(settings['user_count_loc'],
                                       user_id))
        count_command(list_name, name, settings['count_file'])
    return m, tweet_image
Пример #10
0
def mywaifu(user_id, gender, DISCORD=False,
            SKIP_DUP_CHECK=False, repeat_for=1):
    tweet_image = False
    if gender == 0:
        gender = "Waifu"
        filename = "users_waifus.json"
    else:
        gender = "Husbando"
        filename = "users_husbandos.json"
    user_waifus_file = open(
        os.path.join(settings['list_loc'], filename), 'r',
        encoding='utf-8')
    user_waifus = json.load(user_waifus_file)
    user_waifus_file.close()
    for user in user_waifus['users']:
        if int(user['twitter_id']) == int(user_id):
            break
    if int(user['twitter_id']) != int(user_id):
        count_trigger("mywaifu")
        m = ("I don't know who your {0} is!\n"
             "Use {1}Register!\n"
             "or just try say \"{1}\"!\n"
             "Help: {2}").format(gender, gender,
                                 config_get('Help URLs', 'include_name'))
        return m, False
    tags = user['name'] + user['tags']
    if user.get('max_page'):
        max_page = user['max_page']
    else:
        max_page = 20
    path_name = slugify(user['name'],
                        word_boundary=True, separator="_")
    path = os.path.join(settings['image_loc'],
                        gender.lower(), path_name)
    tweet_image_list = []
    for x in range(0, repeat_for):
        if DISCORD:
            ignore_list = "user_ignore/discord_{0}".format(user['twitter_id'])
            tweet_image = utils.get_image(path, ignore_list)
        else:
            ignore_list = "user_ignore/{0}".format(user['twitter_id'])

        if not DISCORD:
            tweet_image = utils.get_image_online(tags, user['web_index'],
                                                 max_page, ignore_list,
                                                 path=path)
        if not tweet_image:
            tweet_image = utils.get_image(path, ignore_list)

        if not tweet_image and SKIP_DUP_CHECK:
            tweet_image = utils.get_image(path)

        if not tweet_image:
            m = ("Failed to grab a new image!\n"
                 "The main image website could be offline.\n"
                 "Help: {0}").format(config_get('Help URLs',
                                                'website_offline'))
            remove_one_limit(user_id, "my" + gender.lower())
            return m, False
        tweet_image_list.append(tweet_image)

    if datetime.datetime.now().isoweekday() == 3:
        m = "#{0}Wednesday".format(gender)
    else:
        m = ""
    if DISCORD:
        # @user's x is x
        m = " {gender} is {name}!".format(
            gender=gender, name=user['name'].replace("_", " ").title())
    if len(tweet_image_list) > 1:
        return m, tweet_image_list
    return m, tweet_image
Пример #11
0
            if img_count <= 0:
                # Has enough images
                if img_count < -3:
                    # Too many images
                    while img_count < 0:
                        files = os.listdir(path_name)
                        os.remove(os.path.join(path_name, files[0]))
                        img_count += 1
                continue
        else:
            os.makedirs(path_name)

        false_count = 0
        print(path_name)
        for x in range(0, img_count):
            tweet_image = get_image_online(tags, 0, 0, "", path_name)
            if false_count == 2:
                break
            if not tweet_image:
                false_count += 1
                print("$ Possible no images for:")
                print(path_name)
                print("$")
                continue
            else:
                img_count -= 1
        SLEEP_COUNT += 1
        if SLEEP_COUNT == 5:
            SLEEP_COUNT = 0
            time.sleep(120)
        else:
Пример #12
0
def random_list(list_name, args=""):
    gender = "waifu"
    hashtag = ""
    search_for = ""
    m = False
    lines = False
    show_series = False
    scrape_images = True
    if list_name == "Shipgirl":
        if "aoki" in args:
            lines = utils.file_to_list('Shipgirl Aoki.txt')
        elif "all" in args:
            if "otp" in args:
                list_name += " OTP"
                lines = utils.file_to_list('Shipgirl All OTP.txt')
            else:
                lines = utils.file_to_list('Shipgirl Aoki.txt')
                lines += utils.file_to_list('Shipgirl.txt')
        else:
            hashtag = "#Kancolle"
            if "otp" in args:
                list_name += " OTP"
                lines = utils.file_to_list('Shipgirl OTP.txt')
            else:
                lines = utils.file_to_list('Shipgirl.txt')
    elif list_name == "Touhou":
        hashtag = "#Touhou"
        if "otp" in args:
            list_name += " OTP"
            lines = utils.file_to_list('Touhou OTP.txt')
        else:
            lines = utils.file_to_list('Touhou.txt')
    elif list_name == "Vocaloid":
        hashtag = "#Vocaloids"
        if "otp" in args:
            list_name += " OTP"
            lines = utils.file_to_list('Vocaloid OTP.txt')
        else:
            lines = utils.file_to_list('Vocaloid.txt')
    elif list_name == "Imouto":
        list_name = "Imouto"
        show_series = True
        lines = utils.file_to_list('Imouto.txt')
    elif list_name == "Idol":
        show_series = True
        if "love live" in args or "lovelive" in args:
            search_for = "Love Live!"
            hashtag = "#LoveLive"
            if "otp" in args:
                list_name = "Love Live! OTP"
                show_series = False
                lines = utils.file_to_list('Idol Love Live OTP.txt')
        elif "cinderella" in args or "cinderella" in args:
            search_for = "Idolmaster Cinderella Girls"
            hashtag = "#Idolmaster"
        elif "idolmaster" in args or "idolm@ster" in args:
            search_for = "Idolmaster"
            hashtag = "#Idolmaster"
        elif "akb0048" in args:
            search_for = "AKB0048"
            hashtag = "#akb0048"
        elif "wake" in args:
            search_for = "Wake Up Girls!"
            hashtag = "#WUG_JP"
        elif "aikatsu" in args:
            search_for = "Aikatsu!"
            hashtag = "#Aikatsu"
        if "male" in args:
            list_name = "Male Idol"
            lines = utils.file_to_list('Idol Males.txt')
        else:
            if not lines:
                lines = utils.file_to_list('Idol.txt')
                if search_for:
                    temp_lines = []
                    for line in lines:
                        if line[1] == search_for:
                            temp_lines.append(line)
                    lines = temp_lines
                    del temp_lines
    elif list_name == "Shota":
        show_series = True
        gender = "husbando"
        lines = utils.file_to_list('Shota.txt')
    elif list_name == "Onii":
        list_name = "Onii-chan"
        show_series = True
        gender = "husbando"
        lines = utils.file_to_list('Onii-chan.txt')
    elif list_name == "Onee":
        list_name = "Onee-chan"
        show_series = True
        lines = utils.file_to_list('Onee-chan.txt')
    elif list_name == "Sensei":
        show_series = True
        if "female" in args:
            lines = utils.file_to_list('Sensei Female.txt')
        elif "male" in args:
            gender = "husbando"
            lines = utils.file_to_list('Sensei Male.txt')
        else:
            lines = utils.file_to_list('Sensei Male.txt')
            lines += utils.file_to_list('Sensei Female.txt')
    elif list_name == "Senpai":
        show_series = True
        if "female" in args:
            lines = utils.file_to_list('Senpai Female.txt')
        elif "male" in args:
            gender = "husbando"
            lines = utils.file_to_list('Senpai Male.txt')
        else:
            lines = utils.file_to_list('Senpai Male.txt')
            lines += utils.file_to_list('Senpai Female.txt')
    elif list_name == "Kouhai":
        show_series = True
        if "female" in args:
            lines = utils.file_to_list('Kouhai Female.txt')
        elif "male" in args:
            gender = "husbando"
            lines = utils.file_to_list('Kouhai Male.txt')
        else:
            lines = utils.file_to_list('Kouhai Male.txt')
            lines += utils.file_to_list('Kouhai Female.txt')
    elif list_name == "Monstergirl":
        show_series = True
        scrape_images = True
        lines = utils.file_to_list('Monstergirl.txt')
    elif list_name == "Witchgirl":
        hashtag = "#s_witch"
        show_series = False
        scrape_images = True
        lines = utils.file_to_list('Witchgirl.txt')
    elif list_name == "Tankgirl":
        hashtag = "#garupan"
        show_series = False
        scrape_images = True
        lines = utils.file_to_list('Tankgirl.txt')

    # Under heavy stuff random.choice can be very weak
    # so just a quick way to make sure it's 'random random'
    random.shuffle(lines)
    entry = random.choice(lines)
    if list_name.endswith("OTP"):
        names = entry.split("(x)")
        if list_name == "Touhou":
            tags = "{0}+{1}+2girls+yuri+touhou+-asai_genji+-comic".format(
                names[0].replace(" ", "_"), names[1].replace(" ", "_"))
        if "love live" in list_name.lower():
            tags = "{0}+{1}+2girls+yuri+-comic".format(
                names[0].replace(" ", "_"), names[1].replace(" ", "_"))
        else:
            tags = "{0}+{1}+yuri+2girls+-comic".format(
                names[0].replace(" ", "_"), names[1].replace(" ", "_"))
        name = "{0}(x){1}".format(names[0], names[1])
    else:
        if isinstance(entry, list):
            name = entry[0]
            show = entry[1]
        else:
            name = entry
        if scrape_images:
            tags = "{0}+solo".format(name.replace(" ", "_"))
    path_name = slugify(name, word_boundary=True, separator="_")
    path = "{0}/{1}".format(gender.lower(), path_name)
    tweet_image = utils.get_image(path)
    if scrape_images and not tweet_image:
        tweet_image = utils.get_image_online(tags, 0, 1, "", path)

    name = re.sub(r' \([^)]*\)', '', name)
    if show_series:
        m = "Your {0} is {1} ({2}) {3}".format(list_name, name, show, hashtag)
    elif list_name.endswith("OTP"):
        name_one = re.sub(r' \([^)]*\)', '', names[0])
        name_two = re.sub(r' \([^)]*\)', '', names[1])
        name = "{0} x {1}".format(name_one, name_two)
    if not m:
        m = "Your {0} is {1} {2}".format(list_name, name, hashtag)
        if not list_name.endswith("OTP"):
            count_trigger(name, gender)
    return m, tweet_image
Пример #13
0
def run_tests():
    print("Login Test:")
    api = functions.login()
    print(api)
    print("\nTest Tweet")
    msg = "@AceStatusBot Running Tests..."
    api.update_status(status=msg)
    print("\nGet Level Test:")
    print(functions.get_level(123))
    print("\nRandom Waifu Test:")
    print(functions.waifu(0))
    print("\nRandom Husbando Test:")
    print(functions.waifu(1))
    # Name should be flipped
    print("\nWaifuRegister Test:")
    print(functions.waifuregister(123, "Test Username", "rin shibuya", 0))
    # Name should return "not enough images"
    print("\nHusbandoReigster Paste Test:")
    print(functions.waifuregister(123, "Test Username", "admiral", 1))
    # Name should work
    print("\nHusbandoReigster Test:")
    print(functions.waifuregister(123, "Test Username",
                                       "admiral (kantai collection)", 1))
    print("\nMyWaifu Test:")
    print(functions.mywaifu(123, 0))
    print("\nMyHusbando Test:")
    print(functions.mywaifu(123, 1))
    print("\nRemoveWaifu Test:")
    print(functions.waifuremove(123, 0))
    print("\nRemoveHusbando Test:")
    print(functions.waifuremove(123, 1))
    print("\nRandom OTP Test:")
    print(functions.otp(""))
    print("\nRandom List Shipgirl Test:")
    m, i = functions.random_list("Shipgirl", "")
    print(m, i)
    print("\nRandom List Imouto Test:")
    m, ii = functions.random_list("Imouto", "")
    if not i:
        i = ii
    print(m, ii)
    print("\nRandom List Shota Test:")
    print(functions.random_list("Shota", ""))
    print("Sleeping for 10 seconds...")
    time.sleep(10)
    print("\nRandom List Sensei Test:")
    print(functions.random_list("Sensei", ""))
    print("\nRandom List Senpai Test:")
    m, ii = functions.random_list("Senpai", "")
    if not i:
        i = ii
    print(m, ii)
    print("\nRandom List Kouhai Test:")
    print(functions.random_list("Kouhai", ""))
    print("\nRandom List Kouhai Male Test:")
    print(functions.random_list("Kouhai", "male"))
    print("\nAiring Test:")
    print(functions.airing("One Piece"))
    print("\nTest Tweet (with Image)")
    msg = "@AceStatusBot Test Tweet with Image..."
    api.update_with_media(i, status=msg)
    print("\nTest Tweet (with Video)")
    tags = ["rating:safe", "webm", "-extremely_large_filesize",
            "-large_filesize", "-no_audio"]
    i = get_image_online(tags, 0, 1, "")
    msg = "@AceStatusBot Test Tweet with Video..."
    api.update_with_media(i, status=msg)
    print("\nFinished all Tests!")