prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  announce: Batch up to MAXTARGETS channels at a time if available
  The simple loop in `announce.py` is kind of...meh. The number of lines it actually sends to the server could be reduced as much as 75% depending on how many channels Sopel is in when `.announce` is called.
  
  Some IRC servers (Hybrid, for example) send a `MAXTARGETS` field in the `ISUPPORT` properties when a client connects. If this is present, it would be useful for `announce.py` to have that information and send its announcement messages to `MAXTARGETS` channels at a time.
  
  Long-term thing, more of an optimization than anything.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `sopel/modules/announce.py`
  Content:
  ```
  1 # coding=utf-8
  2 """
  3 announce.py - Sopel Announcement Plugin
  4 Sends announcements to all channels the bot has joined.
  5 Copyright © 2013, Elad Alfassa, <elad@fedoraproject.org>
  6 Licensed under the Eiffel Forum License 2.
  7 
  8 https://sopel.chat
  9 """
  10 from __future__ import absolute_import, division, print_function, unicode_literals
  11 
  12 from sopel import plugin
  13 
  14 
  15 @plugin.command('announce')
  16 @plugin.example('.announce Some important message here')
  17 @plugin.require_admin('Sorry, I can\'t let you do that', reply=True)
  18 @plugin.output_prefix('[ANNOUNCEMENT] ')
  19 def announce(bot, trigger):
  20     """Send an announcement to all channels the bot is in"""
  21     for channel in bot.channels:
  22         bot.say(trigger.group(2), channel)
  23     bot.reply('Announce complete.')
  24
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/sopel/modules/announce.py b/sopel/modules/announce.py
  --- a/sopel/modules/announce.py
  +++ b/sopel/modules/announce.py
  @@ -12,12 +12,30 @@
   from sopel import plugin
   
   
  +def _chunks(items, size):
  +    """Break a list of items into groups.
  +
  +    :param items: the collection of items to chunk
  +    :type items: :term:`iterable`
  +    :param int size: the size of each chunk
  +    """
  +    # from https://stackoverflow.com/a/312464/5991 with modified names for readability
  +    for delim in range(0, len(items), size):
  +        yield items[delim:delim + size]
  +
  +
   @plugin.command('announce')
   @plugin.example('.announce Some important message here')
   @plugin.require_admin('Sorry, I can\'t let you do that', reply=True)
   @plugin.output_prefix('[ANNOUNCEMENT] ')
   def announce(bot, trigger):
  -    """Send an announcement to all channels the bot is in"""
  -    for channel in bot.channels:
  -        bot.say(trigger.group(2), channel)
  +    """Send an announcement to all channels the bot is in."""
  +    if trigger.group(2) is None:
  +        bot.reply('Announce what? I need a message to say.')
  +        return
  +
  +    size = bot.isupport.get('TARGMAX', {}).get('PRIVMSG', 1)
  +    channels = _chunks(bot.channels.keys(), size)
  +    for cgroup in channels:
  +        bot.say(trigger.group(2), ','.join(cgroup))
       bot.reply('Announce complete.')
  
verification_info: {"golden_diff": "diff --git a/sopel/modules/announce.py b/sopel/modules/announce.py\n--- a/sopel/modules/announce.py\n+++ b/sopel/modules/announce.py\n@@ -12,12 +12,30 @@\n from sopel import plugin\n \n \n+def _chunks(items, size):\n+    \"\"\"Break a list of items into groups.\n+\n+    :param items: the collection of items to chunk\n+    :type items: :term:`iterable`\n+    :param int size: the size of each chunk\n+    \"\"\"\n+    # from https://stackoverflow.com/a/312464/5991 with modified names for readability\n+    for delim in range(0, len(items), size):\n+        yield items[delim:delim + size]\n+\n+\n @plugin.command('announce')\n @plugin.example('.announce Some important message here')\n @plugin.require_admin('Sorry, I can\\'t let you do that', reply=True)\n @plugin.output_prefix('[ANNOUNCEMENT] ')\n def announce(bot, trigger):\n-    \"\"\"Send an announcement to all channels the bot is in\"\"\"\n-    for channel in bot.channels:\n-        bot.say(trigger.group(2), channel)\n+    \"\"\"Send an announcement to all channels the bot is in.\"\"\"\n+    if trigger.group(2) is None:\n+        bot.reply('Announce what? I need a message to say.')\n+        return\n+\n+    size = bot.isupport.get('TARGMAX', {}).get('PRIVMSG', 1)\n+    channels = _chunks(bot.channels.keys(), size)\n+    for cgroup in channels:\n+        bot.say(trigger.group(2), ','.join(cgroup))\n     bot.reply('Announce complete.')\n", "issue": "announce: Batch up to MAXTARGETS channels at a time if available\nThe simple loop in `announce.py` is kind of...meh. The number of lines it actually sends to the server could be reduced as much as 75% depending on how many channels Sopel is in when `.announce` is called.\r\n\r\nSome IRC servers (Hybrid, for example) send a `MAXTARGETS` field in the `ISUPPORT` properties when a client connects. If this is present, it would be useful for `announce.py` to have that information and send its announcement messages to `MAXTARGETS` channels at a time.\r\n\r\nLong-term thing, more of an optimization than anything.\n", "before_files": [{"content": "# coding=utf-8\n\"\"\"\nannounce.py - Sopel Announcement Plugin\nSends announcements to all channels the bot has joined.\nCopyright \u00a9 2013, Elad Alfassa, <elad@fedoraproject.org>\nLicensed under the Eiffel Forum License 2.\n\nhttps://sopel.chat\n\"\"\"\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom sopel import plugin\n\n\n@plugin.command('announce')\n@plugin.example('.announce Some important message here')\n@plugin.require_admin('Sorry, I can\\'t let you do that', reply=True)\n@plugin.output_prefix('[ANNOUNCEMENT] ')\ndef announce(bot, trigger):\n    \"\"\"Send an announcement to all channels the bot is in\"\"\"\n    for channel in bot.channels:\n        bot.say(trigger.group(2), channel)\n    bot.reply('Announce complete.')\n", "path": "sopel/modules/announce.py"}], "after_files": [{"content": "# coding=utf-8\n\"\"\"\nannounce.py - Sopel Announcement Plugin\nSends announcements to all channels the bot has joined.\nCopyright \u00a9 2013, Elad Alfassa, <elad@fedoraproject.org>\nLicensed under the Eiffel Forum License 2.\n\nhttps://sopel.chat\n\"\"\"\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom sopel import plugin\n\n\ndef _chunks(items, size):\n    \"\"\"Break a list of items into groups.\n\n    :param items: the collection of items to chunk\n    :type items: :term:`iterable`\n    :param int size: the size of each chunk\n    \"\"\"\n    # from https://stackoverflow.com/a/312464/5991 with modified names for readability\n    for delim in range(0, len(items), size):\n        yield items[delim:delim + size]\n\n\n@plugin.command('announce')\n@plugin.example('.announce Some important message here')\n@plugin.require_admin('Sorry, I can\\'t let you do that', reply=True)\n@plugin.output_prefix('[ANNOUNCEMENT] ')\ndef announce(bot, trigger):\n    \"\"\"Send an announcement to all channels the bot is in.\"\"\"\n    if trigger.group(2) is None:\n        bot.reply('Announce what? I need a message to say.')\n        return\n\n    size = bot.isupport.get('TARGMAX', {}).get('PRIVMSG', 1)\n    channels = _chunks(bot.channels.keys(), size)\n    for cgroup in channels:\n        bot.say(trigger.group(2), ','.join(cgroup))\n    bot.reply('Announce complete.')\n", "path": "sopel/modules/announce.py"}]}