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

byceps.announce.irc._util   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 52.5 %

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
eloc 18
dl 21
loc 40
rs 10
c 0
b 0
f 0
ccs 15
cts 16
cp 0.9375
wmc 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A send_message() 21 21 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Jochen Kupperschmidt
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