Notify users of new users

This commit is contained in:
jmjl 2022-12-04 10:17:39 +00:00
parent a1ede133e6
commit 40ce70c05f
3 changed files with 44 additions and 1 deletions

View file

@ -55,7 +55,7 @@ case $1 in
#sudo chown $1:$1 "/home/$1/.ssh" -R
#printf "\nannouncing new user on mastodon\n"
#/usr/local/bin/toot "welcome new user ~$1!"
/opt/tools/bin/tooltoot "welcome new user ~$1!"
printf "cleanup current signup\n"
sudo sed -i"" "/\b$1\b/d" /var/signups_current

42
bin/tooltoot Executable file
View file

@ -0,0 +1,42 @@
#!/usr/bin/python3
import click
import emoji
import getpass
import json
import os
import sys
from mastodon import Mastodon
@click.command()
@click.argument('status', required=False)
@click.option('--creds', default='/opt/tools/res/toot.json')
def toot(status, creds):
# get config
with open(creds) as f:
config = json.load(f)
# set up connection to mastodon
mastodon = Mastodon(
client_id=config['client_id'],
client_secret=config['client_secret'],
access_token=config['access_token'],
api_base_url=config['base_url'],
)
# get status from argument or from stdin
if not status:
status = "".join(sys.stdin).strip()
# replace shortcodes with emoji :thumbsup:
status = emoji.emojize(status, use_aliases=True)
# check status length and post status
if len(status) > 5000:
print("Status is too long, try again")
elif len(status) == 0:
print("Did you type a status?")
else:
print(mastodon.status_post(f"{status}\n~{getpass.getuser()}")["uri"],visibility='unlisted')
if __name__=='__main__':
toot()

1
res/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
toot.json