async def suggest(message): if bot.suggestions_channel == None or bot.suggestions_guild == None: await message.channel.send( "Our inbox for Suggestions are currently closed. Sorry!") return arguments = commands.GetArgumentsFromCommand(message.content) if arguments == False: await message.channel.send( "Either I'm perfect, or you forgot to type in a suggestion.") return suggestion = "" for i in range(0, len(arguments)): suggestion = suggestion + arguments[i] if i < len(arguments) - 1: suggestion = suggestion + bot.argumentSeperator await bot.suggestions_channel.send("Suggestion Received from '" + str(message.author) + "':\n'" + suggestion + "'") await message.channel.send( "Thank you! I'll try my best to improve the library's services!") return
async def report(message): if bot.reports_channel == None or bot.reports_guild == None: await message.channel.send( "Our inbox for Reports are currently closed. Sorry!") return arguments = commands.GetArgumentsFromCommand(message.content) if arguments == False: await message.channel.send( "Either I'm perfect, or you forgot to type in a bug report.") return report = "" for i in range(0, len(arguments)): report = report + arguments[i] if i < len(arguments) - 1: report = report + bot.argumentSeperator await bot.reports_channel.send(":warning: Report Received from '" + str(message.author) + "':\n'" + report + "'") await message.channel.send( "Thank you! I'll try my best to improve the library's services!") return
async def evalfunc(message): if not tester_check(message): return arguments = commands.GetArgumentsFromCommand(message.content) if arguments == False: await message.channel.send("No Eval Given.") return eval(arguments[0])
async def help(message): arguments = commands.GetArgumentsFromCommand(message.content) if arguments == False: await message.channel.send(helpMessage) else: if arguments[0] == 'music': await message.author.send(musicHelpMessage) if not isinstance(message.channel, DMChannel): # Are we not in a DM Channel? await message.channel.send( message.author.name + ": There are a LOT of commands! Check your DMs!" ) # Tell the User to check them. if arguments[0] == 'image' or arguments[0] == 'images': await message.channel.send(imageHelpMessage) return
async def get_search(message, getUrls, getImage): arguments = commands.GetArgumentsFromCommand(message.content) force_image = True if arguments == False: await message.channel.send( "You're going to have to give me something to look for.") return else: query = arguments[0] async with message.channel.typing(): searchResults = await get_search_results(query, 5) if len(searchResults) < 1: await message.channel.send( "I couldn't find anything in my library for '" + query + "'.") return if len(searchResults) == 1: getImage = True force_image = False searchResults = [searchResults[0]] if getUrls and not getImage: # Regular Search messageEmbed = discord.Embed(title="Search Results For '" + query + "'", color=bot.hex_color) for i in range(0, len(searchResults)): try: messageEmbed.add_field( name="Result " + str(i + 1), value="https://en.touhouwiki.net/wiki/" + searchResults[i], inline=False) except: print("Skipping Search Result...") pass if getImage: #searchImages = 1 #if getUrls == False: searchImages = len(searchResults) if getUrls: # Lookup image_info = await bot.get_image(searchResults, searchImages, force_image, True) if not getUrls: # Portrait image_info = await bot.get_image(searchResults, searchImages, force_image, False) if not image_info == False: if getUrls: # Lookup messageEmbed = discord.Embed(title=image_info.Name.replace( "_", " "), color=bot.hex_color) messageEmbed.add_field( name="Page URL", value="https://en.touhouwiki.net/wiki/" + searchResults[0], inline=False) if not image_info.Summary == "": messageEmbed.add_field( name="Summary", value=image_info.Summary.replace("_", " "), inline=False) else: # Portrait messageEmbed = discord.Embed( title=image_info.Name.replace("_", " ") + "'s Portrait", color=bot.hex_color) else: if not getUrls: await message.channel.send( "I wasn't able to find any photos in my library on '" + query + "'.") return if image_info: messageEmbed.set_image(url=image_info.Url) try: await message.channel.send(embed=messageEmbed) except: await message.channel.send( "I couldn't find anything in my library for '" + query + "'.")
async def PostImage(message, rating, tags, APILink, genders, negativeGenders): checked_connection = False image_seperator_char = ' ' image_space_char = '_' tags = "rating:" + rating + "+" + tags # Format and add the Rating into the total Tags exclude_unless_wanted_tags = ['comic', 'character_doll'] exclude_unless_wanted_lewd_tags = ['creepy'] exclude_unless_wanted_nsfw_tags = ['futa', 'giantess'] bad_tags = ['guro', 'deep_wound', 'rotting', 'corpse'] bad_lewd_tags = ['style_parody'] bad_nsfw_tags = ['loli', 'shota'] bad_sfw_tags = ['nude', 'pov_feet', 'ass', 'anus', 'thighs', 'underboob', 'sideboob', 'breasts', 'hanging_breasts', 'holding_breasts', 'breast_grab', 'groping', 'nipples', 'erect_nipples', 'futa', 'penis', 'bulge', 'topless', 'panties', 'striped_panties', 'underwear', 'underwear_only', 'thong', 'thong_bikini', 'micro_bikini', 'condom', 'bandaids_on_nipples', 'panty_shot', 'cameltoe', 'dress_lift', 'skirt_lift', 'upskirt', 'under_skirt', 'no_panties', 'bottomless', 'no_bra', 'convenient_censoring', 'convenient_leg', 'removing_panties', 'undressing', 'pussy_juice', 'egg_laying', 'sexually_suggestive', 'suggestive_fluid', 'vibrator', 'rape', 'girl_on_top', 'forced', 'bdsm', 'bound', 'bondage', 'slave', 'sex', 'kiss', 'imminent_kiss', 'face-to-face', 'noses_touching', 'saliva', 'masturbation', 'fingering', 'implied_masturbation', 'vore', 'tentacles', 'cum', 'blood', 'suicide', 'vomit', 'piss', 'pee', 'peeing', 'toilet', 'toilet_use'] # 'yuri', 'yaoi', arguments = commands.GetArgumentsFromCommand(message.content) additional_tags = "" additional_tags_list_check = [] tags_array = [] if not arguments == False: additional_tags = arguments[0] tags_array = additional_tags.split(image_seperator_char) if genders: if len(tags_array) > 6: await message.channel.send("How do you expect me to search for *that* many things?\n(Please only enter a maximum of up to 6 tags!)") return boys = 0 girls = 0 async with message.channel.typing(): if not arguments == False: #character_names = [] #character_links = [] #ParseCharacters(character_names, character_links) translations_before = ['patchy', 'raymoo', 'flan', 'gif', 'dab', 'pc98'] translations_after = ['patchouli', 'reimu', 'flandre', 'animated_gif', 'dab_(dance)', 'touhou_(pc-98)'] #tags_array = list(set(tags_array)) # Removes all Duplicate elements from the Array valid_tags = len(tags_array) additional_tags = "" i = 0 for tag in tags_array: while tag.startswith(' '): tag = tag[1:] while tag.endswith(' '): tag = tag[0:-1] raw_tag = tag if tag.startswith('-'): raw_tag = raw_tag[1:] for i in range(0, len(translations_before)): if raw_tag.lower() == translations_before[i]: new_tag = translations_after[i] if tag.startswith('-'): new_tag = '-' + new_tag tag = new_tag break character = '' character_index = None if tag.startswith("$") and tag.endswith("$"): # Disable Character Recognition tag = tag[1:-1] # Hide the symbols else: # We don't want to disable Character Recognition tag = tag.lower() for i in range(0, len(characters_before)): if characters_before[i].lower() in tag: tag = characters_after[i].lower() #tag = tag.replace(characters_before[i].lower(), characters_after[i].lower()) swap_names_back = False found_character = False #for character_name in character_names: for i in range(0, len(character_names)): character_name = character_names[i] if found_character: break character_index = i character_array = character_name.split(" ") if len(character_array) >= 2: for character_word in character_array: tag_words = tag.split(image_space_char) for tag_word in tag_words: character_word_lower = character_word.lower() if tag_word == character_word_lower and not character_word_lower == 'no' and not character_word_lower == 'giant' and not character_word_lower == 'three' and not character_word_lower == 'mischievous' and not character_word_lower == 'flower': if len(character_array) > 2: character = character_name.replace(" ", "_") else: character = character_array[1] + "_" + character_array[0] swap_names_back = True found_character = True break else: if tag == character_name.lower(): character = character_name found_character = True break if len(character) > 0: if character_tags[character_index] == None: keep_testing = True try_end_touhou_tag = True got_character = False while keep_testing: keep_testing = False html = await bot.get(APILink + "?page=dapi&s=post&q=index&limit=1&json=1&pid=10&tags=" + tags + "+" + character) # We're going to check if our new name has atleast 10 results if not checked_connection: if not await CheckBooru(message, html): return checked_connection = True if not "file_url" in html: # If it doesn't... #print("Trying " + character) if swap_names_back: if character.startswith(character_array[1]): character = character_array[0] + "_" + character_array[1] # Swap the names around again back to it's original positions else: character = character_array[1] + "_" + character_array[0] # Swap the names around again back to it's reversed positions swap_names_back = False keep_testing = True if not try_end_touhou_tag: character = character + "_(touhou)" if not character.endswith("_(touhou)") and swap_names_back == False and keep_testing == False and try_end_touhou_tag: character = character + "_(touhou)" if len(character_array) == 2: swap_names_back = True keep_testing = True try_end_touhou_tag = False else: # If we were able to find atleast 10 images of our character tag... #print("Working " + character) character_tags[character_index] = character # Cache our Tag! keep_testing = False got_character = True tag = character else: got_character = True tag = character_tags[character_index] if not got_character: valid_tags = valid_tags - 1 if valid_tags < 1: #await message.channel.send("I couldn't find any pictures in my library on '" + arguments[0] + "'.") await message.channel.send("I couldn't find an image!") return #await message.channel.send("I couldn't find an image of your character '" + tag + "'!\nPro Tip: Don't want me to treat a tag as a character? Simple! Just let me know by putting a '$' symbol at the start and end of your tag!") #return tag = '' if len(tag) > 0: raw_tag = tag if tag.startswith('-'): raw_tag = raw_tag[1:] is_good_tag = True is_bad_sfw_tag = False if raw_tag.startswith("rating"): # Disallow modification to the Rating tag is_good_tag = False if is_good_tag: for bad_tag in bad_tags: # Disallow certain tags. Cycle through all bad tags if raw_tag == bad_tag: # Check for a match with the current tag is_good_tag = False break if is_good_tag and rating == "questionable": # Disallow certain tags if we're in Questionable for bad_tag in bad_lewd_tags: # Cycle through all bad Lewd tags if raw_tag == bad_tag: # Check for a match with the current tag is_good_tag = False break if is_good_tag and (rating == "questionable" or rating == "explicit"): # Disallow certain tags if we're NSFW for bad_tag in bad_nsfw_tags: # Cycle through all bad NSFW tags if raw_tag == bad_tag: # Check for a match with the current tag is_good_tag = False break if is_good_tag and rating == "safe": # Disallow certain tags if we're supposed to be SFW for bad_tag in bad_sfw_tags: # Cycle through all bad SFW tags if raw_tag == bad_tag: # Check for a match with the current tag is_good_tag = False is_bad_sfw_tag = True break if not is_good_tag: valid_tags -= 1 if not rating == "safe": if valid_tags <= 0: await asyncio.sleep(1) # Looks weird but if we send a message too quickly after starting to type it'll bug out the typing await message.channel.send("I couldn't find an image!") return else: await asyncio.sleep(1) # Looks weird but if we send a message too quickly after starting to type it'll bug out the typing if is_bad_sfw_tag: nsfw_sfw_quotes = ["I-I don't know what you're looking for, but it miight be more suitable in a NSFW channel...", "D-Don't you think it might be more suitable to take that to a NSFW channel..?", "H-Hey, I think a NSFW channel might be more suitable for that sort of thing.", "T-That sort of stuff should probably be taken to a NSFW channel, don't you agree..?"] await message.channel.send(nsfw_sfw_quotes[randint(0, len(nsfw_sfw_quotes) - 1)]) # + "\n(Use '" + bot.prefix + "image' in a NSFW channel to use NSFW tags!)") else: await message.channel.send("I couldn't find an image!") return if is_good_tag: if not tag in additional_tags_list_check: additional_tags_list_check.append(tag) additional_tags = additional_tags + tag + '+' if genders: if not character == None and not character == '' and got_character: # Now that we have our unique working character 100%, let's get it's gender in preparation for adding it to the FINAL LIST if character_genders[character_index] == None: print("Getting Gender of '" + character + "' From '" + character_links[character_index] + "'") #print("https://touhou.fandom.com/wiki/" + character_links[character_index]) gender = await bot.get("https://touhou.fandom.com/wiki/" + character_links[character_index]) gender = gender[gender.index('id="PageHeader"') + 15:] gender = gender[:gender.index('</div>')] try: gender = gender[gender.index('class="page-header__categories-links">') + 38:] except: pass gender = gender[gender.index('<'):] else: print("Loading Cached Gender of '" + character + "' From '" + character_links[character_index] + "' As '" + character_genders[character_index][:-1] + "'") gender_check = character_genders[character_index] while True: try: if character_genders[character_index] == None: gender = gender[gender.index('/Category:') + 10:] gender_check = gender[:gender.index('"')] if gender_check == "Males": character_genders[character_index] = "Males" # Cache our Gender! boys += 1 break if gender_check == "Females": character_genders[character_index] = "Females" # Cache our Gender! girls += 1 break except: break boys_tag = "" if boys > 0: if negativeGenders: boys_tag += '-' if boys > 6: boys_tag = '6%2Bboys' else: boys_tag += str(boys) + "boy" if boys > 1: boys_tag += 's' girls_tag = "" if girls > 0: if negativeGenders: girls_tag += '-' if girls > 6: girls_tag = '6%2Bgirls' else: girls_tag += str(girls) + "girl" if girls > 1: girls_tag += 's' if not negativeGenders and rating == 'safe': # Generally if you search for a Safe image you only want 1 boy or 1 girl. Questionable or Explicit results though could have a mix of the two, so we'll disable this for those if girls > 0 and boys < 1: girls_tag = girls_tag + "+" + no_boys_tags if boys > 0 and girls < 1: boys_tag = boys_tag + "+" + no_girls_tags #if boys == 1 or girls == 1: #additional_tags += "solo+" bad_tag = False for i in range(0, len(exclude_unless_wanted_tags)): for ii in range(0, len(tags_array)): bad_tag = False if exclude_unless_wanted_tags[i] == tags_array[ii].lower(): bad_tag = True break if not bad_tag: additional_tags += '-' + exclude_unless_wanted_tags[i] + '+' if rating == "questionable": bad_tag = False for i in range(0, len(exclude_unless_wanted_lewd_tags)): for ii in range(0, len(tags_array)): bad_tag = False if exclude_unless_wanted_lewd_tags[i] == tags_array[ii].lower(): bad_tag = True break if not bad_tag: additional_tags += '-' + exclude_unless_wanted_lewd_tags[i] + '+' if rating == "questionable" or rating == "explicit": bad_tag = False for i in range(0, len(exclude_unless_wanted_nsfw_tags)): for ii in range(0, len(tags_array)): bad_tag = False if exclude_unless_wanted_nsfw_tags[i] == tags_array[ii].lower(): bad_tag = True break if not bad_tag: additional_tags += '-' + exclude_unless_wanted_nsfw_tags[i] + '+' if len(additional_tags) > 0: print("Using additional tags: '" + additional_tags[0:-1].replace(image_space_char, '_') + "'") for bad_tag in bad_tags: # Add a filter for all bad tags so they aren't shown additional_tags = additional_tags + '-' + bad_tag + '+' if rating == "questionable": for bad_tag in bad_lewd_tags: # Add a filter for all bad tags if we're in Questionable so they aren't shown additional_tags = additional_tags + '-' + bad_tag + '+' if rating == "questionable" or rating == "explicit": for bad_tag in bad_nsfw_tags: # Add a filter for all bad tags if we're NSFW so they aren't shown additional_tags = additional_tags + '-' + bad_tag + '+' if not boys_tag == "": additional_tags += boys_tag + '+' if not girls_tag == "": additional_tags += girls_tag + '+' additional_tags += "score:>=0+" # Filter our results with negative ratings, could be pornography or something else bad if rating == "safe": for bad_tag in bad_sfw_tags: # Add a filter for all bad tags if we're SFW so they aren't shown additional_tags = additional_tags + '-' + bad_tag + '+' if not additional_tags == None: tags = tags + '+' + additional_tags.replace(image_space_char, "_") while tags.endswith('+'): tags = tags[0:-1] # Cut off the last '+'s if len(tags_array) > 0: # If we have a query to check... html = await bot.get(APILink + "?page=dapi&s=post&q=index&limit=1&json=1&pid=1&tags=" + tags) # We're going to check if our query has atleast 1 result if not checked_connection: if not await CheckBooru(message, html): return checked_connection = True if not "file_url" in html: await message.channel.send("I couldn't find an image!") return #print("Using total tags: '" + tags + "'") page_scope = 20000 i = 1 worked = False while not worked: html = await bot.get(APILink + "?page=dapi&s=post&q=index&limit=1&json=1&pid=" + str(randint(0, page_scope)) + "&tags=" + tags) if not checked_connection: if not await CheckBooru(message, html): return checked_connection = True try: fileUrl = html[html.index('file_url":"') + 11 : - 3] fileUrl = fileUrl.replace("\/", "/") fileUrl = fileUrl[0:fileUrl.index('"')] source = html[html.index('source":"') + 9:] source = source[:source.index('"')] source = source.replace("\/", "/") source = source.encode().decode("unicode-escape") print("Posting Image: " + fileUrl) if len(source) > 0: print("Image Source: " + source) worked = True except: i = i + 1 if i <= 2: page_scope = int(page_scope / 2) else: page_scope = int(page_scope / 3) if page_scope < 1: await message.channel.send("I couldn't find an image!") return #else: #print("Dividing our search scope to '" + str(page_scope) + "'... [Attempt " + str(i) + "]") # Mainly for debug purposes messageEmbed = discord.Embed(color=bot.hex_color) messageEmbed.set_image(url=fileUrl) messageEmbed.add_field(name="Image URL", value=fileUrl, inline=False) if len(source) > 0: messageEmbed.add_field(name="Image Source",value=source, inline=False) await message.channel.send(embed=messageEmbed)
async def get_cards(message): async with message.channel.typing(): page_number = 0 arguments = commands.GetArgumentsFromCommand(message.content) id_to_lookup = message.author.id try: if not arguments[1] == None: id_to_lookup = arguments[1] except: pass possessive = "They" if str(id_to_lookup) == str(message.author.id): possessive = "You" cards = await search_data("owned_cards-" + str(id_to_lookup)) if cards == False: await message.channel.send(possessive + " don't have any cards!") return cards_list = cards[:-1].split(';') last_page_number = math.floor((len(cards_list) - 1) / 5) if not arguments == False: if arguments[0].lower() == 'last': page_number = last_page_number else: try: page_number = int(arguments[0]) - 1 except: page_number = 0 try: if not cards_list[page_number * 5] == None: pass except: await message.channel.send("That page doesn't exist!") return raw_names = await get_all_cards() cards_array = [] for i in range(page_number * 5, page_number * 5 + 5): try: card_options = GetCardOptions() card_options.get_name = True card_options.get_rarity_message = True card = await get_card_object(raw_names[int(cards_list[i])], card_options, False, True) cards_array.append("`Card " + str(i + 1) + ") [ " + card.name + " ] |` " + card.rarity_message + "\n") except: break max_length = 0 for i in range(0, len(cards_array)): real_card = cards_array[i] real_card = real_card[1:real_card.index('|') - 1] if len(real_card) > max_length: max_length = len(real_card) for i in range(0, len(cards_array)): real_card = cards_array[i] real_card = real_card[1:real_card.index('|') - 1] cards_array[i] = cards_array[i].replace( "|", (' ' * (max_length - len(real_card))) + "|") if len(cards_list) == 1: cards_array.insert( 0, possessive + " currently own `" + str(len(cards_list)) + "` card!\n\n") else: cards_array.insert( 0, possessive + " currently own `" + str(len(cards_list)) + "` cards!\n\n") cards_string = '' for i in range(0, len(cards_array)): cards_string = cards_string + cards_array[i] ending_string = '\n' + "Page " + str(page_number + 1) + " of " + str( last_page_number + 1) + "\n\n" if page_number > 0: ending_string = ending_string + "Previous Page: `" + bot.prefix + "cards" + bot.argumentChar + str( page_number) + bot.argumentKillChar if possessive == "They": ending_string = ending_string + bot.argumentSeperator + id_to_lookup ending_string = ending_string + "`" if page_number < last_page_number: if page_number > 0: ending_string = ending_string + " | " ending_string = ending_string + "Next Page: `" + bot.prefix + "cards" + bot.argumentChar + str( page_number + 2) + bot.argumentKillChar if possessive == "They": ending_string = ending_string + bot.argumentSeperator + id_to_lookup ending_string = ending_string + "`" await message.channel.send(cards_string + ending_string) return
async def view_card_handler(message): arguments = commands.GetArgumentsFromCommand(message.content) view_card_error_message = "You need to give me a Card number to view!\nGet one by typing `" + bot.prefix + "cards`" if arguments == False: await message.channel.send(view_card_error_message) return else: try: card_id_to_get = int(arguments[0]) - 1 except: await message.channel.send(view_card_error_message) return if card_id_to_get < 0: await message.channel.send(view_card_error_message) return async with message.channel.typing(): raw_names = await get_all_cards() id_to_lookup = message.author.id try: if not arguments[1] == None: id_to_lookup = arguments[1] except: pass possessive = "Their" if str(id_to_lookup) == str(message.author.id): possessive = "Your" cards = await search_data("owned_cards-" + str(id_to_lookup)) if cards == False: await message.channel.send("No cards available!") return cards_list = cards[:-1].split(';') try: if not cards_list[card_id_to_get] == None: pass except: await message.channel.send( "The Card number you've given me doesn't exist!") return card_options = GetCardOptions() card_options.get_character_name = True card_options.get_link = True card_options.get_name = True card_options.get_image = True card_options.get_power = True card_options.get_rarity = True card_options.get_rarity_message = True card_options.get_rarity_string = True card_options.get_price = True card = await get_card_object( raw_names[int(cards_list[card_id_to_get])], card_options, False, False) embed = await view_card(card, message.author.display_name) embed.title = "Viewing " + possessive.lower() + " [ " + card.name + "]" await message.channel.send(embed=embed) return