mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-10 05:55:13 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -87,6 +87,7 @@ import json
|
|||
from urllib.parse import quote
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
|
||||
|
|
@ -94,43 +95,44 @@ from ansible.module_utils.urls import fetch_url
|
|||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
token=dict(type='str', required=True, no_log=True),
|
||||
api_args=dict(type='dict'),
|
||||
token=dict(type="str", required=True, no_log=True),
|
||||
api_args=dict(type="dict"),
|
||||
api_method=dict(type="str", default="SendMessage"),
|
||||
),
|
||||
supports_check_mode=True
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
token = quote(module.params.get('token'))
|
||||
api_args = module.params.get('api_args') or {}
|
||||
api_method = module.params.get('api_method')
|
||||
token = quote(module.params.get("token"))
|
||||
api_args = module.params.get("api_args") or {}
|
||||
api_method = module.params.get("api_method")
|
||||
# filling backward compatibility args
|
||||
api_args['chat_id'] = api_args.get('chat_id')
|
||||
api_args['parse_mode'] = api_args.get('parse_mode')
|
||||
api_args['text'] = api_args.get('text')
|
||||
api_args["chat_id"] = api_args.get("chat_id")
|
||||
api_args["parse_mode"] = api_args.get("parse_mode")
|
||||
api_args["text"] = api_args.get("text")
|
||||
|
||||
if api_args['parse_mode'] == 'plain':
|
||||
del api_args['parse_mode']
|
||||
if api_args["parse_mode"] == "plain":
|
||||
del api_args["parse_mode"]
|
||||
|
||||
url = f'https://api.telegram.org/bot{token}/{api_method}'
|
||||
url = f"https://api.telegram.org/bot{token}/{api_method}"
|
||||
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=False)
|
||||
|
||||
response, info = fetch_url(module, url, method="POST", data=json.dumps(api_args),
|
||||
headers={'Content-Type': 'application/json'})
|
||||
if info['status'] == 200:
|
||||
response, info = fetch_url(
|
||||
module, url, method="POST", data=json.dumps(api_args), headers={"Content-Type": "application/json"}
|
||||
)
|
||||
if info["status"] == 200:
|
||||
module.exit_json(changed=True)
|
||||
elif info['status'] == -1:
|
||||
elif info["status"] == -1:
|
||||
# SSL errors, connection problems, etc.
|
||||
module.fail_json(msg="Failed to send message", info=info, response=response)
|
||||
else:
|
||||
body = json.loads(info['body'])
|
||||
body = json.loads(info["body"])
|
||||
module.fail_json(
|
||||
msg=f"Failed to send message, return status = {info['status']}\nurl = {url}\napi_args = {api_args}",
|
||||
telegram_error=body['description'],
|
||||
telegram_error=body["description"],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue