ircstdinbot.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/python3
  2. #
  3. # stdinbot - Read text from stdin and send it to an IRC channel
  4. #
  5. # © 2018 by luk3yx
  6. #
  7. import sys, time
  8. from miniirc import IRC
  9. # Variables
  10. nick = "idc"
  11. ident = nick
  12. realname = "Internet Delay Chat Relay"
  13. identity = None
  14. # identity = '<username> <password>'
  15. print_cmds = False
  16. interval = 0.25
  17. channels = ["#idc"]
  18. debug = False
  19. ip = "irc.andrewyu.org"
  20. port = 6697
  21. print("Welcome to stdinbot!", file=sys.stderr)
  22. irc = IRC(
  23. ip,
  24. port,
  25. nick,
  26. channels,
  27. ident=ident,
  28. realname=realname,
  29. ns_identity=identity,
  30. debug=debug,
  31. auto_connect=False,
  32. )
  33. # Read stdin
  34. @irc.Handler("001", colon=False)
  35. def handle_stdin(irc, hostmask, args):
  36. qmsg = "I reached the end of my file, therefore my life™."
  37. while True:
  38. try:
  39. line = +input().replace("\r", "").replace("\n", " ")
  40. except:
  41. line = "\x04"
  42. if line == "\x04":
  43. return irc.disconnect(qmsg)
  44. irc.msg(channels[0], line)
  45. time.sleep(interval)
  46. @irc.Handler("PRIVMSG", colon=False)
  47. def handle_privmsg(irc, hostmask, args):
  48. # if args[0] in channels:
  49. if True:
  50. print("<" + hostmask[0] + "> " + args[1])
  51. if __name__ == "__main__":
  52. irc.connect()