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