Completed
Push — main ( 65a384...7d4592 )
by Jochen
06:34
created

byceps.announce.irc._util.send_message()   A

Complexity

Conditions 3

Size

Total Lines 21
Code Lines 14

Duplication

Lines 21
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 3.004

Importance

Changes 0
Metric Value
cc 3
eloc 14
nop 2
dl 21
loc 21
rs 9.7
c 0
b 0
f 0
ccs 12
cts 13
cp 0.9231
crap 3.004
1
"""
2
byceps.announce.irc.util
3
~~~~~~~~~~~~~~~~~~~~~~~~
4
5
Send messages to an IRC bot (Weitersager_) via HTTP.
6
7
.. _Weitersager: https://github.com/homeworkprod/weitersager
8
9
:Copyright: 2006-2020 Jochen Kupperschmidt
10
:License: Modified BSD, see LICENSE for details.
11
"""
12
13 1
from flask import current_app
14 1
import requests
15
16 1
from ...services.webhooks import service as webhook_service
17
18
19 1 View Code Duplication
def send_message(channel: str, text: str) -> None:
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
20
    """Write the text to the channel by sending it to the bot via HTTP."""
21 1
    scope = 'any'
22 1
    scope_id = None
23 1
    format = 'weitersager'
24
25 1
    webhook = webhook_service.find_enabled_outgoing_webhook(scope, scope_id, format)
26
27 1
    if webhook is None:
28 1
        current_app.logger.warning(
29
            f'No enabled IRC webhook found. Not sending message to IRC.'
30
        )
31 1
        return
32
33 1
    text_prefix = webhook.text_prefix
34 1
    if text_prefix:
35
        text = text_prefix + text
36
37 1
    data = {'channel': channel, 'text': text}
38
39
    requests.post(webhook.url, json=data)  # Ignore response code for now.
40