source file: p10/commands/burst.py
file stats: 44 lines, 44 executed: 100.0% covered
   1. #!/usr/bin/env python
   2. 
   3. import genericcommand
   4. import p10.base64
   5. 
   6. class burst(genericcommand.genericcommand):
   7. 
   8.     def handle(self, origin, args):
   9.         # Handle channel collisions
  10.         self._state.lock.acquire()
  11.         try:
  12.             cstatus = self._state.createChannel(origin, args[0], int(args[1]))
  13.             nextarg = 2
  14. 
  15.             # Handle channel modes
  16.             if len(args) > nextarg:
  17.                 if args[nextarg][0] == "+":
  18.                     # But only if this is a new channel
  19.                     if cstatus:
  20.                         modes = []
  21.                         for mode in args[nextarg][1:]:
  22.                             if mode == "k" or mode == "l":
  23.                                 nextarg = nextarg + 1
  24.                                 modes.append(("+" + mode, args[nextarg]))
  25.                             else:
  26.                                 modes.append(("+" + mode, None))
  27.                         self._state.changeChannelMode(origin, args[0], modes)
  28.                     nextarg = nextarg + 1
  29. 
  30.             # Handle users on the channel
  31.             if len(args) > nextarg:
  32.                 umodes = ""
  33.                 for user in args[nextarg].split(','):
  34.                     # Handle any user modes, but only if this is a new channel
  35.                     user = user.split(":")
  36.                     if len(user) > 1:
  37.                         umodes = user[1]
  38.                     if cstatus:
  39.                         self._state.joinChannel(p10.base64.parseNumeric(user[0], self._state.maxClientNumerics), p10.base64.parseNumeric(user[0], self._state.maxClientNumerics), args[0], umodes)
  40.                     else:
  41.                         self._state.joinChannel(p10.base64.parseNumeric(user[0], self._state.maxClientNumerics), p10.base64.parseNumeric(user[0], self._state.maxClientNumerics), args[0], "")
  42.                 nextarg = nextarg + 1
  43. 
  44.             # Handle channel bans, but only if this is a new channel
  45.             if len(args) > nextarg and cstatus:
  46.                 if args[nextarg][0] == "%":
  47.                     for ban in args[nextarg][1:].split():
  48.                         self._state.addChannelBan(origin, args[0], ban)
  49.         finally:
  50.             self._state.lock.release()