Code Duplication    Length = 19-19 lines in 2 locations

modules/replace.py 2 locations

@@ 144-162 (lines=19) @@
141
      #pybot sends the new replacement message to the chat
142
      self.say(event.channel, user + " MEANT to say: " + message)
143
    # because both .r and s// are valid formats now
144
    if event.msg.startswith("s/"):
145
      #alternative notation: s/<substring to replace>/<substring to replace with>
146
      string_token = event.msg[2:].split('/', 1)
147
      find_msg = string_token[0]
148
      try:
149
        replace_msg = string_token[1]
150
      except IndexError:
151
        return
152
      #looking for a message containing our search string
153
      newString = self.get_replacement_message(event.channel, find_msg)
154
      
155
      #because the mem_store line shows "<user> message", we have to split up the username and their message
156
      #this actually works to our advantage so we dont have to do additional calls to find out who sent what
157
      msg_index = newString.find(">")
158
      message = newString[msg_index + 2:]
159
      message = message.replace(find_msg, replace_msg)
160
      user = newString[1:msg_index]
161
      #pybot sends the new replacement message to the chat
162
      self.say(event.channel, user + " MEANT to say: " + message)
163
    if event.user != self.bot.NICK :
164
      self.add_buffer(event)
165
@@ 124-142 (lines=19) @@
121
    
122
  def handle(self, event):
123
    #first we see if we're going to try a replace or just add a line to the mem_store
124
    if event.msg.startswith(".r "):
125
      #split the msg with '.r ' stripped off beginning and divide into a search string and replace string
126
      string_token = event.msg[3:].split('|', 1)
127
      find_msg = string_token[0].rstrip()
128
      try:
129
        replace_msg = string_token[1].lstrip() #if there's nothing after the pipe, then this resolves to '' which is fine
130
      except IndexError:
131
        return
132
      #looking for a message containing our search string
133
      newString = self.get_replacement_message(event.channel, find_msg)
134
      
135
      #because the mem_store line shows "<user> message", we have to split up the username and their message
136
      #this actually works to our advantage so we dont have to do additional calls to find out who sent what
137
      msg_index = newString.find(">")
138
      message = newString[msg_index + 2:]
139
      message = message.replace(find_msg, replace_msg)
140
      user = newString[1:msg_index]
141
      #pybot sends the new replacement message to the chat
142
      self.say(event.channel, user + " MEANT to say: " + message)
143
    # because both .r and s// are valid formats now
144
    if event.msg.startswith("s/"):
145
      #alternative notation: s/<substring to replace>/<substring to replace with>