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.

39 rader
1009 B

  1. # -*- coding: utf-8 -*-
  2. # Actions/commands to interface with IRC.
  3. import string
  4. class Actions:
  5. def __init__(self, sock):
  6. """actions/commands to interface with IRC"""
  7. self.sock = sock
  8. def get(self, size = 4096):
  9. """receive (get) data from the server"""
  10. data = self.sock.recv(4096)
  11. if not data:
  12. raise RuntimeError("socket is dead")
  13. return data
  14. def send(self, msg):
  15. """send data to the server"""
  16. self.sock.send(msg + "\r\n")
  17. print " %s" % msg
  18. def say(self, target, msg):
  19. """send a message"""
  20. self.send("PRIVMSG %s :%s" % (target, msg))
  21. def action(self, target, msg):
  22. """send a message as an action"""
  23. self.say(target,"%sACTION %s%s" % (chr(1), msg, chr(1)))
  24. def notice(self, target, msg):
  25. """send a notice"""
  26. self.send("NOTICE %s :%s" % (target, msg))
  27. def join(self, chan):
  28. """join a channel"""
  29. self.send("JOIN %s" % chan)