on_privnotice.py 6.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import asyncio, time
  2. import commands.public, commands.admin, commands.games, commands.statistics, commands.chat
  3. from common import log, queries, font
  4. from events.common import Inform
  5. def process_event(self, connection, event):
  6. log.info(event) # Log to console.
  7. # Ignore server connect messages.
  8. if event.source == None:
  9. return
  10. # Get and update resources.
  11. user = queries.create_or_get_and_update_last_event(self, 'user', 'pn', user_name=event.source.nick, event_subject_name=event.target)
  12. channel = None
  13. # Respond to commands.
  14. commands.public.do_command(self, connection, event, user, channel)
  15. commands.games.do_command(self, connection, event, user, channel)
  16. commands.statistics.do_command(self, connection, event, user, channel)
  17. commands.chat.do_command(self, connection, event, user, channel)
  18. commands.admin.do_command(self, connection, event, user, channel)
  19. if event.source.nick == connection.get_nickname(): # Message came from myself.
  20. return
  21. elif event.source.nick == "NickServ": # Message from NickServ.
  22. if event.arguments[0].startswith("This nickname is registered"):
  23. connection.privmsg('NickServ', 'identify %s %s' % (self.network.nickname, self.network.password)) # Identify with NickServ. Also doing it on_welcome, but if there is a netsplit or so and there is no welcome, but a need to login, this is needed.
  24. return
  25. elif event.arguments[0].endswith(' is not a registered nickname.') or event.arguments[0].startswith('Nick ') and event.arguments[0].endswith(' isn\'t registered.') or event.arguments[0].startswith('Your nick isn\'t registered.'): # Username from database is not registered.
  26. log.info('Registerring with NickServ.')
  27. Inform.operators(self, connection, 'Regisring %s%s%s with %sNickServ%s.' % (font.red, self.network.nickname, font.reset, font.red, font.reset))
  28. connection.privmsg('NickServ', 'register %s spamtBK@xs4all.nl' % (self.network.password)) # Register with NickServ.
  29. return
  30. elif event.arguments[0].startswith('Nickname ') and event.arguments[0].endswith('registered.') or event.arguments[0].startswith('Nickname ') and ' registered under your account: *' in event.arguments[0]:
  31. Inform.home_channel(self, connection, 'Registerred nickname %s%s%s with NickServ, adjusting settigns.' % font.red, self.network.nickname, font.reset)
  32. connection.privmsg('NickServ', 'ACCESS LIST')
  33. connection.privmsg('NickServ', 'AJOIN ADD %s' % (self.network.home_channel, queries.get_channel_key(self, self.network.home_channel)))
  34. connection.privmsg('NickServ', 'SET AUTOOP ON')
  35. connection.privmsg('NickServ', 'SET HIDE EMAIL ON')
  36. connection.privmsg('NickServ', 'SET KILL QUICK')
  37. connection.privmsg('NickServ', 'SET SECURE ON')
  38. connection.privmsg('NickServ', 'SET URL %snetwork/%s' % (self.webgui['base_url'], self.network.slug))
  39. return
  40. elif event.arguments[0].startswith('You must have been using this nick for at least 30 seconds to register.'):
  41. log.info('Waiting 31 seconds to register with NickServ.')
  42. asyncio.run(register_later(self, connection, 31))
  43. return
  44. elif event.arguments[0].startswith("You are already identified."):
  45. return
  46. elif event.arguments[0].startswith('nick, type ') and '/msg NickServ IDENTIFY ' in event.arguments[0] and event.arguments[0].endswith(' Otherwise,'):
  47. return
  48. elif event.arguments[0].startswith("please choose a different nick."):
  49. return
  50. elif event.arguments[0].startswith('Password accepted - you are now recognized.'):
  51. return
  52. elif event.source.nick == "ChanServ":
  53. if event.arguments[0].startswith("Key for channel ") and len(event.arguments[0]) > 5: # Received channel key.
  54. log.info('Saving channel password received from NickServ for: %s' % event.arguments[0].split(' ')[3])
  55. queries.save_channel_key(self, event.arguments[0].split(' ')[3], event.arguments[0].split(' ')[5][:-1])
  56. connection.join(event.arguments[0].split(' ')[3], event.arguments[0].split(' ')[5][:-1])
  57. Inform.owners(self, connection, "Received " + red + event.arguments[0].split(" ")[3] + reset + " key: " + event.arguments.split(" ")[5][:-1])
  58. returnZZ
  59. elif event.arguments[0].startswith("Password authentication required for that command."): # Not authenticated with NisckServ.
  60. connection.privmsg('NickServ', 'identify %s %s' % (self.network.nickname, self.network.password))
  61. Inform.notice_owners(self, connection, "Not authenticated with NickServ.")
  62. return
  63. elif event.arguments[0].startswith("You have been unbanned from ") or event.arguments[0].endswith(" autokick list is empty.") or event.arguments[0].startswith("You are already in ") or event.arguments[0].startswith("Syntax: UNBAN channel [nick]") or event.arguments[0].startswith("/msg ChanServ HELP UNBAN for more information"):
  64. return
  65. # if event.arguments[0].startswith("Channel ") and event.arguments[0].endswith(" has no key."):
  66. # return
  67. elif event.arguments[0].startswith('*** Looking up your hostname...') or event.arguments[0].startswith('*** Found your hostname') or event.arguments[0].startswith('*** Connected securely via ') or event.arguments[0].startswith('*** Your host is masked (') or event.arguments[0].startswith('You are connected to ') or event.arguments[0].startswith('Highest connection count: ') or event.arguments[0].startswith('*** If you are having problems connecting due to ping timeouts, please type /quote PONG') or event.arguments[0].startswith('*** You are connected using SSL cipher "') :
  68. return # Do not forward these messages.
  69. # Respond to own name.
  70. elif connection.get_nickname().lower() in event.arguments[0].lower() and event.source.nick is not connection.get_nickname(): # Bot's name was mentioned, not by the bot itself.
  71. Replyto.name(self, connection, replyto)
  72. # Forward messages to owners.
  73. if event.source.nick != "Global":
  74. Inform.notice_owners(self, connection, 'Notice from %s%s%s: %s%s' % (font.red, event.source.nick, font.grey, font.reset, event.arguments[0]))
  75. async def register_later(self, connection, seconds):
  76. await asyncio.sleep(seconds)
  77. connection.privmsg('NickServ', 'identify %s %s' % (self.network.nickname, self.network.password))