Beispiel #1
0
    def test_unassignBook(self):
        scrubData()
        b.assignBook(testBookName, "Ethan")

        expected = b.returnMessages.bookUnassigned.format(testBookName, "Ethan")
        actual = b.unassignBook("Ethan")
        self.assertEquals(expected, actual)
Beispiel #2
0
    def test_getAssignedBook(self):
        scrubData()
        b.assignBook(testBookName, "Ethan")

        expected = b.returnMessages.assignedBook.format("Ethan", testBookName)
        actual = b.getAssignedBook("Ethan")
        self.assertEquals(expected, actual)
Beispiel #3
0
    def test_getAllAssignedBooks(self):
        scrubData()
        b.assignBook(testBookName, "Ethan")
        b.assignBook("otherBook1", "Z")
        b.assignBook("", "Gambit")

        expected1 = "Ethan is currently reading {0}.\n".format(testBookName)
        expected2 = "Z is currently reading otherBook1.\n"
        expected3 = "Gambit has no book club book.\n"
        expected = [expected1, expected2, expected3]
        actual = b.getAllAssignedBooks()
        self.assertNotIn(False, [exp in actual for exp in expected])
Beispiel #4
0
 def test_assignBook(self):
     scrubData()
     
     expected = b.returnMessages.bookAssigned.format(testBookName, "Ethan")
     actual = b.assignBook(testBookName, "Ethan")
     self.assertIn(expected, actual)
Beispiel #5
0
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)