Rename TwitchAlerts to StreamAlerts
This commit is contained in:
parent
85bf0ebb15
commit
7444be8c54
11 changed files with 43 additions and 43 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
<h1>Example Extension</h1>
|
<h1>Example Extension</h1>
|
||||||
<h2>*tagline*</h2>
|
<h2>*tagline*</h2>
|
||||||
The TwitchAlerts extension allows you to integrate Bitcoin Lightning (and on-chain) paymnents in to your existing Streamlabs alerts!
|
The StreamAlerts extension allows you to integrate Bitcoin Lightning (and on-chain) paymnents in to your existing Streamlabs alerts!
|
||||||
|
|
||||||
Try to include an image
|
Try to include an image
|
||||||
<img src="https://i.imgur.com/9i4xcQB.png">
|
<img src="https://i.imgur.com/9i4xcQB.png">
|
||||||
|
|
||||||
<h2>If your extension has API endpoints, include useful ones here</h2>
|
<h2>If your extension has API endpoints, include useful ones here</h2>
|
||||||
|
|
||||||
<code>curl -H "Content-type: application/json" -X POST https://YOUR-LNBITS/YOUR-EXTENSION/api/v1/EXAMPLE -d '{"amount":"100","memo":"TwitchAlerts"}' -H "X-Api-Key: YOUR_WALLET-ADMIN/INVOICE-KEY"</code>
|
<code>curl -H "Content-type: application/json" -X POST https://YOUR-LNBITS/YOUR-EXTENSION/api/v1/EXAMPLE -d '{"amount":"100","memo":"StreamAlerts"}' -H "X-Api-Key: YOUR_WALLET-ADMIN/INVOICE-KEY"</code>
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
from quart import Blueprint
|
from quart import Blueprint
|
||||||
from lnbits.db import Database
|
from lnbits.db import Database
|
||||||
|
|
||||||
db = Database("ext_twitchalerts")
|
db = Database("ext_streamalerts")
|
||||||
|
|
||||||
twitchalerts_ext: Blueprint = Blueprint(
|
streamalerts_ext: Blueprint = Blueprint(
|
||||||
"twitchalerts", __name__, static_folder="static", template_folder="templates"
|
"streamalerts", __name__, static_folder="static", template_folder="templates"
|
||||||
)
|
)
|
||||||
|
|
||||||
from .views_api import * # noqa
|
from .views_api import * # noqa
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "Twitch Alerts",
|
"name": "Stream Alerts",
|
||||||
"short_description": "Integrate Bitcoin donations into your stream alerts!",
|
"short_description": "Integrate Bitcoin donations into your stream alerts!",
|
||||||
"icon": "notifications_active",
|
"icon": "notifications_active",
|
||||||
"contributors": ["Fittiboy"]
|
"contributors": ["Fittiboy"]
|
||||||
|
|
@ -17,7 +17,7 @@ from lnbits.core.crud import get_wallet
|
||||||
async def get_service_redirect_uri(request, service_id):
|
async def get_service_redirect_uri(request, service_id):
|
||||||
"""Return the service's redirect URI, to be given to the third party API"""
|
"""Return the service's redirect URI, to be given to the third party API"""
|
||||||
uri_base = request.scheme + "://"
|
uri_base = request.scheme + "://"
|
||||||
uri_base += request.headers["Host"] + "/twitchalerts/api/v1"
|
uri_base += request.headers["Host"] + "/streamalerts/api/v1"
|
||||||
redirect_uri = uri_base + f"/authenticate/{service_id}"
|
redirect_uri = uri_base + f"/authenticate/{service_id}"
|
||||||
return redirect_uri
|
return redirect_uri
|
||||||
|
|
||||||
|
|
@ -191,7 +191,7 @@ async def authenticate_service(service_id, code, redirect_uri):
|
||||||
print(response)
|
print(response)
|
||||||
token = response["access_token"]
|
token = response["access_token"]
|
||||||
success = await service_add_token(service_id, token)
|
success = await service_add_token(service_id, token)
|
||||||
return f"/twitchalerts/?usr={user}", success
|
return f"/streamalerts/?usr={user}", success
|
||||||
|
|
||||||
|
|
||||||
async def service_add_token(service_id, token):
|
async def service_add_token(service_id, token):
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<h4 class="text-subtitle1 q-my-none">
|
<h4 class="text-subtitle1 q-my-none">
|
||||||
Twitch Alerts: Integrate Bitcoin into your stream alerts!
|
Stream Alerts: Integrate Bitcoin into your stream alerts!
|
||||||
</h4>
|
</h4>
|
||||||
<p>
|
<p>
|
||||||
Accept Bitcoin donations on Twitch, and integrate them into your alerts.
|
Accept Bitcoin donations on Twitch, and integrate them into your alerts.
|
||||||
|
|
@ -76,7 +76,7 @@
|
||||||
Invoice: function () {
|
Invoice: function () {
|
||||||
var self = this
|
var self = this
|
||||||
axios
|
axios
|
||||||
.post('/twitchalerts/api/v1/donations', {
|
.post('/streamalerts/api/v1/donations', {
|
||||||
service: {{ service }},
|
service: {{ service }},
|
||||||
name: self.donationDialog.data.name,
|
name: self.donationDialog.data.name,
|
||||||
sats: self.donationDialog.data.sats,
|
sats: self.donationDialog.data.sats,
|
||||||
|
|
@ -151,11 +151,11 @@
|
||||||
<div class="col-12 col-md-4 col-lg-5 q-gutter-y-md">
|
<div class="col-12 col-md-4 col-lg-5 q-gutter-y-md">
|
||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<h6 class="text-subtitle1 q-my-none">LNbits Twitch Alerts extension</h6>
|
<h6 class="text-subtitle1 q-my-none">LNbits Stream Alerts extension</h6>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section class="q-pa-none">
|
<q-card-section class="q-pa-none">
|
||||||
<q-separator></q-separator>
|
<q-separator></q-separator>
|
||||||
<q-list> {% include "twitchalerts/_api_docs.html" %} </q-list>
|
<q-list> {% include "streamalerts/_api_docs.html" %} </q-list>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -229,14 +229,14 @@
|
||||||
</div>
|
</div>
|
||||||
{% endblock %} {% block scripts %} {{ window_vars(user) }}
|
{% endblock %} {% block scripts %} {{ window_vars(user) }}
|
||||||
<script>
|
<script>
|
||||||
var mapTwitchAlerts = function (obj) {
|
var mapStreamAlerts = function (obj) {
|
||||||
obj.date = Quasar.utils.date.formatDate(
|
obj.date = Quasar.utils.date.formatDate(
|
||||||
new Date(obj.time * 1000),
|
new Date(obj.time * 1000),
|
||||||
'YYYY-MM-DD HH:mm'
|
'YYYY-MM-DD HH:mm'
|
||||||
)
|
)
|
||||||
obj.fsat = new Intl.NumberFormat(LOCALE).format(obj.amount)
|
obj.fsat = new Intl.NumberFormat(LOCALE).format(obj.amount)
|
||||||
obj.authUrl = ['/twitchalerts/api/v1/getaccess/', obj.id].join('')
|
obj.authUrl = ['/streamalerts/api/v1/getaccess/', obj.id].join('')
|
||||||
obj.displayUrl = ['/twitchalerts/', obj.state].join('')
|
obj.displayUrl = ['/streamalerts/', obj.state].join('')
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,12 +316,12 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/twitchalerts/api/v1/donations',
|
'/streamalerts/api/v1/donations',
|
||||||
this.g.user.wallets[0].inkey
|
this.g.user.wallets[0].inkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
self.donations = response.data.map(function (obj) {
|
self.donations = response.data.map(function (obj) {
|
||||||
return mapTwitchAlerts(obj)
|
return mapStreamAlerts(obj)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
@ -335,7 +335,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'DELETE',
|
'DELETE',
|
||||||
'/twitchalerts/api/v1/donations/' + donationId,
|
'/streamalerts/api/v1/donations/' + donationId,
|
||||||
_.findWhere(self.g.user.wallets, {id: donations.wallet}).inkey
|
_.findWhere(self.g.user.wallets, {id: donations.wallet}).inkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
@ -358,12 +358,12 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/twitchalerts/api/v1/services',
|
'/streamalerts/api/v1/services',
|
||||||
this.g.user.wallets[0].inkey
|
this.g.user.wallets[0].inkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
self.services = response.data.map(function (obj) {
|
self.services = response.data.map(function (obj) {
|
||||||
return mapTwitchAlerts(obj)
|
return mapStreamAlerts(obj)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
@ -379,9 +379,9 @@
|
||||||
createService: function (wallet, data) {
|
createService: function (wallet, data) {
|
||||||
var self = this
|
var self = this
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request('POST', '/twitchalerts/api/v1/services', wallet.inkey, data)
|
.request('POST', '/streamalerts/api/v1/services', wallet.inkey, data)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
self.services.push(mapTwitchAlerts(response.data))
|
self.services.push(mapStreamAlerts(response.data))
|
||||||
self.serviceDialog.show = false
|
self.serviceDialog.show = false
|
||||||
self.serviceDialog.data = {}
|
self.serviceDialog.data = {}
|
||||||
})
|
})
|
||||||
|
|
@ -410,7 +410,7 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'DELETE',
|
'DELETE',
|
||||||
'/twitchalerts/api/v1/services/' + servicesId,
|
'/streamalerts/api/v1/services/' + servicesId,
|
||||||
_.findWhere(self.g.user.wallets, {id: services.wallet}).inkey
|
_.findWhere(self.g.user.wallets, {id: services.wallet}).inkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
@ -3,24 +3,24 @@ from quart import g, abort, render_template
|
||||||
from lnbits.decorators import check_user_exists, validate_uuids
|
from lnbits.decorators import check_user_exists, validate_uuids
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
from . import twitchalerts_ext
|
from . import streamalerts_ext
|
||||||
from .crud import get_service
|
from .crud import get_service
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/")
|
@streamalerts_ext.route("/")
|
||||||
@validate_uuids(["usr"], required=True)
|
@validate_uuids(["usr"], required=True)
|
||||||
@check_user_exists()
|
@check_user_exists()
|
||||||
async def index():
|
async def index():
|
||||||
"""Return the extension's settings page"""
|
"""Return the extension's settings page"""
|
||||||
return await render_template("twitchalerts/index.html", user=g.user)
|
return await render_template("streamalerts/index.html", user=g.user)
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/<state>")
|
@streamalerts_ext.route("/<state>")
|
||||||
async def donation(state):
|
async def donation(state):
|
||||||
"""Return the donation form for the Service corresponding to state"""
|
"""Return the donation form for the Service corresponding to state"""
|
||||||
service = await get_service(0, by_state=state)
|
service = await get_service(0, by_state=state)
|
||||||
if not service:
|
if not service:
|
||||||
abort(HTTPStatus.NOT_FOUND, "Service does not exist.")
|
abort(HTTPStatus.NOT_FOUND, "Service does not exist.")
|
||||||
return await render_template(
|
return await render_template(
|
||||||
"twitchalerts/display.html", twitchuser=service.twitchuser, service=service.id
|
"streamalerts/display.html", twitchuser=service.twitchuser, service=service.id
|
||||||
)
|
)
|
||||||
|
|
@ -5,7 +5,7 @@ from lnbits.decorators import api_validate_post_request, api_check_wallet_key
|
||||||
from lnbits.core.crud import get_wallet, get_user
|
from lnbits.core.crud import get_wallet, get_user
|
||||||
from lnbits.utils.exchange_rates import btc_price
|
from lnbits.utils.exchange_rates import btc_price
|
||||||
|
|
||||||
from . import twitchalerts_ext
|
from . import streamalerts_ext
|
||||||
from .crud import (
|
from .crud import (
|
||||||
get_charge_details,
|
get_charge_details,
|
||||||
get_service_redirect_uri,
|
get_service_redirect_uri,
|
||||||
|
|
@ -25,7 +25,7 @@ from .crud import (
|
||||||
from ..satspay.crud import create_charge, get_charge
|
from ..satspay.crud import create_charge, get_charge
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/api/v1/services", methods=["POST"])
|
@streamalerts_ext.route("/api/v1/services", methods=["POST"])
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
@api_validate_post_request(
|
@api_validate_post_request(
|
||||||
schema={
|
schema={
|
||||||
|
|
@ -43,11 +43,11 @@ async def api_create_service():
|
||||||
wallet = await get_wallet(service.wallet)
|
wallet = await get_wallet(service.wallet)
|
||||||
user = wallet.user
|
user = wallet.user
|
||||||
redirect_url = request.scheme + "://" + request.headers["Host"]
|
redirect_url = request.scheme + "://" + request.headers["Host"]
|
||||||
redirect_url += f"/twitchalerts/?usr={user}&created={str(service.id)}"
|
redirect_url += f"/streamalerts/?usr={user}&created={str(service.id)}"
|
||||||
return redirect(redirect_url)
|
return redirect(redirect_url)
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/api/v1/getaccess/<service_id>", methods=["GET"])
|
@streamalerts_ext.route("/api/v1/getaccess/<service_id>", methods=["GET"])
|
||||||
async def api_get_access(service_id):
|
async def api_get_access(service_id):
|
||||||
"""Redirect to Streamlabs' Approve/Decline page for API access for Service
|
"""Redirect to Streamlabs' Approve/Decline page for API access for Service
|
||||||
with service_id
|
with service_id
|
||||||
|
|
@ -70,7 +70,7 @@ async def api_get_access(service_id):
|
||||||
return (jsonify({"message": "Service does not exist!"}), HTTPStatus.BAD_REQUEST)
|
return (jsonify({"message": "Service does not exist!"}), HTTPStatus.BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/api/v1/authenticate/<service_id>", methods=["GET"])
|
@streamalerts_ext.route("/api/v1/authenticate/<service_id>", methods=["GET"])
|
||||||
async def api_authenticate_service(service_id):
|
async def api_authenticate_service(service_id):
|
||||||
"""Endpoint visited via redirect during third party API authentication
|
"""Endpoint visited via redirect during third party API authentication
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ async def api_authenticate_service(service_id):
|
||||||
if service.state != state:
|
if service.state != state:
|
||||||
return (jsonify({"message": "State doesn't match!"}), HTTPStatus.BAD_Request)
|
return (jsonify({"message": "State doesn't match!"}), HTTPStatus.BAD_Request)
|
||||||
redirect_uri = request.scheme + "://" + request.headers["Host"]
|
redirect_uri = request.scheme + "://" + request.headers["Host"]
|
||||||
redirect_uri += f"/twitchalerts/api/v1/authenticate/{service_id}"
|
redirect_uri += f"/streamalerts/api/v1/authenticate/{service_id}"
|
||||||
url, success = await authenticate_service(service_id, code, redirect_uri)
|
url, success = await authenticate_service(service_id, code, redirect_uri)
|
||||||
if success:
|
if success:
|
||||||
return redirect(url)
|
return redirect(url)
|
||||||
|
|
@ -94,7 +94,7 @@ async def api_authenticate_service(service_id):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/api/v1/donations", methods=["POST"])
|
@streamalerts_ext.route("/api/v1/donations", methods=["POST"])
|
||||||
@api_validate_post_request(
|
@api_validate_post_request(
|
||||||
schema={
|
schema={
|
||||||
"name": {"type": "string"},
|
"name": {"type": "string"},
|
||||||
|
|
@ -122,7 +122,7 @@ async def api_create_donation():
|
||||||
amount=sats,
|
amount=sats,
|
||||||
completelink=f"https://twitch.tv/{service.twitchuser}",
|
completelink=f"https://twitch.tv/{service.twitchuser}",
|
||||||
completelinktext="Back to Stream!",
|
completelinktext="Back to Stream!",
|
||||||
webhook=webhook_base + "/twitchalerts/api/v1/postdonation",
|
webhook=webhook_base + "/streamalerts/api/v1/postdonation",
|
||||||
description=description,
|
description=description,
|
||||||
**charge_details,
|
**charge_details,
|
||||||
)
|
)
|
||||||
|
|
@ -139,7 +139,7 @@ async def api_create_donation():
|
||||||
return (jsonify({"redirect_url": f"/satspay/{charge.id}"}), HTTPStatus.OK)
|
return (jsonify({"redirect_url": f"/satspay/{charge.id}"}), HTTPStatus.OK)
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/api/v1/postdonation", methods=["POST"])
|
@streamalerts_ext.route("/api/v1/postdonation", methods=["POST"])
|
||||||
@api_validate_post_request(
|
@api_validate_post_request(
|
||||||
schema={
|
schema={
|
||||||
"id": {"type": "string", "required": True},
|
"id": {"type": "string", "required": True},
|
||||||
|
|
@ -158,7 +158,7 @@ async def api_post_donation():
|
||||||
return (jsonify({"message": "Not a paid charge!"}), HTTPStatus.BAD_REQUEST)
|
return (jsonify({"message": "Not a paid charge!"}), HTTPStatus.BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/api/v1/services", methods=["GET"])
|
@streamalerts_ext.route("/api/v1/services", methods=["GET"])
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_get_services():
|
async def api_get_services():
|
||||||
"""Return list of all services assigned to wallet with given invoice key"""
|
"""Return list of all services assigned to wallet with given invoice key"""
|
||||||
|
|
@ -173,7 +173,7 @@ async def api_get_services():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/api/v1/donations", methods=["GET"])
|
@streamalerts_ext.route("/api/v1/donations", methods=["GET"])
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_get_donations():
|
async def api_get_donations():
|
||||||
"""Return list of all donations assigned to wallet with given invoice
|
"""Return list of all donations assigned to wallet with given invoice
|
||||||
|
|
@ -190,7 +190,7 @@ async def api_get_donations():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/api/v1/donations/<donation_id>", methods=["PUT"])
|
@streamalerts_ext.route("/api/v1/donations/<donation_id>", methods=["PUT"])
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_update_donation(donation_id=None):
|
async def api_update_donation(donation_id=None):
|
||||||
"""Update a donation with the data given in the request"""
|
"""Update a donation with the data given in the request"""
|
||||||
|
|
@ -215,7 +215,7 @@ async def api_update_donation(donation_id=None):
|
||||||
return jsonify(donation._asdict()), HTTPStatus.CREATED
|
return jsonify(donation._asdict()), HTTPStatus.CREATED
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/api/v1/services/<service_id>", methods=["PUT"])
|
@streamalerts_ext.route("/api/v1/services/<service_id>", methods=["PUT"])
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_update_service(service_id=None):
|
async def api_update_service(service_id=None):
|
||||||
"""Update a service with the data given in the request"""
|
"""Update a service with the data given in the request"""
|
||||||
|
|
@ -237,7 +237,7 @@ async def api_update_service(service_id=None):
|
||||||
return jsonify(service._asdict()), HTTPStatus.CREATED
|
return jsonify(service._asdict()), HTTPStatus.CREATED
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/api/v1/donations/<donation_id>", methods=["DELETE"])
|
@streamalerts_ext.route("/api/v1/donations/<donation_id>", methods=["DELETE"])
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_delete_donation(donation_id):
|
async def api_delete_donation(donation_id):
|
||||||
"""Delete the donation with the given donation_id"""
|
"""Delete the donation with the given donation_id"""
|
||||||
|
|
@ -254,7 +254,7 @@ async def api_delete_donation(donation_id):
|
||||||
return "", HTTPStatus.NO_CONTENT
|
return "", HTTPStatus.NO_CONTENT
|
||||||
|
|
||||||
|
|
||||||
@twitchalerts_ext.route("/api/v1/services/<service_id>", methods=["DELETE"])
|
@streamalerts_ext.route("/api/v1/services/<service_id>", methods=["DELETE"])
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_delete_service(service_id):
|
async def api_delete_service(service_id):
|
||||||
"""Delete the service with the given service_id"""
|
"""Delete the service with the given service_id"""
|
||||||
Loading…
Add table
Add a link
Reference in a new issue