Completed
Push — main ( e74a90...1f5fd4 )
by Jochen
03:37
created

announce_news_item_published()   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 1
dl 0
loc 8
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
"""
2
byceps.announce.discord.news
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
Announce news events on Discord.
6
7
:Copyright: 2006-2020 Jochen Kupperschmidt
8
:License: Modified BSD, see LICENSE for details.
9
"""
10
11 1
from typing import Optional
12
13 1
from ...events.news import NewsItemPublished
14 1
from ...services.news.transfer.models import ChannelID
15 1
from ...signals import news as news_signals
16 1
from ...util.jobqueue import enqueue
17
18 1
from ._util import send_message
19
20
21 1
@news_signals.item_published.connect
22 1
def _on_news_item_published(
23
    sender, *, event: Optional[NewsItemPublished] = None
24
) -> None:
25 1
    enqueue(announce_news_item_published, event)
26
27
28 1
def announce_news_item_published(event: NewsItemPublished) -> None:
29
    """Announce that a news item has been published."""
30 1
    text = (
31
        f'Die News "{event.title}" wurde veröffentlicht. '
32
        f'{event.external_url}'
33
    )
34
35 1
    send_news_message(event.channel_id, text)
36
37
38 1
def send_news_message(channel_id: ChannelID, text: str) -> None:
39 1
    scope = 'news'
40 1
    scope_id = str(channel_id)
41
42
    send_message(scope, scope_id, text)
43