Moving to pipenv, adding initial fedi goodies
This commit is contained in:
parent
8becebbab9
commit
80130c168e
|
@ -0,0 +1,16 @@
|
|||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
flask = "2.2.2"
|
||||
requests = "2.28.1"
|
||||
"mastodon.py" = "1.7.0"
|
||||
markupsafe = "*"
|
||||
|
||||
[dev-packages]
|
||||
flake8 = "5.0.4"
|
||||
|
||||
[requires]
|
||||
python_version = "3.10"
|
|
@ -0,0 +1,234 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "109edde692a06984b577e92ba87d253183b0fcb28ffdf1891f7753093132e6bd"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.10"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"blurhash": {
|
||||
"hashes": [
|
||||
"sha256:7611c1bc41383d2349b6129208587b5d61e8792ce953893cb49c38beeb400d1d",
|
||||
"sha256:da56b163e5a816e4ad07172f5639287698e09d7f3dc38d18d9726d9c1dbc4cee"
|
||||
],
|
||||
"version": "==1.1.4"
|
||||
},
|
||||
"certifi": {
|
||||
"hashes": [
|
||||
"sha256:0d9c601124e5a6ba9712dbc60d9c53c21e34f5f641fe83002317394311bdce14",
|
||||
"sha256:90c1a32f1d68f940488354e36370f6cca89f0f106db09518524c88d6ed83f382"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==2022.9.24"
|
||||
},
|
||||
"charset-normalizer": {
|
||||
"hashes": [
|
||||
"sha256:5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845",
|
||||
"sha256:83e9a75d1911279afd89352c68b45348559d1fc0506b054b346651b5e7fee29f"
|
||||
],
|
||||
"markers": "python_full_version >= '3.6.0'",
|
||||
"version": "==2.1.1"
|
||||
},
|
||||
"click": {
|
||||
"hashes": [
|
||||
"sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e",
|
||||
"sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==8.1.3"
|
||||
},
|
||||
"decorator": {
|
||||
"hashes": [
|
||||
"sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330",
|
||||
"sha256:b8c3f85900b9dc423225913c5aace94729fe1fa9763b38939a95226f02d37186"
|
||||
],
|
||||
"markers": "python_version >= '3.5'",
|
||||
"version": "==5.1.1"
|
||||
},
|
||||
"flask": {
|
||||
"hashes": [
|
||||
"sha256:642c450d19c4ad482f96729bd2a8f6d32554aa1e231f4f6b4e7e5264b16cca2b",
|
||||
"sha256:b9c46cc36662a7949f34b52d8ec7bb59c0d74ba08ba6cb9ce9adc1d8676d9526"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.2.2"
|
||||
},
|
||||
"idna": {
|
||||
"hashes": [
|
||||
"sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4",
|
||||
"sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"
|
||||
],
|
||||
"markers": "python_version >= '3.5'",
|
||||
"version": "==3.4"
|
||||
},
|
||||
"itsdangerous": {
|
||||
"hashes": [
|
||||
"sha256:2c2349112351b88699d8d4b6b075022c0808887cb7ad10069318a8b0bc88db44",
|
||||
"sha256:5dbbc68b317e5e42f327f9021763545dc3fc3bfe22e6deb96aaf1fc38874156a"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==2.1.2"
|
||||
},
|
||||
"jinja2": {
|
||||
"hashes": [
|
||||
"sha256:31351a702a408a9e7595a8fc6150fc3f43bb6bf7e319770cbc0db9df9437e852",
|
||||
"sha256:6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==3.1.2"
|
||||
},
|
||||
"markupsafe": {
|
||||
"hashes": [
|
||||
"sha256:0212a68688482dc52b2d45013df70d169f542b7394fc744c02a57374a4207003",
|
||||
"sha256:089cf3dbf0cd6c100f02945abeb18484bd1ee57a079aefd52cffd17fba910b88",
|
||||
"sha256:10c1bfff05d95783da83491be968e8fe789263689c02724e0c691933c52994f5",
|
||||
"sha256:33b74d289bd2f5e527beadcaa3f401e0df0a89927c1559c8566c066fa4248ab7",
|
||||
"sha256:3799351e2336dc91ea70b034983ee71cf2f9533cdff7c14c90ea126bfd95d65a",
|
||||
"sha256:3ce11ee3f23f79dbd06fb3d63e2f6af7b12db1d46932fe7bd8afa259a5996603",
|
||||
"sha256:421be9fbf0ffe9ffd7a378aafebbf6f4602d564d34be190fc19a193232fd12b1",
|
||||
"sha256:43093fb83d8343aac0b1baa75516da6092f58f41200907ef92448ecab8825135",
|
||||
"sha256:46d00d6cfecdde84d40e572d63735ef81423ad31184100411e6e3388d405e247",
|
||||
"sha256:4a33dea2b688b3190ee12bd7cfa29d39c9ed176bda40bfa11099a3ce5d3a7ac6",
|
||||
"sha256:4b9fe39a2ccc108a4accc2676e77da025ce383c108593d65cc909add5c3bd601",
|
||||
"sha256:56442863ed2b06d19c37f94d999035e15ee982988920e12a5b4ba29b62ad1f77",
|
||||
"sha256:671cd1187ed5e62818414afe79ed29da836dde67166a9fac6d435873c44fdd02",
|
||||
"sha256:694deca8d702d5db21ec83983ce0bb4b26a578e71fbdbd4fdcd387daa90e4d5e",
|
||||
"sha256:6a074d34ee7a5ce3effbc526b7083ec9731bb3cbf921bbe1d3005d4d2bdb3a63",
|
||||
"sha256:6d0072fea50feec76a4c418096652f2c3238eaa014b2f94aeb1d56a66b41403f",
|
||||
"sha256:6fbf47b5d3728c6aea2abb0589b5d30459e369baa772e0f37a0320185e87c980",
|
||||
"sha256:7f91197cc9e48f989d12e4e6fbc46495c446636dfc81b9ccf50bb0ec74b91d4b",
|
||||
"sha256:86b1f75c4e7c2ac2ccdaec2b9022845dbb81880ca318bb7a0a01fbf7813e3812",
|
||||
"sha256:8dc1c72a69aa7e082593c4a203dcf94ddb74bb5c8a731e4e1eb68d031e8498ff",
|
||||
"sha256:8e3dcf21f367459434c18e71b2a9532d96547aef8a871872a5bd69a715c15f96",
|
||||
"sha256:8e576a51ad59e4bfaac456023a78f6b5e6e7651dcd383bcc3e18d06f9b55d6d1",
|
||||
"sha256:96e37a3dc86e80bf81758c152fe66dbf60ed5eca3d26305edf01892257049925",
|
||||
"sha256:97a68e6ada378df82bc9f16b800ab77cbf4b2fada0081794318520138c088e4a",
|
||||
"sha256:99a2a507ed3ac881b975a2976d59f38c19386d128e7a9a18b7df6fff1fd4c1d6",
|
||||
"sha256:a49907dd8420c5685cfa064a1335b6754b74541bbb3706c259c02ed65b644b3e",
|
||||
"sha256:b09bf97215625a311f669476f44b8b318b075847b49316d3e28c08e41a7a573f",
|
||||
"sha256:b7bd98b796e2b6553da7225aeb61f447f80a1ca64f41d83612e6139ca5213aa4",
|
||||
"sha256:b87db4360013327109564f0e591bd2a3b318547bcef31b468a92ee504d07ae4f",
|
||||
"sha256:bcb3ed405ed3222f9904899563d6fc492ff75cce56cba05e32eff40e6acbeaa3",
|
||||
"sha256:d4306c36ca495956b6d568d276ac11fdd9c30a36f1b6eb928070dc5360b22e1c",
|
||||
"sha256:d5ee4f386140395a2c818d149221149c54849dfcfcb9f1debfe07a8b8bd63f9a",
|
||||
"sha256:dda30ba7e87fbbb7eab1ec9f58678558fd9a6b8b853530e176eabd064da81417",
|
||||
"sha256:e04e26803c9c3851c931eac40c695602c6295b8d432cbe78609649ad9bd2da8a",
|
||||
"sha256:e1c0b87e09fa55a220f058d1d49d3fb8df88fbfab58558f1198e08c1e1de842a",
|
||||
"sha256:e72591e9ecd94d7feb70c1cbd7be7b3ebea3f548870aa91e2732960fa4d57a37",
|
||||
"sha256:e8c843bbcda3a2f1e3c2ab25913c80a3c5376cd00c6e8c4a86a89a28c8dc5452",
|
||||
"sha256:efc1913fd2ca4f334418481c7e595c00aad186563bbc1ec76067848c7ca0a933",
|
||||
"sha256:f121a1420d4e173a5d96e47e9a0c0dcff965afdf1626d28de1460815f7c4ee7a",
|
||||
"sha256:fc7b548b17d238737688817ab67deebb30e8073c95749d55538ed473130ec0c7"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.1.1"
|
||||
},
|
||||
"mastodon.py": {
|
||||
"hashes": [
|
||||
"sha256:d97d855131fafcd9d0091b8a5d10130b3eaf673bbde45bce1d13037d1d6a9106",
|
||||
"sha256:ea57f16bb9c79c810c122867ecc706e1f272b4e68614b6069a86d62a911ae4e7"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.7.0"
|
||||
},
|
||||
"python-dateutil": {
|
||||
"hashes": [
|
||||
"sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86",
|
||||
"sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==2.8.2"
|
||||
},
|
||||
"python-magic": {
|
||||
"hashes": [
|
||||
"sha256:c1ba14b08e4a5f5c31a302b7721239695b2f0f058d125bd5ce1ee36b9d9d3c3b",
|
||||
"sha256:c212960ad306f700aa0d01e5d7a325d20548ff97eb9920dcd29513174f0294d3"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
|
||||
"version": "==0.4.27"
|
||||
},
|
||||
"pytz": {
|
||||
"hashes": [
|
||||
"sha256:222439474e9c98fced559f1709d89e6c9cbf8d79c794ff3eb9f8800064291427",
|
||||
"sha256:e89512406b793ca39f5971bc999cc538ce125c0e51c27941bef4568b460095e2"
|
||||
],
|
||||
"version": "==2022.6"
|
||||
},
|
||||
"requests": {
|
||||
"hashes": [
|
||||
"sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983",
|
||||
"sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.28.1"
|
||||
},
|
||||
"six": {
|
||||
"hashes": [
|
||||
"sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926",
|
||||
"sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==1.16.0"
|
||||
},
|
||||
"urllib3": {
|
||||
"hashes": [
|
||||
"sha256:47cc05d99aaa09c9e72ed5809b60e7ba354e64b59c9c173ac3018642d8bb41fc",
|
||||
"sha256:c083dd0dce68dbfbe1129d5271cb90f9447dea7d52097c6e0126120c521ddea8"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'",
|
||||
"version": "==1.26.13"
|
||||
},
|
||||
"werkzeug": {
|
||||
"hashes": [
|
||||
"sha256:7ea2d48322cc7c0f8b3a215ed73eabd7b5d75d0b50e31ab006286ccff9e00b8f",
|
||||
"sha256:f979ab81f58d7318e064e99c4506445d60135ac5cd2e177a2de0089bfd4c9bd5"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==2.2.2"
|
||||
}
|
||||
},
|
||||
"develop": {
|
||||
"flake8": {
|
||||
"hashes": [
|
||||
"sha256:3833794e27ff64ea4e9cf5d410082a8b97ff1a06c16aa3d2027339cd0f1195c7",
|
||||
"sha256:c61007e76655af75e6785a931f452915b371dc48f56efd765247c8fe68f2b181"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==6.0.0"
|
||||
},
|
||||
"mccabe": {
|
||||
"hashes": [
|
||||
"sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325",
|
||||
"sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==0.7.0"
|
||||
},
|
||||
"pycodestyle": {
|
||||
"hashes": [
|
||||
"sha256:347187bdb476329d98f695c213d7295a846d1152ff4fe9bacb8a9590b8ee7053",
|
||||
"sha256:8a4eaf0d0495c7395bdab3589ac2db602797d76207242c17d470186815706610"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==2.10.0"
|
||||
},
|
||||
"pyflakes": {
|
||||
"hashes": [
|
||||
"sha256:ec55bf7fe21fff7f1ad2f7da62363d749e2a470500eab1b555334b67aa1ef8cf",
|
||||
"sha256:ec8b276a6b60bd80defed25add7e439881c19e64850afd9b346283d4165fd0fd"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==3.0.1"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,7 +17,8 @@ Code attributions can be found in `ATTRIBUTION.adoc`
|
|||
|
||||
== Setup
|
||||
|
||||
* Install Flask (`pip --user install Flask`)
|
||||
|
||||
* Install dependencies with `pipenv install`
|
||||
* Create an Owncast webhook url pointing to your bot's location
|
||||
** http://localhost:5000/webhook/owncast if bot and owncast are on the same machine
|
||||
* Run ameliabot the first time to generate a minimal configuration file
|
||||
|
@ -25,7 +26,7 @@ Code attributions can be found in `ATTRIBUTION.adoc`
|
|||
|
||||
Ameliabot can be run by executing `start.sh` or:
|
||||
```
|
||||
FLASK_APP=bot.py python3 -m flask run
|
||||
FLASK_APP=bot.py pipenv run python3 -m flask run
|
||||
```
|
||||
|
||||
Please use a proper uWSGI proxy if the bot is not on the same machine as owncast.
|
||||
|
|
28
bot.py
28
bot.py
|
@ -1,20 +1,38 @@
|
|||
#!/usr/bin/env python
|
||||
from flask import Flask, Response
|
||||
from core import owncast, __version__
|
||||
# import argparse
|
||||
from flask import Flask, Response, request
|
||||
from core import config, fedi, owncast, __version__, root_logger
|
||||
from core.logger import logging
|
||||
|
||||
# parser = argparse.ArgumentParser(description="Stream service selection")
|
||||
# parser.add_argument("-s", "--service",
|
||||
# default="all",
|
||||
# help="connect to a service. Needs all, twitch, fedi, or owncast")
|
||||
|
||||
# args = parser.parse_args()
|
||||
app = Flask(__name__)
|
||||
|
||||
logging.info("Loaded %s, running ameliabot v%s" % (
|
||||
owncast.config["DEFAULT"]["BotName"], __version__))
|
||||
logging.debug("Loaded %s, running ameliabot v%s" % (
|
||||
config["DEFAULT"]["BotName"], __version__))
|
||||
|
||||
# the url of the Owncast API for bot posts
|
||||
owncast_url = "{}/api/integrations/chat/send".format(
|
||||
owncast.config["owncast"]["ServerURL"])
|
||||
config["owncast"]["ServerURL"])
|
||||
|
||||
|
||||
@app.route('/webhook/owncast', methods=['POST'])
|
||||
def respond():
|
||||
owncast.parse_webhook()
|
||||
return Response(status=200)
|
||||
|
||||
|
||||
@app.route('/webhook/fedi', methods=['POST'])
|
||||
def fedipost():
|
||||
args = request.args
|
||||
repo = args.get("repo")
|
||||
|
||||
# Incredibly insecure lmao
|
||||
if repo != None:
|
||||
fedi.parse_webhook(args.get("repo"))
|
||||
return Response(status=200)
|
||||
return 400
|
||||
|
|
|
@ -8,3 +8,8 @@ AccessToken = Someaccesstoken23-209523dfsd
|
|||
|
||||
[quotes]
|
||||
Enabled = False
|
||||
|
||||
[fedi]
|
||||
Enabled = False
|
||||
BaseURL = https://your.fediverse.server
|
||||
AccessToken = Someaccesstoken23242930s3
|
|
@ -29,7 +29,7 @@ root_logger.addHandler(file_handler)
|
|||
config = ConfigParser()
|
||||
try:
|
||||
config.read("config.ini")
|
||||
logging.info("Configuration loaded")
|
||||
logging.debug("Configuration loaded")
|
||||
except FileNotFoundError:
|
||||
config["DEFAULT"] = {"BotName": "ameliabot", "BotOwner": "Some Name"}
|
||||
config["owncast"] = {
|
||||
|
@ -46,10 +46,10 @@ cmd_file = ConfigParser()
|
|||
try:
|
||||
cmd_file.read("commands.ini")
|
||||
commands = cmd_file["commands"]
|
||||
logging.info("Commands loaded")
|
||||
logging.debug("Commands loaded")
|
||||
|
||||
aliases = cmd_file["aliases"]
|
||||
logging.info("Aliases loaded")
|
||||
logging.debug("Aliases loaded")
|
||||
except FileNotFoundError:
|
||||
cmd_file["commands"] = {
|
||||
"!version": "I am running ameliabot {bot_version}"}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
from mastodon import Mastodon
|
||||
from flask import request
|
||||
from core import config
|
||||
from core.logger import logging
|
||||
|
||||
|
||||
logging.debug("Fedi started")
|
||||
|
||||
|
||||
# I don't like typing toot
|
||||
def post(contents):
|
||||
return fedi.status_post(contents, visibility="unlisted")
|
||||
|
||||
|
||||
def parse_webhook(repo):
|
||||
print(repo)
|
||||
data = request.json["commits"][0]
|
||||
print(data)
|
||||
message = "[{}] \"{}\"\n{}".format(
|
||||
#message = "{}: \"{}\" {}".format(
|
||||
#data["author"]["name"],
|
||||
repo,
|
||||
data["message"].strip(),
|
||||
data["url"],
|
||||
)
|
||||
post(message)
|
||||
|
||||
fedi = Mastodon(
|
||||
api_base_url = config["fedi"]["BaseURL"],
|
||||
access_token = config["fedi"]["AccessToken"],
|
||||
)
|
Loading…
Reference in New Issue