예제 #1
0
 def display_quote(self, request):
     """
     Select a quote from database and post it to a channel.
     
     Usage: .quote [<text>|<id>]
     
     @param request: A runtime request of an InteractiveModule command.
     
     @return InteractiveModuleResponse
     """
     response = InteractiveModuleResponse()
     
     try:
         text = request.parameter[0]
         if (len(text) > 0):
             try:
                 id = int(text)
                 quote = self.component.get_quote_by_id(id)
             except ValueError:
                 quote = self.component.get_random_quote_by_string(request.parameter[0])
         else:
             quote = self.component.get_random_quote()
          
         response.add_line("{0} ({1})".format(quote.text,quote.id))
     except NoQuoteAvailable:
         response.add_line("No quotes in database.")
         
     return response
예제 #2
0
 def roll(self, request):
     response = InteractiveModuleResponse()
     
     if request.parameter[1]:
         min_value = int(request.parameter[0])
         max_value = int(request.parameter[1])
     else:
         min_value = 1
         max_value = int(request.parameter[0])
 
     if max_value <= 0:
         response.add_line('Zahl muss groesser als 0 sein')
         return response
         
     if max_value <= 1:
         response.add_line('Zahl muss groesser als 1 sein')
         return response
     
     if max_value == min_value:
         response.add_line('Erste Zahl ({0}) == zweite Zahl ({0}), wie soll das denn gehen du Trottel?'.format(min_value, min_value))
         return response
     
     if max_value < min_value:
         max_value, min_value = min_value, max_value
         
     result = random.randint(min_value, max_value)
     
     response.add_line('{0} has rolled: {1} ({2}-{3})'.format(
         request.source.nickname,
         result,
         min_value,
         min_value
     ))
     
     return response
예제 #3
0
    def who(self, request):
        response = InteractiveModuleResponse()

        channel_name = request.target

        channel = self.usermgmt.chanlist.get(channel_name)

        user = random.choice(channel.get_users().keys())

        response.add_line('Meine Wahl fällt auf {0}!'.format(user))

        return response
예제 #4
0
 def who(self, request):
     response = InteractiveModuleResponse()
     
     channel_name = request.target
     
     channel = self.usermgmt.chanlist.get(channel_name)
     
     user = random.choice(channel.get_users().keys())
     
     response.add_line('Meine Wahl fällt auf {0}!'.format(user))
     
     return response
예제 #5
0
    def del_quote(self, request):
        """
        Delete a quote with the given id from database.
        
        Usage: .delquote <id>
        
        @param request: A runtime request of an InteractiveModule command.
        
        @return InteractiveModuleResponse
        """
        response = InteractiveModuleResponse()
        try:
            id = int(request.parameter[0])
            self.component.delete_quote_by_id(id)
            response.add_line("Delete was successful.")
        except ValueError:
            response.add_line(
                "If you like to delete a quote, you'll have to declare an ID instead of a string."
            )
        except NoAffectedRows:
            response.add_line(
                "Delete didn't work. Maybe, there isn't a quote with the given ID."
            )

        return response
예제 #6
0
 def add_new_addition(self, request):
     """
     Insert a new addition to database
     
     Usage: .addtopic <addtion(text)>
     
     @param request: A runtime request of an InteractiveModule command.
     
     @return InteractiveModuleResponse
     """
     response = InteractiveModuleResponse()
     self.component.insert_addition(request.parameter[0],request.source.nickname)
     response.add_line("The process was successful.")
     
     return response
예제 #7
0
    def insert_user(self, request):
        """
        .adduser [password]
        """
        """password = request.parameter[0]
        
        try:
            user = self.getAuth(request.source)
            return "User '???' wurde als Admin hinzugefügt."
        
            if not user:
                raise UserNotAuthenticated
            
            if self.isPrivateUser(user):
                raise UserExists
        
            # TODO impl
            #password_hash = hashlib.sha1(password).hexdigest()
        
        except UserNotAuthenticated:
            return "Du bist nicht geauthed!"
        
        except UserExists:
            return "Du hast bereits einen Account!"
        
        return "Dein Account wurde erstellt!"""
        response = InteractiveModuleResponse('not implemented')

        return response
예제 #8
0
    def add_new_addition(self, request):
        """
        Insert a new addition to database
        
        Usage: .addtopic <addtion(text)>
        
        @param request: A runtime request of an InteractiveModule command.
        
        @return InteractiveModuleResponse
        """
        response = InteractiveModuleResponse()
        self.component.insert_addition(request.parameter[0],
                                       request.source.nickname)
        response.add_line("The process was successful.")

        return response
예제 #9
0
    def search_contact(self, request):
        """
        """

        response = InteractiveModuleResponse("not implemented")

        return response
예제 #10
0
    def display_calendar_address(self, request):
        """
        Display the web calendar's address.
        """

        response = InteractiveModuleResponse(self.config.get('calendarUrl'))

        return response
예제 #11
0
 def display_current_topic(self, request):
     """
     Display the current topic.
     
     Usage: .topic
            
     @return InteractiveModuleResponse
     """
     response = InteractiveModuleResponse()
     
     try:
         topic = self.component.get_last_topic()           
         topic_string = self.component.create_topic_string(topic.text,topic.addition.text,topic.year)
         response.add_line('{0} set by {1}'.format(topic_string,topic.user))
     except TopicNotFound:
         response.add_line("No topic available.")
     
     return response
예제 #12
0
 def display_topic_additions(self, request):
     """
     Send a link to a list with all additions.
     
     Usage: .listtopic
     
     @return: InteractiveModuleResponse
     """
     return InteractiveModuleResponse("www.derlinkfehltnoch.de")
예제 #13
0
 def sort(self,request):
     """
     Reorder the given items.
     
     @return: InteractiveModuleResponse()
     """
     response = InteractiveModuleResponse()
     
     items_unsorted = request.parameter[0].split(',')
     items_sorted = []
     
     while len(items_unsorted) > 0:
         num = random.randint(0,len(items_unsorted)-1)
         items_sorted.append(items_unsorted[num].strip())
         del items_unsorted[num]
     
     response.add_line(", ".join(items_sorted))
     
     return response
예제 #14
0
    def sort(self, request):
        """
        Reorder the given items.
        
        @return: InteractiveModuleResponse()
        """
        response = InteractiveModuleResponse()

        items_unsorted = request.parameter[0].split(',')
        items_sorted = []

        while len(items_unsorted) > 0:
            num = random.randint(0, len(items_unsorted) - 1)
            items_sorted.append(items_unsorted[num].strip())
            del items_unsorted[num]

        response.add_line(", ".join(items_sorted))

        return response
예제 #15
0
    def set_new_topic(self, request):
        """
        Change the topic of a channel.
        
        Usage: .settopic <text|'reset'>
        If the module receive the string 'reset', it will set the default topic
        
        @param request: A runtime request of an InteractiveModule command.
        
        @return InteractiveModuleResponse 
        """        
        response = InteractiveModuleResponse()
        
        #Normally, here I would check if there was set the mode +t in channel modes
        #because if it was set, I won't need to check the userMode.
        #But get_modes() is not implemnted, yet :(
        #channelModes = channelObject.get_modes()
        
        channel_object = self.usermgmt.chanlist.get(request.target)
        userMode = channel_object.get_user_mode(self.me.source.nickname)
        try:
            if (userMode == BOT_IS_OPERATOR):
                text = request.parameter[0]
                
                if (text == 'reset'): #default topic
                    text = DEFAULT_TOPIC
    
                addition = self.component.get_random_addition().text
                year = random.randint(RANDOM_YEAR_START,RANDOM_YEAR_END)
                               
                topic_cmd = self.client.get_command('Topic').get_sender()  
                topic_cmd.channel = request.target
                topic_cmd.topic = self.create_topic_string(text,addition,year)
                topic_cmd.send()
                
                self.component.insert_topic(text,addition,year,request.source.nickname)                                
            else:
                response.add_line("Bot needs to be an operator to do this.")
        except NoAdditionAvailable:
                response.add_line("There are no topic additions available at the moment.")

        return response
예제 #16
0
 def search_quotes(self,request):
     """
     Search in database for quote with the given string.
     It will display all IDs of the founded quotes
     
     Usage: .searchquote <text>
     
     @param request: A runtime request of an InteractiveModule command.
     
     @return InteractiveModuleResponse
     """
     response = InteractiveModuleResponse()
     
     ids = self.component.get_ids_by_string(request.parameter[0])
     if len(ids) > 0:
         response.add_line("Found the string in following quotes: {0}".format(" ".join(str(ids))))
     else:
         response.add_line("There isn't a quote with the given id.")
     
     return response    
예제 #17
0
    def display_quote(self, request):
        """
        Select a quote from database and post it to a channel.
        
        Usage: .quote [<text>|<id>]
        
        @param request: A runtime request of an InteractiveModule command.
        
        @return InteractiveModuleResponse
        """
        response = InteractiveModuleResponse()

        try:
            text = request.parameter[0]
            if (len(text) > 0):
                try:
                    id = int(text)
                    quote = self.component.get_quote_by_id(id)
                except ValueError:
                    quote = self.component.get_random_quote_by_string(
                        request.parameter[0])
            else:
                quote = self.component.get_random_quote()

            response.add_line("{0} ({1})".format(quote.text, quote.id))
        except NoQuoteAvailable:
            response.add_line("No quotes in database.")

        return response
예제 #18
0
 def add_new_quote(self, request):
     """
     Add a new quote to database.
     Max length of the quote is 375 letters.
     
     Usage: .addquote <text>
     
     @param request: A runtime request of an InteractiveModule command.
     
     @return InteractiveModuleResponse
     """
     response = InteractiveModuleResponse()
     
     text = request.parameter[0]
     if len(text) <= MAX_LENGTH_QUOTE:
         self.component.insert_quote(text,request.source.nickname)
         response.add_line("The process was successful.")
     else:
         response.add_line("Max length of a quote is {0} letters. Yours is {1}."
                           .format(MAX_LENGTH_QUOTE,str(len(text))))
     
     return response
예제 #19
0
    def search_event(self, request):
        """
        Search for an event
        
        .searchevent <text>
        """

        response = InteractiveModuleResponse()

        query = request.parameter[0]

        try:
            events = self.component.find_events_by_substring(query)

            [
                response.add_line("(ID={0}) {1}".format(event.id, event.title))
                for event in events
            ]

        except NoEventsFound:
            response.add_line("Keine Einträge mit diesem Inhalt gefunden.")

        return response
예제 #20
0
    def change_event(self, event, location, command, parameter):
        """
        Change an existing event.
        The event is identified by its ID.
        
        Syntax: <id> <start|ende|titel|beschreibung|ort> <wert>
        """

        response = InteractiveModuleResponse()

        eventId = parameter[0]
        attribute = parameter[1]
        value = parameter[2]

        try:
            map = {
                'start': 'start',
                'ende': 'end',
                'titel': 'title',
                'beschreibung': 'description',
                'ort': 'location'
            }

            if attribute in ['start', 'ende']:
                value = self._get_date(value)

            event = self.component.find_event_by_id(eventId)

            setattr(event, map[attribute], value)

            self.component.update_object(event)

            response.add_line(
                '{0} fuer Eintrag {1} wurde auf {2} gesetzt'.format(
                    attribute.capitalize(), event.id, value))

        except DateFormatInvalid:
            response.add_line(
                "Datum muss im Format [d]d.[m]m.yyyy sein. Bsp: 12.5.2010")

        except EventNotFound:
            response.add_line('Kein Event mit ID {0} gefunden'.format(eventId))

        return response
예제 #21
0
    def insert_event(self, request):
        """
        Create a new event.
        
        .addevent <startdate>[-<enddate>] title
        """

        response = InteractiveModuleResponse()

        date = request.parameter[0]
        title = request.parameter[1]

        try:
            if '-' not in date:
                dateFrom = self._get_date(date)
                dateTo = dateFrom

            else:
                dates = date.split('-')

                dateFrom = self._get_date(dates[0])
                dateTo = self._get_date(dates[1])

            calendar = self.component.find_default_calendar()

            event = Event(calendar=calendar,
                          start=dateFrom,
                          end=dateTo,
                          title=title)
            event = self.component.insert_object(event)

            response.add_line("Eintrag erfolgreich eingefügt! ID: {0}".format(
                event.id))

        except DateFormatInvalid:
            response.add_line(
                "Datum muss im Format [d]d.[m]m.yyyy sein. Bsp: 12.5.2010")

        except DateRangeInvalid as e:
            response.add_line('Ungültiges Datum: {0}.'.format(e))

        return response
예제 #22
0
    def del_addition(self, request):
        """
        Delete a addition with the given id.
        
        .deltopic <id>
        
        @param request: A runtime request of an InteractiveModule command.
        
        @return: InteractiveModuleResponse
        """
        response = InteractiveModuleResponse()

        try:
            id = int(request.parameter[0])
            self.component.delete_addition_by_id(id)
            response.add_line("Delete was successful.")
        except NoAffectedRows:
            response.add_line("No entry was deleted.")
        except ValueError:
            response.add_line("Please enter a valid ID!")

        return response
예제 #23
0
    def del_quote(self,request):
        """
        Delete a quote with the given id from database.
        
        Usage: .delquote <id>
        
        @param request: A runtime request of an InteractiveModule command.
        
        @return InteractiveModuleResponse
        """
        response = InteractiveModuleResponse()   
        try:
            id = int(request.parameter[0])
            self.component.delete_quote_by_id(id)
            response.add_line("Delete was successful.")
        except ValueError:
            response.add_line("If you like to delete a quote, you'll have to declare an ID instead of a string.")
        except NoAffectedRows:
            response.add_line("Delete didn't work. Maybe, there isn't a quote with the given ID.")    
 
        return response
예제 #24
0
    def set_new_topic(self, request):
        """
        Change the topic of a channel.
        
        Usage: .settopic <text|'reset'>
        If the module receive the string 'reset', it will set the default topic
        
        @param request: A runtime request of an InteractiveModule command.
        
        @return InteractiveModuleResponse 
        """
        response = InteractiveModuleResponse()

        #Normally, here I would check if there was set the mode +t in channel modes
        #because if it was set, I won't need to check the userMode.
        #But get_modes() is not implemnted, yet :(
        #channelModes = channelObject.get_modes()

        channel_object = self.usermgmt.chanlist.get(request.target)
        userMode = channel_object.get_user_mode(self.me.source.nickname)
        try:
            if (userMode == BOT_IS_OPERATOR):
                text = request.parameter[0]

                if (text == 'reset'):  #default topic
                    text = DEFAULT_TOPIC

                addition = self.component.get_random_addition().text
                year = random.randint(RANDOM_YEAR_START, RANDOM_YEAR_END)

                topic_cmd = self.client.get_command('Topic').get_sender()
                topic_cmd.channel = request.target
                topic_cmd.topic = self.create_topic_string(
                    text, addition, year)
                topic_cmd.send()

                self.component.insert_topic(text, addition, year,
                                            request.source.nickname)
            else:
                response.add_line("Bot needs to be an operator to do this.")
        except NoAdditionAvailable:
            response.add_line(
                "There are no topic additions available at the moment.")

        return response
예제 #25
0
    def del_addition(self, request):
        """
        Delete a addition with the given id.
        
        .deltopic <id>
        
        @param request: A runtime request of an InteractiveModule command.
        
        @return: InteractiveModuleResponse
        """
        response = InteractiveModuleResponse()               

        try:
            id = int(request.parameter[0])
            self.component.delete_addition_by_id(id)
            response.add_line("Delete was successful.")
        except NoAffectedRows:
            response.add_line("No entry was deleted.")
        except ValueError:
            response.add_line("Please enter a valid ID!")
        
        return response
예제 #26
0
    def display_current_topic(self, request):
        """
        Display the current topic.
        
        Usage: .topic
               
        @return InteractiveModuleResponse
        """
        response = InteractiveModuleResponse()

        try:
            topic = self.component.get_last_topic()
            topic_string = self.component.create_topic_string(
                topic.text, topic.addition.text, topic.year)
            response.add_line('{0} set by {1}'.format(topic_string,
                                                      topic.user))
        except TopicNotFound:
            response.add_line("No topic available.")

        return response
예제 #27
0
    def search_quotes(self, request):
        """
        Search in database for quote with the given string.
        It will display all IDs of the founded quotes
        
        Usage: .searchquote <text>
        
        @param request: A runtime request of an InteractiveModule command.
        
        @return InteractiveModuleResponse
        """
        response = InteractiveModuleResponse()

        ids = self.component.get_ids_by_string(request.parameter[0])
        if len(ids) > 0:
            response.add_line(
                "Found the string in following quotes: {0}".format(" ".join(
                    str(ids))))
        else:
            response.add_line("There isn't a quote with the given id.")

        return response
예제 #28
0
    def add_new_quote(self, request):
        """
        Add a new quote to database.
        Max length of the quote is 375 letters.
        
        Usage: .addquote <text>
        
        @param request: A runtime request of an InteractiveModule command.
        
        @return InteractiveModuleResponse
        """
        response = InteractiveModuleResponse()

        text = request.parameter[0]
        if len(text) <= MAX_LENGTH_QUOTE:
            self.component.insert_quote(text, request.source.nickname)
            response.add_line("The process was successful.")
        else:
            response.add_line(
                "Max length of a quote is {0} letters. Yours is {1}.".format(
                    MAX_LENGTH_QUOTE, str(len(text))))

        return response
예제 #29
0
    def display_events_by_date(self, request):
        """
        Display events occuring at the given date.
        """

        response = InteractiveModuleResponse()

        date = request.parameter[0]

        try:
            calendar_events = self.component.find_events_by_date(date)

            if len(calendar_events) == 0:
                raise NoEventsFound

            for calendar_event in calendar_events:
                response.add_line("ID {0}: {1}".format(calendar_event.id,
                                                       calendar_event.title))

        except NoEventsFound:
            response.add_line('Keine Termine gefunden.')

        return response
예제 #30
0
    def topic_event(self, request):
        """
        Post the given event to the current topic.
        .topicevent 
        
        TODO: implement
        """

        response = InteractiveModuleResponse()

        eventId = int(request.parameter[0])

        try:
            result = self.component.find_event_by_id(eventId)

            if result is None:
                raise EventNotFound

            response.add_line('currently not implemented')

        except EventNotFound:
            response.add_line('Kein Event mit ID {0} gefunden'.format(eventId))

        return response
예제 #31
0
    def delete_event(self, request):
        """
        .delevent [<id>|<datum>]
        """

        response = InteractiveModuleResponse()

        # when only one parameter is defined a string is returned
        id_or_date = request.parameter[0]

        try:
            try:
                date = self._get_date(id_or_date)

                #---------------------------------------------------------------
                # delete by date
                #---------------------------------------------------------------
                events = self.component.find_events_by_date(date)

                count = len(events)

                if count == 0:
                    raise NoEventsFound

                if count > 1:
                    raise AmbiguousEventsFound(events)

                event = events[0]

            except DateFormatInvalid:
                #---------------------------------------------------------------
                # delete by id
                #---------------------------------------------------------------
                eventId = int(id_or_date)

                event = self.component.find_event_by_id(eventId)

                if not event:
                    raise NoEventsFound

            self.component.delete_object(event)

            response.add_line(
                "Eintrag {0} wurde geloescht.".format(id_or_date))

        except InvalidObjectId:
            response.add_line("Kein Eintrag zu dieser ID gefunden.")

        except NoEventsFound:
            response.add_line("Kein Eintrag zu diesem Datum gefunden.")

        except AmbiguousEventsFound as error:
            response.add_line('Mehrere Einträge gefunden:')
            [
                response.add_line("(ID={0}) {1}".format(event.id, event.title))
                for event in error.message
            ]

        return response
예제 #32
0
 def quit(self, request):
     response = InteractiveModuleResponse('not implemented')
     
     return response
예제 #33
0
    def restore_deleted_object(self, request):
        """
        """

        return InteractiveModuleResponse('not implemented')
예제 #34
0
    def decide(self, request):
        response = InteractiveModuleResponse()

        issue = request.parameter[0]

        if len(issue) == 0:
            if random.randint(1, 1000) % 2 == 0:
                response.add_line('Du solltst dich dafür entscheiden!')
            else:
                response.add_line('Du solltst dich dagegen entscheiden!')

        else:
            choices = re.sub('( oder | or )', ',', issue).split(',')

            if len(choices) == 1:
                pick = choices[0]

                if random.randint(1, 1000) % 2 == 0:
                    response.add_line(
                        'Du solltst dich für \'{0}\' entscheiden!'.format(
                            pick.strip()))
                else:
                    response.add_line(
                        'Du solltst dich gegen \'{0}\' entscheiden'.format(
                            pick.strip()))

            else:
                pick = random.choice(choices)

                response.add_line(
                    'Du solltst dich für \'{0}\' entscheiden'.format(
                        pick.strip()))

        return response
예제 #35
0
 def decide(self, request):
     response = InteractiveModuleResponse()
     
     issue = request.parameter[0]
     
     if len(issue) == 0:
         if random.randint(1,1000) % 2 == 0:
             response.add_line('Du solltst dich dafür entscheiden!')
         else:
             response.add_line('Du solltst dich dagegen entscheiden!')
     
     else:
         choices = re.sub('( oder | or )', ',', issue).split(',')
         
         if len(choices) == 1:
             pick = choices[0]
             
             if random.randint(1,1000) % 2 == 0:
                 response.add_line('Du solltst dich für \'{0}\' entscheiden!'.format(pick.strip()))
             else:
                 response.add_line('Du solltst dich gegen \'{0}\' entscheiden'.format(pick.strip()))
         
         else:
             pick = random.choice(choices)
             
             response.add_line('Du solltst dich für \'{0}\' entscheiden'.format(pick.strip()))
     
     return response
예제 #36
0
    def delete_user(self, request):
        response = InteractiveModuleResponse('not implemented')

        return response
예제 #37
0
 def change_nickname(self, request):
     response = InteractiveModuleResponse('not implemented')
     
     return response
예제 #38
0
 def part_channel(self, request):
     response = InteractiveModuleResponse('not implemented')
     
     return response
예제 #39
0
    def display_deleted_objects(self, event, location, command, parameter):
        """
        """

        return InteractiveModuleResponse('not implemented')