コード例 #1
0
    def test_AddBook(self):
        scrubData()

        expected = b.returnMessages.bookAdded.format(testBookName)
        actual = b.addBookToList(testBookName)
        self.assertEqual(expected, actual)
        
        expected = b.returnMessages.bookInList.format(testBookName)
        actual = b.addBookToList(testBookName)
        self.assertEquals(expected, actual)
コード例 #2
0
 def test_removeBook(self):
     scrubData()
     b.addBookToList(testBookName)
     
     expected = b.returnMessages.bookRemoved.format(testBookName)
     actual = b.removeBookFromList(testBookName)
     self.assertEquals(expected, actual)
     
     expected = b.returnMessages.bookNotInList.format(testBookName)
     actual = b.removeBookFromList(testBookName)
     self.assertEquals(expected, actual)
コード例 #3
0
    def test_assignRandomBook(self):
        scrubData()
        b.addBookToList(testBookName)
        b.addBookToList("testBook2")

        expected1 = b.returnMessages.bookAssigned.format(testBookName, "Ethan")
        expected2 = b.returnMessages.bookAssigned.format("testBook2", "Ethan")
        actual = b.assignRandomBook("Ethan")

        try: 
            self.assertIn(expected1, actual)
        except AssertionError:
            expectedFragment = "'{0}' and '{1}' are".format(expected1, expected2)
            responseFragment = "'{0}'".format(actual)
            assertErrorMessage = containsErrorMessage.format(expectedFragment, responseFragment)
            self.assertIn(expected2, actual, assertErrorMessage)
コード例 #4
0
    def test_listBooks(self):
        scrubData()
        b.addBookToList(testBookName)
        b.addBookToList("another book")
        b.addBookToList("one more book")

        expected1 = testBookName + '\n'
        expected2 = "another book\n"
        expected3 = "one more book\n"
        expected = [expected1, expected2, expected3]
        actual = b.listBooks()
        self.assertNotIn(False, [exp in actual for exp in expected])
コード例 #5
0
ファイル: neat_bot.py プロジェクト: superjkm/NeatBot
async def on_message(message):
    if message.author.bot:
        return

    userName = message.author.name
    response = ""
    cmd = message.content.lower()

    if cmd == 'hey ' + botName:
        response = getGif("hello")
    elif cmd == 'aw_yeah':
        response = aw_yeahUrl
    elif cmd.startswith(gifTriggerString):
        searchTerm = ""
        if len(message.content) > len(gifTriggerString):
            searchTerm = message.content[len(gifTriggerString):].lstrip()
        response = getGif(searchTerm)
    elif cmd.startswith(topTrendingGifTrigger):
        response = getTrendingGif(0, "1")
    elif cmd.startswith(randomTrendingGifTrigger):
        response = getRandomTrendingGif()
    elif cmd.startswith(rollTriggerString):
        maxRoll = 100
        if (len(message.content) > len(rollTriggerString)):
            maxRoll = int(cmd[len(rollTriggerString):].lstrip())

        response = roll(maxRoll)
    elif cmd == 'randomwinner':
        highRoll = 0
        winner = ""
        for member in getActiveMembers():
            currRoll = roll(100)
            if currRoll > highRoll:
                highRoll = currRoll
                winner = member.name

        response = winner + " wins with a roll of " + str(highRoll)
    elif cmd == 'fillscreen':
        response = fillScreenImageUrl
    elif notifyTriggerString in cmd:
        channel = message.channel
        member = channel.server.get_member_named(memberToNotify)
        # Only notify if the member is offline
        if member not in getActiveMembers():
            await client.send_message(member,
                                      'PUBG was mentioned in ' + channel.name)
    elif cmd.startswith(addBookTrigger):
        if len(message.content) > len(addBookTrigger):
            bookName = message.content[len(addBookTrigger):].lstrip()
            response = bookService.addBookToList(bookName)
    elif cmd == listBooksTrigger:
        response = bookService.listBooks()
    elif cmd.startswith(removeBookTrigger):
        if len(message.content) > len(removeBookTrigger):
            bookName = message.content[len(removeBookTrigger):].lstrip()
            response = bookService.removeBookFromList(bookName)
    elif cmd.startswith(assignBookTrigger):
        if len(message.content) > len(assignBookTrigger):
            bookName = message.content[len(assignBookTrigger):].lstrip()
            response = bookService.assignBook(bookName, userName)
    elif cmd == assignRandomBookTrigger:
        response = bookService.assignRandomBook(userName)
    elif cmd == unassignBookTrigger:
        response = bookService.unassignBook(userName)
    elif cmd == getMyBookTrigger:
        response = bookService.getAssignedBook(userName)
    elif cmd == getAllBooksTrigger:
        response = bookService.getAllAssignedBooks()

    if response != "":
        await client.send_message(message.channel, response)