Now compiles
This commit is contained in:
parent
cac52711e3
commit
bc28a0faa0
7 changed files with 68 additions and 66 deletions
4
Makefile
4
Makefile
|
@ -1,4 +1,4 @@
|
|||
all: broker
|
||||
all: clessy-broker
|
||||
|
||||
broker:
|
||||
clessy-broker:
|
||||
go build -o clessy-broker ./broker
|
|
@ -1,4 +1,4 @@
|
|||
package broker
|
||||
package main
|
||||
|
||||
import (
|
||||
"../tg"
|
||||
|
|
|
@ -50,7 +50,7 @@ func handleClient(c net.Conn) {
|
|||
}
|
||||
|
||||
func removeCon(c net.Conn) {
|
||||
for i, con := range Clients {
|
||||
for i, con := range clients {
|
||||
if c == con {
|
||||
clients = append(clients[:i], clients[i+1:]...)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ func assert(err error) {
|
|||
}
|
||||
}
|
||||
|
||||
var api Telegram
|
||||
var api *Telegram
|
||||
|
||||
func main() {
|
||||
cfgpath := flag.String("config", "config.json", "Path to configuration file")
|
||||
|
@ -39,7 +39,7 @@ func main() {
|
|||
|
||||
// Setup webhook handler
|
||||
go func() {
|
||||
http.HandlerFunc(config.Token, webhook)
|
||||
http.HandleFunc(config.Token, webhook)
|
||||
err := http.ListenAndServe(config.BindServer, nil)
|
||||
assert(err)
|
||||
}()
|
||||
|
|
|
@ -30,11 +30,11 @@ func (t Telegram) setWebhook(webhook string) {
|
|||
}
|
||||
}
|
||||
|
||||
func (t Telegram) apiURL(method string) {
|
||||
func (t Telegram) apiURL(method string) string {
|
||||
return APIEndpoint + "bot" + t.Token + "/" + method
|
||||
}
|
||||
|
||||
func checkerr(method string, err error) {
|
||||
func checkerr(method string, err error) bool {
|
||||
if err != nil {
|
||||
log.Printf("Received error with call to %s: %s\n", method, err.Error())
|
||||
return true
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"../tg"
|
||||
)
|
||||
|
||||
func webhook(rw http.ResponseWriter, req *http.Request) {
|
||||
|
|
84
tg/api.go
84
tg/api.go
|
@ -19,70 +19,70 @@ const (
|
|||
type APIChat struct {
|
||||
UserID int `json:"id"`
|
||||
Type ChatType `json:"type"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
FirstName string `json:"first_name,omitempty"`
|
||||
LastName string `json:"last_name,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
Username *string `json:"username,omitempty"`
|
||||
FirstName *string `json:"first_name,omitempty"`
|
||||
LastName *string `json:"last_name,omitempty"`
|
||||
}
|
||||
|
||||
type APIMessage struct {
|
||||
MessageID int `json:"message_id"`
|
||||
User APIUser `json:"from"`
|
||||
Time int `json:"date"`
|
||||
Chat APIChat `json:"chat"`
|
||||
FwdUser APIUpdate `json:"forward_from,omitempty"`
|
||||
FwdTime int `json:"forward_date,omitempty"`
|
||||
ReplyTo APIMessage `json:"reply_to_message,omitempty"`
|
||||
Text string `json:"text,omitempty"`
|
||||
Audio APIAudio `json:"audio,omitempty"`
|
||||
Document APIDocument `json:"document,omitempty"`
|
||||
Chat *APIChat `json:"chat"`
|
||||
FwdUser *APIUpdate `json:"forward_from,omitempty"`
|
||||
FwdTime *int `json:"forward_date,omitempty"`
|
||||
ReplyTo *APIMessage `json:"reply_to_message,omitempty"`
|
||||
Text *string `json:"text,omitempty"`
|
||||
Audio *APIAudio `json:"audio,omitempty"`
|
||||
Document *APIDocument `json:"document,omitempty"`
|
||||
Photo []APIPhotoSize `json:"photo,omitempty"`
|
||||
Sticker APISticker `json:"sticker,omitempty"`
|
||||
Video APIVideo `json:"video,omitempty"`
|
||||
Voice APIVoice `json:"voice,omitempty"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
Contact APIContact `json:"contact,omitempty"`
|
||||
Location APILocation `json:"location,omitempty"`
|
||||
NewUser APIUser `json:"new_chat_partecipant",omitempty"`
|
||||
LeftUser APIUser `json:"left_chat_partecipant,omitempty"`
|
||||
PhotoDeleted bool `json:"delete_chat_photo,omitempty"`
|
||||
GroupCreated bool `json:"group_chat_created,omitempty"`
|
||||
SupergroupCreated bool `json:"supergroup_chat_created,omitempty"`
|
||||
ChannelCreated bool `json:"channel_chat_created,omitempty"`
|
||||
GroupToSuper int `json:"migrate_to_chat_id,omitempty"`
|
||||
GroupFromSuper int `json:"migrate_from_chat_id,omitempty"`
|
||||
Sticker *APISticker `json:"sticker,omitempty"`
|
||||
Video *APIVideo `json:"video,omitempty"`
|
||||
Voice *APIVoice `json:"voice,omitempty"`
|
||||
Caption *string `json:"caption,omitempty"`
|
||||
Contact *APIContact `json:"contact,omitempty"`
|
||||
Location *APILocation `json:"location,omitempty"`
|
||||
NewUser *APIUser `json:"new_chat_partecipant",omitempty"`
|
||||
LeftUser *APIUser `json:"left_chat_partecipant,omitempty"`
|
||||
PhotoDeleted *bool `json:"delete_chat_photo,omitempty"`
|
||||
GroupCreated *bool `json:"group_chat_created,omitempty"`
|
||||
SupergroupCreated *bool `json:"supergroup_chat_created,omitempty"`
|
||||
ChannelCreated *bool `json:"channel_chat_created,omitempty"`
|
||||
GroupToSuper *int `json:"migrate_to_chat_id,omitempty"`
|
||||
GroupFromSuper *int `json:"migrate_from_chat_id,omitempty"`
|
||||
}
|
||||
|
||||
type APIPhotoSize struct {
|
||||
FileID string `json:"file_id"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
FileSize int `json:"file_size,omitempty"`
|
||||
FileSize *int `json:"file_size,omitempty"`
|
||||
}
|
||||
|
||||
type APIAudio struct {
|
||||
FileID string `json:"file_id"`
|
||||
Duration int `json:"duration"`
|
||||
Performer string `json:"performer,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
MimeType string `json:"mime_type,omitempty"`
|
||||
FileSize int `json:"file_size,omitempty"`
|
||||
Performer *string `json:"performer,omitempty"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
MimeType *string `json:"mime_type,omitempty"`
|
||||
FileSize *int `json:"file_size,omitempty"`
|
||||
}
|
||||
|
||||
type APIDocument struct {
|
||||
FileID string `json:"file_id"`
|
||||
Thumbnail APIPhotoSize `json:"thumb,omitempty"`
|
||||
Thumbnail *APIPhotoSize `json:"thumb,omitempty"`
|
||||
Filename string `json:"file_name"`
|
||||
MimeType string `json:"mime_type,omitempty"`
|
||||
FileSize int `json:"file_size,omitempty"`
|
||||
MimeType *string `json:"mime_type,omitempty"`
|
||||
FileSize *int `json:"file_size,omitempty"`
|
||||
}
|
||||
|
||||
type APISticker struct {
|
||||
FileID string `json:"file_id"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Thumbnail APIPhotoSize `json:"thumb,omitempty"`
|
||||
FileSize int `json:"file_size,omitempty"`
|
||||
Thumbnail *APIPhotoSize `json:"thumb,omitempty"`
|
||||
FileSize *int `json:"file_size,omitempty"`
|
||||
}
|
||||
|
||||
type APIVideo struct {
|
||||
|
@ -90,23 +90,23 @@ type APIVideo struct {
|
|||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Duration int `json:"duration"`
|
||||
Thumbnail APIPhotoSize `json:"thumb,omitempty"`
|
||||
MimeType string `json:"mime_type,omitempty"`
|
||||
FileSize int `json:"file_size,omitempty"`
|
||||
Thumbnail *APIPhotoSize `json:"thumb,omitempty"`
|
||||
MimeType *string `json:"mime_type,omitempty"`
|
||||
FileSize *int `json:"file_size,omitempty"`
|
||||
}
|
||||
|
||||
type APIVoice struct {
|
||||
FileID string `json:"file_id"`
|
||||
Duration int `json:"duration"`
|
||||
MimeType string `json:"mime_type,omitempty"`
|
||||
FileSize int `json:"file_size,omitempty"`
|
||||
MimeType *string `json:"mime_type,omitempty"`
|
||||
FileSize *int `json:"file_size,omitempty"`
|
||||
}
|
||||
|
||||
type APIContact struct {
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name,omitempty"`
|
||||
UserID int `json:"user_id,omitempty"`
|
||||
LastName *string `json:"last_name,omitempty"`
|
||||
UserID *int `json:"user_id,omitempty"`
|
||||
}
|
||||
|
||||
type APILocation struct {
|
||||
|
|
Reference in a new issue