A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. ## Imports
  3. from config.irc import *
  4. from config.main import *
  5. from config.watcher import *
  6. from irc.connection import *
  7. from irc.rc import RC
  8. global frontend_conn
  9. def get_connection():
  10. connection = Connection(WATCHER_HOST, WATCHER_PORT, NICK, IDENT, REALNAME)
  11. return connection
  12. def main(connection, f_conn):
  13. global frontend_conn
  14. frontend_conn = f_conn
  15. read_buffer = str()
  16. while 1:
  17. try:
  18. read_buffer = read_buffer + connection.get()
  19. except BrokenSocketException:
  20. return
  21. lines = read_buffer.split("\n")
  22. read_buffer = lines.pop()
  23. for line in lines:
  24. line = line.strip().split()
  25. if line[1] == "PRIVMSG":
  26. chan = line[2]
  27. if chan != WATCHER_CHAN: # if we're getting a msg from another channel, ignore it
  28. continue
  29. msg = ' '.join(line[3:])[1:]
  30. rc = RC(msg) # create a new RC object to store this change's data
  31. rc.parse()
  32. check(rc)
  33. if line[0] == "PING": # If we are pinged, pong back to the server
  34. connection.send("PONG %s" % line[1])
  35. if line[1] == "376": # Join the recent changes channel when we've finished starting up
  36. connection.join(WATCHER_CHAN)
  37. def check(rc):
  38. """check if we're supposed to report this message anywhere"""
  39. results = process(rc) # process the message in config/watcher.py, and get a list of channels to send it to
  40. if not results:
  41. return
  42. pretty = rc.get_pretty()
  43. if enable_irc_frontend:
  44. for chan in results:
  45. frontend_conn.say(chan, pretty)