A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

data.py 1.1 KiB

123456789101112131415161718192021222324252627282930313233
  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