prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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.
  
  </issue>
  <code>
  [start of sopel/modules/announce.py]
  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 of sopel/modules/announce.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
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"}]}