A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # A class to store data from an individual line received on IRC.
  3. class Data(object):
  4. def __init__(self):
  5. """store data from an individual line received on IRC"""
  6. self.chan = str()
  7. self.nick = str()
  8. self.ident = str()
  9. self.host = str()
  10. self.msg = str()
  11. def parse_args(self):
  12. """parse command arguments from self.msg into self.command and self.args"""
  13. args = self.msg.strip().split(' ') # strip out extra whitespace and split the message into a list
  14. while '' in args: # remove any empty arguments
  15. args.remove('')
  16. self.args = args[1:] # the command arguments
  17. self.is_command = False # whether this is a real command or not
  18. try:
  19. self.command = args[0] # the command itself
  20. except IndexError:
  21. self.command = None
  22. try:
  23. if self.command.startswith('!') or self.command.startswith('.'):
  24. self.is_command = True
  25. self.command = self.command[1:] # strip '!' or '.'
  26. except AttributeError:
  27. pass