Add TwitchAlerts plugin

This commit is contained in:
Fitti
2021-06-20 06:34:01 +02:00
parent 8472efb1b5
commit fd8d4d3e67
8 changed files with 160 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
<h1>Example Extension</h1>
<h2>*tagline*</h2>
This is an TwitchAlerts extension to help you organise and build you own.
Try to include an image
<img src="https://i.imgur.com/9i4xcQB.png">
<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>

View File

@@ -0,0 +1,12 @@
from quart import Blueprint
from lnbits.db import Database
db = Database("ext_TwitchAlerts")
TwitchAlerts_ext: Blueprint = Blueprint(
"TwitchAlerts", __name__, static_folder="static", template_folder="templates"
)
from .views_api import * # noqa
from .views import * # noqa

View File

@@ -0,0 +1,6 @@
{
"name": "Build your own!",
"short_description": "Join us, make an extension",
"icon": "info",
"contributors": ["github_username"]
}

View File

@@ -0,0 +1,11 @@
# async def m001_initial(db):
# await db.execute(
# """
# CREATE TABLE IF NOT EXISTS TwitchAlerts (
# id TEXT PRIMARY KEY,
# wallet TEXT NOT NULL,
# time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
# );
# """
# )

View File

@@ -0,0 +1,11 @@
# from sqlite3 import Row
# from typing import NamedTuple
# class Example(NamedTuple):
# id: str
# wallet: str
#
# @classmethod
# def from_row(cls, row: Row) -> "Example":
# return cls(**dict(row))

View File

@@ -0,0 +1,57 @@
{% extends "base.html" %} {% from "macros.jinja" import window_vars with context
%} {% block page %}
<q-card>
<q-card-section>
<h5 class="text-subtitle1 q-mt-none q-mb-md">Frameworks used by LNbits</h5>
<q-list>
<q-item
v-for="tool in tools"
:key="tool.name"
tag="a"
:href="tool.url"
target="_blank"
>
{% raw %}
<!-- with raw Flask won't try to interpret the Vue moustaches -->
<q-item-section>
<q-item-label>{{ tool.name }}</q-item-label>
<q-item-label caption>{{ tool.language }}</q-item-label>
</q-item-section>
{% endraw %}
</q-item>
</q-list>
<q-separator class="q-my-lg"></q-separator>
<p>
A magical "g" is always available, with info about the user, wallets and
extensions:
</p>
<code class="text-caption">{% raw %}{{ g }}{% endraw %}</code>
</q-card-section>
</q-card>
{% endblock %} {% block scripts %} {{ window_vars(user) }}
<script>
new Vue({
el: '#vue',
mixins: [windowMixin],
data: function () {
return {
tools: []
}
},
created: function () {
var self = this
// axios is available for making requests
axios({
method: 'GET',
url: '/TwitchAlerts/api/v1/tools',
headers: {
'X-TwitchAlerts-header': 'not-used'
}
}).then(function (response) {
self.tools = response.data
})
}
})
</script>
{% endblock %}

View File

@@ -0,0 +1,12 @@
from quart import g, render_template
from lnbits.decorators import check_user_exists, validate_uuids
from . import TwitchAlerts_ext
@TwitchAlerts_ext.route("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("TwitchAlerts/index.html", user=g.user)

View File

@@ -0,0 +1,40 @@
# views_api.py is for you API endpoints that could be hit by another service
# add your dependencies here
# import json
# import httpx
# (use httpx just like requests, except instead of response.ok there's only the
# response.is_error that is its inverse)
from quart import jsonify
from http import HTTPStatus
from . import TwitchAlerts_ext
# add your endpoints here
@TwitchAlerts_ext.route("/api/v1/tools", methods=["GET"])
async def api_TwitchAlerts():
"""Try to add descriptions for others."""
tools = [
{
"name": "Quart",
"url": "https://pgjones.gitlab.io/quart/",
"language": "Python",
},
{
"name": "Vue.js",
"url": "https://vuejs.org/",
"language": "JavaScript",
},
{
"name": "Quasar Framework",
"url": "https://quasar.dev/",
"language": "JavaScript",
},
]
return jsonify(tools), HTTPStatus.OK