2023-02-22 01:44:27 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from json import dumps
|
|
|
|
from sys import stderr
|
|
|
|
|
|
|
|
from py.lib.http import discord
|
|
|
|
from py.lib.scwrypts import execute
|
|
|
|
|
|
|
|
from py.lib.scwrypts.exceptions import ImportedExecutableError
|
|
|
|
|
|
|
|
if __name__ != '__main__':
|
|
|
|
raise ImportedExecutableError()
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
def main(args, stream):
|
2023-06-24 13:40:31 +00:00
|
|
|
if args.content is None:
|
2023-02-22 01:44:27 +00:00
|
|
|
print(f'reading input from {stream.input.name}', file=stderr)
|
2023-06-24 13:40:31 +00:00
|
|
|
args.content = ''.join(stream.readlines()).strip()
|
2023-02-22 01:44:27 +00:00
|
|
|
|
2023-06-24 13:40:31 +00:00
|
|
|
if len(args.content) == 0:
|
|
|
|
args.content = 'PING'
|
2023-02-22 01:44:27 +00:00
|
|
|
|
2023-06-24 13:40:31 +00:00
|
|
|
response = discord.send_message(**vars(args))
|
2023-02-22 01:44:27 +00:00
|
|
|
|
|
|
|
stream.writeline(dumps({
|
|
|
|
**(response.json() if response.text != '' else {'message': 'OK'}),
|
|
|
|
'scwrypts_metadata': {},
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
execute(main,
|
|
|
|
description = 'post a message to the indicated discord channel',
|
|
|
|
parse_args = [
|
|
|
|
( ['-b', '--body'], {
|
2023-06-24 13:40:31 +00:00
|
|
|
'dest' : 'content',
|
2023-02-22 01:44:27 +00:00
|
|
|
'help' : 'message body',
|
|
|
|
'required' : False,
|
|
|
|
}),
|
|
|
|
( ['-c', '--channel-id'], {
|
|
|
|
'dest' : 'channel_id',
|
2023-06-24 13:40:31 +00:00
|
|
|
'help' : 'override default target channel id',
|
2023-02-22 01:44:27 +00:00
|
|
|
'required' : False,
|
|
|
|
}),
|
|
|
|
( ['-w', '--webhook'], {
|
|
|
|
'dest' : 'webhook',
|
2023-06-24 13:40:31 +00:00
|
|
|
'help' : 'override default target webhook (takes precedence over -c)',
|
2023-02-22 01:44:27 +00:00
|
|
|
'required' : False,
|
|
|
|
}),
|
|
|
|
( ['--avatar-url'], {
|
|
|
|
'dest' : 'avatar_url',
|
2023-06-24 13:40:31 +00:00
|
|
|
'help' : 'override default avatar_url',
|
|
|
|
'required' : False,
|
|
|
|
}),
|
|
|
|
( ['--username'], {
|
|
|
|
'dest' : 'username',
|
|
|
|
'help' : 'override default username',
|
2023-02-22 01:44:27 +00:00
|
|
|
'required' : False,
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
)
|