Skip to content

Commit 27f3410

Browse files
committed
Initial commit
0 parents  commit 27f3410

File tree

11 files changed

+242
-0
lines changed

11 files changed

+242
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
config.json
8+
# Test binary, build with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 CtrCat
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# UcodeQrTelebot
2+
Simple use of QR and U-code in telegram bot using UTOPIA API

desktop.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[ViewState]
2+
Mode=
3+
Vid=
4+
FolderType=Generic

go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module example.com/UcodeQrTelebot_ver2
2+
3+
go 1.17
4+
5+
require (
6+
github.com/Sagleft/utopialib-go v1.2.6
7+
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.0
8+
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
9+
)
10+
11+
require gopkg.in/grignaak/tribool.v1 v1.0.0-20150312065122-d6bb19d816df // indirect

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
github.com/Sagleft/utopialib-go v1.2.6 h1:TpvqILNbXpiJYyh5LY6UDxfFwK4JJ1gLVoPH+0VvC20=
2+
github.com/Sagleft/utopialib-go v1.2.6/go.mod h1:4/F9ivBk17cBHldczN6R60vyYjAwzqL/0fXq5elFXfo=
3+
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.0 h1:BtndtqqCQfPsL2uMkYmduOip1+dPcSmh40l82mBUPKk=
4+
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.0/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
5+
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
6+
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
7+
gopkg.in/grignaak/tribool.v1 v1.0.0-20150312065122-d6bb19d816df h1:SCh+kVSG+MN/pU/l0/3ehkc3i9T+G6AQS6jEoxM4ddY=
8+
gopkg.in/grignaak/tribool.v1 v1.0.0-20150312065122-d6bb19d816df/go.mod h1:ikoZVciJt+u3It4kEk89OVqIKHPU9BjrgkHSr++TA2w=

main.go

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
package main
2+
3+
import (
4+
"io/ioutil"
5+
"log"
6+
7+
"encoding/base64"
8+
"encoding/json"
9+
"fmt"
10+
"os"
11+
12+
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
13+
14+
qrcode "github.com/skip2/go-qrcode"
15+
16+
utopiago "github.com/Sagleft/utopialib-go"
17+
)
18+
19+
const (
20+
qrFilePath = "qr.png"
21+
)
22+
23+
type Config struct {
24+
TelegramBotToken string
25+
UtpToken string
26+
UtpPort int
27+
PublicKey string
28+
}
29+
30+
func main() {
31+
32+
//read congig
33+
file, _ := os.Open("config.json")
34+
decoder := json.NewDecoder(file)
35+
configuration := Config{}
36+
err := decoder.Decode(&configuration)
37+
if err != nil {
38+
log.Panic(err)
39+
}
40+
fmt.Println(configuration.TelegramBotToken)
41+
fmt.Println(configuration.UtpToken)
42+
fmt.Println(configuration.UtpPort)
43+
44+
// bot-token
45+
46+
bot, err := tgbotapi.NewBotAPI(configuration.TelegramBotToken)
47+
if err != nil {
48+
log.Panic(err)
49+
}
50+
51+
bot.Debug = true
52+
log.Printf("Authorized on account %s", bot.Self.UserName)
53+
54+
// ini channel
55+
var ucfg tgbotapi.UpdateConfig = tgbotapi.NewUpdate(0)
56+
ucfg.Timeout = 60
57+
updatesChann := bot.GetUpdatesChan(ucfg)
58+
59+
//utp
60+
client := utopiago.UtopiaClient{
61+
Protocol: "http",
62+
Token: configuration.UtpToken,
63+
Host: "127.0.0.1",
64+
Port: configuration.UtpPort,
65+
}
66+
67+
//send bool
68+
69+
// update
70+
for {
71+
select {
72+
73+
case update := <-updatesChann:
74+
// User bot
75+
UserName := update.Message.From.UserName
76+
77+
// ID chat.
78+
79+
ChatID := update.Message.Chat.ID
80+
81+
// Text massage user
82+
Text := update.Message.Text
83+
84+
log.Printf("[%s] %d %s", UserName, ChatID, Text)
85+
86+
//commands
87+
88+
switch Text {
89+
90+
case "/ucode":
91+
92+
//send to channel
93+
94+
//ucodeEncode
95+
96+
Ucodius64, err := client.UCodeEncode(configuration.PublicKey, "BASE64", "PNG", 256)
97+
if err != nil {
98+
log.Println(err)
99+
}
100+
//decode
101+
log.Println(Ucodius64)
102+
log.Println("Ucode COMPLIIIITE")
103+
104+
err = ioutil.WriteFile("sample.b64", []byte(Ucodius64), 0644)
105+
106+
if err != nil {
107+
log.Println(err)
108+
}
109+
110+
b64Data, err := ioutil.ReadFile("sample.b64")
111+
if err != nil {
112+
log.Println(err)
113+
}
114+
115+
// base64 to png
116+
outPngData, err := base64.StdEncoding.DecodeString(string(b64Data))
117+
118+
if err != nil {
119+
log.Println(err)
120+
}
121+
122+
//send
123+
124+
photoFileBytes := tgbotapi.FileBytes{
125+
Name: "ucode",
126+
Bytes: outPngData,
127+
}
128+
129+
msg := tgbotapi.NewPhoto(ChatID, photoFileBytes)
130+
131+
bot.Send(msg)
132+
133+
case "/qrcode":
134+
135+
//send to channel
136+
137+
//create Qr
138+
139+
err := qrcode.WriteFile(configuration.PublicKey, qrcode.Medium, 256, qrFilePath)
140+
if err != nil {
141+
log.Println("write error")
142+
}
143+
log.Println("CREATE QR")
144+
//Send Qr
145+
146+
photoBytes, err := ioutil.ReadFile(qrFilePath)
147+
if err != nil {
148+
panic(err)
149+
}
150+
photoFileBytes := tgbotapi.FileBytes{
151+
Name: "qr",
152+
Bytes: photoBytes,
153+
}
154+
155+
msg := tgbotapi.NewPhoto(ChatID, photoFileBytes)
156+
157+
bot.Send(msg)
158+
159+
case "/how":
160+
161+
log.Println("/how")
162+
163+
msg := tgbotapi.NewMessage(ChatID, "create config.json and use")
164+
165+
bot.Send(msg)
166+
167+
default:
168+
169+
fmt.Println("commands")
170+
171+
reply := "Commands:\n /ucode \n /qrcode"
172+
msg := tgbotapi.NewMessage(ChatID, reply)
173+
174+
bot.Send(msg)
175+
176+
}
177+
178+
}
179+
180+
}
181+
}

qr.png

574 Bytes
Loading

sample.b64

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)