Skip to content

Commit f5b4f42

Browse files
authored
feat: update to lnbits 1.0.0 (#21)
1 parent f34244e commit f5b4f42

15 files changed

Lines changed: 1578 additions & 1582 deletions

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Streamer Copilot",
33
"short_description": "Video tips/animations/webhooks",
44
"tile": "/copilot/static/bitcoin-streaming.png",
5-
"min_lnbits_version": "0.12.6",
5+
"min_lnbits_version": "1.0.0",
66
"contributors": [
77
{
88
"name": "Ben Arc",

crud.py

Lines changed: 17 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -8,89 +8,35 @@
88
db = Database("ext_copilot")
99

1010

11-
async def create_copilot(data: CreateCopilotData, inkey: Optional[str] = "") -> Copilot:
11+
async def create_copilot(data: CreateCopilotData) -> Copilot:
1212
copilot_id = urlsafe_short_hash()
13-
await db.execute(
14-
"""
15-
INSERT INTO copilot.newer_copilots (
16-
id,
17-
"user",
18-
lnurl_toggle,
19-
wallet,
20-
title,
21-
animation1,
22-
animation2,
23-
animation3,
24-
animation1threshold,
25-
animation2threshold,
26-
animation3threshold,
27-
animation1webhook,
28-
animation2webhook,
29-
animation3webhook,
30-
lnurl_title,
31-
show_message,
32-
show_ack,
33-
show_price,
34-
fullscreen_cam,
35-
iframe_url,
36-
amount_made
37-
)
38-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
39-
""",
40-
(
41-
copilot_id,
42-
data.user,
43-
int(data.lnurl_toggle),
44-
data.wallet,
45-
data.title,
46-
data.animation1,
47-
data.animation2,
48-
data.animation3,
49-
data.animation1threshold,
50-
data.animation2threshold,
51-
data.animation3threshold,
52-
data.animation1webhook,
53-
data.animation2webhook,
54-
data.animation3webhook,
55-
data.lnurl_title,
56-
int(data.show_message),
57-
int(data.show_ack),
58-
data.show_price,
59-
0,
60-
None,
61-
0,
62-
),
63-
)
64-
copilot = await get_copilot(copilot_id)
65-
assert copilot, "Newly created copilot couldn't be retrieved"
13+
copilot = Copilot(id=copilot_id, **data.dict())
14+
await db.insert("copilot.newer_copilots", copilot)
6615
return copilot
6716

6817

69-
async def update_copilot(data: CreateCopilotData, copilot_id: str) -> Copilot:
70-
q = ", ".join([f"{field[0]} = ?" for field in data])
71-
items = [f"{field[1]}" for field in data]
72-
items.append(copilot_id)
73-
await db.execute(f"UPDATE copilot.newer_copilots SET {q} WHERE id = ?", (items,))
74-
row = await db.fetchone(
75-
"SELECT * FROM copilot.newer_copilots WHERE id = ?", (copilot_id,)
76-
)
77-
assert row, "Updated copilot couldn't be retrieved"
78-
return Copilot(**row)
18+
async def update_copilot(copilot: Copilot) -> Copilot:
19+
await db.update("copilot.newer_copilots", copilot)
20+
return copilot
7921

8022

8123
async def get_copilot(copilot_id: str) -> Optional[Copilot]:
82-
row = await db.fetchone(
83-
"SELECT * FROM copilot.newer_copilots WHERE id = ?", (copilot_id,)
24+
return await db.fetchone(
25+
"SELECT * FROM copilot.newer_copilots WHERE id = :id",
26+
{"id": copilot_id},
27+
Copilot,
8428
)
85-
return Copilot(**row) if row else None
8629

8730

8831
async def get_copilots(user: str) -> List[Copilot]:
89-
rows = await db.fetchall(
90-
'SELECT * FROM copilot.newer_copilots WHERE "user" = ?', (user,)
32+
return await db.fetchall(
33+
'SELECT * FROM copilot.newer_copilots WHERE "user" = :user',
34+
{"user": user},
35+
Copilot,
9136
)
92-
return [Copilot(**row) for row in rows]
9337

9438

9539
async def delete_copilot(copilot_id: str) -> None:
96-
await db.execute("DELETE FROM copilot.newer_copilots WHERE id = ?", (copilot_id,))
40+
await db.execute(
41+
"DELETE FROM copilot.newer_copilots WHERE id = :id", {"id": copilot_id}
42+
)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poetry.lock

Lines changed: 1161 additions & 1037 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = ["Alan Bits <alan@lnbits.com>"]
66

77
[tool.poetry.dependencies]
88
python = "^3.10 | ^3.9"
9-
lnbits = "*"
9+
lnbits = {version = "*", allow-prereleases = true}
1010

1111
[tool.poetry.group.dev.dependencies]
1212
black = "^24.3.0"

static/js/index.js

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
const mapCopilot = obj => {
2+
obj._data = _.clone(obj)
3+
4+
obj.theTime = obj.time * 60 - (Date.now() / 1000 - obj.timestamp)
5+
obj.time = obj.time + 'mins'
6+
7+
if (obj.time_elapsed) {
8+
obj.date = 'Time elapsed'
9+
} else {
10+
obj.date = Quasar.date.formatDate(
11+
new Date((obj.theTime - 3600) * 1000),
12+
'HH:mm:ss'
13+
)
14+
}
15+
obj.displayComposeUrl = ['/copilot/cp/', obj.id].join('')
16+
obj.displayPanelUrl = ['/copilot/', obj.id].join('')
17+
return obj
18+
}
19+
20+
window.app = Vue.createApp({
21+
el: '#vue',
22+
mixins: [windowMixin],
23+
data() {
24+
return {
25+
filter: '',
26+
copilotLinks: [],
27+
copilotLinksObj: [],
28+
copilotsTable: {
29+
columns: [
30+
{
31+
name: 'theId',
32+
align: 'left',
33+
label: 'id',
34+
field: 'id'
35+
},
36+
{
37+
name: 'lnurl_toggle',
38+
align: 'left',
39+
label: 'Show lnurl pay link',
40+
field: 'lnurl_toggle'
41+
},
42+
{
43+
name: 'title',
44+
align: 'left',
45+
label: 'title',
46+
field: 'title'
47+
},
48+
{
49+
name: 'amount_made',
50+
align: 'left',
51+
label: 'amount made',
52+
field: 'amount_made'
53+
}
54+
],
55+
pagination: {
56+
rowsPerPage: 10
57+
}
58+
},
59+
passedCopilot: {},
60+
formDialog: {
61+
show: false,
62+
data: {}
63+
},
64+
formDialogCopilot: {
65+
show: false,
66+
data: {
67+
lnurl_toggle: false,
68+
show_message: false,
69+
show_ack: false,
70+
show_price: 'None',
71+
title: ''
72+
}
73+
},
74+
qrCodeDialog: {
75+
show: false,
76+
data: null
77+
},
78+
options: ['bitcoin', 'confetti', 'rocket', 'face', 'martijn', 'rick'],
79+
currencyOptions: ['None', 'btcusd', 'btceur', 'btcgbp']
80+
}
81+
},
82+
methods: {
83+
cancelCopilot(data) {
84+
this.formDialogCopilot.show = false
85+
this.clearFormDialogCopilot()
86+
},
87+
closeFormDialog() {
88+
this.clearFormDialogCopilot()
89+
this.formDialog.data = {
90+
lnurl_toggle: false,
91+
show_message: false,
92+
show_ack: false,
93+
show_price: 'None',
94+
title: ''
95+
}
96+
},
97+
sendFormDataCopilot() {
98+
if (this.formDialogCopilot.data.id) {
99+
this.updateCopilot(
100+
this.g.user.wallets[0].adminkey,
101+
this.formDialogCopilot.data
102+
)
103+
} else {
104+
this.createCopilot(
105+
this.g.user.wallets[0].adminkey,
106+
this.formDialogCopilot.data
107+
)
108+
}
109+
},
110+
111+
createCopilot(wallet, data) {
112+
const updatedData = {}
113+
for (const property in data) {
114+
if (data[property]) {
115+
updatedData[property] = data[property]
116+
}
117+
if (property == 'animation1threshold' && data[property]) {
118+
updatedData[property] = parseInt(data[property])
119+
}
120+
if (property == 'animation2threshold' && data[property]) {
121+
updatedData[property] = parseInt(data[property])
122+
}
123+
if (property == 'animation3threshold' && data[property]) {
124+
updatedData[property] = parseInt(data[property])
125+
}
126+
}
127+
128+
LNbits.api
129+
.request('POST', '/copilot/api/v1/copilot', wallet, updatedData)
130+
.then(response => {
131+
this.copilotLinks.push(mapCopilot(response.data))
132+
this.formDialogCopilot.show = false
133+
this.clearFormDialogCopilot()
134+
})
135+
.catch(LNbits.utils.notifyApiError)
136+
},
137+
getCopilots() {
138+
LNbits.api
139+
.request('GET', '/copilot/api/v1/copilot', this.g.user.wallets[0].inkey)
140+
.then(response => {
141+
if (response.data) {
142+
this.copilotLinks = response.data.map(mapCopilot)
143+
}
144+
})
145+
.catch(LNbits.utils.notifyApiError)
146+
},
147+
getCopilot(copilot_id) {
148+
LNbits.api
149+
.request(
150+
'GET',
151+
'/copilot/api/v1/copilot/' + copilot_id,
152+
this.g.user.wallets[0].inkey
153+
)
154+
.then(response => {
155+
localStorage.setItem('copilot', JSON.stringify(response.data))
156+
localStorage.setItem('inkey', this.g.user.wallets[0].inkey)
157+
})
158+
.catch(LNbits.utils.notifyApiError)
159+
},
160+
openCopilotCompose(copilot_id) {
161+
this.getCopilot(copilot_id)
162+
let params =
163+
'scrollbars=no, resizable=no,status=no,location=no,toolbar=no,menubar=no,width=1200,height=644,left=410,top=100'
164+
open('../copilot/cp/', '_blank', params)
165+
},
166+
openCopilotPanel(copilot_id) {
167+
this.getCopilot(copilot_id)
168+
let params =
169+
'scrollbars=no, resizable=no,status=no,location=no,toolbar=no,menubar=no,width=300,height=450,left=10,top=400'
170+
open('../copilot/pn/', '_blank', params)
171+
},
172+
deleteCopilotLink(copilotId) {
173+
const link = _.findWhere(this.copilotLinks, {id: copilotId})
174+
LNbits.utils
175+
.confirmDialog('Are you sure you want to delete this pay link?')
176+
.onOk(() => {
177+
LNbits.api
178+
.request(
179+
'DELETE',
180+
'/copilot/api/v1/copilot/' + copilotId,
181+
this.g.user.wallets[0].adminkey
182+
)
183+
.then(response => {
184+
this.copilotLinks = _.reject(this.copilotLinks, function (obj) {
185+
return obj.id === copilotId
186+
})
187+
})
188+
.catch(LNbits.utils.notifyApiError)
189+
})
190+
},
191+
openUpdateCopilotLink(copilotId) {
192+
const copilot = _.findWhere(this.copilotLinks, {id: copilotId})
193+
this.formDialogCopilot.data = {...copilot._data}
194+
this.formDialogCopilot.data.lnurl_toggle = Boolean(
195+
this.formDialogCopilot.data.lnurl_toggle
196+
)
197+
this.formDialogCopilot.data.show_message = Boolean(
198+
this.formDialogCopilot.data.show_message
199+
)
200+
this.formDialogCopilot.data.show_ack = Boolean(
201+
this.formDialogCopilot.data.show_ack
202+
)
203+
this.formDialogCopilot.show = true
204+
},
205+
updateCopilot(wallet, data) {
206+
const updatedData = {}
207+
208+
const updateThreshold = property => {
209+
if (data[property] && data[property] !== 0) {
210+
updatedData[property] = parseInt(data[property])
211+
}
212+
}
213+
214+
for (const property in data) {
215+
if (data[property]) {
216+
updatedData[property] = data[property]
217+
}
218+
switch (property) {
219+
case 'animation1threshold':
220+
case 'animation2threshold':
221+
case 'animation3threshold':
222+
updateThreshold(property)
223+
break
224+
}
225+
}
226+
227+
LNbits.api
228+
.request(
229+
'PUT',
230+
'/copilot/api/v1/copilot/' + updatedData.id,
231+
wallet,
232+
updatedData
233+
)
234+
.then(response => {
235+
this.copilotLinks = _.reject(this.copilotLinks, function (obj) {
236+
return obj.id === updatedData.id
237+
})
238+
this.copilotLinks.push(mapCopilot(response.data))
239+
this.formDialogCopilot.show = false
240+
this.clearFormDialogCopilot()
241+
})
242+
.catch(LNbits.utils.notifyApiError)
243+
},
244+
clearFormDialogCopilot() {
245+
this.formDialogCopilot.data = {
246+
lnurl_toggle: false,
247+
show_message: false,
248+
show_ack: false,
249+
show_price: 'None',
250+
title: ''
251+
}
252+
},
253+
exportcopilotCSV() {
254+
LNbits.utils.exportCSV(this.copilotsTable.columns, this.copilotLinks)
255+
}
256+
},
257+
created() {
258+
this.getCopilots()
259+
}
260+
})

0 commit comments

Comments
 (0)