A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

37 lignes
994 B

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