Skip to content

Commit

Permalink
Added to method
Browse files Browse the repository at this point in the history
  • Loading branch information
matzipan committed Dec 4, 2012
1 parent 5acff6f commit d055439
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions csbot/plugins/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def topic(self, e):
if position is None:
position, payload = payload.split(" ", 1)

if not position.isdigit() or int(position) >= len(splitted_topic):
if self.valid_position(position, splitted_topic):
raise TopicException(u"Invalid position number")

position = int(position)
Expand All @@ -62,7 +62,7 @@ def topic(self, e):
elif command == "remove":
position = payload

if not position.isdigit() or int(position) >= len(splitted_topic):
if self.valid_position(position, splitted_topic):
raise TopicException(u"Invalid position number")

position = int(position)
Expand All @@ -72,7 +72,7 @@ def topic(self, e):
elif command == "change":
position, payload = payload.split(" ", 1)

if not position.isdigit() or int(position) >= len(splitted_topic):
if self.valid_position(position, splitted_topic):
raise TopicException(u"Invalid position number")

position = int(position)
Expand All @@ -82,3 +82,6 @@ def topic(self, e):
e.protocol.topic(e["reply_to"], (" "+separator+" ").join(splitted_topic))
except TopicException as exception:
e.protocol.msg(e["reply_to"], "Topic error: " + str(exception))

def valid_position(self, position, splitted_topic):
return not position.isdigit() or int(position) >= len(splitted_topic)

0 comments on commit d055439

Please sign in to comment.