diff --git a/README.md b/README.md index 7974733..debb513 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,21 @@ -# post2discord -Simple Python Script to post/update a message on Discord via Webhook +# post2discord.py + +A simple Python script to post/update a message on Discord via Webhook + +usage: post2discord.py [-h] [--id ID] [--username USERNAME] url message + +post or update a message on a Discord webhook, returns message.id on success + +positional arguments: + url webhook URL + message "the message contents" + +optional arguments: + -h, --help show this help message and exit + --id ID message.id to update + --username USERNAME override the default username of the webhook, will be ignored by Discord if we are updating + +examples: + post2discord.py https://discord.com/api/123456789098765432/xx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxx "Hello world!" + post2discord.py --username Mr.X https://discord.com/api/123456789098765432/xx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxx "Hello world!" + post2discord.py --id 234567890987654321 https://discord.com/api/123456789098765432/xx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxx "Hello updated world!" diff --git a/post2discord.py b/post2discord.py new file mode 100644 index 0000000..a5f589b --- /dev/null +++ b/post2discord.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# post2discord.py +# A smple Python script to post/update a message on Discord via Webhook +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . + +import json +import argparse +import requests + +parser = argparse.ArgumentParser(description='post or update a message on a Discord webhook, returns message.id on success') +parser.add_argument ('url', help='webhook URL') +parser.add_argument ('message', help='"the message contents"') +parser.add_argument ('--id', help='message.id to update') +parser.add_argument ('--username', help='override the default username of the webhook, will be ignored by Discord if we are updating') +args = parser.parse_args() + +data = { 'content': args.message } +if args.username: data['username'] = args.username + +if args.id is None: + response = requests.post(args.url+'?wait=true',data) +else: + response = requests.patch(args.url+'/messages/'+args.id+'?wait=true',data) + +if response.ok: + jsonres = response.json() + print(jsonres['id']) +else: + print('%s: %s',response.status_code, response.text)