示例#1
0
async def on_ready():
    print(f'{bot.user} has connected to discord')
    severs = list(bot.guilds)
    for sever in severs:
        print(f'{bot.user} in connected to {sever}')
    await bot.change_presence(status=discord.Status.do_not_disturb, activity=discord.Game(name='Crying Suns'))
    print(owoify('===============Loading furry memes============'))
    print(owoify('===============Loaded furry memes============'))
示例#2
0
async def command_uvuify(ctx, *args):
    mess = ctx.message
    ref = mess.reference
    if ref:
        replied_message = None
        if ref.cached_message:
            replied_message = ref.cached_message
        else:
            replied_message = await ctx.fetch_message(ref.message_id)
        print(replied_message.content)
        await ctx.send(owoify(replied_message.content, "uvu"))
    else:
        await ctx.send(owoify(" ".join(args), "uvu"))
示例#3
0
def inline_owoify(update, context):
    query = update.inline_query.query
    if not query:
        return
    userid = update.effective_user.id
    username = update.effective_user.username
    logger.info(f"{username} {userid} INLINE: {query}")
    results = list()
    results.append(
        InlineQueryResultArticle(
            id=0,
            title='Owoified Text Preview (press to send)',
            description=owoify(query),
            thumb_url='https://avatarfiles.alphacoders.com/161/161188.png',
            input_message_content=InputTextMessageContent(owoify(query))))
    context.bot.answer_inline_query(update.inline_query.id,
                                    results,
                                    cache_time=0)
示例#4
0
def echo(update, context):
    userid = update.message.chat_id
    try:
        username = update.message.from_user["username"]
    except:
        username = userid
    text = update.message.text
    context.bot.send_message(chat_id=update.message.chat_id,
                             text=owoify(text),
                             disable_web_page_preview=True)
    logger.info(f"{username} {userid}: {text}")
示例#5
0
def owo(update, context):
    try:
        message = update.message.reply_to_message.text
        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text=owoify.owoify(message),
            reply_to_message_id=update.message.reply_to_message.message_id)
    except AttributeError:
        context.bot.send_message(chat_id=update.effective_chat.id,
                                 text="Please reply to a text message")
    except TypeError:
        context.bot.send_message(chat_id=update.effective_chat.id,
                                 text="Please reply to a text message")
示例#6
0
def owo(update, context):
    userid = update.message.chat_id
    try:
        username = update.message.from_user["username"]
    except:
        username = userid
    try:
        text = update.message.reply_to_message.text
    except Exception as e:
        context.bot.send_message(
            chat_id=update.message.chat_id,
            text=("Bbb..but master-sama, you need to reply to a message! "
                  "I have no idea what text you want to be owoified..."
                  " (。•́︿•̀。)"))
        return
    context.bot.send_message(
        chat_id=update.message.chat_id,
        text=owoify(text),
        reply_to_message_id=update.message.reply_to_message.message_id,
        disable_web_page_preview=True)
    logger.info(f"{username} {userid} GROUP: {text}")
示例#7
0
    async def owo(self, ctx, *, text):
        """Turns text into OwO.

        **Usage:** `$furry owo <text>`"""
        await ctx.send(owoify(text, 'owo'))
示例#8
0
    async def uwu(self, ctx, *, text):
        """Turns text into UwU.

        **Usage:** `$furry uwu <text>`"""
        await ctx.send(owoify(text, 'uwu'))
示例#9
0
def test_nya():
    assert owoify("Magni") == "Magnyi"
    assert owoify("MAGNI") == "MAGNyI"
示例#10
0
def test_w():
    assert owoify("Hello") == "Hewwo"
    assert owoify("HELLO") == "HEWWO"
示例#11
0
def test_kaomoji():
    assert owoify("!")[1:] in kaomoji
示例#12
0
def test_uv():
    assert owoify("oven") == "uvn"
示例#13
0
def test_d():
    assert owoify("the") == "de"
示例#14
0
async def on_message(message):

    if message.author == client.user:
        return

    msg = message.content

    # If bot is mentioned or in dm's
    mention = f'<@!{client.user.id}>'
    if msg.find(mention) == -1:
        mention = f'<@{client.user.id}>'

    isDM = isinstance(message.channel, discord.DMChannel)
    channel_nsfw = False
    if not isDM:
        channel_nsfw = message.channel.is_nsfw()

    if mention in msg or isDM:
        try:
            if isDM:
                userText = msg
            else:
                userText = msg.split(mention, 1)[1]

            response = ""

            # If another user is mentioned, we would do an 8 ball response
            if len(message.mentions) > 1:
                # print("test")
                try:
                    mes = userText.lower()
                    if mes.find("what") != -1 or mes.find("where") != -1:
                        response = eight_ball.what_ball()
                    elif mes.find("who") != -1:
                        response = eight_ball.who_ball()
                    elif mes.find("why") != -1:
                        response = eight_ball.why_ball()
                    else:
                        response = eight_ball.eight_ball()
                except Exception as err:
                    print(err)

            # If Binary, convert to string
            elif to_binary.is_Binary(userText):
                response = to_binary.binaryConvert(userText)

# If indicated to find an image
            elif any(word in msg.lower() for word in findImage):
                if channel_nsfw:
                    try:
                        random.seed(time.time())
                        response = google_search.image_search(
                            removeIndicators(userText, findImage), False)

                    except Exception as err:
                        if str(err).find("429") != -1:
                            message.channel.send(
                                "Img quota exceeded, scraping...")
                            response = google_search.image_search2(
                                removeIndicators(userText, findImage), False)
                        else:
                            response = "Something with image search went wrong."

                        print(err)
                else:
                    try:
                        random.seed(time.time())
                        response = google_search.image_search(
                            removeIndicators(userText, findImage), True)
                        print(response)

                    except Exception as err:
                        if str(err).find("429") != -1:
                            message.channel.send(
                                "Img quota exceeded, scraping...")
                            response = google_search.image_search2(
                                removeIndicators(userText, findImage), True)
                        else:
                            response = "Something with image search went wrong."
                        print(err)

# Disconnect from voice channel
            elif any(word in msg.lower() for word in discionnectIndicators):
                try:
                    for x in client.voice_clients:
                        if (x.guild == message.guild):
                            return await x.disconnect()
                    response = "Done :+1:"
                except:
                    response = "Something went wrong..."

            # If video/youtube key word, search for a YouTube video or play a youtube song
            elif any(word in msg.lower()
                     for word in videoIndicatorWords) or any(
                         word in msg.lower() for word in playIndicator):
                try:

                    toPlayMusic = any(word in msg.lower()
                                      for word in playIndicator)
                    response = google_search.youtube_search(
                        removeIndicators(
                            removeIndicators(userText, videoIndicatorWords),
                            playIndicator))

                    if toPlayMusic:
                        await message.channel.send("Loading Song")
                        YDL_OPTIONS = {
                            'format': 'bestaudio',
                            'noplaylist': 'True'
                        }
                        FFMPEG_OPTIONS = {
                            'before_options':
                            '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
                            'options': '-vn'
                        }
                        voice = get(client.voice_clients, guild=message.guild)
                        voice_channel = message.author.voice.channel

                        if not voice or not voice.is_playing(
                        ) or voice != voice_channel:
                            if voice != voice_channel:
                                voice = await voice_channel.connect()

                            with YoutubeDL(YDL_OPTIONS) as ydl:
                                info = ydl.extract_info(response,
                                                        download=False)
                            URL = info['formats'][0]['url']
                            voice.play(FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))
                            voice.is_playing()
                            await message.channel.send("Playing")
                        else:
                            await message.channel.send("Already playing song")
                            return

                except Exception as err:
                    print(err)

# If indicated to find a meme
            elif any(word in msg.lower() for word in memeIndicator):
                response = reddit_file.get_meme()

# If indicated as gif
            elif any(word in msg.lower() for word in gifIndicators):
                try:
                    random.seed(time.time())
                    response = tenorBot.random(
                        removeIndicators(userText, gifIndicators))
                except Exception as err:
                    print(err)
# If indicated to find article
            elif any(word in msg.lower() for word in findArticle):
                try:
                    random.seed(time.time())
                    links = google_search.get_links(
                        removeIndicators(userText, findArticle))
                    response = random.choice(links)
                except Exception as err:
                    print(err)

# If indicated to calculate and do math
            elif any(word in msg.lower()
                     for word in calculateIndicator) or any(
                         word in msg.lower() for word in calcWhitelistWords):
                try:
                    textToUse = removeIndicators(userText, calculateIndicator)
                    inputVal = textToUse.replace("+", "%2B")
                    inputVal = inputVal.replace(" ", "+")
                    wolfUrl = "https://api.wolframalpha.com/v2/query?input=" + inputVal + "&format=image&output=JSON&appid=" + WolframAppId + "&podstate=Step-by-step%20solution&format=plaintext"

                    now = datetime.now()

                    current_time = now.strftime("%H:%M:%S")
                    print(message.author.name, "requested url", wolfUrl, "at",
                          current_time)
                    with urllib.request.urlopen(wolfUrl) as url:
                        data = json.loads(url.read().decode())
                        if data["queryresult"]:

                            await message.channel.send(
                                "Note that log is the natural log ln, and there may be absolute values not present when calculating the integral."
                            )
                            resp1 = data["queryresult"]["pods"][0]["subpods"][
                                0]["img"]["src"]
                            print("Response 1", resp1)
                            await message.channel.send(resp1)

                            response = data["queryresult"]["pods"][1][
                                "subpods"][0]["img"]["src"]

                            resp2 = data["queryresult"]["pods"][0]["subpods"][
                                0]["plaintext"]
                            print("Response 2", resp2)
                            await message.channel.send(resp2)
                            await message.channel.send(
                                data["queryresult"]["pods"][0]["subpods"][1]
                                ["img"]["src"])

                except Exception as err:
                    print(err)

# If indicated to search for information
            elif any(word in msg.lower() for word in searchIndicator):
                try:
                    textToUse = removeIndicators(userText, calculateIndicator)
                    inputVal = textToUse.replace("+", "%2B")
                    inputVal = inputVal.replace(" ", "+")
                    wolfUrl = "https://api.wolframalpha.com/v2/query?input=" + inputVal + "&format=plaintext&output=JSON&appid=" + WolframAppId
                    print(wolfUrl)
                    with urllib.request.urlopen(wolfUrl) as url:
                        data = json.loads(url.read().decode())
                        if data["queryresult"]:
                            response = data["queryresult"]["pods"][1][
                                "subpods"][0]["plaintext"]

                except Exception as err:
                    print(err)

# If indicated to uwuify text
            elif any(word in msg.lower() for word in uwuifyIndicators):
                try:
                    response = owoify(
                        removeIndicators(userText, uwuifyIndicators))
                except Exception as err:
                    print(err)

# If indicated to receive help indications
            elif any(word in msg.lower() for word in helpindicators):
                cmd = help()
                await message.author.send(cmd)

                if not isDM:
                    response = message.author.name + ", check your DM's bro"
                else:
                    response = "Hope this helps"

# If indicated to search for a random quote
            elif any(word in msg.lower() for word in inspireIndicator):
                response = quote_search.get_quote()

# Else, search Google for a response
            else:
                try:
                    # First query type tries to find if Google has
                    # a system to find resources
                    response = google_search.chatbot_query(userText)
                    print(response)
                except:
                    # If not, try to find our own resource
                    response = google_search.chatbot_query2(userText)
            await message.channel.send(response)

        except:
            # Soon gonna add a small-talk AI bot here, if all else doesn't work
            await message.channel.send(
                "I'm sorry, it appears that something wrong has occured. Please try again."
            )