aboutsummaryrefslogtreecommitdiffstats
path: root/slack/util.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-10-14 13:54:15 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:54 +0100
commit205363244afab703127cbb8d836505684c73a284 (patch)
tree2e270240cb389542fdcc190e218acaa2f422e3d2 /slack/util.py
parent62dd42910c42097f857181f7a65061f47c5ec2e4 (diff)
downloadwee-slack-205363244afab703127cbb8d836505684c73a284.tar.gz
Support highlight notifications without rendering history
Diffstat (limited to 'slack/util.py')
-rw-r--r--slack/util.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/slack/util.py b/slack/util.py
index 5c45d9d..41993c5 100644
--- a/slack/util.py
+++ b/slack/util.py
@@ -2,13 +2,23 @@ from __future__ import annotations
from functools import partial
from itertools import islice
-from typing import Callable, Iterable, Iterator, List, Optional, TypeVar
+from typing import (
+ Callable,
+ Iterable,
+ Iterator,
+ List,
+ Optional,
+ Sequence,
+ TypeVar,
+ Union,
+)
import weechat
from slack.shared import WeechatCallbackReturnType, shared
T = TypeVar("T")
+T2 = TypeVar("T2")
def get_callback_name(callback: Callable[..., WeechatCallbackReturnType]) -> str:
@@ -58,3 +68,11 @@ def chunked(iterable: Iterable[T], n: int, strict: bool = False) -> Iterator[Lis
"""
return iter(partial(take, n, iter(iterable)), [])
+
+
+# From https://stackoverflow.com/a/5921708
+def intersperse(lst: Sequence[Union[T, T2]], item: T2) -> List[Union[T, T2]]:
+ """Inserts item between each item in lst"""
+ result: List[Union[T, T2]] = [item] * (len(lst) * 2 - 1)
+ result[0::2] = lst
+ return result