plugin.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from time import time
  2. import supybot.utils as utils
  3. from supybot.commands import *
  4. import supybot.plugins as plugins
  5. import supybot.ircutils as ircutils
  6. import supybot.callbacks as callbacks
  7. import supybot.ircmsgs as ircmsgs
  8. import supybot.schedule as schedule
  9. class Greet(callbacks.Plugin):
  10. """
  11. This plugin greets users with a defined message when they join the
  12. channel. In order to use this plugin, supybot.plugins.Greet.enable
  13. must be True, and supybot.plugins.Greet.message must be set to the
  14. message you wish to send to users when they join.
  15. """
  16. _ignore = set([])
  17. def __init__(self, irc):
  18. self.__parent = super(Greet, self)
  19. self.__parent.__init__(irc)
  20. def _rememberNick(nick):
  21. if nick in self._ignore:
  22. self._ignore.remove()
  23. def _ignoreNick(self, irc, msg):
  24. channel = msg.args[0]
  25. if not self.registryValue('enable', channel):
  26. return
  27. delay = self.registryValue('grace', channel)
  28. if not msg.nick in self._ignore:
  29. self._ignore.add(msg.nick)
  30. schedule.addEvent(self._rememberNick, time() + delay,
  31. args=(msg.nick,))
  32. def doJoin(self, irc, msg):
  33. channel = msg.args[0]
  34. if not self.registryValue('enable', channel):
  35. return
  36. greeting = self.registryValue('message', channel)
  37. delay = self.registryValue('grace', channel)
  38. if len(greeting.strip()) == 0:
  39. self.log.warn('Greeting empty for %s' % channel)
  40. return
  41. if (not ircutils.strEqual(msg.nick, irc.nick)
  42. and msg.nick not in self._ignore):
  43. self._ignore.add(msg.nick)
  44. irc = callbacks.SimpleProxy(irc, msg)
  45. irc.queueMsg(ircmsgs.privmsg(msg.nick, greeting))
  46. schedule.addEvent(self._rememberNick, time() + delay,
  47. args=(msg.nick,))
  48. doPart = _ignoreNick
  49. doKick = _ignoreNick
  50. doQuit = _ignoreNick
  51. Class = Greet