示例#1
0
文件: app.py 项目: fiston/jukebox
    def handle (self, message):
        parser = Parser(message.text)
        first_word = parser.next_word()

        user = get_connection_user(message.connection)

        if first_word.lower() == 'yay' or first_word.lower() == 'boo':
            playing = Request.objects.filter(status='P')
            if not playing:
                message.respond("There is no playing track to vote on")
                return True
            
            track = playing[0].track
            if first_word.lower() == 'yay':
                score = 1
            else:
                score = -1

            existing = Vote.objects.filter(request=playing[0],
                                           created_by=user)
            if existing:
                message.respond("You have already voted on this request")
                return True
            
            Vote.objects.create(request=playing[0], track=track, score=score,
                                created_by=user, modified_by=user)

            if score == 1:
                message.respond("Your positive vote has been recorded for %s" % track.name)
                call(["mpg123", '/Users/nicp/nyaruka/jukebox/yay.mp3'])
            else:
                message.respond("Your negative vote has been recorded for %s" % track.name)
                call(["mpg123", '/Users/nicp/nyaruka/jukebox/boo.mp3'])

        else:
            matching = Track.objects.filter(album__artist__name__icontains=message.text).order_by('?')

            if matching:
                existing = Request.objects.filter(status__in=['Q', 'P'], 
                                                  track__album__artist=matching[0].album.artist)

                if not existing:
                    Request.objects.create(track=matching[0],
                                           created_by=user,
                                           modified_by=user)
                    message.respond("Queuing the track: %s" % matching[0].name)
                else:
                    message.respond("That artist is already in the queue, please pick something else");
            else:
                message.respond("No matching song found for: %s" % message.text)

        return True
示例#2
0
    def handle (self, message):
        parser = Parser(message.text)
        first_word = parser.next_word()

        user = get_connection_user(message.connection)

        if first_word.lower() == 'yay' or first_word.lower() == 'boo':
            playing = Request.objects.filter(status='P')
            if not playing:
                message.respond("There is no playing track to vote on")
                return True
            
            track = playing[0].track
            if first_word.lower() == 'yay':
                score = 1
            else:
                score = -1

            existing = Vote.objects.filter(request=playing[0],
                                           created_by=user)
            if existing:
                message.respond("You have already voted on this request")
                return True
            
            Vote.objects.create(request=playing[0], track=track, score=score,
                                created_by=user, modified_by=user)

            if score == 1:
                message.respond("Your positive vote has been recorded for %s" % track.name)
                call(["mpg123", '/home/precise/Projects/jukebox/jukebox/yay.mp3'])
            else:
                message.respond("Your negative vote has been recorded for %s" % track.name)
                call(["mpg123", '/home/precise/Projects/jukebox/jukebox/boo.mp3'])

        else:
            matching = Track.objects.filter(album__artist__name__icontains=message.text).order_by('?')

            if matching:
                existing = Request.objects.filter(status__in=['Q', 'P'], 
                                                  track__album__artist=matching[0].album.artist)

                if not existing:
                    Request.objects.create(track=matching[0],
                                           created_by=user,
                                           modified_by=user)
                    message.respond("Queuing the track: %s" % matching[0].name)
                else:
                    message.respond("That artist is already in the queue, please pick something else");
            else:
                message.respond("No matching song found for: %s" % message.text)

        return True
示例#3
0
文件: app.py 项目: bamartial/jukebox
    def handle_message(self, message):
        """
        Messages have the following keywords:
            'miles' or 'car'
        """
        parser = Parser(message.text)
        keyword = parser.next_keyword(KEYWORDS, _('unrecognized', "That message is not recognized, must start with miles or car"))

        if keyword in ['car', 'c']:
            return self.handle_car(message, parser)

        elif keyword in ['miles', 'm']:
            return self.handle_miles(message, parser)
示例#4
0
文件: app.py 项目: kitaka/nsms
    def handle_message(self, message):
        """
        Messages have the following keywords:
            'miles' or 'car'
        """
        parser = Parser(message.text)
        keyword = parser.next_keyword(
            KEYWORDS,
            _('unrecognized',
              "That message is not recognized, must start with miles or car"))

        if keyword in ['car', 'c']:
            return self.handle_car(message, parser)

        elif keyword in ['miles', 'm']:
            return self.handle_miles(message, parser)
示例#5
0
    def handle(self, message):
        profile = get_sms_profile(message.connection)

        # handle activating the appropriate SMS language

        # if this connection has a profile, use that language
        if profile:
            translation.activate(profile.language)

        # otherwise use the default SMS language
        else:
            translation.activate(settings.DEFAULT_SMS_LANGUAGE)

        parser = Parser(message.text)

        # check whether this is a lang message
        keyword = parser.next_keyword(['lang'])
        if keyword:
            if not profile:
                message.respond(
                    _('lang-unknown-user',
                      "Sorry, your phone number is not registered."))
                return True

            # just querying the language
            language = parser.next_word()
            if not language:
                message.respond(
                    _('lang-current-lang',
                      "Your language is set to {{ language }}.",
                      dict(language=profile.get_language_display())))
                return True

            else:
                # lowercase the language they passed us
                language = language.lower()

                lang_mapping = dict()
                for lang in settings.LANGUAGES:
                    code = lang[0].lower()
                    lang_mapping[code] = code

                    parts = code.split('_')
                    if not parts[0] in lang_mapping:
                        lang_mapping[parts[0]] = code

                # this language doesn't exit
                if not language.lower() in lang_mapping:
                    message.respond(
                        _(
                            'lang-unknown-language',
                            "Sorry, the language code '{{ code }}' is not supported.",
                            dict(code=language.lower())))
                    return True

                profile.language = lang_mapping[language.lower()]
                profile.save()

                # activate the new language
                translation.activate(profile.language)
                message.respond(
                    _('lang-set-success',
                      "Success, your language is now set to {{ language }}.",
                      dict(language=profile.get_language_display())))

                return True

        return False
示例#6
0
文件: app.py 项目: hack-alex/nsms
    def handle (self, message):
        """
        Tries to look up a profile for the user and set the default language.

        Also takes care of handing the 'lang' keyword
        """

        profile = get_sms_profile(message.connection)

        # handle activating the appropriate SMS language

        # if this connection has a profile, use that language
        if profile:
            translation.activate(profile.language)

        # otherwise use the default SMS language
        else:
            translation.activate(settings.DEFAULT_SMS_LANGUAGE)

        parser = Parser(message.text)

        # check whether this is a lang message
        keyword = parser.next_keyword(['lang'])
        if keyword:
            if not profile:
                message.respond(_('lang-unknown-user', "Sorry, your phone number is not registered."))
                return True

            # just querying the language
            language = parser.next_word()
            if not language:
                message.respond(_('lang-current-lang', "Your language is set to {{ language }}.",
                                  dict(language=App.get_language_display(profile.language))))
                return True

            else:
                # lowercase the language they passed us
                language = language.lower()

                lang_mapping = dict()
                for lang in settings.LANGUAGES:
                    code = lang[0].lower()
                    lang_mapping[code] = code

                    parts = code.split('_')
                    if not parts[0] in lang_mapping:
                        lang_mapping[parts[0]] = code

                # this language doesn't exit
                if not language.lower() in lang_mapping:
                    message.respond(_('lang-unknown-language', "Sorry, the language code '{{ code }}' is not supported.",
                                      dict(code=language.lower())))
                    return True

                profile.language = lang_mapping[language.lower()]
                profile.save()
                
                # activate the new language
                translation.activate(profile.language)
                message.respond(_('lang-set-success', "Success, your language is now set to {{ language }}.",
                                  dict(language=App.get_language_display(profile.language))))

                return True

        return False