Code Duplication    Length = 58-58 lines in 2 locations

libs/displayname.py 2 locations

@@ 135-192 (lines=58) @@
132
    # Should never get here
133
    return None
134
135
def checkRoleForInt(name, server):
136
    theList = name.split()
137
    # We see if we have multiple parts split by a space
138
    if len(theList)<2:
139
        # Only one part - no int included (or not separated by space)
140
        # Check if role exists - and if not throw an error, if so, throw a diff error
141
        amember = roleForName(name, server)
142
        if amember:
143
            # We at least have a member
144
            return { "Role" : amember, "Int" : None }
145
        else:
146
            # Now we check if we got an ID instead
147
            # Get just the numbers
148
            memID = ''.join(list(filter(str.isdigit, name)))
149
            newMem = roleForID(memID, server)
150
            if newMem:
151
                # We FOUND it!
152
                return { "Role" : newMem, "Int" : None }
153
            else:
154
                # Nothing was right about this...
155
                return { "Role" : None, "Int" : None }
156
    try:
157
        # Let's cast the last item as an int and catch any exceptions
158
        theInt = int(theList[len(theList)-1])
159
        newMemberName = " ".join(theList[:-1])
160
        amember = roleForName(newMemberName, server)
161
        if amember:
162
            return { "Role" : amember, "Int" : theInt }
163
        else:
164
            # Now we check if we got an ID instead
165
            # Get just the numbers
166
            memID = ''.join(list(filter(str.isdigit, newMemberName)))
167
            newMem = roleForID(memID, server)
168
            if newMem:
169
                # We FOUND it!
170
                return { "Role" : newMem, "Int" : theInt }
171
            else:
172
                # Nothing was right about this...
173
                return { "Role" : None, "Int" : None }
174
    except ValueError:
175
        # Last section wasn't an int
176
        amember = roleForName(name, server)
177
        if amember:
178
            # Name was just a role - return
179
            return { "Role" : amember, "Int" : None }
180
        else:
181
            # Now we check if we got an ID instead
182
            # Get just the numbers
183
            memID = ''.join(list(filter(str.isdigit, name)))
184
            newMem = roleForID(memID, server)
185
            if newMem:
186
                # We FOUND it!
187
                return { "Role" : newMem, "Int" : None }
188
            else:
189
                # Nothing was right about this...
190
                return { "Role" : None, "Int" : None }
191
    # Should never get here
192
    return None
193
@@ 76-133 (lines=58) @@
73
            return name(member)
74
    return None
75
76
def checkNameForInt(name, server):
77
    theList = name.split()
78
    # We see if we have multiple parts split by a space
79
    if len(theList)<2:
80
        # Only one part - no int included (or not separated by space)
81
        # Check if member exists - and if not throw an error, if so, throw a diff error
82
        amember = memberForName(name, server)
83
        if amember:
84
            # We at least have a member
85
            return { "Member" : amember, "Int" : None }
86
        else:
87
            # Now we check if we got an ID instead
88
            # Get just the numbers
89
            memID = ''.join(list(filter(str.isdigit, name)))
90
            newMem = memberForID(memID, server)
91
            if newMem:
92
                # We FOUND it!
93
                return { "Member" : newMem, "Int" : None }
94
            else:
95
                # Nothing was right about this...
96
                return { "Member" : None, "Int" : None }
97
    try:
98
        # Let's cast the last item as an int and catch any exceptions
99
        theInt = int(theList[len(theList)-1])
100
        newMemberName = " ".join(theList[:-1])
101
        amember = memberForName(newMemberName, server)
102
        if amember:
103
            return { "Member" : amember, "Int" : theInt }
104
        else:
105
            # Now we check if we got an ID instead
106
            # Get just the numbers
107
            memID = ''.join(list(filter(str.isdigit, newMemberName)))
108
            newMem = memberForID(memID, server)
109
            if newMem:
110
                # We FOUND it!
111
                return { "Member" : newMem, "Int" : theInt }
112
            else:
113
                # Nothing was right about this...
114
                return { "Member" : None, "Int" : None }
115
    except ValueError:
116
        # Last section wasn't an int
117
        amember = memberForName(name, server)
118
        if amember:
119
            # Name was just a member - return
120
            return { "Member" : amember, "Int" : None }
121
        else:
122
            # Now we check if we got an ID instead
123
            # Get just the numbers
124
            memID = ''.join(list(filter(str.isdigit, name)))
125
            newMem = memberForID(memID, server)
126
            if newMem:
127
                # We FOUND it!
128
                return { "Member" : newMem, "Int" : None }
129
            else:
130
                # Nothing was right about this...
131
                return { "Member" : None, "Int" : None }
132
    # Should never get here
133
    return None
134
135
def checkRoleForInt(name, server):
136
    theList = name.split()