text: # This Source Code Form is subject to the terms of the Mozilla Public
  # License, v. 2.0. If a copy of the MPL was not distributed with this
  # file, You can obtain one at https://mozilla.org/MPL/2.0/.
  
  # Copyright (c) 2021 Rapptz
  
  from datetime import timezone
  
  
  class plural:
      def __init__(self, value):
          self.value = value
  
      def __format__(self, format_spec):
          v = self.value
          singular, sep, plural = format_spec.partition("|")
          plural = plural or f"{singular}s"
          if abs(v) != 1:
              return f"{v} {plural}"
          return f"{v} {singular}"
  
  
  def human_join(seq, delim=", ", final="or"):
      size = len(seq)
      if size == 0:
          return ""
  
      if size == 1:
          return seq[0]
  
      if size == 2:
          return f"{seq[0]} {final} {seq[1]}"
  
      return delim.join(seq[:-1]) + f" {final} {seq[-1]}"
  
  
  class TabularData:
      def __init__(self):
          self._widths = []
          self._columns = []
          self._rows = []
  
      def set_columns(self, columns):
          self._columns = columns
          self._widths = [len(c) + 2 for c in columns]
  
      def add_row(self, row):
          rows = [str(r) for r in row]
          self._rows.append(rows)
          for index, element in enumerate(rows):
              width = len(element) + 2
              if width > self._widths[index]:
                  self._widths[index] = width
  
      def add_rows(self, rows):
          for row in rows:
              self.add_row(row)
  
      def render(self):
          """Renders a table in rST format.
  
          Example:
  
          +-------+-----+
          | Name  | Age |
          +-------+-----+
          | Alice | 24  |
          |  Bob  | 19  |
          +-------+-----+
          """
  
          sep = "+".join("-" * w for w in self._widths)
          sep = f"+{sep}+"
  
          to_draw = [sep]
  
          def get_entry(d):
              elem = "|".join(f"{e:^{self._widths[i]}}" for i, e in enumerate(d))
              return f"|{elem}|"
  
          to_draw.append(get_entry(self._columns))
          to_draw.append(sep)
  
          for row in self._rows:
              to_draw.append(get_entry(row))
  
          to_draw.append(sep)
          return "\n".join(to_draw)
  
  
  def format_dt(dt, style=None):
      if dt.tzinfo is None:
          dt = dt.replace(tzinfo=timezone.utc)
  
      if style is None:
          return f"<t:{int(dt.timestamp())}>"
      return f"<t:{int(dt.timestamp())}:{style}>"
  