-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhou Xiaopeng
committed
Aug 2, 2019
1 parent
054c458
commit b1a0046
Showing
4 changed files
with
436 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
builds/* | ||
t/* | ||
td/* | ||
files/* | ||
db/* | ||
errors.txt | ||
|
||
getchats/db/* | ||
getchats/files/* | ||
getchats/errors.txt | ||
getchats/builds/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
tag_name = -X main.tagName=$(shell git describe --abbrev=0 --tags) | ||
branch = -X main.branch=$(shell git rev-parse --abbrev-ref HEAD) | ||
commit_id = -X main.commitID=$(shell git log --pretty=format:"%h" -1) | ||
build_time = -X main.buildTime=$(shell date -u '+%Y-%m-%d_%I:%M:%S%p') | ||
|
||
VERSION = $(tag_name) $(branch) $(commit_id) $(build_time) | ||
|
||
.PHONY: all | ||
.DEFAULT_GOAL := osx_amd64 | ||
|
||
osx_amd64: | ||
env GOOS=darwin GOARCH=amd64 go build -v -ldflags "-s -w ${VERSION}" -o builds/btcFaucet_osx | ||
cd getchats && env GOOS=darwin GOARCH=amd64 go build -v -ldflags "-s -w ${VERSION}" -o builds/getChats_osx | ||
mv getchats/builds/getChats_osx builds | ||
cd builds && 7z a btcFaucet_OSX.7z btcFaucet_osx getChats_osx | ||
|
||
linux: linux_amd64 | ||
|
||
linux_amd64: | ||
env GOOS=linux GOARCH=amd64 go build -v -ldflags "-s -w ${VERSION}" -o builds/btcFaucet_lin | ||
|
||
windows: windows_amd64 | ||
|
||
windows_amd64: | ||
env CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CC_FOR_TARGET=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ GOOS=windows GOARCH=amd64 CGO_CFLAGS="-I/Users/zxp/go/src/github.com/Arman92/go-tdlib/winlib -g -O2" CGO_LDFLAGS="-L/Users/zxp/go/src/github.com/Arman92/go-tdlib/winlib/td/build -ltdjson -g -O2" go build -x -v -ldflags "-s -w" -o builds/btcFaucet_x64.exe | ||
cd getchats && env CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CC_FOR_TARGET=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ GOOS=windows GOARCH=amd64 CGO_CFLAGS="-I/Users/zxp/go/src/github.com/Arman92/go-tdlib/winlib -g -O2" CGO_LDFLAGS="-L/Users/zxp/go/src/github.com/Arman92/go-tdlib/winlib/td/build -ltdjson -g -O2" go build -x -v -ldflags "-s -w" -o builds/getChats_x64.exe | ||
mv getchats/builds/getChats_x64.exe builds | ||
cd builds && 7z a btcFaucet_WinX64.7z *.dll *.exe | ||
|
||
all: osx_amd64 linux windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"math/rand" | ||
"net" | ||
"os" | ||
"os/signal" | ||
"regexp" | ||
"strconv" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/Arman92/go-tdlib" | ||
"github.com/howeyc/gopass" | ||
) | ||
|
||
var ( | ||
version, tagName, branch, commitID, buildTime string | ||
) | ||
|
||
func main() { | ||
fmt.Println("比特币水龙头") | ||
version = fmt.Sprintf("Version: %s, Branch: %s, Build: %s, Build time: %s", tagName, branch, commitID, buildTime) | ||
|
||
tdlib.SetLogVerbosityLevel(0) | ||
tdlib.SetFilePath("./errors.txt") | ||
|
||
// Create new instance of client | ||
client := tdlib.NewClient(tdlib.Config{ | ||
APIID: "952817", | ||
APIHash: "217d192bf3884ee374dd742eb2ddeba8", | ||
SystemLanguageCode: "en", | ||
DeviceModel: "Server", | ||
SystemVersion: "1.0.0", | ||
ApplicationVersion: version, | ||
UseMessageDatabase: true, | ||
UseFileDatabase: true, | ||
UseChatInfoDatabase: true, | ||
UseTestDataCenter: false, | ||
DatabaseDirectory: "./db", | ||
FileDirectory: "./files", | ||
IgnoreFileNames: false, | ||
}) | ||
|
||
var proxyHost, proxyPort, proxyType string | ||
var proxyUser, proxyPass, mtprotoSecret string | ||
var waitTime int | ||
|
||
flag.Usage = func() { | ||
fmt.Println(version) | ||
fmt.Println("Usage:") | ||
flag.PrintDefaults() | ||
} | ||
|
||
flag.IntVar(&waitTime, "wait", 30, "开启水龙头间隔时间,随机增加0-30秒") | ||
flag.StringVar(&proxyHost, "host", "", "代理服务器IP") | ||
flag.StringVar(&proxyPort, "port", "", "代理服务器端口号") | ||
flag.StringVar(&proxyType, "type", "", "代理服务器类型(http, socks5, mtproto)") | ||
flag.StringVar(&proxyUser, "user", "", "代理服务器用户名(http, socks5)") | ||
flag.StringVar(&proxyPass, "password", "", "代理服务器密码(http, socks5)") | ||
flag.StringVar(&mtprotoSecret, "secret", "", "Mtproto 代理密钥(Mtproto)") | ||
flag.CommandLine.SetOutput(os.Stdout) | ||
flag.Parse() | ||
|
||
if proxyHost != "" && proxyPort != "" && proxyType != "" { | ||
if ip := net.ParseIP(proxyHost); ip == nil { | ||
fmt.Println("代理服务器IP错误!") | ||
os.Exit(1) | ||
} | ||
|
||
i, err := strconv.ParseInt(proxyPort, 10, 32) | ||
if err != nil { | ||
fmt.Println("代理服务器端口号错误") | ||
os.Exit(1) | ||
} | ||
port := int32(i) | ||
|
||
switch proxyType { | ||
case "http": | ||
fmt.Printf("设置HTTP代理,%s:%s\n", proxyHost, proxyPort) | ||
client.AddProxy(proxyHost, port, true, tdlib.NewProxyTypeHttp(proxyUser, proxyPass, false)) | ||
case "socks5": | ||
fmt.Printf("设置Socks5代理,%s:%s\n", proxyHost, proxyPort) | ||
client.AddProxy(proxyHost, port, true, tdlib.NewProxyTypeSocks5(proxyUser, proxyPass)) | ||
case "mtproto": | ||
fmt.Printf("设置Mtproto代理,%s:%s\n", proxyHost, proxyPort) | ||
client.AddProxy(proxyHost, port, true, tdlib.NewProxyTypeMtproto(mtprotoSecret)) | ||
default: | ||
fmt.Println("未知代理类型") | ||
flag.Usage() | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// Handle Ctrl+C , Gracefully exit and shutdown tdlib | ||
ch := make(chan os.Signal, 2) | ||
signal.Notify(ch, os.Interrupt, syscall.SIGTERM) | ||
go func() { | ||
<-ch | ||
client.DestroyInstance() | ||
os.Exit(1) | ||
}() | ||
|
||
// Wait while we get AuthorizationReady! | ||
// Note: See authorization example for complete auhtorization sequence example | ||
for { | ||
currentState, _ := client.Authorize() | ||
if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitPhoneNumberType { | ||
fmt.Print("电话号码:") | ||
var number string | ||
fmt.Scanln(&number) | ||
_, err := client.SendPhoneNumber(number) | ||
if err != nil { | ||
fmt.Printf("错误电话号码:%v\n", err) | ||
} | ||
} else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitCodeType { | ||
fmt.Print("验证码:") | ||
var code string | ||
fmt.Scanln(&code) | ||
_, err := client.SendAuthCode(code) | ||
if err != nil { | ||
fmt.Printf("错误验证码:%v\n", err) | ||
} | ||
} else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitPasswordType { | ||
fmt.Print("密码:") | ||
var password string | ||
var maskPassword []byte | ||
for len(maskPassword) < 1 { | ||
maskPassword, _ = gopass.GetPasswdMasked() | ||
} | ||
password = string(maskPassword) | ||
//fmt.Scanln(&password) | ||
_, err := client.SendAuthPassword(password) | ||
if err != nil { | ||
fmt.Printf("密码错误:%v\n", err) | ||
} | ||
} else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateReadyType { | ||
fmt.Println("已认证,开启水龙头!") | ||
break | ||
} | ||
} | ||
|
||
go func() { | ||
// Create an filter function which will be used to filter out unwanted tdlib messages | ||
eventFilter := func(msg *tdlib.TdMessage) bool { | ||
updateMsg := (*msg).(*tdlib.UpdateNewMessage) | ||
// For example, we want incomming messages from user with below id: | ||
if updateMsg.Message.SenderUserID == 848714900 { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// Here we can add a receiver to retreive any message type we want | ||
// We like to get UpdateNewMessage events and with a specific FilterFunc | ||
receiver := client.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100) | ||
for newMsg := range receiver.Chan { | ||
//fmt.Println(newMsg) | ||
updateMsg := (newMsg).(*tdlib.UpdateNewMessage) | ||
// We assume the message content is simple text: (should be more sophisticated for general use) | ||
msgText := updateMsg.Message.Content.(*tdlib.MessageText) | ||
re := regexp.MustCompile(`^.+฿([0-9.]+).+฿([0-9.]+)$`) | ||
account := re.FindStringSubmatch(msgText.Text.Text) | ||
if len(account) > 0 { | ||
fmt.Printf("%s 得到:%s,账户总额:%s\n", time.Now().Format("2006-01-02 15:04:05"), account[1], account[2]) | ||
} | ||
//fmt.Printf("MsgText: %s\n\n", msgText.Text.Text) | ||
} | ||
|
||
}() | ||
|
||
go func() { | ||
rand.Seed(time.Now().UnixNano()) | ||
// Should get chatID somehow, check out "getChats" example | ||
chatID := int64(848714900) | ||
inputMsgTxt := tdlib.NewInputMessageText(tdlib.NewFormattedText("💦 Faucet", nil), true, true) | ||
var w int | ||
for { | ||
client.SendMessage(chatID, 0, false, true, nil, inputMsgTxt) | ||
|
||
w = waitTime + rand.Intn(30) | ||
//fmt.Printf("sleep %d second\n", w) | ||
time.Sleep(time.Duration(w) * time.Second) | ||
} | ||
}() | ||
|
||
for { | ||
time.Sleep(1 * time.Second) | ||
} | ||
// rawUpdates gets all updates comming from tdlib | ||
//rawUpdates := client.GetRawUpdatesChannel(100) | ||
//for update := range rawUpdates { | ||
// Show all updates | ||
// fmt.Println(update.Data) | ||
// fmt.Print("\n\n----------\n\n") | ||
//} | ||
} |
Oops, something went wrong.