Compare commits
32
Commits
#428
...
fix/grou_webhook
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5033f2dbd4 | ||
|
|
681bf390b3 | ||
|
|
51f2812ac6 | ||
|
|
6d0bc87f15 | ||
|
|
b3bbe614ff | ||
|
|
3ea9ef0684 | ||
|
|
97226991ac | ||
|
|
0225a5998a | ||
|
|
56318b3d0b | ||
|
|
ab5da78e39 | ||
|
|
9271668e94 | ||
|
|
7eaef102dd | ||
|
|
ab00715f51 | ||
|
|
7204d85837 | ||
|
|
84fe1d7cc2 | ||
|
|
0efc5c4e43 | ||
|
|
9e64dbb2fd | ||
|
|
058278046f | ||
|
|
998967c81e | ||
|
|
1a21a1519f | ||
|
|
c47038fa1c | ||
|
|
2c76764421 | ||
|
|
b0e43f17f0 | ||
|
|
120d7c4419 | ||
|
|
73d87fc4bb | ||
|
|
2f61a96e87 | ||
|
|
3112b79c0d | ||
|
|
b50270fe0a | ||
|
|
8598adb280 | ||
|
|
74e9f7aabf | ||
|
|
8b32e5fda5 | ||
|
|
d264650207 |
@@ -26,6 +26,7 @@ database:
|
||||
shop_buntdb_path: "data/shop.db"
|
||||
groupsdb_path: "data/groups.db"
|
||||
generate:
|
||||
open_ai_bearer_token: "token_here"
|
||||
dalle_key: "asd"
|
||||
dalle_price: 1000
|
||||
worker: 2
|
||||
@@ -5,6 +5,7 @@ go 1.17
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/PuerkitoBio/goquery v1.8.0
|
||||
github.com/PullRequestInc/go-gpt3 v1.1.10
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.2.0
|
||||
github.com/eko/gocache v1.2.0
|
||||
github.com/fiatjaf/go-lnurl v1.11.3-0.20220819192234-5c5819dd0aa7
|
||||
@@ -18,6 +19,7 @@ require (
|
||||
github.com/orcaman/concurrent-map v1.0.0
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/r3labs/sse v0.0.0-20210224172625-26fe804710bc
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/sirupsen/logrus v1.7.0
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||
github.com/tidwall/buntdb v1.2.7
|
||||
@@ -26,6 +28,7 @@ require (
|
||||
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f
|
||||
golang.org/x/text v0.3.7
|
||||
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
|
||||
gopkg.in/lightningtipbot/telebot.v3 v3.0.0-20220828121412-0dea11ecc6dd
|
||||
gorm.io/driver/sqlite v1.1.4
|
||||
gorm.io/gorm v1.21.12
|
||||
)
|
||||
@@ -55,7 +58,6 @@ require (
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
|
||||
github.com/decred/dcrd/lru v1.0.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/dillonstreator/dalle v0.0.0-20220826164958-b15c236ceadc // indirect
|
||||
github.com/go-errors/errors v1.0.1 // indirect
|
||||
github.com/go-redis/redis/v8 v8.8.2 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
@@ -84,11 +86,11 @@ require (
|
||||
go.opentelemetry.io/otel/metric v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v0.20.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
|
||||
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde // indirect
|
||||
golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 // indirect
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
|
||||
gopkg.in/lightningtipbot/telebot.v3 v3.0.0-20220828121412-0dea11ecc6dd // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
||||
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
|
||||
@@ -46,6 +46,8 @@ github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0g
|
||||
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
|
||||
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/PullRequestInc/go-gpt3 v1.1.10 h1:Z2fYKq7oGrr4Cs0yDmuq25FYR4hgvCowIR9sENHmSZ0=
|
||||
github.com/PullRequestInc/go-gpt3 v1.1.10/go.mod h1:F9yzAy070LhkqHS2154/IH0HVj5xq5g83gLTj7xzyfw=
|
||||
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
||||
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
||||
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
|
||||
@@ -157,6 +159,7 @@ github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtE
|
||||
github.com/btcsuite/winsvc v1.0.0 h1:J9B4L7e3oqhXOcm+2IuNApwzQec85lE+QaikUcCs+dk=
|
||||
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
|
||||
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||
github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm4fSc=
|
||||
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
|
||||
@@ -219,8 +222,6 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUn
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
github.com/dillonstreator/dalle v0.0.0-20220826164958-b15c236ceadc h1:gI9DEfWBOylVhQSIAuvKbaTkqvtlDmOTKGcg7i3Y3uE=
|
||||
github.com/dillonstreator/dalle v0.0.0-20220826164958-b15c236ceadc/go.mod h1:FyvK9n5UiK1wDTgGSkyMckbBAYVZiqaTH1LINKCgbIQ=
|
||||
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
|
||||
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
|
||||
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
|
||||
@@ -251,8 +252,6 @@ github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGE
|
||||
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||
github.com/fergusstrange/embedded-postgres v1.10.0 h1:YnwF6xAQYmKLAXXrrRx4rHDLih47YJwVPvg8jeKfdNg=
|
||||
github.com/fergusstrange/embedded-postgres v1.10.0/go.mod h1:a008U8/Rws5FtIOTGYDYa7beVWsT3qVKyqExqYYjL+c=
|
||||
github.com/fiatjaf/go-lnurl v1.11.2 h1:XyZS6Uuu/2ZbhkZjOm3W+FaFvRzRRTFel3aMoO6eDUE=
|
||||
github.com/fiatjaf/go-lnurl v1.11.2/go.mod h1:9PAgeVpZ5u6olV/dfkoyPSOJs3j4q0JIGLSbBbmMci8=
|
||||
github.com/fiatjaf/go-lnurl v1.11.3-0.20220819192234-5c5819dd0aa7 h1:0m0ph1FcZY7p89OpaXOUs8N44GhP7gE/98l+eWCNSkQ=
|
||||
github.com/fiatjaf/go-lnurl v1.11.3-0.20220819192234-5c5819dd0aa7/go.mod h1:KJfs14iAY3gCgt/3T6fxfBvPhU67OfIp7PSrBg/v/R8=
|
||||
github.com/fiatjaf/ln-decodepay v1.1.0 h1:HigjqNH+ApiO6gm7RV23jXNFuvwq+zgsWl4BJAfPWwE=
|
||||
@@ -265,6 +264,7 @@ github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVB
|
||||
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
|
||||
github.com/frankban/quicktest v1.2.2/go.mod h1:Qh/WofXFeiAFII1aEBu529AtJo6Zg2VHscnEsbBnJ20=
|
||||
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
|
||||
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
@@ -366,6 +366,7 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
|
||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
@@ -497,6 +498,8 @@ github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/
|
||||
github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI=
|
||||
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/joefitzgerald/rainbow-reporter v0.1.0/go.mod h1:481CNgqmVHQZzdIbN52CupLJyoVwB10FQ/IQlF1pdL8=
|
||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
|
||||
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
|
||||
@@ -573,6 +576,7 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
@@ -659,6 +663,7 @@ github.com/mattn/go-sqlite3 v1.14.5 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KK
|
||||
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.3/go.mod h1:1ftk08SazyElaaNvmqAfZWGwJzshjCfBXDLoQtPAMNk=
|
||||
github.com/mholt/archiver/v3 v3.5.0 h1:nE8gZIrw66cu4osS/U7UW7YDuGMHssxKutU8IfWxwWE=
|
||||
github.com/mholt/archiver/v3 v3.5.0/go.mod h1:qqTTPUK/HZPFgFQ/TJ3BzvTpF/dPtFVJXdQbCmeMxwc=
|
||||
github.com/miekg/dns v0.0.0-20171125082028-79bfde677fa8/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
@@ -710,6 +715,7 @@ github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:v
|
||||
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
||||
@@ -720,6 +726,7 @@ github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ=
|
||||
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
|
||||
@@ -800,13 +807,17 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
|
||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
|
||||
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
|
||||
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
|
||||
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/sclevine/spec v1.2.0/go.mod h1:W4J29eT/Kzv7/b9IWLB055Z+qvVC9vt0Arko24q7p+U=
|
||||
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
@@ -856,8 +867,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
|
||||
@@ -1113,9 +1124,9 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde h1:ejfdSekXMDxDLbRrJMwUk6KnSLZ2McaUCVcIKM+N6jc=
|
||||
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -1137,6 +1148,7 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -1253,6 +1265,7 @@ golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapK
|
||||
golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200301222351-066e0c02454c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
|
||||
golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
|
||||
golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
|
||||
@@ -1394,8 +1407,6 @@ gopkg.in/httprequest.v1 v1.1.1/go.mod h1:/CkavNL+g3qLOrpFHVrEx4NKepeqR4XTZWNj4sG
|
||||
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
|
||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/lightningtipbot/telebot.v3 v3.0.0-20220326213923-f323bb71ac8e h1:x58PfjVq6dbYSzM4URM9QfKDKVru1CpngxCM5pGqwbk=
|
||||
gopkg.in/lightningtipbot/telebot.v3 v3.0.0-20220326213923-f323bb71ac8e/go.mod h1:kIC/Dlp2OjWhVrOkZDN4iEoCaqoac5w1UjpKY6Ftf+U=
|
||||
gopkg.in/lightningtipbot/telebot.v3 v3.0.0-20220828121412-0dea11ecc6dd h1:LI1Q9RRmTKusLTpLGAHFUVT+wgzc0GHFKd3+34fARE8=
|
||||
gopkg.in/lightningtipbot/telebot.v3 v3.0.0-20220828121412-0dea11ecc6dd/go.mod h1:BefN0q4hcqXE1jXo4mTXZ9+29zl7IGsoSFXEQF455Oc=
|
||||
gopkg.in/macaroon-bakery.v2 v2.0.1/go.mod h1:B4/T17l+ZWGwxFSZQmlBwp25x+og7OkhETfr3S9MbIA=
|
||||
@@ -1422,8 +1433,8 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
|
||||
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
|
||||
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
||||
|
||||
+4
-3
@@ -18,9 +18,10 @@ var Configuration = struct {
|
||||
}{}
|
||||
|
||||
type GenerateConfiguration struct {
|
||||
DalleKey string `yaml:"dalle_key"`
|
||||
DallePrice int64 `yaml:"dalle_price"`
|
||||
Worker int `yaml:"worker"`
|
||||
OpenAiBearerToken string `yaml:"open_ai_bearer_token"`
|
||||
DalleKey string `yaml:"dalle_key"`
|
||||
DallePrice int64 `yaml:"dalle_price"`
|
||||
Worker int `yaml:"worker"`
|
||||
}
|
||||
|
||||
type SocksConfiguration struct {
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package gpt
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/LightningTipBot/LightningTipBot/internal"
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Message struct {
|
||||
ID string `json:"id"`
|
||||
Role string `json:"role"`
|
||||
User interface{} `json:"user"`
|
||||
CreateTime interface{} `json:"create_time"`
|
||||
UpdateTime interface{} `json:"update_time"`
|
||||
Content struct {
|
||||
ContentType string `json:"content_type"`
|
||||
Parts []string `json:"parts"`
|
||||
} `json:"content"`
|
||||
EndTurn interface{} `json:"end_turn"`
|
||||
Weight float64 `json:"weight"`
|
||||
Metadata struct {
|
||||
} `json:"metadata"`
|
||||
Recipient string `json:"recipient"`
|
||||
} `json:"message"`
|
||||
ConversationID string `json:"conversation_id"`
|
||||
Error interface{} `json:"error"`
|
||||
}
|
||||
type Request struct {
|
||||
Action string `json:"action"`
|
||||
ConversationId string `json:"conversation_id,omitempty"`
|
||||
Messages []Messages `json:"messages"`
|
||||
ParentMessageID string `json:"parent_message_id"`
|
||||
Model string `json:"model"`
|
||||
}
|
||||
type Content struct {
|
||||
ContentType string `json:"content_type"`
|
||||
Parts []string `json:"parts"`
|
||||
}
|
||||
type Messages struct {
|
||||
ID string `json:"id"`
|
||||
Role string `json:"role"`
|
||||
Content Content `json:"content"`
|
||||
}
|
||||
|
||||
var dataPrefix = []byte("data: ")
|
||||
var doneSequence = []byte("[DONE]")
|
||||
|
||||
func GetRawCompletion(ctx intercept.Context, rr Request, cb func(s string)) (*Response, error) {
|
||||
rawClient := http.Client{}
|
||||
r, err := json.Marshal(rr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx.Context, "POST", "https://chat.openai.com/backend-api/conversation", bytes.NewBuffer(r))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", internal.Configuration.Generate.OpenAiBearerToken))
|
||||
req.Header.Set("accept", "text/event-stream")
|
||||
req.Header.Set("authority", "chat.openai.com")
|
||||
req.Header.Set("accept-language", "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7")
|
||||
req.Header.Set("Content-type", "application/json")
|
||||
req.Header.Set("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36")
|
||||
|
||||
resp, err := rawClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reader := bufio.NewReader(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
output := new(Response)
|
||||
for {
|
||||
line, err := reader.ReadBytes('\n')
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// make sure there isn't any extra whitespace before or after
|
||||
line = bytes.TrimSpace(line)
|
||||
// the completion API only returns data events
|
||||
if !bytes.HasPrefix(line, dataPrefix) {
|
||||
continue
|
||||
}
|
||||
line = bytes.TrimPrefix(line, dataPrefix)
|
||||
|
||||
// the stream is completed when terminated by [DONE]
|
||||
if bytes.HasPrefix(line, doneSequence) {
|
||||
break
|
||||
}
|
||||
if err := json.Unmarshal(line, output); err != nil {
|
||||
return nil, fmt.Errorf("invalid json stream data: %v", err)
|
||||
}
|
||||
if len(output.Message.Content.Parts) > 0 {
|
||||
cb(output.Message.Content.Parts[len(output.Message.Content.Parts)-1])
|
||||
}
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
@@ -54,6 +54,9 @@ func GetClient(clientType ClientType) (*http.Client, error) {
|
||||
if cfg == nil {
|
||||
return &client, nil
|
||||
}
|
||||
if cfg.Host == "" {
|
||||
return &client, nil
|
||||
}
|
||||
proxyURL, _ := url.Parse(cfg.Host)
|
||||
specialTransport := &http.Transport{}
|
||||
specialTransport.Proxy = http.ProxyURL(proxyURL)
|
||||
|
||||
@@ -5,72 +5,127 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var tickerMap cmap.ConcurrentMap
|
||||
var functionMap cmap.ConcurrentMap
|
||||
|
||||
func init() {
|
||||
tickerMap = cmap.New()
|
||||
functionMap = cmap.New()
|
||||
}
|
||||
|
||||
var defaultTickerCoolDown = time.Second * 10
|
||||
var DefaultTickerDuration = time.Second * 10
|
||||
|
||||
// ResettableFunctionTicker will reset the user state as soon as tick is delivered.
|
||||
type ResettableFunctionTicker struct {
|
||||
// ResettableFunction will reset the user state as soon as tick is delivered.
|
||||
type ResettableFunction struct {
|
||||
Ticker *time.Ticker
|
||||
Timer *time.Timer
|
||||
ResetChan chan struct{} // channel used to reset the ticker
|
||||
StopChan chan struct{} // channel used to reset the ticker
|
||||
duration time.Duration
|
||||
Started bool
|
||||
name string
|
||||
}
|
||||
type ResettableFunctionTickerOption func(*ResettableFunctionTicker)
|
||||
|
||||
type ResettableFunctionTickerOption func(*ResettableFunction)
|
||||
|
||||
func WithTicker(t *time.Ticker) ResettableFunctionTickerOption {
|
||||
return func(a *ResettableFunction) {
|
||||
a.Ticker = t
|
||||
}
|
||||
}
|
||||
func WithDuration(d time.Duration) ResettableFunctionTickerOption {
|
||||
return func(a *ResettableFunctionTicker) {
|
||||
return func(a *ResettableFunction) {
|
||||
a.duration = d
|
||||
}
|
||||
}
|
||||
func WithTimer(t *time.Timer) ResettableFunctionTickerOption {
|
||||
return func(a *ResettableFunction) {
|
||||
a.Timer = t
|
||||
}
|
||||
}
|
||||
func RemoveTicker(name string) {
|
||||
tickerMap.Remove(name)
|
||||
functionMap.Remove(name)
|
||||
}
|
||||
func GetTicker(name string, option ...ResettableFunctionTickerOption) *ResettableFunctionTicker {
|
||||
|
||||
if t, ok := tickerMap.Get(name); ok {
|
||||
return t.(*ResettableFunctionTicker)
|
||||
func Get(name string) (*ResettableFunction, bool) {
|
||||
if t, ok := functionMap.Get(name); ok {
|
||||
return t.(*ResettableFunction), ok
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
func GetFunction(name string, option ...ResettableFunctionTickerOption) *ResettableFunction {
|
||||
if t, ok := functionMap.Get(name); ok {
|
||||
return t.(*ResettableFunction)
|
||||
} else {
|
||||
t := NewResettableFunctionTicker(name, option...)
|
||||
tickerMap.Set(name, t)
|
||||
t := NewResettableFunction(name, option...)
|
||||
functionMap.Set(name, t)
|
||||
return t
|
||||
}
|
||||
}
|
||||
func NewResettableFunctionTicker(name string, option ...ResettableFunctionTickerOption) *ResettableFunctionTicker {
|
||||
t := &ResettableFunctionTicker{
|
||||
|
||||
func NewResettableFunction(name string, option ...ResettableFunctionTickerOption) *ResettableFunction {
|
||||
t := &ResettableFunction{
|
||||
ResetChan: make(chan struct{}, 1),
|
||||
StopChan: make(chan struct{}, 1),
|
||||
name: name,
|
||||
}
|
||||
if t.duration == 0 {
|
||||
t.duration = DefaultTickerDuration
|
||||
}
|
||||
|
||||
for _, opt := range option {
|
||||
opt(t)
|
||||
}
|
||||
if t.duration == 0 {
|
||||
t.duration = defaultTickerCoolDown
|
||||
}
|
||||
t.Ticker = time.NewTicker(t.duration)
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *ResettableFunctionTicker) Do(f func()) {
|
||||
// Do will listen for timers and invoke functionCallback on tick.
|
||||
func (t *ResettableFunction) Do(functionCallback func()) {
|
||||
t.Started = true
|
||||
tickerMap.Set(t.name, t)
|
||||
// persist function
|
||||
functionMap.Set(t.name, t)
|
||||
go func() {
|
||||
for {
|
||||
if t.Timer != nil {
|
||||
// timer is set. checking event
|
||||
select {
|
||||
case <-t.Timer.C:
|
||||
functionCallback()
|
||||
return
|
||||
default:
|
||||
}
|
||||
}
|
||||
if t.Ticker != nil {
|
||||
// ticker is set. checking event
|
||||
select {
|
||||
case <-t.Ticker.C:
|
||||
// ticker delivered signal. do function functionCallback
|
||||
functionCallback()
|
||||
return
|
||||
default:
|
||||
}
|
||||
}
|
||||
// check stop and reset channels
|
||||
select {
|
||||
case <-t.Ticker.C:
|
||||
// ticker delivered signal. do function f
|
||||
f()
|
||||
case <-t.StopChan:
|
||||
if t.Timer != nil {
|
||||
t.Timer.Stop()
|
||||
}
|
||||
if t.Ticker != nil {
|
||||
t.Ticker.Stop()
|
||||
}
|
||||
return
|
||||
case <-t.ResetChan:
|
||||
// reset signal received. creating new ticker.
|
||||
t.Ticker = time.NewTicker(t.duration)
|
||||
if t.Ticker != nil {
|
||||
t.Ticker.Reset(t.duration)
|
||||
}
|
||||
if t.Timer != nil {
|
||||
t.Timer.Reset(t.duration)
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -5,13 +5,14 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// todo -- use function.go instead!
|
||||
// var retryMap cmap.ConcurrentMap
|
||||
|
||||
// func init() {
|
||||
// retryMap = cmap.New()
|
||||
// }
|
||||
|
||||
// ResettableFunctionTicker will reset the user state as soon as tick is delivered.
|
||||
// ResettableFunction will reset the user state as soon as tick is delivered.
|
||||
type FunctionRetry struct {
|
||||
Ticker *time.Ticker
|
||||
duration time.Duration
|
||||
@@ -35,14 +36,14 @@ func NewRetryTicker(ctx context.Context, name string, option ...FunctionRetryOpt
|
||||
opt(t)
|
||||
}
|
||||
if t.duration == 0 {
|
||||
t.duration = defaultTickerCoolDown
|
||||
t.duration = DefaultTickerDuration
|
||||
}
|
||||
t.Ticker = time.NewTicker(t.duration)
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *FunctionRetry) Do(f func(), cancel_f func(), deadline_f func()) {
|
||||
tickerMap.Set(t.name, t)
|
||||
functionMap.Set(t.name, t)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
|
||||
@@ -2,6 +2,7 @@ package storage
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/buntdb"
|
||||
@@ -56,6 +57,7 @@ func (db *DB) Get(object Storable) error {
|
||||
}
|
||||
err = json.Unmarshal([]byte(val), object)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -135,6 +135,7 @@ func (bot *TipBot) Start() {
|
||||
// start the telegram bot
|
||||
go bot.Telegram.Start()
|
||||
|
||||
go bot.restartPersistedTickets()
|
||||
// gracefully shutdown
|
||||
exit := make(chan os.Signal, 1) // we need to reserve to buffer size 1, so the notifier are not blocked
|
||||
// we need to catch SIGTERM and SIGSTOP
|
||||
|
||||
@@ -19,7 +19,7 @@ const (
|
||||
// MainMenuCommandHelp = "📖 Help"
|
||||
// MainMenuCommandSend = "⤴️ Send"
|
||||
// SendMenuCommandEnter = "👤 Enter"
|
||||
MainMenuCommandWebApp = "⤵️"
|
||||
MainMenuCommandWebApp = "🗳️ App"
|
||||
MainMenuCommandBalance = "Balance"
|
||||
MainMenuCommandInvoice = "⚡️ Invoice"
|
||||
MainMenuCommandHelp = "📖 Help"
|
||||
@@ -44,7 +44,8 @@ func init() {
|
||||
btnBalanceMainMenu = mainMenu.Text(MainMenuCommandBalance)
|
||||
mainMenu.Reply(
|
||||
mainMenu.Row(btnBalanceMainMenu),
|
||||
mainMenu.Row(btnInvoiceMainMenu, btnWebAppMainMenu, btnSendMainMenu, btnHelpMainMenu),
|
||||
// mainMenu.Row(btnInvoiceMainMenu, btnWebAppMainMenu, btnSendMainMenu, btnHelpMainMenu), // TODO: fix btnSendMainMenu
|
||||
mainMenu.Row(btnInvoiceMainMenu, btnWebAppMainMenu, btnHelpMainMenu),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -106,7 +107,8 @@ func (bot *TipBot) mainMenuBalanceButtonUpdate(to int64) {
|
||||
bot.appendWebAppLinkToButton(&btnWebAppMainMenu, user)
|
||||
mainMenu.Reply(
|
||||
mainMenu.Row(btnBalanceMainMenu),
|
||||
mainMenu.Row(btnInvoiceMainMenu, btnWebAppMainMenu, btnSendMainMenu, btnHelpMainMenu),
|
||||
// mainMenu.Row(btnInvoiceMainMenu, btnWebAppMainMenu, btnSendMainMenu, btnHelpMainMenu), // TODO: fix btnSendMainMenu
|
||||
mainMenu.Row(btnInvoiceMainMenu, btnWebAppMainMenu, btnHelpMainMenu),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ type Databases struct {
|
||||
}
|
||||
|
||||
const (
|
||||
JoinTicketIndex = "join-ticket:*"
|
||||
MessageOrderedByReplyToFrom = "message.reply_to_message.from.id"
|
||||
TipTooltipKeyPattern = "tip-tool-tip:*"
|
||||
)
|
||||
@@ -47,6 +48,10 @@ func createBunt(file string) *storage.DB {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = bunt.CreateIndex("join-ticket", JoinTicketIndex, buntdb.IndexString)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return bunt
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/runtime"
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
|
||||
tb "gopkg.in/lightningtipbot/telebot.v3"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (bot *TipBot) fileHandler(ctx intercept.Context) (intercept.Context, error) {
|
||||
@@ -16,7 +17,7 @@ func (bot *TipBot) fileHandler(ctx intercept.Context) (intercept.Context, error)
|
||||
if c := stateCallbackMessage[user.StateKey]; c != nil {
|
||||
// found ctx for this state
|
||||
// now looking for user state reset ticker
|
||||
ticker := runtime.GetTicker(user.ID)
|
||||
ticker := runtime.GetFunction(user.ID, runtime.WithTicker(time.NewTicker(runtime.DefaultTickerDuration)))
|
||||
if !ticker.Started {
|
||||
ticker.Do(func() {
|
||||
ResetUserState(user, bot)
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/gpt"
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/lightningtipbot/telebot.v3"
|
||||
)
|
||||
|
||||
func (bot *TipBot) gptHandler(ctx intercept.Context) (intercept.Context, error) {
|
||||
question := GetMemoFromCommand(ctx.Text(), 1)
|
||||
req := gpt.Request{
|
||||
Action: "next",
|
||||
Model: "text-davinci-002-render",
|
||||
Messages: []gpt.Messages{{
|
||||
ID: uuid.NewV4().String(),
|
||||
Role: "user",
|
||||
Content: gpt.Content{
|
||||
ContentType: "text",
|
||||
Parts: []string{question},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
conversationIdCacheKey := fmt.Sprintf("conversation_%d", ctx.Chat().ID)
|
||||
parentIdCacheKey := fmt.Sprintf("conversation_parent_%d", ctx.Chat().ID)
|
||||
conversationId, _ := bot.Cache.Get(conversationIdCacheKey)
|
||||
|
||||
if parentId, _ := bot.Cache.Get(parentIdCacheKey); parentId != nil {
|
||||
req.ParentMessageID = parentId.(string)
|
||||
}
|
||||
if conversationId != nil {
|
||||
req.ConversationId = conversationId.(string)
|
||||
}
|
||||
cbc := 0
|
||||
var msg *telebot.Message
|
||||
completion, err := gpt.GetRawCompletion(ctx, req, func(s string) {
|
||||
cbc++
|
||||
if ctx.Chat().Type == telebot.ChatPrivate {
|
||||
if cbc == 20 {
|
||||
msg = bot.trySendMessageEditable(ctx.Sender(), s)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if cbc == 20 {
|
||||
msg = bot.tryReplyMessage(ctx.Message(), s)
|
||||
return
|
||||
}
|
||||
}
|
||||
if cbc%20 == 0 {
|
||||
bot.tryEditMessage(msg, s)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
bot.tryEditMessage(ctx.Message(), fmt.Sprintf(Translate(ctx, "errorReasonMessage"), "Could not create completion."))
|
||||
return ctx, err
|
||||
}
|
||||
answer := completion.Message.Content.Parts[len(completion.Message.Content.Parts)-1]
|
||||
bot.tryEditMessage(msg, answer)
|
||||
err = bot.Cache.Set(conversationIdCacheKey, completion.ConversationID, nil)
|
||||
if err != nil {
|
||||
log.Errorf("[/gpt] error setting conversation id %s: %v", conversationIdCacheKey, err)
|
||||
}
|
||||
err = bot.Cache.Set(parentIdCacheKey, completion.Message.ID, nil)
|
||||
if err != nil {
|
||||
log.Errorf("[/gpt] error setting parent message id %s: %v", parentIdCacheKey, err)
|
||||
}
|
||||
log.Infof("[/gpt] \"%s\" => \"%s\"", question, answer)
|
||||
return ctx, nil
|
||||
}
|
||||
+155
-22
@@ -5,7 +5,9 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
|
||||
|
||||
@@ -22,6 +24,30 @@ import (
|
||||
tb "gopkg.in/lightningtipbot/telebot.v3"
|
||||
)
|
||||
|
||||
type JoinTicket struct {
|
||||
Sender *tb.User `json:"sender"`
|
||||
Message *tb.Message `json:"message"`
|
||||
CreatedTimestamp time.Time `json:"created_timestamp"`
|
||||
Ticket *Ticket `json:"ticket"`
|
||||
}
|
||||
|
||||
func (jt JoinTicket) Key() string {
|
||||
return fmt.Sprintf("join-ticket:%d_%d", jt.Message.Chat.ID, jt.Sender.ID)
|
||||
}
|
||||
|
||||
func (jt JoinTicket) Type() EventType {
|
||||
return EventTypeTicketInvoice
|
||||
}
|
||||
|
||||
func (bot *TipBot) loadGroup(groupName string) (*Group, error) {
|
||||
group := &Group{}
|
||||
tx := bot.DB.Groups.Where("name = ? COLLATE NOCASE", groupName).First(group)
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
return group, nil
|
||||
}
|
||||
|
||||
type Ticket struct {
|
||||
Price int64 `json:"price"`
|
||||
Memo string `json:"memo"`
|
||||
@@ -83,8 +109,9 @@ var (
|
||||
btnPayTicket = paymentConfirmationMenu.Data("✅ Pay", "pay_ticket")
|
||||
)
|
||||
|
||||
var (
|
||||
groupInvoiceMemo = "🎟 Ticket for group %s"
|
||||
const (
|
||||
groupInvoiceMemo = "🎟 Ticket for group %s"
|
||||
groupInvoiceCommissionMemo = "🎟 Commission for group %s"
|
||||
)
|
||||
|
||||
// groupHandler is called if the /group <cmd> command is invoked. It then decides with other
|
||||
@@ -92,15 +119,18 @@ var (
|
||||
func (bot TipBot) groupHandler(ctx intercept.Context) (intercept.Context, error) {
|
||||
m := ctx.Message()
|
||||
splits := strings.Split(m.Text, " ")
|
||||
user := LoadUser(ctx)
|
||||
// user := LoadUser(ctx)
|
||||
if len(splits) == 1 {
|
||||
// command: /group
|
||||
if ctx.Message().Private() {
|
||||
// /group help message
|
||||
bot.trySendMessage(ctx.Message().Chat, fmt.Sprintf(Translate(ctx, "groupHelpMessage"), GetUserStr(bot.Telegram.Me), GetUserStr(bot.Telegram.Me)))
|
||||
} else {
|
||||
if bot.isOwner(ctx.Message().Chat, user.Telegram) {
|
||||
bot.trySendMessage(ctx.Message().Chat, fmt.Sprintf(Translate(ctx, "commandPrivateMessage"), GetUserStr(bot.Telegram.Me)))
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// if bot.isOwner(ctx.Message().Chat, user.Telegram) {
|
||||
// bot.trySendMessage(ctx.Message().Chat, fmt.Sprintf(Translate(ctx, "commandPrivateMessage"), GetUserStr(bot.Telegram.Me)))
|
||||
// }
|
||||
// }
|
||||
return ctx, nil
|
||||
} else if len(splits) > 1 {
|
||||
if splits[1] == "join" {
|
||||
@@ -109,6 +139,9 @@ func (bot TipBot) groupHandler(ctx intercept.Context) (intercept.Context, error)
|
||||
if splits[1] == "add" {
|
||||
return bot.addGroupHandler(ctx)
|
||||
}
|
||||
if splits[1] == "ticket" {
|
||||
return bot.handleJoinTicketPayWall(ctx)
|
||||
}
|
||||
if splits[1] == "remove" {
|
||||
// todo -- implement this
|
||||
// return bot.addGroupHandler(ctx, m)
|
||||
@@ -213,6 +246,11 @@ func (bot TipBot) groupRequestJoinHandler(ctx intercept.Context) (intercept.Cont
|
||||
// groupSendPayButtonHandler is invoked if the user has enough balance so a message with a
|
||||
// pay button is sent to the user.
|
||||
func (bot *TipBot) groupSendPayButtonHandler(ctx intercept.Context, ticket TicketEvent) (intercept.Context, error) {
|
||||
confirmText, confirmationMenu := bot.getSendPayButton(ctx, ticket)
|
||||
bot.trySendMessageEditable(ctx.Message().Chat, confirmText, confirmationMenu)
|
||||
return ctx, nil
|
||||
}
|
||||
func (bot *TipBot) getSendPayButton(ctx intercept.Context, ticket TicketEvent) (string, *tb.ReplyMarkup) {
|
||||
// object that holds all information about the send payment
|
||||
// // // create inline buttons
|
||||
btnPayTicket := ticketPayConfirmationMenu.Data(Translate(ctx, "payButtonMessage"), "pay_ticket", ticket.Base.ID)
|
||||
@@ -221,11 +259,10 @@ func (bot *TipBot) groupSendPayButtonHandler(ctx intercept.Context, ticket Ticke
|
||||
btnPayTicket),
|
||||
)
|
||||
confirmText := fmt.Sprintf(Translate(ctx, "confirmPayInvoiceMessage"), ticket.Group.Ticket.Price)
|
||||
if len(ticket.Group.Ticket.Memo) > 0 {
|
||||
confirmText = confirmText + fmt.Sprintf(Translate(ctx, "confirmPayAppendMemo"), str.MarkdownEscape(ticket.Group.Ticket.Memo))
|
||||
}
|
||||
bot.trySendMessageEditable(ctx.Message().Chat, confirmText, ticketPayConfirmationMenu)
|
||||
return ctx, nil
|
||||
// if len(ticket.Group.Ticket.Memo) > 0 {
|
||||
// confirmText = confirmText + fmt.Sprintf(Translate(ctx, "confirmPayAppendMemo"), str.MarkdownEscape(ticket.Group.Ticket.Memo))
|
||||
// }
|
||||
return confirmText, ticketPayConfirmationMenu
|
||||
}
|
||||
|
||||
// groupConfirmPayButtonHandler is invoked if th user clicks the pay button.
|
||||
@@ -266,13 +303,17 @@ func (bot *TipBot) groupConfirmPayButtonHandler(ctx intercept.Context) (intercep
|
||||
if err != nil {
|
||||
errmsg := fmt.Sprintf("[/pay] Could not pay invoice of %s: %s", GetUserStr(user.Telegram), err)
|
||||
err = fmt.Errorf(i18n.Translate(ticketEvent.LanguageCode, "invoiceUndefinedErrorMessage"))
|
||||
bot.tryEditMessage(c, fmt.Sprintf(i18n.Translate(ticketEvent.LanguageCode, "invoicePaymentFailedMessage"), err.Error()), &tb.ReplyMarkup{})
|
||||
if ticketEvent.Callback != InvoiceCallbackPayJoinTicket {
|
||||
bot.tryEditMessage(c, fmt.Sprintf(i18n.Translate(ticketEvent.LanguageCode, "invoicePaymentFailedMessage"), err.Error()), &tb.ReplyMarkup{})
|
||||
}
|
||||
log.Errorln(errmsg)
|
||||
return ctx, err
|
||||
}
|
||||
// if this was a join-ticket, we want to delete the invoice message
|
||||
|
||||
// update the message and remove the button
|
||||
bot.tryEditMessage(c, i18n.Translate(ticketEvent.LanguageCode, "invoicePaidMessage"), &tb.ReplyMarkup{})
|
||||
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
@@ -328,19 +369,12 @@ func (bot *TipBot) groupGetInviteLinkHandler(event Event) {
|
||||
|
||||
// take a commission
|
||||
ticketSat := ticketEvent.Group.Ticket.Price
|
||||
if ticketEvent.Group.Ticket.Price > 20 {
|
||||
if commissionSat := getTicketCommission(ticketEvent.Group.Ticket); commissionSat > 0 {
|
||||
me, err := GetUser(bot.Telegram.Me, *bot)
|
||||
if err != nil {
|
||||
log.Errorf("[groupGetInviteLinkHandler] Could not get bot user from DB: %s", err.Error())
|
||||
return
|
||||
}
|
||||
// 2% cut + 100 sat base fee
|
||||
commissionSat := ticketEvent.Group.Ticket.Price*ticketEvent.Group.Ticket.Cut/100 + ticketEvent.Group.Ticket.BaseFee
|
||||
if ticketEvent.Group.Ticket.Price <= 1000 {
|
||||
// if < 1000, then 10% cut + 10 sat base fee
|
||||
commissionSat = ticketEvent.Group.Ticket.Price*ticketEvent.Group.Ticket.CutCheap/100 + ticketEvent.Group.Ticket.BaseFeeCheap
|
||||
}
|
||||
|
||||
ticketSat = ticketEvent.Group.Ticket.Price - commissionSat
|
||||
invoice, err := me.Wallet.Invoice(
|
||||
lnbits.InvoiceParams{
|
||||
@@ -372,6 +406,105 @@ func (bot *TipBot) groupGetInviteLinkHandler(event Event) {
|
||||
}
|
||||
}
|
||||
|
||||
func (bot TipBot) handleJoinTicketPayWall(ctx intercept.Context) (intercept.Context, error) {
|
||||
var err error
|
||||
var cmd string
|
||||
if cmd, err = getArgumentFromCommand(ctx.Message().Text, 2); err == nil {
|
||||
switch strings.TrimSpace(strings.ToLower(cmd)) {
|
||||
case "del":
|
||||
fallthrough
|
||||
case "delete":
|
||||
fallthrough
|
||||
case "remove":
|
||||
return bot.removeJoinTicketPayWallHandler(ctx)
|
||||
default:
|
||||
return bot.addJoinTicketPayWallHandler(ctx)
|
||||
}
|
||||
}
|
||||
return ctx, err
|
||||
}
|
||||
func (bot TipBot) removeJoinTicketPayWallHandler(ctx intercept.Context) (intercept.Context, error) {
|
||||
groupName := strconv.FormatInt(ctx.Chat().ID, 10)
|
||||
tx := bot.DB.Groups.Where("id = ? COLLATE NOCASE", groupName).Delete(&Group{})
|
||||
if tx.Error != nil {
|
||||
return ctx, tx.Error
|
||||
}
|
||||
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
// addJoinTicketPayWallHandler is invoked if the user calls the "/group ticket" command
|
||||
func (bot TipBot) addJoinTicketPayWallHandler(ctx intercept.Context) (intercept.Context, error) {
|
||||
m := ctx.Message()
|
||||
if m.Chat.Type == tb.ChatPrivate {
|
||||
bot.trySendMessage(m.Chat, Translate(ctx, "groupAddGroupHelpMessage"))
|
||||
return ctx, fmt.Errorf("not in group")
|
||||
}
|
||||
// parse command "/group ticket <grou_name> [<amount>]"
|
||||
splits := strings.Split(m.Text, " ")
|
||||
if len(splits) < 3 || len(m.Text) > 100 {
|
||||
bot.trySendMessage(m.Chat, Translate(ctx, "groupAddGroupHelpMessage"))
|
||||
return ctx, nil
|
||||
}
|
||||
groupName := strconv.FormatInt(ctx.Chat().ID, 10)
|
||||
|
||||
user := LoadUser(ctx)
|
||||
// check if the user is the owner of the group
|
||||
if !bot.isOwner(m.Chat, user.Telegram) {
|
||||
return ctx, fmt.Errorf("not owner")
|
||||
}
|
||||
|
||||
if !bot.isAdminAndCanInviteUsers(m.Chat, bot.Telegram.Me) {
|
||||
bot.trySendMessage(m.Chat, Translate(ctx, "groupBotIsNotAdminMessage"))
|
||||
return ctx, fmt.Errorf("bot is not admin")
|
||||
}
|
||||
|
||||
// check if the group with this name is already in db
|
||||
// only if a group with this name is owned by this user, it can be overwritten
|
||||
group := &Group{}
|
||||
tx := bot.DB.Groups.Where("id = ? COLLATE NOCASE", groupName).First(group)
|
||||
if tx.Error == nil {
|
||||
// if it is already added, check if this user is the admin
|
||||
if user.Telegram.ID != group.Owner.ID || group.ID != m.Chat.ID {
|
||||
bot.trySendMessage(m.Chat, Translate(ctx, "groupNameExists"))
|
||||
return ctx, fmt.Errorf("not owner")
|
||||
}
|
||||
}
|
||||
|
||||
amount := int64(0) // default amount is zero
|
||||
if amount_str, err := getArgumentFromCommand(m.Text, 2); err == nil {
|
||||
amount, err = GetAmount(amount_str)
|
||||
if err != nil {
|
||||
bot.trySendMessage(m.Sender, Translate(ctx, "lnurlInvalidAmountMessage"))
|
||||
return ctx, err
|
||||
}
|
||||
}
|
||||
|
||||
ticket := &Ticket{
|
||||
Price: amount,
|
||||
Memo: "Ticket for group " + groupName,
|
||||
Creator: user,
|
||||
Cut: 2,
|
||||
BaseFee: 100,
|
||||
CutCheap: 10,
|
||||
BaseFeeCheap: 10,
|
||||
}
|
||||
|
||||
group = &Group{
|
||||
Name: groupName,
|
||||
Title: m.Chat.Title,
|
||||
ID: m.Chat.ID,
|
||||
Owner: user.Telegram,
|
||||
Ticket: ticket,
|
||||
}
|
||||
|
||||
bot.DB.Groups.Save(group)
|
||||
log.Infof("[group] Ticket of %d sat added to group %s.", group.Ticket.Price, group.Name)
|
||||
bot.trySendMessage(m.Chat, Translate(ctx, "groupAddedMessagePublic"))
|
||||
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
// addGroupHandler is invoked if the user calls the "/group add" command
|
||||
func (bot TipBot) addGroupHandler(ctx intercept.Context) (intercept.Context, error) {
|
||||
m := ctx.Message()
|
||||
@@ -439,7 +572,7 @@ func (bot TipBot) addGroupHandler(ctx intercept.Context) (intercept.Context, err
|
||||
|
||||
bot.DB.Groups.Save(group)
|
||||
log.Infof("[group] Ticket of %d sat added to group %s.", group.Ticket.Price, group.Name)
|
||||
bot.trySendMessage(m.Chat, fmt.Sprintf(Translate(ctx, "groupAddedMessage"), str.MarkdownEscape(m.Chat.Title), group.Name, group.Ticket.Price, GetUserStrMd(bot.Telegram.Me), group.Name))
|
||||
bot.trySendMessage(m.Chat, fmt.Sprintf(Translate(ctx, "groupAddedMessagePrivate"), str.MarkdownEscape(m.Chat.Title), group.Name, group.Ticket.Price, GetUserStrMd(bot.Telegram.Me), group.Name))
|
||||
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
@@ -227,6 +227,22 @@ func (bot TipBot) getHandler() []InterceptionWrapper {
|
||||
bot.unlockInterceptor,
|
||||
}},
|
||||
},
|
||||
// {
|
||||
// Endpoints: []interface{}{"/gpt", "/chat"},
|
||||
// Handler: bot.gptHandler,
|
||||
// Interceptor: &Interceptor{
|
||||
|
||||
// Before: []intercept.Func{
|
||||
// bot.localizerInterceptor,
|
||||
// bot.logMessageInterceptor,
|
||||
// bot.requireUserInterceptor,
|
||||
// bot.lockInterceptor,
|
||||
// },
|
||||
// OnDefer: []intercept.Func{
|
||||
// bot.unlockInterceptor,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
{
|
||||
Endpoints: []interface{}{"/balance", &btnBalanceMainMenu},
|
||||
Handler: bot.balanceHandler,
|
||||
@@ -481,6 +497,22 @@ func (bot TipBot) getHandler() []InterceptionWrapper {
|
||||
},
|
||||
},
|
||||
},
|
||||
// group join
|
||||
{
|
||||
Endpoints: []interface{}{tb.OnUserJoined, tb.OnAddedToGroup},
|
||||
Handler: bot.handleTelegramNewMember,
|
||||
Interceptor: &Interceptor{
|
||||
Before: []intercept.Func{
|
||||
bot.localizerInterceptor,
|
||||
bot.logMessageInterceptor,
|
||||
bot.tryLoadUserInterceptor,
|
||||
bot.lockInterceptor,
|
||||
},
|
||||
OnDefer: []intercept.Func{
|
||||
bot.unlockInterceptor,
|
||||
},
|
||||
},
|
||||
},
|
||||
// group tickets
|
||||
{
|
||||
Endpoints: []interface{}{"/group"},
|
||||
|
||||
@@ -131,6 +131,10 @@ func (bot TipBot) loadUserInterceptor(ctx intercept.Context) (intercept.Context,
|
||||
}
|
||||
return ctx, nil
|
||||
}
|
||||
func (bot TipBot) tryLoadUserInterceptor(ctx intercept.Context) (intercept.Context, error) {
|
||||
ctx, _ = bot.requireUserInterceptor(ctx)
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
// loadReplyToInterceptor Loading the Telegram user with message intercept
|
||||
func (bot TipBot) loadReplyToInterceptor(ctx intercept.Context) (intercept.Context, error) {
|
||||
|
||||
@@ -41,6 +41,7 @@ func initInvoiceEventCallbacks(bot *TipBot) {
|
||||
InvoiceCallbackGroupTicket: EventHandler{Function: bot.groupGetInviteLinkHandler, Type: EventTypeInvoice},
|
||||
InvoiceCallbackSatdressProxy: EventHandler{Function: bot.satdressProxyRelayPaymentHandler, Type: EventTypeInvoice},
|
||||
InvoiceCallbackGenerateDalle: EventHandler{Function: bot.generateDalleImages, Type: EventTypeInvoice},
|
||||
InvoiceCallbackPayJoinTicket: EventHandler{Function: bot.stopJoinTicketTimer, Type: EventTypeInvoice},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +54,7 @@ const (
|
||||
InvoiceCallbackGroupTicket
|
||||
InvoiceCallbackSatdressProxy
|
||||
InvoiceCallbackGenerateDalle
|
||||
InvoiceCallbackPayJoinTicket
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -36,7 +36,7 @@ type LnurlPayState struct {
|
||||
}
|
||||
|
||||
// lnurlPayHandler is invoked when the first lnurl response was a lnurlpay response
|
||||
// at this point, the user hans't necessarily entered an amount yet
|
||||
// at this point, the user hasn't necessarily entered an amount yet
|
||||
func (bot *TipBot) lnurlPayHandler(ctx intercept.Context, payParams *LnurlPayState) (context.Context, error) {
|
||||
m := ctx.Message()
|
||||
user := LoadUser(ctx)
|
||||
@@ -201,27 +201,15 @@ func (bot *TipBot) lnurlPayHandlerSend(ctx intercept.Context) (intercept.Context
|
||||
return ctx, fmt.Errorf("error in LNURLPayValues: %s", error_reason)
|
||||
}
|
||||
|
||||
// todo: doesn't work with lnurls from lnbits??
|
||||
// check whether description hash matches with expected hash
|
||||
// decode invoice
|
||||
// bolt11, err := decodepay.Decodepay(response2.PR)
|
||||
// if err != nil {
|
||||
// bot.trySendMessage(ctx.Sender(), helpPayInvoiceUsage(ctx, Translate(ctx, "invalidInvoiceHelpMessage")))
|
||||
// errmsg := fmt.Sprintf("[/pay] Error: Could not decode invoice: %s", err.Error())
|
||||
// log.Errorln(errmsg)
|
||||
// return ctx, errors.New(errors.InvalidSyntaxError, err)
|
||||
// }
|
||||
// if bolt11.DescriptionHash != lnurlPayState.DescriptionHash {
|
||||
// log.Errorf("[lnurlPayHandlerSend] Error: description hash doesn't match")
|
||||
// bot.tryEditMessage(statusMsg, fmt.Sprintf(Translate(ctx, "errorReasonMessage"), "description hash doesn't match.\nExpected: `"+lnurlPayState.DescriptionHash+"` Received: `"+bolt11.DescriptionHash+"`"))
|
||||
// return ctx, fmt.Errorf("description hash doesn't match")
|
||||
// }
|
||||
|
||||
// all good
|
||||
lnurlPayState.LNURLPayValues = response2
|
||||
// add result to persistent struct
|
||||
runtime.IgnoreError(lnurlPayState.Set(lnurlPayState, bot.Bunt))
|
||||
bot.Telegram.Delete(statusMsg)
|
||||
|
||||
// store success action in context for printing after the payHandler
|
||||
ctx.Context = context.WithValue(ctx, "SuccessAction", lnurlPayState.LNURLPayValues.SuccessAction)
|
||||
|
||||
m.Text = fmt.Sprintf("/pay %s", response2.PR)
|
||||
return bot.payHandler(ctx)
|
||||
}
|
||||
|
||||
+31
-12
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/runtime"
|
||||
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/str"
|
||||
lnurl "github.com/fiatjaf/go-lnurl"
|
||||
decodepay "github.com/fiatjaf/ln-decodepay"
|
||||
log "github.com/sirupsen/logrus"
|
||||
tb "gopkg.in/lightningtipbot/telebot.v3"
|
||||
@@ -38,15 +39,16 @@ func helpPayInvoiceUsage(ctx context.Context, errormsg string) string {
|
||||
|
||||
type PayData struct {
|
||||
*storage.Base
|
||||
From *lnbits.User `json:"from"`
|
||||
Invoice string `json:"invoice"`
|
||||
Hash string `json:"hash"`
|
||||
Proof string `json:"proof"`
|
||||
Memo string `json:"memo"`
|
||||
Message string `json:"message"`
|
||||
Amount int64 `json:"amount"`
|
||||
LanguageCode string `json:"languagecode"`
|
||||
TelegramMessage *tb.Message `json:"telegrammessage"`
|
||||
From *lnbits.User `json:"from"`
|
||||
Invoice string `json:"invoice"`
|
||||
Hash string `json:"hash"`
|
||||
Proof string `json:"proof"`
|
||||
Memo string `json:"memo"`
|
||||
Message string `json:"message"`
|
||||
Amount int64 `json:"amount"`
|
||||
LanguageCode string `json:"languagecode"`
|
||||
SuccessAction *lnurl.SuccessAction `json:"successAction"`
|
||||
TelegramMessage *tb.Message `json:"telegrammessage"`
|
||||
}
|
||||
|
||||
// payHandler invoked on "/pay lnbc..." command
|
||||
@@ -132,6 +134,12 @@ func (bot *TipBot) payHandler(ctx intercept.Context) (intercept.Context, error)
|
||||
cancelButton),
|
||||
)
|
||||
payMessage := bot.trySendMessageEditable(ctx.Chat(), confirmText, paymentConfirmationMenu)
|
||||
// read successaction
|
||||
sa, ok := ctx.Value("SuccessAction").(*lnurl.SuccessAction)
|
||||
if !ok {
|
||||
sa = &lnurl.SuccessAction{}
|
||||
}
|
||||
|
||||
payData := &PayData{
|
||||
Base: storage.New(storage.ID(id)),
|
||||
From: user,
|
||||
@@ -140,6 +148,7 @@ func (bot *TipBot) payHandler(ctx intercept.Context) (intercept.Context, error)
|
||||
Memo: bolt11.Description,
|
||||
Message: confirmText,
|
||||
LanguageCode: ctx.Value("publicLanguageCode").(string),
|
||||
SuccessAction: sa,
|
||||
TelegramMessage: payMessage,
|
||||
}
|
||||
// add result to persistent struct
|
||||
@@ -183,8 +192,6 @@ func (bot *TipBot) confirmPayHandler(ctx intercept.Context) (intercept.Context,
|
||||
return ctx, errors.Create(errors.UserNoWalletError)
|
||||
}
|
||||
|
||||
invoiceString := payData.Invoice
|
||||
|
||||
// reset state immediately
|
||||
ResetUserState(user, bot)
|
||||
|
||||
@@ -203,7 +210,7 @@ func (bot *TipBot) confirmPayHandler(ctx intercept.Context) (intercept.Context,
|
||||
|
||||
log.Infof("[/pay] Attempting %s's invoice %s (%d sat)", userStr, payData.ID, payData.Amount)
|
||||
// pay invoice
|
||||
invoice, err := user.Wallet.Pay(lnbits.PaymentParams{Out: true, Bolt11: invoiceString}, bot.Client)
|
||||
invoice, err := user.Wallet.Pay(lnbits.PaymentParams{Out: true, Bolt11: payData.Invoice}, bot.Client)
|
||||
if err != nil {
|
||||
errmsg := fmt.Sprintf("[/pay] Could not pay invoice of %s: %s", userStr, err)
|
||||
err = fmt.Errorf(i18n.Translate(payData.LanguageCode, "invoiceUndefinedErrorMessage"))
|
||||
@@ -236,6 +243,18 @@ func (bot *TipBot) confirmPayHandler(ctx intercept.Context) (intercept.Context,
|
||||
bot.trySendMessage(ctx.Sender(), i18n.Translate(payData.LanguageCode, "invoicePaidMessage"))
|
||||
bot.tryEditMessage(ctx.Message(), fmt.Sprintf(i18n.Translate(payData.LanguageCode, "invoicePublicPaidMessage"), userStr), &tb.ReplyMarkup{})
|
||||
}
|
||||
|
||||
// display LNURL success action if present
|
||||
sa := payData.SuccessAction
|
||||
if sa.Tag == "message" && len(sa.Message) > 0 {
|
||||
bot.trySendMessage(ctx.Sender(), fmt.Sprintf("✉️: `%s`", sa.Message))
|
||||
} else if sa.Tag == "url" && len(sa.URL) > 0 {
|
||||
bot.trySendMessage(ctx.Sender(), fmt.Sprintf("🔗: %s", str.MarkdownEscape(sa.URL)), tb.NoPreview)
|
||||
if len(sa.Description) > 0 {
|
||||
bot.trySendMessage(ctx.Sender(), fmt.Sprintf("✉️: %s", sa.Description))
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("[⚡️ pay] User %s paid invoice %s (%d sat)", userStr, payData.ID, payData.Amount)
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
@@ -175,10 +175,6 @@ func (bot *TipBot) enterShopItemPriceHandler(ctx intercept.Context) (intercept.C
|
||||
}
|
||||
}
|
||||
|
||||
if amount > 2000 {
|
||||
bot.sendStatusMessageAndDelete(ctx, m.Sender, "ℹ️ During testing, price can be max 2000 sat.")
|
||||
amount = 2000
|
||||
}
|
||||
item.Price = amount
|
||||
shop.Items[item.ID] = item
|
||||
runtime.IgnoreError(shop.Set(shop, bot.ShopBunt))
|
||||
@@ -757,7 +753,7 @@ func (bot *TipBot) addItemFileHandler(ctx intercept.Context) (intercept.Context,
|
||||
// // start a ticker to check if the user has sent more files
|
||||
// if t, ok := fileStateResetTicker.Get(shop.ID); ok {
|
||||
// // state reset ticker found. resetting ticker.
|
||||
// t.(*runtime.ResettableFunctionTicker).ResetChan <- struct{}{}
|
||||
// t.(*runtime.ResettableFunction).ResetChan <- struct{}{}
|
||||
// } else {
|
||||
// // state reset ticker not found. creating new one.
|
||||
// ticker := runtime.NewResettableFunctionTicker(runtime.WithDuration(time.Second * 5))
|
||||
@@ -951,7 +947,6 @@ func (bot *TipBot) sendFileByID(ctx context.Context, to tb.Recipient, fileId str
|
||||
var ShopsText = ""
|
||||
var ShopsTextWelcome = "*You are browsing %s shop.*"
|
||||
var ShopsTextShopCount = "*Browse %d shops:*"
|
||||
var ShopsTextHelp = "⚠️ Shops are still in beta. Expect bugs."
|
||||
var ShopsNoShopsText = "*There are no shops here yet.*"
|
||||
|
||||
// shopsHandlerCallback is a warpper for shopsHandler for callbacks
|
||||
@@ -1061,7 +1056,6 @@ func (bot *TipBot) shopsHandler(ctx intercept.Context) (intercept.Context, error
|
||||
if len(shops.Shops) > 0 {
|
||||
ShopsText += fmt.Sprintf("%s\n", shopTitles)
|
||||
}
|
||||
ShopsText += fmt.Sprintf("\n%s", ShopsTextHelp)
|
||||
|
||||
// fmt.Sprintf(ShopsText, shopOwnerText, len(shops.Shops), shopTitles)
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ func (bot *TipBot) sendStatusMessageAndDelete(ctx intercept.Context, to tb.Recip
|
||||
id := fmt.Sprintf("shopview-delete-%d", user.Telegram.ID)
|
||||
statusMsg := bot.sendStatusMessage(ctx, to, what, options...)
|
||||
// kick off ticker to remove all messages
|
||||
ticker := runtime.GetTicker(id, runtime.WithDuration(5*time.Second))
|
||||
ticker := runtime.GetFunction(id, runtime.WithTicker(time.NewTicker(5*time.Second)), runtime.WithDuration(5*time.Second))
|
||||
if !ticker.Started {
|
||||
ticker.Do(func() {
|
||||
bot.shopViewDeleteAllStatusMsgs(ctx, user)
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/LightningTipBot/LightningTipBot/internal"
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/errors"
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/lnbits"
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/runtime"
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/storage"
|
||||
"github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/skip2/go-qrcode"
|
||||
"github.com/tidwall/buntdb"
|
||||
tb "gopkg.in/lightningtipbot/telebot.v3"
|
||||
)
|
||||
|
||||
var defaultTicketDuration = time.Minute * 15
|
||||
|
||||
// handleTelegramNewMember is invoked when users join groups.
|
||||
// handler will create a new invoice and send it to the group chat.
|
||||
// a ticket callback timer function is stored in the blunt db.
|
||||
func (bot *TipBot) handleTelegramNewMember(ctx intercept.Context) (intercept.Context, error) {
|
||||
id := strconv.FormatInt(ctx.Chat().ID, 10)
|
||||
group, err := bot.loadGroup(id)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
if !bot.isAdmin(ctx.Chat(), bot.Telegram.Me) {
|
||||
log.Traceln("[TICKET] I am not an admin of this group")
|
||||
return ctx, fmt.Errorf("no admin rights")
|
||||
}
|
||||
user := LoadUser(ctx)
|
||||
// if the user does not have an account we put his Telegram user here
|
||||
// because we will need it after the invoice callback has been triggered in stopJoinTicketTimer
|
||||
if user == nil {
|
||||
user = &lnbits.User{
|
||||
ID: "",
|
||||
Telegram: ctx.Message().Sender,
|
||||
}
|
||||
}
|
||||
|
||||
ownerUser, err := GetUser(group.Owner, *bot)
|
||||
if err != nil {
|
||||
log.Errorln("[TICKET] Error: no owner found")
|
||||
return ctx, err
|
||||
}
|
||||
ticket := JoinTicket{
|
||||
Sender: ctx.Sender(),
|
||||
Ticket: group.Ticket,
|
||||
}
|
||||
// group owner creates invoice
|
||||
invoice, err := ownerUser.Wallet.Invoice(
|
||||
lnbits.InvoiceParams{
|
||||
Out: false,
|
||||
Amount: ticket.Ticket.Price,
|
||||
Memo: ticket.Ticket.Memo,
|
||||
Webhook: internal.Configuration.Lnbits.WebhookServer},
|
||||
bot.Client)
|
||||
if err != nil {
|
||||
errmsg := fmt.Sprintf("[handleTelegramNewMember] Could not create an invoice: %s", err.Error())
|
||||
log.Errorln(errmsg)
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
// send the owner invoice to chat
|
||||
// TicketEvent is used for callback button (if user has balance)
|
||||
ticketEvent := TicketEvent{
|
||||
// invoice event is used for invoice callbacks (do not kick if invoice is paid)
|
||||
InvoiceEvent: &InvoiceEvent{
|
||||
Base: storage.New(storage.ID(fmt.Sprintf("invoice-event:%s", id))),
|
||||
Invoice: &Invoice{PaymentHash: invoice.PaymentHash,
|
||||
PaymentRequest: invoice.PaymentRequest,
|
||||
Amount: ticket.Ticket.Price,
|
||||
Memo: ticket.Ticket.Memo},
|
||||
Payer: user,
|
||||
Chat: ctx.Chat(),
|
||||
Callback: InvoiceCallbackPayJoinTicket,
|
||||
CallbackData: "",
|
||||
LanguageCode: ctx.Value("publicLanguageCode").(string),
|
||||
},
|
||||
Group: group,
|
||||
Base: storage.New(storage.ID(fmt.Sprintf("ticket-event:%s", id))),
|
||||
}
|
||||
captionText := fmt.Sprintf("⚠️ %s, this group requires you to pay *%d sat* to join. You have 15 minutes to pay or you will be kicked for one day.", GetUserStrMd(ctx.Message().Sender), ticket.Ticket.Price)
|
||||
|
||||
var balance int64 = 0
|
||||
if user.ID != "" {
|
||||
// if the user has an account
|
||||
// // if the user has enough balance, we send him a payment button
|
||||
balance, err = bot.GetUserBalance(user)
|
||||
if err != nil {
|
||||
errmsg := fmt.Sprintf("[/group] Error: Could not get user balance: %s", err.Error())
|
||||
log.Errorln(errmsg)
|
||||
bot.trySendMessage(ctx.Message().Sender, Translate(ctx, "errorTryLaterMessage"))
|
||||
return ctx, errors.New(errors.GetBalanceError, err)
|
||||
}
|
||||
} else {
|
||||
balance = 0
|
||||
}
|
||||
|
||||
var msg *tb.Message
|
||||
if balance >= group.Ticket.Price {
|
||||
_, menu := bot.getSendPayButton(ctx, ticketEvent)
|
||||
msg = bot.trySendMessageEditable(ctx.Chat(), captionText, menu)
|
||||
} else {
|
||||
// create qr code
|
||||
qr, err := qrcode.Encode(invoice.PaymentRequest, qrcode.Medium, 256)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
entryMessage := &tb.Photo{
|
||||
File: tb.File{FileReader: bytes.NewReader(qr)},
|
||||
Caption: captionText}
|
||||
entryMessage.Caption = fmt.Sprintf("%s\n\n`%s`", entryMessage.Caption, invoice.PaymentRequest)
|
||||
msg = bot.trySendMessageEditable(ctx.Chat(), entryMessage)
|
||||
}
|
||||
ticketEvent.Message = msg
|
||||
ticket.Message = msg
|
||||
ticket.CreatedTimestamp = time.Now()
|
||||
err = bot.Bunt.Set(&ticket)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
// save invoice struct for later use
|
||||
err = ticketEvent.Set(&ticketEvent, bot.Bunt)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
err = ticketEvent.InvoiceEvent.Set(ticketEvent.InvoiceEvent, bot.Bunt)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
bot.startTicketCallbackFunctionTimer(ticket)
|
||||
fmt.Println(ctx.Message())
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
// stopTicketTimer will load the timer function based on the event.
|
||||
// should stop the ticker timer function and remove ticket from bluntDB.
|
||||
func (bot *TipBot) stopJoinTicketTimer(event Event) {
|
||||
ev := event.(*InvoiceEvent)
|
||||
ticket := JoinTicket{Sender: ev.Payer.Telegram, Message: ev.Message}
|
||||
err := bot.Bunt.Get(&ticket)
|
||||
if err != nil {
|
||||
log.Errorf("[stopJoinTicketTimer] %v", err)
|
||||
return
|
||||
}
|
||||
if commission := getTicketCommission(ticket.Ticket); commission > 0 {
|
||||
me, err := GetUser(bot.Telegram.Me, *bot)
|
||||
if err != nil {
|
||||
log.Errorf("[stopJoinTicketTimer] %v", err)
|
||||
return
|
||||
}
|
||||
invoice, err := me.Wallet.Invoice(
|
||||
lnbits.InvoiceParams{
|
||||
Out: false,
|
||||
Amount: commission,
|
||||
Memo: "🎟 Ticket commission",
|
||||
Webhook: internal.Configuration.Lnbits.WebhookServer},
|
||||
bot.Client)
|
||||
if err != nil {
|
||||
log.Errorf("[stopJoinTicketTimer] %v", err)
|
||||
return
|
||||
}
|
||||
_, err = ticket.Ticket.Creator.Wallet.Pay(lnbits.PaymentParams{Bolt11: invoice.PaymentRequest, Out: true}, bot.Client)
|
||||
if err != nil {
|
||||
log.Errorf("[stopJoinTicketTimer] %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
d := time.Until(time.Now().Add(defaultTicketDuration))
|
||||
bot.tryDeleteMessage(ev.Message)
|
||||
t := runtime.GetFunction(ticket.Key(), runtime.WithDuration(d))
|
||||
t.StopChan <- struct{}{}
|
||||
err = bot.Bunt.Delete(ticket.Key(), &ticket)
|
||||
if err != nil {
|
||||
log.Errorf("[stopJoinTicketTimer] %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// startTicketCallbackFunctionTimer will start a ticket which will ban users if the timer runs out.
|
||||
func (bot *TipBot) startTicketCallbackFunctionTimer(ticket JoinTicket) {
|
||||
// check if ticket is already expired
|
||||
if ticket.CreatedTimestamp.Add(defaultTicketDuration).Before(time.Now()) {
|
||||
return
|
||||
}
|
||||
// ticket is valid. create duration until kick
|
||||
ticketDuration := time.Until(ticket.CreatedTimestamp.Add(defaultTicketDuration))
|
||||
// create function timer
|
||||
t := runtime.NewResettableFunction(ticket.Key(),
|
||||
runtime.WithTimer(time.NewTimer(ticketDuration)))
|
||||
// run the ticket callback function
|
||||
t.Do(func() {
|
||||
// ticket expired
|
||||
member, err := bot.Telegram.ChatMemberOf(ticket.Message.Chat, ticket.Sender)
|
||||
if err != nil {
|
||||
log.Errorln("🧨 could not fetch / ban chat member")
|
||||
return
|
||||
}
|
||||
// ban user
|
||||
err = bot.Telegram.Ban(ticket.Message.Chat, member)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
err = bot.Bunt.Delete(ticket.Key(), &ticket)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
bot.tryDeleteMessage(ticket.Message)
|
||||
})
|
||||
}
|
||||
|
||||
// restartPersistedTickets kicks of all ticket timers
|
||||
func (bot *TipBot) restartPersistedTickets() {
|
||||
bot.Bunt.View(func(tx *buntdb.Tx) error {
|
||||
err := tx.Ascend("join-ticket", func(key, value string) bool {
|
||||
ticket := JoinTicket{}
|
||||
err := json.Unmarshal([]byte(value), &ticket)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
bot.startTicketCallbackFunctionTimer(ticket)
|
||||
return true // continue iteration
|
||||
})
|
||||
return err
|
||||
})
|
||||
}
|
||||
func getTicketCommission(ticket *Ticket) int64 {
|
||||
if ticket.Price < 20 {
|
||||
return 0
|
||||
}
|
||||
// 2% cut + 100 sat base fee
|
||||
commissionSat := ticket.Price*ticket.Cut/100 + ticket.BaseFee
|
||||
if ticket.Price <= 1000 {
|
||||
// if < 1000, then 10% cut + 10 sat base fee
|
||||
commissionSat = ticket.Price*ticket.CutCheap/100 + ticket.BaseFeeCheap
|
||||
}
|
||||
return commissionSat
|
||||
}
|
||||
@@ -123,14 +123,13 @@ advancedMessage = """%s
|
||||
⚙️ *Pokročilé příkazy*
|
||||
*/transactions* 📊 Seznam transakcí
|
||||
*/link* 🔗 Propojit peněženku s [BlueWallet](https://bluewallet.io/) nebo [Zeus](https://zeusln.app/)
|
||||
*/lnurl* ⚡️ LNURL obdržet nebo zaplatit: `/lnurl` nebo `/lnurl <lnurl>`
|
||||
*/lnurl* ⚡️ LNURL obdržet nebo zaplatit: `/lnurl` nebo `/lnurl <lnurl> [memo]`
|
||||
*/faucet* 🚰 Vytvořit faucet: `/faucet <kapacita> <částka_na_uživatele>`
|
||||
*/tipjar* 🍯 Vytvořit tipjar: `/tipjar <kapacita> <částka_na_uživatele>`
|
||||
*/group* 🎟 Vytvořit vstupenky do skupiny: `/group add <název_skupiny> [<cena_vstupenky>]`
|
||||
*/shop* 🛍 Prohlížet obchody: `/shop` nebo `/shop <uživatel/id_obchodu>`
|
||||
*/generate* 🎆 Vytvořit obrázky od DALLE 2: `/generate <prompt>`"""
|
||||
|
||||
|
||||
# GENERIC
|
||||
enterAmountRangeMessage = """💯 Zadej částku mezi %d a %d sats."""
|
||||
enterAmountMessage = """💯 Zadej částku."""
|
||||
|
||||
@@ -120,12 +120,13 @@ advancedMessage = """%s
|
||||
⚙️ *Fortgeschrittene Befehle*
|
||||
*/transactions* 📊 Liste der Transaktionen
|
||||
*/link* 🔗 Verbinde dein Wallet mit [BlueWallet](https://bluewallet.io/) oder [Zeus](https://zeusln.app/)
|
||||
*/lnurl* ⚡️ Lnurl empfangen oder senden: `/lnurl` oder `/lnurl <lnurl>`
|
||||
*/lnurl* ⚡️ Lnurl empfangen oder senden: `/lnurl` oder `/lnurl <lnurl> [memo]`
|
||||
*/faucet* 🚰 Erzeuge einen Zapfhahn: `/faucet <gesamt> <pro_user>`
|
||||
*/tipjar* 🍯 Erzeuge eine Spendendose: `/tipjar <gesamt> <pro_user>`
|
||||
*/group* 🎟 Tickets für Gruppenchats: `/group add <meine_gruppe> [<ticket_preis>]`
|
||||
*/group* 🎟 Gruppenchat Funktionen: `/group`
|
||||
*/shop* 🛍 Durchsuche Shops: `/shop` oder `/shop <user/shop_id>`
|
||||
*/generate* 🎆 Generiere Bilder mit DALLE-2: `/generate <beschreibung>`"""
|
||||
*/generate* 🎆 Generiere Bilder mit DALLE-2: `/generate <beschreibung>`
|
||||
*/chat* 💬 Chatte mit GPT: `/chat <nachricht>`"""
|
||||
|
||||
# GENERIC
|
||||
enterAmountRangeMessage = """💯 Gebe Betrag zwuschen %d und %d sat ein."""
|
||||
|
||||
+14
-8
@@ -123,14 +123,13 @@ advancedMessage = """%s
|
||||
⚙️ *Advanced commands*
|
||||
*/transactions* 📊 List transactions
|
||||
*/link* 🔗 Link your wallet to [BlueWallet](https://bluewallet.io/) or [Zeus](https://zeusln.app/)
|
||||
*/lnurl* ⚡️ Lnurl receive or pay: `/lnurl` or `/lnurl <lnurl>`
|
||||
*/lnurl* ⚡️ Lnurl receive or pay: `/lnurl` or `/lnurl <lnurl> [memo]`
|
||||
*/faucet* 🚰 Create a faucet: `/faucet <capacity> <per_user>`
|
||||
*/tipjar* 🍯 Create a tipjar: `/tipjar <capacity> <per_user>`
|
||||
*/group* 🎟 Create group tickets: `/group add <mygroup> [<ticket_price>]`
|
||||
*/group* 🎟 Group chat features: `/group`
|
||||
*/shop* 🛍 Browse shops: `/shop` or `/shop <user/shop_id>`
|
||||
*/generate* 🎆 Generate DALLE-2 images: `/generate <prompt>`"""
|
||||
|
||||
|
||||
# GENERIC
|
||||
enterAmountRangeMessage = """💯 Enter an amount between %d and %d sat."""
|
||||
enterAmountMessage = """💯 Enter an amount."""
|
||||
@@ -371,14 +370,21 @@ groupJoinGroupHelpMessage = """📖 Oops, that didn't work. Please try
|
||||
groupClickToJoinMessage = """🎟 [Click here](%s) 👈 to join `%s`."""
|
||||
groupTicketIssuedGroupMessage = """🎟 User %s has received a ticket for this group."""
|
||||
groupPayInvoiceMessage = """🎟 To join the group %s, pay the invoice above."""
|
||||
groupBotIsNotAdminMessage = """🚫 Oops, that didn't work. You must make me admin and grant me rights to invite users."""
|
||||
groupBotIsNotAdminMessage = """🚫 Oops, that didn't work. You must make me admin and grant me rights to invite and ban users."""
|
||||
groupNameExists = """🚫 A group with this name already exists. Please choose a different name."""
|
||||
groupAddedMessage = """🎟 Tickets for group `%s` added.\nAlias: `%s` Price: %d sat\n\nTo request a ticket for this group, start a private chat with %s and write `/join %s`."""
|
||||
groupAddedMessagePrivate = """🎟 Tickets for group `%s` added.\n\nAlias: `%s` Price: %d sat\n\nTo request a ticket for this group, start a private chat with %s and write `/join %s`."""
|
||||
groupAddedMessagePublic = """🎟 Tickets enabled."""
|
||||
groupNotFoundMessage = """🚫 Could not find a group with this name."""
|
||||
groupReceiveTicketInvoiceCommission = """🎟 You received *%d sat* (excl. %d sat commission) for a ticket for group `%s` paid by user %s."""
|
||||
groupReceiveTicketInvoice = """🎟 You received *%d sat* for a ticket for group `%s` paid by user %s."""
|
||||
commandPrivateMessage = """Please use this command in a private chat with %s."""
|
||||
groupHelpMessage = """🎟 Private group tickets 🎟
|
||||
groupHelpMessage = """👥 *Group commands*
|
||||
|
||||
🎟 *Public tickets*
|
||||
|
||||
For admins (in group chat): `/group ticket <ticket_price>`\nExample: `/group ticket 1000`
|
||||
|
||||
🎟 *Private tickets*
|
||||
|
||||
Sell tickets for your _private Group_ and get rid of spam bots.
|
||||
|
||||
@@ -395,8 +401,8 @@ _Fees: The bot takes a 10%% +10 sat commission for cheap tickets. If the ticket
|
||||
To join a group, talk to %s and write in a private message `/join <mygroup>`.
|
||||
|
||||
📖 *Usage:*
|
||||
*For admins (in group chat):* `/group add <group_name> [<ticket_price>]`\nExample: `/group add TheBestBitcoinGroup 1000`
|
||||
*For users (in private chat):* `/join <group_name>`\nExample: `/join TheBestBitcoinGroup`"""
|
||||
For admins (in group chat): `/group add <group_name> [<ticket_price>]`\nExample: `/group add TheBestBitcoinGroup 1000`
|
||||
For users (in private chat): `/join <group_name>`\nExample: `/join TheBestBitcoinGroup`"""
|
||||
|
||||
# DALLE GENERATE
|
||||
generateDalleHelpMessage = """Generate images using OpenAI DALLE 2.\nUsage: `/generate <prompt>`\nPrice: 1000 sat"""
|
||||
|
||||
@@ -119,13 +119,12 @@ advancedMessage = """%s
|
||||
⚙️ *Comandos avanzados*
|
||||
*/transactions* 📊 List transactions
|
||||
*/link* 🔗 Enlaza tu monedero a [ BlueWallet ](https://bluewallet.io/) o [ Zeus ](https://zeusln.app/)
|
||||
*/lnurl* ⚡️ Lnurl recibir o pagar: `/lnurl` o `/lnurl <lnurl>`
|
||||
*/lnurl* ⚡️ Lnurl recibir o pagar: `/lnurl` o `/lnurl <lnurl> [memo]`
|
||||
*/faucet* 🚰 Crear un grifo: `/faucet <capacidad> <por_usuario>`
|
||||
*/tipjar* 🍯 Crear un tipjar: `/tipjar <capacidad> <por_usuario>`
|
||||
*/group* 🎟 Create group tickets: `/group add <mygroup> [<ticket_price>]`
|
||||
*/shop* 🛍 Browse shops: `/shop` or `/shop <user/shop_id>`
|
||||
*/generate* 🎆 Generate DALLE-2 images: `/generate <prompt>`"""
|
||||
|
||||
# GENERIC
|
||||
enterAmountRangeMessage = """💯 Introduce un monto entre %d y %d sat."""
|
||||
enterAmountMessage = """💯 Introduce un monto."""
|
||||
|
||||
@@ -119,13 +119,12 @@ advancedMessage = """%s
|
||||
⚙️ *Commandes avancées*
|
||||
*/transactions* 📊 List transactions
|
||||
*/link* 🔗 Lier votre wallet à [BlueWallet](https://bluewallet.io/) ou [Zeus](https://zeusln.app/)
|
||||
*/lnurl* ⚡️ Lnurl recevoir ou payer: `/lnurl` ou `/lnurl <lnurl>`
|
||||
*/lnurl* ⚡️ Lnurl recevoir ou payer: `/lnurl` ou `/lnurl <lnurl> [memo]`
|
||||
*/faucet* 🚰 Créer un faucet: `/faucet <capacité> <par_utilisateur>`
|
||||
*/tipjar* 🍯 Créer un tipjar: `/tipjar <capacité> <par_utilisateur>`
|
||||
*/group* 🎟 Create group tickets: `/group add <mygroup> [<ticket_price>]`
|
||||
*/shop* 🛍 Browse shops: `/shop` or `/shop <user/shop_id>`
|
||||
*/generate* 🎆 Generate DALLE-2 images: `/generate <prompt>`"""
|
||||
|
||||
# GENERIC
|
||||
enterAmountRangeMessage = """💯 Choisissez un montant entre %d et %d sat."""
|
||||
enterAmountMessage = """💯 Choisissez un montant."""
|
||||
@@ -229,7 +228,7 @@ photoQrRecognizedMessage = """✅ QR code:
|
||||
|
||||
# LNURL
|
||||
|
||||
lnurlReceiveInfoText = """👇 Vous ne pouvez pas utiliser cet LNURL pour recevoir des paiements."""
|
||||
lnurlReceiveInfoText = """👇 Vous pouvez utiliser cet LNURL pour recevoir des paiements."""
|
||||
lnurlResolvingUrlMessage = """🧮 Recherche de l'adresse..."""
|
||||
lnurlGettingUserMessage = """🧮 Préparation du paiement..."""
|
||||
lnurlPaymentFailed = """🚫 Echec du paiement : %s"""
|
||||
|
||||
@@ -119,13 +119,12 @@ advancedMessage = """%s
|
||||
⚙️ *Perintah lanjutan*
|
||||
*/transactions* 📊 List transactions
|
||||
*/link* 🔗 Menghubungkan dompet mu ke [BlueWallet](https://bluewallet.io/) atau [Zeus](https://zeusln.app/)
|
||||
*/lnurl* ⚡️ Lnurl menerima atau membayar: `/lnurl` atau `/lnurl <lnurl>`
|
||||
*/lnurl* ⚡️ Lnurl menerima atau membayar: `/lnurl` atau `/lnurl <lnurl> [memo]`
|
||||
*/faucet* 🚰 Membuat sebuah keran `/faucet <kapasitas> <per_pengguna>`
|
||||
*/tipjar* 🍯 Create a tipjar: `/tipjar <capacity> <per_user>`
|
||||
*/group* 🎟 Create group tickets: `/group add <mygroup> [<ticket_price>]`
|
||||
*/shop* 🛍 Browse shops: `/shop` or `/shop <user/shop_id>`
|
||||
*/generate* 🎆 Generate DALLE-2 images: `/generate <prompt>`"""
|
||||
|
||||
# GENERIC
|
||||
enterAmountRangeMessage = """💯 Masukkan jumlah diantara %d dan %d sat."""
|
||||
enterAmountMessage = """💯 Masukkan jumlah."""
|
||||
|
||||
@@ -119,13 +119,12 @@ advancedMessage = """%s
|
||||
⚙️ *Comandi avanzati*
|
||||
*/transactions* 📊 List transactions
|
||||
*/link* 🔗 Crea un collegamento al tuo wallet [BlueWallet](https://bluewallet.io/) o [Zeus](https://zeusln.app/)
|
||||
*/lnurl* ⚡️ Ricevi o paga un Lnurl: `/lnurl` or `/lnurl <lnurl>`
|
||||
*/lnurl* ⚡️ Ricevi o paga un Lnurl: `/lnurl` or `/lnurl <lnurl> [memo]`
|
||||
*/faucet* 🚰 Crea una distribuzione: `/faucet <totale> <per_utente>`
|
||||
*/tipjar* 🍯 Crea un tipjar: `/tipjar <totale> <per_utente>`
|
||||
*/group* 🎟 Create group tickets: `/group add <mygroup> [<ticket_price>]`
|
||||
*/shop* 🛍 Browse shops: `/shop` or `/shop <user/shop_id>`
|
||||
*/generate* 🎆 Generate DALLE-2 images: `/generate <prompt>`"""
|
||||
|
||||
# GENERIC
|
||||
enterAmountRangeMessage = """💯 Imposta un ammontare tra %d e %d sat."""
|
||||
enterAmountMessage = """💯 Imposta un ammontare."""
|
||||
|
||||
@@ -119,13 +119,12 @@ advancedMessage = """%s
|
||||
⚙️ *Geavanceerde opdrachten*
|
||||
*/transactions* 📊 List transactions
|
||||
*/link* 🔗 Koppel uw wallet aan [BlueWallet](https://bluewallet.io/) of [Zeus](https://zeusln.app/)
|
||||
*/lnurl* ⚡️ Lnurl ontvangen of betalen: `/lnurl` of `/lnurl <lnurl>`
|
||||
*/lnurl* ⚡️ Lnurl ontvangen of betalen: `/lnurl` of `/lnurl <lnurl> [memo]`
|
||||
*/faucet* 🚰 Maak een kraan: `/faucet <capacity> <per_user>`
|
||||
*/tipjar* 🍯 Maak een tipjar: `/tipjar <capacity> <per_user>`
|
||||
*/group* 🎟 Create group tickets: `/group add <mygroup> [<ticket_price>]`
|
||||
*/shop* 🛍 Browse shops: `/shop` or `/shop <user/shop_id>`
|
||||
*/generate* 🎆 Generate DALLE-2 images: `/generate <prompt>`"""
|
||||
|
||||
# GENERIC
|
||||
enterAmountRangeMessage = """💯 Voer een bedrag in tussen %d en %d sat."""
|
||||
enterAmountMessage = """💯 Voer een bedrag."""
|
||||
|
||||
@@ -124,14 +124,13 @@ advancedMessage = """%s
|
||||
⚙️ *Komendy zaawansowane*
|
||||
*/transactions* 📊 Lista transakcji
|
||||
*/link* 🔗 Połączenie Twojego portfela z [BlueWallet](https://bluewallet.io/) lub [Zeus](https://zeusln.app/)
|
||||
*/lnurl* ⚡️ Przyjmij płatność lub zapłać za pomocą Lnurl: `/lnurl` lub `/lnurl <lnurl>`
|
||||
*/lnurl* ⚡️ Przyjmij płatność lub zapłać za pomocą Lnurl: `/lnurl` lub `/lnurl <lnurl> [memo]`
|
||||
*/faucet* 🚰 Stwórz kranik (_faucet_): `/faucet <pojemność> <na_użytkownika>`
|
||||
*/tipjar* 🍯 Stwórz słoik na napiwki (_tipjar_): `/tipjar <pojemność> <na_użytkownika>`
|
||||
*/group* 🎟 Stwórz bilety na wejście do grupy: `/group add <mojagrupa> [<cena_biletu>]`
|
||||
*/shop* 🛍 Przeglądaj sklepy: `/shop` lub `/shop <użytkownik/id_sklepu>`
|
||||
*/generate* 🎆 Generuj obrazy przy użyciu DALLE-2: `/generate <podpowiedź>`"""
|
||||
|
||||
|
||||
# GENERIC
|
||||
enterAmountRangeMessage = """💯 Wprowadź kwotę między %d a %d sat."""
|
||||
enterAmountMessage = """💯 Wprowadź kwotę."""
|
||||
|
||||
@@ -119,12 +119,12 @@ advancedMessage = """%s
|
||||
⚙️ *Comandos avançados*
|
||||
*/transactions* 📊 List transactions
|
||||
*/link* 🔗 Vincule sua carteira a [ BlueWallet ](https://bluewallet.io/) ou [ Zeus ](https://zeusln.app/)
|
||||
*/lnurl* ⚡️ Receber ou pagar com lnurl: `/lnurl` o `/lnurl <lnurl>`
|
||||
*/lnurl* ⚡️ Receber ou pagar com lnurl: `/lnurl` o `/lnurl <lnurl> [memo]`
|
||||
*/faucet* 🚰 Criar uma torneira: `/faucet <capacidade> <por_usuário>`
|
||||
*/tipjar* 🍯 Criar uma tipjar: `/tipjar <capacidade> <por_usuário>`
|
||||
*/group* 🎟 Create group tickets: `/group add <mygroup> [<ticket_price>]`
|
||||
*/shop* 🛍 Browse shops: `/shop` or `/shop <user/shop_id>`"""
|
||||
|
||||
*/shop* 🛍 Browse shops: `/shop` or `/shop <user/shop_id>`
|
||||
*/generate* 🎆 Generate DALLE-2 images: `/generate <prompt>`"""
|
||||
# GENERIC
|
||||
enterAmountRangeMessage = """💯 Insira uma quantia entre %d e %d sat."""
|
||||
enterAmountMessage = """💯 Insira uma quantia."""
|
||||
|
||||
@@ -123,7 +123,7 @@ advancedMessage = """%s
|
||||
⚙️ *Продвинутые команды*
|
||||
*/transactions* 📊 List transactions
|
||||
*/link* 🔗 Link your wallet to [BlueWallet](https://bluewallet.io/) or [Zeus](https://zeusln.app/)
|
||||
*/lnurl* Получить или оплатить через ⚡️Lnurl: `/lnurl` or `/lnurl <lnurl>`
|
||||
*/lnurl* Получить или оплатить через ⚡️Lnurl: `/lnurl` or `/lnurl <lnurl> [memo]`
|
||||
*/faucet* 🚰 Создать криптораздачу: `/faucet <ёмкость> <на_пользователя>`
|
||||
*/tipjar* 🍯 Создать копилку: `/tipjar <ёмкость> <на_пользователя>`
|
||||
*/group* 🎟 Create group tickets: `/group add <mygroup> [<ticket_price>]`
|
||||
|
||||
@@ -119,7 +119,7 @@ advancedMessage = """%s
|
||||
⚙️ *Gelişmiş komutlar*
|
||||
*/transactions* 📊 List transactions
|
||||
*/link* 🔗 Cüzdanını bağla: [BlueWallet](https://bluewallet.io/) veya [Zeus](https://zeusln.app/)
|
||||
*/lnurl* ⚡️ Lnurl iste veya gönder: `/lnurl` veya `/lnurl <lnurl>`
|
||||
*/lnurl* ⚡️ Lnurl iste veya gönder: `/lnurl` veya `/lnurl <lnurl> [memo]`
|
||||
*/faucet* 🚰 Bir fıçı oluştur: `/faucet <toplam> <kullanıcı_başına>`
|
||||
*/tipjar* 🍯 Bir tipjar oluştur: `/tipjar <capacity> <per_user>`
|
||||
*/group* 🎟 Create group tickets: `/group add <mygroup> [<ticket_price>]`
|
||||
|
||||
Reference in New Issue
Block a user