예제 #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 open(self, filename):
		# Patterns Object
		song = Song()

		f = open(filename)
		line = f.readline()
		#f.write("Desfonema Sequencer File Format Version 1.1\n")
		version = line[40:-1]
		
		#Old version 1 format used 8 ticks for each beat instead of 24
		#so we need to compensate if it's an old format file.
		if version == '1':
			shifter = 3
		else:
			shifter = 1
		#Level Pattern(0) Track(1) or Notes(2)
		level = 0
		while line:
			line = line[:-1]
			if line == "Pattern":
				pattern = Pattern()
				song.add_pattern(pattern)
				level = 1

			if line == "Track":
				track = pattern.add_track()
				level = 2
			
			if line == "Notes":
				level = 3
				
			if line == "Controls":
				level = 5
				
			if line == "Pitchbends":
				level = 6

			if line == "Channel":
				channel = Channel()
				song.add_channel(channel)
				level = 4

			if level == 0:
				if line[:5] == "Bpm: ":
					song.set_bpm(int(line[5:]))
			if level == 1:
				#On Pattern Data
				if line[:5] == "Num: ":
					pattern.set_num(int(line[5:]))
				elif line[:5] == "Len: ":
					pattern.set_len(int(line[5:]))
				elif line[:6] == "Name: ":
					pattern.set_name(line[6:])
			elif level == 2:
				if line[:5] == "Len: ":
					track.set_len(int(line[5:]))
				elif line[:6] == "Name: ":
					track.set_name(line[6:])
				elif line[:8] == "Volume: ":
					track.set_volume(int(line[8:]))
				elif line[:7] == "Synth: ":
					track.set_synth(line[7:])
				elif line[:6] == "Port: ":
					track.set_port(int(line[6:]))
			elif level == 3:
				if line == "Notes":
					pass
				elif line == "EndNotes":
					level = 2
				else:
					line_data = line.split(', ')
					(note, pos, duration) = (line_data[0], line_data[1], line_data[2])
					if len(line_data) == 4:
						volume = int(line_data[3])
					else:
						volume = 127
					track.add_note(int(note),int(pos)*shifter,int(duration)*shifter, volume)
			elif level == 5:
				if line == "Controls":
					pass
				elif line == "EndControls":
					level = 2
				else:
					line_data = line.split(', ')
					(pos, param, value) = (line_data[0], line_data[1], line_data[2])
					track.set_control(int(pos), int(param), int(value))
					
			elif level == 5:
				if line == "Pitchbends":
					pass
				elif line == "EndPitchbends":
					level = 2
				else:
					line_data = line.split(', ')
					(pos, value) = (line_data[0], line_data[1])
					track.set_control(int(pos), int(value))
			elif level == 4:
				if line[:5] == "Pat: ":
					channel.add_pattern(song.get_pattern_by_name(line[5:]))
			
			line = f.readline()

		f.close()
		
		return song
예제 #8
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()