예제 #1
0
    def test_message_does_not_contain_command(self):
        message = Message("I just pooped my pants :(", "randomuser")
        channel = Channel(Config.CHANNEL_NAME)
        commandhandler = CommandHandler(channel)

        commandres, argumentres = commandhandler.message_contains_command(
            message)

        self.assertEqual(None, commandres)
        self.assertEqual(None, argumentres)
예제 #2
0
    def test_message_contains_command(self):
        command = "!uptime"
        commandname = "uptime"
        message = Message(command, "randomuser")
        channel = Channel(Config.CHANNEL_NAME)
        commandhandler = CommandHandler(channel)

        commandres, argumentres = commandhandler.message_contains_command(
            message)

        self.assertEqual(commandname, commandres)
        self.assertEqual(None, argumentres)
예제 #3
0
    def test_message_contains_command_with_arguments(self):
        command = "!bonus"
        commandname = "bonus"
        argument = "ToMiSmE 1000"
        message = Message(command + " " + argument, "randomuser")
        channel = Channel(Config.CHANNEL_NAME)
        commandhandler = CommandHandler(channel)

        commandres, argumentres = commandhandler.message_contains_command(
            message)

        self.assertEqual(commandname, commandres)
        self.assertEqual(argument, argumentres)
예제 #4
0
    def test_command_does_not_exists_is_not_triggered(self):
        command = "!boguscommand"
        message = Message(command, "randomuser")
        channel = Channel(Config.CHANNEL_NAME)
        channel.commands.append(
            Command(-1, Config.CHANNEL_NAME, "Blizzard id", True,
                    "My Blizzard ID is UncleBob#199", True, True, True, False,
                    False, False, None, None))
        commandhandler = CommandHandler(channel)

        commandres, can_trigger = commandhandler.is_command_triggered(message)

        self.assertEqual(None, commandres)
        self.assertEqual(None, can_trigger)
예제 #5
0
    def test_command_exists_and_is_triggered(self):
        command = "!social"
        commandname = "social"
        message = Message(command, "randomuser")
        channel = Channel(Config.CHANNEL_NAME)
        channel.commands.append(
            Command(-1, Config.CHANNEL_NAME, "social", True,
                    "Join my Discord at www.discord.com", True, True, True,
                    True, True, True, None, None))
        commandhandler = CommandHandler(channel)

        commandres, can_trigger = commandhandler.is_command_triggered(message)

        self.assertEqual(commandname, commandres.name)
        self.assertEqual(True, can_trigger)
예제 #6
0
def getComment(json, replyCount=0):
    """Create Comment model from json"""
    channel = Channel(json["snippet"]["authorChannelId"]["value"])
    video = Video_stub(json["snippet"]["videoId"])
    comment = Comment(
        commentId=json["id"],
        etag=json["etag"],
        publishedAt=datetime.strptime(json["snippet"]["publishedAt"],
                                      '%Y-%m-%dT%H:%M:%SZ'),
        updatedAt=datetime.strptime(json["snippet"]["updatedAt"],
                                    '%Y-%m-%dT%H:%M:%SZ'),
        likeCount=int(json["snippet"]["likeCount"]),
        totalReplyCount=int(replyCount),
        textOriginal=json["snippet"]["textOriginal"],
    )

    comment.channel.add(channel)
    comment.video.add(video)
    return comment
예제 #7
0
    def loadDB(self):
        #- Load all data of DB into globalusers and globalchannels
        #- Follow models to see how to store them
        #- Suggested order:
        #users: Load ivleid, email, fullname, nickname and create User objects
        #mute: Load to user.mute
        #channel: Load channel name, topic, public, registered
        #permission: Load chan.permissions
        #acl: Load chan.users and chan.userslevels
        #autojoin: Load user.autojoin
        #- two objects are returned, (channels, users)
        #- channels maps channel.name to channel object
        #- users map user.ivleid to user object
        #- all the data in DB are initialised to all these objects
        try:
            usersql = "SELECT * FROM _User"
            self.cursor.execute(usersql)
            userslist = self.cursor.fetchall()
            self.db.commit()
            userobjlist = {}
            #Storing user objects into user-map.
            for user in userslist:
                userobjlist[user[0]] = User(user[0], user[2], user[1], user[3])

            mutesql = "SELECT * FROM _Mute"
            self.cursor.execute(mutesql)
            mutelist = self.cursor.fetchall()
            self.db.commit()
            #storing mute-d users data to the respective users
            for mute in mutelist:
                userobjlist[mute[0]].mute[mute[1]] = userobjlist[mute[1]]

            channelsql = "SELECT * FROM _Channel"
            self.cursor.execute(channelsql)
            channellist = self.cursor.fetchall()
            self.db.commit()
            channelobjlist = {}
            #permissions = PermissionList()
            #Storing channel objects into channel-map (includes permissions)
            for channel in channellist:
                #permissions.permissionTypes = json.loads(channel[4])
                permissions = PermissionList(json.loads(channel[4]))
                if channel[2] == '1' and channel[3] == '1':
                    channelobjlist[channel[0].lower()] = Channel(
                        channel[0], channel[1], True, True, permissions, None)
                elif channel[2] == '0' and channel[3] == '1':
                    channelobjlist[channel[0].lower()] = Channel(
                        channel[0], channel[1], False, True, permissions, None)
                elif channel[3] == '0' and channel[2] == '1':
                    channelobjlist[channel[0].lower()] = Channel(
                        channel[0], channel[1], True, False, permissions, None)
                else:
                    channelobjlist[channel[0].lower()] = Channel(
                        channel[0], channel[1], False, False, permissions,
                        None)

            aclsql = "SELECT * FROM _ACL"
            self.cursor.execute(aclsql)
            acllist = self.cursor.fetchall()
            self.db.commit()
            #Storing ACL into channel object and populating users in a channel into channel object
            for acl in acllist:
                channelobjlist[acl[1].lower()].accesscontrollist.add(
                    acl[0], acl[2])

            autojoinsql = "SELECT * FROM _AutoJoin"
            self.cursor.execute(autojoinsql)
            autojoinlist = self.cursor.fetchall()
            self.db.commit()
            #Storing autojoin into user object
            for autojoin in autojoinlist:
                userobjlist[autojoin[0]].autojoin[
                    autojoin[1]] = channelobjlist[autojoin[1].lower()]

            foldersql = "SELECT * FROM _Document"
            self.cursor.execute(foldersql)
            doclist = self.cursor.fetchall()
            self.db.commit()
            hangoutfolderlist = {}

            for doc in doclist:
                documentobj = Document(doc[0], doc[1], doc[2], doc[3], doc[4],
                                       doc[5])
                if doc[0] not in hangoutfolderlist:
                    hangoutfolderlist[doc[0]] = {}
                hangoutfolderlist[doc[0]][doc[1]] = documentobj

            return (channelobjlist, userobjlist, hangoutfolderlist)
        except Exception, e:
            print "Error connecting db, sleeping for 5 secs:"
            print e
            time.sleep(5)
            self._conDB_()
            return self.loadDB()