Esempio n. 1
0
    def test_usageExample_empty_list(self, mock_api_call):
        res = {
            "list": [{
                "definition": "a small mound or hill",
                "thumbs_up": 0,
                "word": "hillock",
                "example": "I went to the to of the hillock to look around.",
                "thumbs_down": 3
            }]
        }

        mock_api_call.return_value = mock.Mock()
        mock_api_call.return_value.status_code = 200
        mock_api_call.return_value.json.return_value = res

        self.assertFalse(vb.usage_example("hillock"))
Esempio n. 2
0
def get_dictionary(subject):
    cons = {"meaning": [], "synonym": [], "antonym": [], "example": [], "part of speech": []}
    meanings = vb.meaning(subject, format="list")
    if meanings:
        cons["meaning"] = [e.replace("<i>", "").replace("</i>", "").replace("[i]", "") .replace("[/i]", "") for e in meanings]
    synonyms = vb.synonym(subject, format="list")
    if synonyms:
        cons["synonym"] = synonyms
    antonyms = vb.antonym(subject, format="list")
    if antonyms:
        cons["antonym"] = antonyms
    ps = vb.part_of_speech(subject, format="list")
    if ps:
        cons["part of speech"] = ps
    examples = vb.usage_example(subject, format="list")
    if examples:
        cons["example"] = [e.replace("[", "").replace("]", "") for e in examples]
    return cons
Esempio n. 3
0
def details(word):
    meaning = vb.meaning(word)
    antonym = vb.antonym(word)
    synonym = vb.synonym(word)
    usage = vb.usage_example(word)

    if meaning == False:
        meaning = 'Not Found'
    else:
        meaning = json.loads(meaning)
        # meaning = str(meaning[0]['text'])
        meaning = [unescape(meaning[i]['text']) for i in range(len(meaning))]

    if antonym == False:
        antonym = 'Not Found'
    else:
        antonym = json.loads(antonym)
        antonym = str(antonym[0]['text'])

    if synonym == False:
        synonym = 'Not Found'
    else:
        synonym = json.loads(synonym)
        synonym = str(synonym[0]['text'])

    if usage == False:
        usage = 'Not Found'
    else:
        usage = json.loads(usage)
        usage = str(usage[-1]['text'])

    values = {
        'meaning': meaning,
        'antonym': antonym,
        'synonym': synonym,
        'usage': usage
    }

    return values
Esempio n. 4
0
    def test_usageExample_found(self, mock_api_call):
        res = {
            "list": [{
                "definition": "a small mound or hill",
                "thumbs_up": 18,
                "word": "hillock",
                "example": "I went to the to of the hillock to look around.",
                "thumbs_down": 3
            }]
        }

        mock_api_call.return_value = mock.Mock()
        mock_api_call.return_value.status_code = 200
        mock_api_call.return_value.json.return_value = res

        expected_result = '[{"seq": 0, "text": "I went to the to of the hillock to look around."}]'
        result = vb.usage_example("hillock")

        if sys.version_info[:2] <= (2, 7):
            self.assertItemsEqual(expected_result, result)
        else:
            self.assertCountEqual(expected_result, result)
Esempio n. 5
0
    def test_usageExample_not_found(self, mock_api_call):
        mock_api_call.return_value = mock.Mock()
        mock_api_call.return_value.status_code = 404

        self.assertFalse(vb.usage_example("hillock"))
Esempio n. 6
0
def getusageexample(word):
    return vb.usage_example(word, format="list")
Esempio n. 7
0
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return

    #check if bot is working
    if message.content.startswith('!heck'):
        msg = 'Heck Off {0.author.mention}'.format(message)
        await client.send_message(message.channel, msg)

    #text response
    if message.content.startswith('!venom'):
        msg = 'is cute uwu'.format(message)
        await client.send_message(message.channel, msg)

    #text response
    if message.content[0:4] == "ayy":
        await client.send_message(message.channel, "lmao".format(message))

    #text response
    if message.content[0:5] == "lmao":
        await client.send_message(message.channel, "ayy".format(message))

    #using giphy api post a random happy birthday gif
    if message.content.startswith("!hbd"):
        msg = "HAPPPY BARTHDAYYYYY "
        if len(message.mentions) > 0:
            msg += message.mentions[0].mention
        hbds = [x for x in g.search("happy birthday")]
        hbd = hbds[random.randint(0, len(hbds))]
        msg += " " + hbd.media_url
        await client.send_message(message.channel, msg)

    #tag spam a user(not recommended)
    if message.content.startswith("!tagspam"):
        msg = ""
        if len(message.mentions) > 0:
            for i in message.mentions:
                if i.mention == "<@199515135142920192>":  #hardcoded to not work against me xd
                    await client.send_message(message.channel, "Nope")
                    return
                msg += i.mention + "\t"
        else:
            msg = "Mention someone."
            await client.send_message(message.channel, msg)
            return
        if len(message.content.split(" ")) > 2:
            try:
                r = int(message.content.split(" ")[2])
                if r > 50:
                    r = 50
            except:
                r = 5
        else:
            r = 5
        for x in range(r):
            await client.send_message(message.channel, msg)

    #synonym using vocabulary api
    if message.content[0:3] == "!s ":  #match first 3 charachters
        query = message.content.split(" ")[
            1]  #seperate the content from the identifier
        result = vb.synonym(query)
        msg = ""
        if result == False:  #if no reply from api
            msg = "Not found"
        else:
            result = json.loads(result)  #parse json string
            for i in result:
                msg += i["text"] + "\n"  #add all results
        await client.send_message(message.channel, msg)

    #antonym using vocabulary api
    if message.content[0:3] == "!a ":
        query = message.content.split(" ")[1]
        result = vb.antonym(query)
        msg = ""
        if result == False:
            msg = "Not found"
        else:
            result = json.loads(result)
            for i in result:
                msg += i["text"] + "\n"
        await client.send_message(message.channel, msg)

    #usage
    if message.content[0:3] == "!u ":
        query = message.content.split(" ")[1:]
        query = ' '.join(query)
        result = vb.usage_example(query)
        msg = ""
        if result == False:
            msg = "Not found"
        else:
            result = json.loads(result)
            for i in result:
                msg += i["text"] + "\n"
        await client.send_message(message.channel, msg)

    #meaning
    if message.content[0:3] == "!m ":
        query = message.content.split(" ")[1]
        result = vb.meaning(query)
        msg = ""
        if result == False:
            msg = "Not found"
        else:
            result = json.loads(result)
            for i in result:
                msg += i["text"] + "\n"
        await client.send_message(message.channel, msg)

    #despacito
    if message.content.startswith("!despacito"):
        with open("despacito.txt") as file:
            content = file.readlines()
        j = 0
        while j < len(content):
            msg = ""
            i = 0
            while i < 10 and j < len(
                    content
            ):  #10 lines at a time to prevent getting rate limited by discord
                msg += content[j]
                i += 1
                j += 1
            await client.send_message(message.channel, msg)