Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions models.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
from datetime import datetime, timezone

from fastapi import Query
from pydantic import BaseModel
from pydantic import BaseModel, Field


class CreateCopilotData(BaseModel):
user: str = Query(None)
title: str = Query(None)
lnurl_toggle: int = Query(0)
wallet: str = Query(None)
animation1: str = Query(None)
animation2: str = Query(None)
animation3: str = Query(None)
animation1threshold: int = Query(0)
animation2threshold: int = Query(0)
animation3threshold: int = Query(0)
animation1webhook: str = Query(None)
animation2webhook: str = Query(None)
animation3webhook: str = Query(None)
lnurl_title: str = Query(None)
show_message: int = Query(0)
show_ack: int = Query(0)
show_price: str = Query(None)
amount_made: int = Query(0)
timestamp: int = Query(0)
fullscreen_cam: int = Query(0)
iframe_url: str = Query(None)
user: str | None = None
title: str | None = None
lnurl_toggle: int | None = 0
wallet: str | None = None
animation1: str | None = None
animation2: str | None = None
animation3: str | None = None
animation1threshold: int | None = 0
animation2threshold: int | None = 0
animation3threshold: int | None = 0
animation1webhook: str | None = None
animation2webhook: str | None = None
animation3webhook: str | None = None
lnurl_title: str | None = None
show_message: int | None = 0
show_ack: int | None = 0
show_price: str | None = None
amount_made: int | None = 0
timestamp: datetime | None = Field(
default_factory=lambda: datetime.now(timezone.utc)
)
fullscreen_cam: int | None = 0
iframe_url: str | None = None


class Copilot(BaseModel):
Expand All @@ -46,6 +50,6 @@ class Copilot(BaseModel):
show_ack: int
show_price: str | None
amount_made: int
timestamp: int
timestamp: datetime
fullscreen_cam: int
iframe_url: str | None
26 changes: 8 additions & 18 deletions templates/copilot/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,21 @@
initTrollBox() {
this.troll_box = !this.troll_box

if (location.protocol !== 'http:') {
this.chatUrl =
'wss://' +
document.domain +
':' +
location.port +
'/api/v1/ws/' +
this.chat_id
} else {
this.chatUrl =
'ws://' +
document.domain +
':' +
location.port +
'/api/v1/ws/' +
this.chat_id
}
this.connectionchat = new WebSocket(this.chatUrl)
const url = new URL(window.location)
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'
url.pathname = `/api/v1/ws/${chatId}`

this.connectionchat = new WebSocket(url)
this.chatUrl = url.toString()
this.connectionchat.onmessage = e => {
console.log(e.data)
this.trollbox.push(e.data)
}
this.connectionchat.onopen = () => this.launch
}
},
created() {
this.chatId = '{{ chat_id }}'
this.initTrollBox()
}
})
Expand Down
81 changes: 38 additions & 43 deletions templates/copilot/compose.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<q-card-section>
<div class="row">
<div class="col" style="max-width: 100px">
<lnbits-qrcode :value="chatUrl"></lnbits-qrcode>
<lnbits-qrcode :value="chatUrl" :show-buttons="false"></lnbits-qrcode>
</div>
<div class="col">
<div class="text-h6 q-ml-md">Trollbox</div>
Expand Down Expand Up @@ -75,12 +75,12 @@
:url="url"
:show-buttons="false"
></lnbits-qrcode-lnurl>
<center
class="absolute-bottom"
style="color: black; font-size: 20px"
v-text="copilot.lnurl_title"
></center>
</div>
<center
class="absolute-bottom"
style="color: black; font-size: 20px"
v-text="copilot.lnurl_title"
></center>
</div>

<h2
Expand Down Expand Up @@ -212,24 +212,12 @@
},
initTrollBox() {
this.troll_box = !this.troll_box
if (location.protocol !== 'http:') {
this.chatUrl =
'wss://' +
document.domain +
':' +
location.port +
'/api/v1/ws/' +
this.chat_id
} else {
this.chatUrl =
'ws://' +
document.domain +
':' +
location.port +
'/api/v1/ws/' +
this.chat_id
}
this.connectionchat = new WebSocket(this.chatUrl)
const url = new URL(window.location)
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'
url.pathname = `/api/v1/ws/${this.chat_id}`

this.connectionchat = new WebSocket(url)
this.chatUrl = url.toString()
this.connectionchat.onmessage = e => {
res = e.data.split('-')
if (res[0].length < 1 || res[1].length < 1) {
Expand Down Expand Up @@ -335,27 +323,34 @@
return data => (pending = run(data))
})()

if (location.protocol !== 'http:') {
localUrl =
'wss://' +
document.domain +
':' +
location.port +
'/api/v1/ws/' +
this.copilot.id
} else {
localUrl =
'ws://' +
document.domain +
':' +
location.port +
'/api/v1/ws/' +
this.copilot.id
}
const localUrl = new URL(window.location)
localUrl.protocol = localUrl.protocol === 'https:' ? 'wss:' : 'ws:'
localUrl.pathname = `/api/v1/ws/${this.copilot.id}`

// if (location.protocol !== 'http:') {
// localUrl =
// 'wss://' +
// document.domain +
// ':' +
// location.port +
// '/api/v1/ws/' +
// this.copilot.id
// } else {
// localUrl =
// 'ws://' +
// document.domain +
// ':' +
// location.port +
// '/api/v1/ws/' +
// this.copilot.id
// }
this.connection = new WebSocket(localUrl)
this.connection.onmessage = e => {
console.log(e)
res = e.data.replace(' ', '').split('-')
res = e.data
.replace(' ', '')
.split('-')
.map(s => s.trim())
if (res[0] == 'rocket') {
addTask(['40%', '/copilot/static/rocket.gif', res[1]])
}
Expand All @@ -376,7 +371,7 @@
}
if (res[0] == 'trollbox') {
this.chat_id = res[1]
this.chatLink = '/copilot/chat/' + this.chat_id
this.chatLink = `/copilot/chat/${this.chat_id}`
this.initTrollBox()
}
if (res[0] == 'trollboxchat') {
Expand Down
8 changes: 2 additions & 6 deletions templates/copilot/panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</div>
</div>

<q-input v-model="chatId" label="Troll box ID">
<q-input v-model.trim="chatId" label="Troll box ID">
<template v-slot:after>
<q-btn round dense flat icon="launch" @click="launchChat" />
</template>
Expand Down Expand Up @@ -153,11 +153,7 @@
LNbits.api
.request(
'GET',
'/copilot/api/v1/copilot/ws/' +
this.copilot.id +
'/' +
this.chatId +
'/trollbox'
`/copilot/api/v1/copilot/ws/${this.copilot.id}/${this.chatId}/trollbox`
)
.then(response1 => {
Quasar.Notify.create({
Expand Down