Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskcenter
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
taskcenter
Commits
2a47dede
Commit
2a47dede
authored
Aug 21, 2024
by
贾浩@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
e99d95e9
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
336 additions
and
182 deletions
+336
-182
Dockerfile
Dockerfile
+7
-18
config.toml
config.toml
+12
-8
config.go
config/config.go
+3
-2
constant.go
constant/constant.go
+1
-1
dao.go
dao/dao.go
+13
-8
db.go
dao/db.go
+15
-4
tg_task.go
dao/tg_task.go
+16
-0
tw_task.go
dao/tw_task.go
+23
-18
api.go
model/api/api.go
+49
-29
auth.go
model/db/auth.go
+2
-2
taskcenter.go
model/db/taskcenter.go
+29
-25
readme.md
readme.md
+4
-4
group.go
server/group.go
+23
-1
project.go
server/project.go
+4
-2
router.go
server/router.go
+1
-0
task.go
server/task.go
+1
-0
group.go
service/group.go
+69
-20
project.go
service/project.go
+58
-35
task.go
service/task.go
+6
-5
No files found.
Dockerfile
View file @
2a47dede
FROM
golang:1.21-alpine AS base
# Set up dependencies
ENV
PACKAGES git openssh-client build-base
FROM
golang:1.21-alpine AS builder
# Install dependencies
RUN
apk add
--update
$PACKAGES
# Add source files
RUN
mkdir
-p
./sdk-api
COPY
./ ./sdk-api/
WORKDIR
/app
FROM
base AS build
COPY
. .
RUN
cd
sdk-api
&&
go mod tidy
&&
go build
-v
-o
/tmp/api ./cmd/api
&&
go build
-v
-o
/tmp/messenger ./cmd/messenger
RUN
go mod tidy
&&
go build
-v
-o
/tmp/api ./cmd/api
FROM
alpine
FROM
alpine
:latest
WORKDIR
/app
COPY
./config.toml /config.toml
COPY
--from=build /tmp/api /usr/bin/api
COPY
./config.toml .
COPY
--from=build
/tmp/messenger /usr/bin/messenger
COPY
--from=build
er /tmp/api /usr/bin/api
EXPOSE
8080
\ No newline at end of file
config.toml
View file @
2a47dede
debug
=
true
[
my
sql]
host
=
"
127.0.0.1
"
port
=
3306
user
=
"
root
"
[
pg
sql]
host
=
"
aws-0-ap-northeast-1.pooler.supabase.com
"
port
=
5432
user
=
"
postgres.vbxtvjffhsirnyxjcuku
"
password
=
""
database
=
"
task
"
max_conn
=
10
database
=
"
postgres
"
max_conn
=
5
max_idle_conn
=
2
enable_log
=
true
cert_file
=
"ca.crt"
[server]
listen
=
"0.0.0.0:8080"
[tg_bot]
token
=
"6507972032:AAFAjaNz70ibA42kSH7k2gblyIQa1gWJiW0"
[tg_task]
url
=
"http://16.163.191.255:30001"
[twitter_task]
url
=
"http://43.198.54.207:8001"
\ No newline at end of file
config/config.go
View file @
2a47dede
...
...
@@ -11,7 +11,7 @@ type Config struct {
PGSQL
PGSQLConfig
`toml:"pgsql"`
Server
ServerConfig
`toml:"server"`
TGTask
TGTaskConfig
`toml:"tg_task"`
Tw
eeterTask
TweeterTaskConfig
`toml:"twee
ter_task"`
Tw
itterTask
TwitterTaskConfig
`toml:"twit
ter_task"`
}
type
SupabaseConfig
struct
{
...
...
@@ -30,13 +30,14 @@ type PGSQLConfig struct {
MaxConn
int
`toml:"max_conn"`
MaxIdleConn
int
`toml:"max_idle_conn"`
EnableLog
bool
`toml:"enable_log"`
CertFile
string
`toml:"cert_file"`
}
type
TGTaskConfig
struct
{
URL
string
`toml:"url"`
}
type
Tw
ee
terTaskConfig
struct
{
type
Tw
it
terTaskConfig
struct
{
URL
string
`toml:"url"`
}
...
...
constant/constant.go
View file @
2a47dede
...
...
@@ -66,7 +66,7 @@ var TaskAction = map[string][]string{
}
const
(
TwitterAPIActionRetw
ee
ter
=
"retweeters"
TwitterAPIActionRetw
it
ter
=
"retweeters"
TwitterAPIActionLike
=
"like"
TwitterAPIActionFollow
=
"follow"
)
dao/dao.go
View file @
2a47dede
...
...
@@ -2,6 +2,7 @@ package dao
import
(
"fmt"
"os"
"sdk_api/config"
dbModel
"sdk_api/model/db"
"time"
...
...
@@ -27,8 +28,8 @@ func New(_c *config.Config) (dao *Dao, err error) {
// dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True",
// _c.PGSQL.User, _c.PGSQL.Password, _c.PGSQL.Host, _c.PGSQL.Port, _c.PGSQL.Database)
dsn
:=
fmt
.
Sprintf
(
"host=%s user=%s password=%s dbname=%s port=%d sslmode=verify-ca sslrootcert=
ca.crt
"
,
_c
.
PGSQL
.
Host
,
_c
.
PGSQL
.
User
,
_c
.
PGSQL
.
Password
,
_c
.
PGSQL
.
Database
,
_c
.
PGSQL
.
Port
,
dsn
:=
fmt
.
Sprintf
(
"host=%s user=%s password=%s dbname=%s port=%d sslmode=verify-ca sslrootcert=
%s
"
,
_c
.
PGSQL
.
Host
,
_c
.
PGSQL
.
User
,
_c
.
PGSQL
.
Password
,
_c
.
PGSQL
.
Database
,
_c
.
PGSQL
.
Port
,
_c
.
PGSQL
.
CertFile
,
)
lgr
:=
logger
.
Default
...
...
@@ -53,12 +54,16 @@ func New(_c *config.Config) (dao *Dao, err error) {
sqlDB
.
SetMaxOpenConns
(
_c
.
PGSQL
.
MaxConn
)
sqlDB
.
SetMaxIdleConns
(
_c
.
PGSQL
.
MaxIdleConn
)
sqlDB
.
SetConnMaxIdleTime
(
time
.
Hour
)
err
=
dao
.
db
.
AutoMigrate
(
&
dbModel
.
TaskAction
{},
&
dbModel
.
Project
{},
&
dbModel
.
TaskGroup
{},
&
dbModel
.
Task
{},
&
dbModel
.
TaskHistory
{})
if
err
!=
nil
{
return
}
if
err
=
dao
.
InitTaskAction
();
err
!=
nil
{
panic
(
err
)
if
os
.
Getenv
(
"MIGRATE"
)
==
"true"
{
err
=
dao
.
db
.
AutoMigrate
(
&
dbModel
.
TaskAction
{},
&
dbModel
.
Project
{},
&
dbModel
.
TaskGroup
{},
&
dbModel
.
Task
{},
&
dbModel
.
TaskHistory
{})
if
err
!=
nil
{
return
}
if
err
=
dao
.
InitTaskAction
();
err
!=
nil
{
panic
(
err
)
}
}
return
dao
,
nil
}
dao/db.go
View file @
2a47dede
...
...
@@ -31,8 +31,13 @@ func (d *Dao) CreateProject(p *dbModel.Project) (err error) {
return
d
.
db
.
Create
(
p
)
.
Error
}
func
(
d
*
Dao
)
GetProjectList
(
page
,
pageSize
int
)
(
list
[]
*
dbModel
.
Project
,
err
error
)
{
return
list
,
d
.
db
.
Limit
(
pageSize
)
.
Offset
((
page
-
1
)
*
pageSize
)
.
Find
(
&
list
)
.
Error
func
(
d
*
Dao
)
GetProjectList
(
page
,
pageSize
int
)
(
list
[]
*
dbModel
.
Project
,
totalCount
int
,
err
error
)
{
var
tmpCount
int64
err
=
d
.
db
.
Model
(
&
dbModel
.
Project
{})
.
Count
(
&
tmpCount
)
.
Error
if
err
!=
nil
{
return
}
return
list
,
int
(
tmpCount
),
d
.
db
.
Limit
(
pageSize
)
.
Offset
((
page
-
1
)
*
pageSize
)
.
Find
(
&
list
)
.
Error
}
func
(
d
*
Dao
)
GetProject
(
id
int
)
(
p
*
dbModel
.
Project
,
err
error
)
{
...
...
@@ -48,8 +53,14 @@ func (d *Dao) CreateGroup(g *dbModel.TaskGroup) (err error) {
return
d
.
db
.
Create
(
g
)
.
Error
}
func
(
d
*
Dao
)
GetGroupList
(
page
,
pageSize
int
)
(
list
[]
*
dbModel
.
TaskGroup
,
err
error
)
{
return
list
,
d
.
db
.
Limit
(
pageSize
)
.
Offset
((
page
-
1
)
*
pageSize
)
.
Find
(
&
list
)
.
Error
func
(
d
*
Dao
)
GetGroupList
(
page
,
pageSize
int
)
(
list
[]
*
dbModel
.
TaskGroup
,
totalCount
int
,
err
error
)
{
var
tmpCount
int64
err
=
d
.
db
.
Model
(
&
dbModel
.
TaskGroup
{})
.
Count
(
&
tmpCount
)
.
Error
if
err
!=
nil
{
return
}
totalCount
=
int
(
tmpCount
)
return
list
,
totalCount
,
d
.
db
.
Limit
(
pageSize
)
.
Offset
((
page
-
1
)
*
pageSize
)
.
Find
(
&
list
)
.
Error
}
func
(
d
*
Dao
)
GetGroup
(
id
int
)
(
g
*
dbModel
.
TaskGroup
,
err
error
)
{
...
...
dao/tg_task.go
View file @
2a47dede
...
...
@@ -13,6 +13,22 @@ import (
"github.com/tidwall/gjson"
)
func
(
d
*
Dao
)
GetTGGroupInfo
(
chatId
int
)
(
title
,
username
string
,
err
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/api/v1/chat?chatId=%d"
,
strings
.
TrimSuffix
(
d
.
c
.
TGTask
.
URL
,
"/"
),
chatId
)
log
.
WithField
(
"url"
,
url
)
.
Debug
(
"get tg group info"
)
data
,
err
:=
httpGet
(
url
)
if
err
!=
nil
{
return
}
retCode
:=
gjson
.
Get
(
string
(
data
),
"code"
)
.
Int
()
if
retCode
==
1
{
return
""
,
""
,
errors
.
New
(
string
(
data
))
}
return
gjson
.
Get
(
string
(
data
),
"data.title"
)
.
String
(),
gjson
.
Get
(
string
(
data
),
"data.username"
)
.
String
(),
nil
}
func
(
d
*
Dao
)
CheckTGJoin
(
userId
string
,
chatId
int
)
(
ok
bool
,
err
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/api/v1/user/joined?chatId=%d&userId=%s"
,
strings
.
TrimSuffix
(
d
.
c
.
TGTask
.
URL
,
"/"
),
chatId
,
userId
)
log
.
WithField
(
"url"
,
url
)
.
Debug
(
"check tg join"
)
...
...
dao/tw_task.go
View file @
2a47dede
...
...
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
"time"
...
...
@@ -12,10 +13,10 @@ import (
"github.com/tidwall/gjson"
)
func
(
d
*
Dao
)
CreateTwitterProject
(
apiKey
,
apiSecret
,
accessToken
,
accessSecret
,
token
,
projectName
string
)
(
tw
eetId
,
tweetHandle
,
tweet
Name
string
,
err
error
)
{
func
(
d
*
Dao
)
CreateTwitterProject
(
apiKey
,
apiSecret
,
accessToken
,
accessSecret
,
token
,
projectName
string
)
(
tw
itterUserId
int
,
twitterHandle
,
twitter
Name
string
,
err
error
)
{
body
:=
map
[
string
]
string
{
"api_key"
:
apiKey
,
"api_
secret"
:
apiSecret
,
"api_
key_secret"
:
apiSecret
,
"access_token"
:
accessToken
,
"access_token_secret"
:
accessSecret
,
"token"
:
token
,
...
...
@@ -26,8 +27,7 @@ func (d *Dao) CreateTwitterProject(apiKey, apiSecret, accessToken, accessSecret,
if
err
!=
nil
{
return
}
resp
,
err
:=
httpPost
(
fmt
.
Sprintf
(
"%s/project"
,
strings
.
TrimRight
(
d
.
c
.
TweeterTask
.
URL
,
"/"
)),
buf
)
resp
,
err
:=
httpPost
(
fmt
.
Sprintf
(
"%s/project"
,
strings
.
TrimRight
(
d
.
c
.
TwitterTask
.
URL
,
"/"
)),
buf
)
if
err
!=
nil
{
return
}
...
...
@@ -47,18 +47,21 @@ func (d *Dao) CreateTwitterProject(apiKey, apiSecret, accessToken, accessSecret,
return
}
if
respTemp
.
Code
!=
200
&&
respTemp
.
Msg
!=
"task already existed"
{
// if respTemp.Code != 200 && respTemp.Msg != "task already existed" {
if
respTemp
.
Code
!=
200
&&
respTemp
.
Msg
!=
"already existed"
{
err
=
errors
.
New
(
string
(
resp
))
return
}
return
respTemp
.
Data
.
UserID
,
respTemp
.
Data
.
Username
,
respTemp
.
Data
.
Name
,
nil
userId
,
_
:=
strconv
.
Atoi
(
respTemp
.
Data
.
UserID
)
return
userId
,
respTemp
.
Data
.
Username
,
respTemp
.
Data
.
Name
,
nil
}
func
(
d
*
Dao
)
DoTweetTask
(
tw
eetUserId
,
tweetId
,
action
string
,
start
bool
)
(
err
error
)
{
func
(
d
*
Dao
)
DoTweetTask
(
tw
itterUserId
int
,
tweetId
int
,
action
string
,
start
bool
)
(
err
error
)
{
body
:=
map
[
string
]
string
{
"user_id"
:
tweetUserId
,
"task_id"
:
tweetId
,
"user_id"
:
fmt
.
Sprintf
(
"%d"
,
twitterUserId
)
,
"task_id"
:
fmt
.
Sprintf
(
"%d"
,
tweetId
)
,
"task_type"
:
action
,
}
...
...
@@ -68,9 +71,11 @@ func (d *Dao) DoTweetTask(tweetUserId, tweetId, action string, start bool) (err
return
}
url
:=
fmt
.
Sprintf
(
"%s/task/add"
,
strings
.
TrimRight
(
d
.
c
.
TweeterTask
.
URL
,
"/"
))
log
.
Info
(
buf
.
String
())
url
:=
fmt
.
Sprintf
(
"%s/task/add"
,
strings
.
TrimRight
(
d
.
c
.
TwitterTask
.
URL
,
"/"
))
if
!
start
{
url
=
fmt
.
Sprintf
(
"%s/task/stop"
,
strings
.
TrimRight
(
d
.
c
.
Tw
ee
terTask
.
URL
,
"/"
))
url
=
fmt
.
Sprintf
(
"%s/task/stop"
,
strings
.
TrimRight
(
d
.
c
.
Tw
it
terTask
.
URL
,
"/"
))
}
resp
,
err
:=
httpPost
(
url
,
buf
)
...
...
@@ -78,15 +83,15 @@ func (d *Dao) DoTweetTask(tweetUserId, tweetId, action string, start bool) (err
return
}
if
gjson
.
Get
(
string
(
resp
),
"code"
)
.
Int
()
!=
200
{
if
gjson
.
Get
(
string
(
resp
),
"code"
)
.
Int
()
!=
200
&&
gjson
.
Get
(
string
(
resp
),
"msg"
)
.
String
()
!=
"task already existed"
{
return
errors
.
New
(
string
(
resp
))
}
return
}
func
(
d
*
Dao
)
CheckTw
eeterFollow
(
userId
,
followerId
string
)
(
ok
bool
,
err
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/verify/follow?user_id=%
s&follower_id=%s"
,
strings
.
TrimSuffix
(
d
.
c
.
Twee
terTask
.
URL
,
"/"
),
userId
,
followerId
)
func
(
d
*
Dao
)
CheckTw
itterFollow
(
userId
int
,
followerId
string
)
(
ok
bool
,
err
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/verify/follow?user_id=%
d&follower_id=%s"
,
strings
.
TrimSuffix
(
d
.
c
.
Twit
terTask
.
URL
,
"/"
),
userId
,
followerId
)
log
.
WithField
(
"url"
,
url
)
.
Debug
(
"check tweet follow"
)
data
,
err
:=
httpGet
(
url
)
if
err
!=
nil
{
...
...
@@ -99,8 +104,8 @@ func (d *Dao) CheckTweeterFollow(userId, followerId string) (ok bool, err error)
return
gjson
.
Get
(
string
(
data
),
"data.ok"
)
.
Bool
(),
nil
}
func
(
d
*
Dao
)
CheckTw
eeterLike
(
tweetId
,
userId
string
,
begin
,
end
int
)
(
ok
bool
,
err
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/verify/like?tweet_id=%
s&user_id=%s"
,
strings
.
TrimSuffix
(
d
.
c
.
Twee
terTask
.
URL
,
"/"
),
tweetId
,
userId
)
func
(
d
*
Dao
)
CheckTw
itterLike
(
tweetId
int
,
userId
string
,
begin
,
end
int
)
(
ok
bool
,
err
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/verify/like?tweet_id=%
d&user_id=%s"
,
strings
.
TrimSuffix
(
d
.
c
.
Twit
terTask
.
URL
,
"/"
),
tweetId
,
userId
)
if
begin
!=
0
&&
end
!=
0
{
url
+=
fmt
.
Sprintf
(
"&begin=%s&end=%s"
,
time
.
Unix
(
int64
(
begin
),
0
)
.
Format
(
time
.
RFC3339
),
time
.
Unix
(
int64
(
end
),
0
)
.
Format
(
time
.
RFC3339
))
}
...
...
@@ -117,8 +122,8 @@ func (d *Dao) CheckTweeterLike(tweetId, userId string, begin, end int) (ok bool,
return
gjson
.
Get
(
string
(
data
),
"data.ok"
)
.
Bool
(),
nil
}
func
(
d
*
Dao
)
CheckTw
eeterRetweet
(
tweetId
,
userId
string
,
begin
,
end
int
)
(
ok
bool
,
err
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/verify/retweeter?tweet_id=%
s&retweeter_id=%s"
,
strings
.
TrimSuffix
(
d
.
c
.
Twee
terTask
.
URL
,
"/"
),
tweetId
,
userId
)
func
(
d
*
Dao
)
CheckTw
itterRetweet
(
tweetId
int
,
userId
string
,
begin
,
end
int
)
(
ok
bool
,
err
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/verify/retweeter?tweet_id=%
d&retweeter_id=%s"
,
strings
.
TrimSuffix
(
d
.
c
.
Twit
terTask
.
URL
,
"/"
),
tweetId
,
userId
)
if
begin
!=
0
&&
end
!=
0
{
url
+=
fmt
.
Sprintf
(
"&begin=%s&end=%s"
,
time
.
Unix
(
int64
(
begin
),
0
)
.
Format
(
time
.
RFC3339
),
time
.
Unix
(
int64
(
end
),
0
)
.
Format
(
time
.
RFC3339
))
}
...
...
model/api/api.go
View file @
2a47dede
...
...
@@ -2,48 +2,68 @@ package api_model
type
CreateProjectRequest
struct
{
ProjectName
string
`json:"projectName" binding:"required"`
Description
string
`json:"description"
binding:"required"
`
Tw
eeterAPIKey
string
`json:"twee
terAPIKey" binding:"required"`
Tw
eeterAPISecret
string
`json:"twee
terAPISecret" binding:"required"`
Tw
eeterAccessToken
string
`json:"twee
terAccessToken" binding:"required"`
Tw
eeterAccessSecret
string
`json:"twee
terAccessSecret" binding:"required"`
Tw
eeterToken
string
`json:"twee
terToken" binding:"required"`
Description
string
`json:"description"`
Tw
itterAPIKey
string
`json:"twit
terAPIKey" binding:"required"`
Tw
itterAPISecret
string
`json:"twit
terAPISecret" binding:"required"`
Tw
itterAccessToken
string
`json:"twit
terAccessToken" binding:"required"`
Tw
itterAccessSecret
string
`json:"twit
terAccessSecret" binding:"required"`
Tw
itterToken
string
`json:"twit
terToken" binding:"required"`
TelegramChatId
int
`json:"telegramChatId" binding:"required"`
}
type
CreateProjectResponse
struct
{
ProjectId
int
`json:"projectId"`
TwitterHandle
string
`json:"twitterHandle"`
TwitterName
string
`json:"twitterName"`
TelegramChatTitle
string
`json:"telegramChatTitle"`
TelegramChatUsername
string
`json:"telegramChatUsername"`
}
type
GetProjectResponse
struct
{
TelegramChatId
int
`json:"telegramChatId"`
TwitterHandle
string
`json:"twitterHandle"`
TweeterName
string
`json:"tweeterName"`
TweeterUserId
string
`json:"tweeterUserId"`
ProjectName
string
`json:"projectName"`
Description
string
`json:"description"`
TweeterAPIKey
string
`json:"tweeterAPIKey,omitempty"`
TweeterAPISecret
string
`json:"tweeterAPISecret,omitempty"`
TweeterAccessToken
string
`json:"tweeterAccessToken,omitempty"`
TweeterAccessSecret
string
`json:"tweeterAccessSecret,omitempty"`
TweeterToken
string
`json:"tweeterToken,omitempty"`
ProjectId
int
`json:"projectId,omitempty"`
TelegramChatId
int
`json:"telegramChatId"`
TelegramChatUsername
string
`json:"telegramChatUsername"`
TelegramChatTitle
string
`json:"telegramChatTitle"`
TwitterHandle
string
`json:"twitterHandle"`
TwitterName
string
`json:"twitterName"`
TwitterUserId
int
`json:"twitterUserId"`
ProjectName
string
`json:"projectName"`
Description
string
`json:"description"`
TwitterAPIKey
string
`json:"twitterAPIKey,omitempty"`
TwitterAPISecret
string
`json:"twitterAPISecret,omitempty"`
TwitterAccessToken
string
`json:"twitterAccessToken,omitempty"`
TwitterAccessSecret
string
`json:"twitterAccessSecret,omitempty"`
TwitterToken
string
`json:"twitterToken,omitempty"`
}
type
CreateGroupRequest
struct
{
ProjectId
int
`json:"projectId" binding:"required"`
GroupId
int
`json:"groupId,omitempty"`
Description
string
`json:"description"`
Tasks
[]
Task
`json:"tasks"`
}
type
Task
struct
{
TaskId
int
`json:"taskId,omitempty"`
Platform
string
`json:"platform" binding:"required"`
Action
string
`json:"action" binding:"required"`
Url
string
`json:"url" binding:"required"`
TwitterUserId
string
`json:"twitterUserId"`
TelegramChatId
int
`json:"telegramChatId"`
TweetId
string
`json:"tweetId"`
Description
string
`json:"description" binding:"required"`
Reward
int
`json:"reward" binding:"required"`
Start
int
`json:"start" binding:"required"`
End
int
`json:"end" binding:"required"`
Daily
bool
`json:"daily" binding:"required"`
TaskId
int
`json:"taskId,omitempty"`
Platform
string
`json:"platform" binding:"required"`
Action
string
`json:"action" binding:"required"`
Url
string
`json:"url"`
TweetId
int
`json:"tweetId"`
Description
string
`json:"description" binding:"required"`
Reward
int
`json:"reward" binding:"required"`
Start
int
`json:"start" binding:"required"`
End
int
`json:"end" binding:"required"`
Daily
bool
`json:"daily" binding:"required"`
}
type
GetGroupResponse
CreateGroupRequest
type
GetGroupListResponse
struct
{
TotalCount
int
`json:"totalCount"`
Items
[]
*
GetGroupResponse
`json:"items"`
}
type
GetProjectListResponse
struct
{
TotalCount
int
`json:"totalCount"`
Items
[]
*
GetProjectResponse
`json:"items"`
}
model/db/auth.go
View file @
2a47dede
...
...
@@ -4,7 +4,6 @@ import (
"time"
"gorm.io/datatypes"
"gorm.io/gorm"
)
type
Identity
struct
{
...
...
@@ -15,7 +14,8 @@ type Identity struct {
Provider
string
`gorm:"type:text;not null;comment:第三方用户平台"`
LastSignInAt
time
.
Time
`gorm:"type:timestamp;not null;comment:最后登录时间"`
Email
string
`gorm:"type:text;not null;comment:用户邮箱"`
gorm
.
Model
CreatedAt
time
.
Time
UpdatedAt
time
.
Time
}
func
(
*
Identity
)
TableName
()
string
{
...
...
model/db/taskcenter.go
View file @
2a47dede
...
...
@@ -16,18 +16,20 @@ func (t *TaskAction) TableName() string {
}
type
Project
struct
{
Id
int
`gorm:"primaryKey;autoIncrement:false"`
Name
string
`gorm:"type:text;not null;comment:项目名称"`
Description
string
`gorm:"type:text;not null;comment:项目描述"`
TweeterAPIKey
string
`gorm:"type:text;not null;comment:tweet api key"`
TweeterAPISecret
string
`gorm:"type:text;not null;comment:tweet api secret"`
TweeterAccessToken
string
`gorm:"type:text;not null;comment:tweet access token"`
TweeterAccessSecret
string
`gorm:"type:text;not null;comment:tweet access secret"`
TweeterToken
string
`gorm:"type:text;not null;comment:tweet token"`
TweeterHandle
string
`gorm:"type:text;not null;comment:tweet handle"`
TweeterName
string
`gorm:"type:text;not null;comment:tweet name"`
TweeterUserId
string
`gorm:"type:text;not null;comment:tweet user id"`
TelegramChatId
int
`gorm:"type:int;not null;comment:telegram chat id"`
Id
int
`gorm:"primaryKey;autoIncrement:false"`
Name
string
`gorm:"type:text;not null;comment:项目名称"`
Description
string
`gorm:"type:text;not null;comment:项目描述"`
TwitterAPIKey
string
`gorm:"type:text;not null;comment:tweet api key"`
TwitterAPISecret
string
`gorm:"type:text;not null;comment:tweet api secret"`
TwitterAccessToken
string
`gorm:"type:text;not null;comment:tweet access token"`
TwitterAccessSecret
string
`gorm:"type:text;not null;comment:tweet access secret"`
TwitterToken
string
`gorm:"type:text;not null;comment:tweet token"`
TwitterHandle
string
`gorm:"type:text;not null;comment:tweet handle"`
TwitterName
string
`gorm:"type:text;not null;comment:tweet name"`
TwitterUserId
int
`gorm:"type:int;not null;comment:tweet user id"`
TelegramChatId
int
`gorm:"type:int;not null;comment:telegram chat id"`
TelegramChatUsername
string
`gorm:"type:text;not null;comment:telegram chat username"`
TelegramChatTitle
string
`gorm:"type:text;not null;comment:telegram chat title"`
gorm
.
Model
Groups
[]
*
TaskGroup
...
...
@@ -49,19 +51,21 @@ func (t *TaskGroup) TableName() string {
}
type
Task
struct
{
Id
int
`gorm:"primaryKey;autoIncrement:false"`
GroupId
int
`gorm:"type:int;index;not null;comment:任务组id"`
Platform
string
`gorm:"type:text;not null;comment:任务平台"`
Action
string
`gorm:"type:text;not null;comment:任务动作"`
Url
string
`gorm:"type:text;not null;comment:任务链接"`
TweeterUserId
string
`gorm:"type:int;not null;comment:tweet用户id,用于关注"`
TweetId
string
`gorm:"type:int;not null;comment:推文id,用于转发点赞"`
TelegramChatId
int
`gorm:"type:int;not null;comment:telegram群id"`
Description
string
`gorm:"type:text;not null;comment:任务描述"`
Reward
int
`gorm:"type:int;not null;comment:任务奖励"`
Start
int
`gorm:"type:int;not null;comment:任务开始时间"`
End
int
`gorm:"type:int;not null;comment:任务结束时间"`
Daily
int
`gorm:"type:int;not null;comment:是否是每日任务"`
Id
int
`gorm:"primaryKey;autoIncrement:false"`
GroupId
int
`gorm:"type:int;index;not null;comment:任务组id"`
Platform
string
`gorm:"type:text;not null;comment:任务平台"`
Action
string
`gorm:"type:text;not null;comment:任务动作"`
Url
string
`gorm:"type:text;not null;comment:任务链接"`
TwitterUserId
int
`gorm:"type:int;not null;comment:tweet user id,用于关注"`
TwitterHandle
string
`gorm:"type:text;not null;comment:tweet handle,用于关注"`
TweetId
int
`gorm:"type:int;not null;comment:推文id,用于转发点赞"`
TelegramChatId
int
`gorm:"type:int;not null;comment:telegram群id"`
TelegramChatUsername
string
`gorm:"type:text;not null;comment:telegram群用户名"`
Description
string
`gorm:"type:text;not null;comment:任务描述"`
Reward
int
`gorm:"type:int;not null;comment:任务奖励"`
Start
int
`gorm:"type:int;not null;comment:任务开始时间"`
End
int
`gorm:"type:int;not null;comment:任务结束时间"`
Daily
int
`gorm:"type:int;not null;comment:是否是每日任务"`
gorm
.
Model
}
...
...
readme.md
View file @
2a47dede
#
telegram-
任务中心
# 任务中心
和sdk部分共用一个数据库,
启动&停止命令
启动&停止命令
```
docker compose up -d
tg-messenger-api
docker compose up -d
docker compose down
tg-messenger-api
docker compose down
```
\ No newline at end of file
server/group.go
View file @
2a47dede
...
...
@@ -6,11 +6,13 @@ import (
"strconv"
"github.com/gin-gonic/gin"
log
"github.com/sirupsen/logrus"
)
func
createGroup
(
c
*
gin
.
Context
)
{
req
:=
&
apiModel
.
CreateGroupRequest
{}
if
err
:=
c
.
ShouldBindJSON
(
req
);
err
!=
nil
{
log
.
Info
(
"11111"
,
err
)
c
.
JSON
(
200
,
withError
(
constant
.
InvalidParam
))
return
}
...
...
@@ -33,6 +35,7 @@ func createGroup(c *gin.Context) {
for
_
,
task
:=
range
req
.
Tasks
{
if
!
constant
.
IsValidAction
(
task
.
Action
)
||
!
constant
.
IsValidPlatform
(
task
.
Platform
)
{
log
.
Info
(
"1111"
,
task
.
Action
,
task
.
Platform
)
c
.
JSON
(
200
,
withError
(
constant
.
InvalidParam
))
return
}
...
...
@@ -45,7 +48,7 @@ func createGroup(c *gin.Context) {
// return
// }
if
task
.
Platform
==
constant
.
TaskPlatformTwitter
&&
task
.
Action
==
constant
.
TaskActionFollow
&&
task
.
TweetId
==
""
{
if
task
.
Platform
==
constant
.
TaskPlatformTwitter
&&
task
.
Action
!=
constant
.
TaskActionFollow
&&
task
.
TweetId
==
0
{
c
.
JSON
(
200
,
withError
(
constant
.
InvalidParam
))
return
}
...
...
@@ -75,3 +78,22 @@ func getGroup(c *gin.Context) {
}
c
.
JSON
(
200
,
withSuccess
(
resp
))
}
func
listGroup
(
c
*
gin
.
Context
)
{
_page
:=
c
.
DefaultQuery
(
"page"
,
"1"
)
_pageSize
:=
c
.
DefaultQuery
(
"pageSize"
,
"10"
)
page
,
_
:=
strconv
.
Atoi
(
_page
)
pageSize
,
_
:=
strconv
.
Atoi
(
_pageSize
)
if
page
<
1
||
pageSize
<
1
||
pageSize
>
100
{
c
.
JSON
(
200
,
withError
(
constant
.
InvalidParam
))
return
}
resp
,
err
:=
srv
.
GetGroupList
(
page
,
pageSize
)
if
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
constant
.
InternalError
))
return
}
c
.
JSON
(
200
,
withSuccess
(
resp
))
}
server/project.go
View file @
2a47dede
package
server
import
(
"fmt"
"sdk_api/constant"
apiModel
"sdk_api/model/api"
"strconv"
...
...
@@ -11,16 +12,17 @@ import (
func
createProject
(
c
*
gin
.
Context
)
{
req
:=
&
apiModel
.
CreateProjectRequest
{}
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
fmt
.
Println
(
err
)
c
.
JSON
(
200
,
withError
(
constant
.
InvalidParam
))
return
}
pid
,
err
:=
srv
.
CreateProject
(
req
)
resp
,
err
:=
srv
.
CreateProject
(
req
)
if
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
constant
.
InternalError
))
return
}
c
.
JSON
(
200
,
withSuccess
(
gin
.
H
{
"projectId"
:
pid
}
))
c
.
JSON
(
200
,
withSuccess
(
resp
))
}
func
listProject
(
c
*
gin
.
Context
)
{
...
...
server/router.go
View file @
2a47dede
...
...
@@ -21,6 +21,7 @@ func initRouter(e *gin.Engine) {
{
group
:=
v1
.
Group
(
"/group"
)
group
.
GET
(
"/:gid"
,
getGroup
)
// 获取任务组任务详情
group
.
GET
(
"/list"
,
listGroup
)
// 获取任务组任务详情
group
.
POST
(
"/create"
,
createGroup
)
// 创建任务组
}
...
...
server/task.go
View file @
2a47dede
...
...
@@ -30,6 +30,7 @@ func checkTask(c *gin.Context) {
if
done
||
expired
{
c
.
JSON
(
200
,
withSuccess
(
gin
.
H
{
"done"
:
done
}))
return
}
done
,
err
=
srv
.
SyncTask
(
taskId
,
userId
)
...
...
service/group.go
View file @
2a47dede
package
service
import
(
"fmt"
"sdk_api/constant"
apiModel
"sdk_api/model/api"
dbModel
"sdk_api/model/db"
...
...
@@ -21,7 +22,7 @@ func (s *Service) CreateGroup(req *apiModel.CreateGroupRequest) (gid int, err er
return
}
project
,
err
:=
s
.
GetProject
(
req
.
ProjectId
)
project
,
err
:=
s
.
d
.
GetProject
(
req
.
ProjectId
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"get project error"
)
return
0
,
err
...
...
@@ -33,39 +34,39 @@ func (s *Service) CreateGroup(req *apiModel.CreateGroupRequest) (gid int, err er
daily
=
1
}
gt
:=
&
dbModel
.
Task
{
Id
:
util
.
GenFlakeID
(),
GroupId
:
g
.
Id
,
Platform
:
task
.
Platform
,
Action
:
task
.
Action
,
Url
:
task
.
Url
,
Description
:
task
.
Description
,
Reward
:
task
.
Reward
,
Start
:
task
.
Start
,
End
:
task
.
End
,
Daily
:
daily
,
Id
:
util
.
GenFlakeID
(),
GroupId
:
g
.
Id
,
Platform
:
task
.
Platform
,
Action
:
task
.
Action
,
TwitterHandle
:
project
.
TwitterHandle
,
TwitterUserId
:
project
.
TwitterUserId
,
Description
:
task
.
Description
,
Reward
:
task
.
Reward
,
Start
:
task
.
Start
,
End
:
task
.
End
,
Daily
:
daily
,
}
if
task
.
Platform
==
constant
.
TaskPlatformTwitter
{
if
task
.
Action
==
constant
.
TaskActionFollow
{
gt
.
TweeterUserId
=
project
.
TweeterUserId
}
else
{
gt
.
TweetId
=
task
.
TweetId
}
var
twitterAPIAction
string
switch
task
.
Action
{
case
constant
.
TaskActionFollow
:
twitterAPIAction
=
constant
.
TwitterAPIActionFollow
gt
.
Url
=
fmt
.
Sprintf
(
"https://x.com/intent/follow?screen_name=%s"
,
project
.
TwitterHandle
)
case
constant
.
TaskActionLike
:
twitterAPIAction
=
constant
.
TwitterAPIActionLike
gt
.
TweetId
=
task
.
TweetId
gt
.
Url
=
fmt
.
Sprintf
(
"https://x.com/intent/like?tweet_id=%d"
,
task
.
TweetId
)
case
constant
.
TaskActionRetweet
:
twitterAPIAction
=
constant
.
TwitterAPIActionRetweeter
twitterAPIAction
=
constant
.
TwitterAPIActionRetwitter
gt
.
TweetId
=
task
.
TweetId
gt
.
Url
=
fmt
.
Sprintf
(
"https://x.com/intent/retweet?tweet_id=%d"
,
task
.
TweetId
)
}
tweetId
:=
gt
.
TweetId
if
task
.
Action
==
constant
.
TaskActionFollow
{
tweetId
=
gt
.
Tw
ee
terUserId
tweetId
=
gt
.
Tw
it
terUserId
}
// 推特任务中心,启动任务
err
=
s
.
d
.
DoTweetTask
(
gt
.
Tw
ee
terUserId
,
tweetId
,
twitterAPIAction
,
true
)
err
=
s
.
d
.
DoTweetTask
(
gt
.
Tw
it
terUserId
,
tweetId
,
twitterAPIAction
,
true
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"do tweet task error"
)
return
0
,
err
...
...
@@ -74,6 +75,8 @@ func (s *Service) CreateGroup(req *apiModel.CreateGroupRequest) (gid int, err er
}
if
task
.
Platform
==
constant
.
TaskPlatformTelegram
{
gt
.
TelegramChatId
=
project
.
TelegramChatId
gt
.
TelegramChatUsername
=
project
.
TelegramChatUsername
gt
.
Url
=
fmt
.
Sprintf
(
"https://t.me/%s"
,
project
.
TelegramChatUsername
)
}
err
=
s
.
d
.
CreateGroupTask
(
gt
)
...
...
@@ -97,6 +100,9 @@ func (s *Service) GetGroup(gid int) (resp *apiModel.GetGroupResponse, err error)
return
nil
,
nil
}
resp
.
ProjectId
=
g
.
ProjectId
resp
.
Description
=
g
.
Description
tasks
,
err
:=
s
.
d
.
GetGroupTasks
(
g
.
Id
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"get group tasks error"
)
...
...
@@ -114,7 +120,50 @@ func (s *Service) GetGroup(gid int) (resp *apiModel.GetGroupResponse, err error)
Start
:
task
.
Start
,
End
:
task
.
End
,
Daily
:
task
.
Daily
==
1
,
TweetId
:
task
.
TweetId
,
})
}
return
}
func
(
s
*
Service
)
GetGroupList
(
page
,
pageSize
int
)
(
resp
*
apiModel
.
GetGroupListResponse
,
err
error
)
{
resp
=
&
apiModel
.
GetGroupListResponse
{}
list
,
count
,
err
:=
s
.
d
.
GetGroupList
(
page
,
pageSize
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"get group list error"
)
return
}
resp
.
TotalCount
=
count
resp
.
Items
=
make
([]
*
apiModel
.
GetGroupResponse
,
0
)
for
_
,
v
:=
range
list
{
resp
.
Items
=
append
(
resp
.
Items
,
&
apiModel
.
GetGroupResponse
{
GroupId
:
v
.
Id
,
ProjectId
:
v
.
ProjectId
,
Description
:
v
.
Description
,
})
tasks
,
err
:=
s
.
d
.
GetGroupTasks
(
v
.
Id
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"get group tasks error"
)
return
resp
,
err
}
log
.
Error
(
"len: "
,
len
(
tasks
))
for
_
,
task
:=
range
tasks
{
resp
.
Items
[
len
(
resp
.
Items
)
-
1
]
.
Tasks
=
append
(
resp
.
Items
[
len
(
resp
.
Items
)
-
1
]
.
Tasks
,
apiModel
.
Task
{
TaskId
:
task
.
Id
,
Platform
:
task
.
Platform
,
Action
:
task
.
Action
,
Url
:
task
.
Url
,
Description
:
task
.
Description
,
Reward
:
task
.
Reward
,
Start
:
task
.
Start
,
End
:
task
.
End
,
Daily
:
task
.
Daily
==
1
,
TweetId
:
task
.
TweetId
,
})
}
}
return
}
service/project.go
View file @
2a47dede
...
...
@@ -8,49 +8,70 @@ import (
log
"github.com/sirupsen/logrus"
)
func
(
s
*
Service
)
CreateProject
(
req
*
apiModel
.
CreateProjectRequest
)
(
pid
int
,
err
error
)
{
tweetId
,
tweetHandle
,
tweetName
,
err
:=
s
.
d
.
CreateTwitterProject
(
req
.
TweeterAPIKey
,
req
.
TweeterAPISecret
,
req
.
TweeterAccessToken
,
req
.
TweeterAccessSecret
,
req
.
TweeterToken
,
req
.
ProjectName
)
func
(
s
*
Service
)
CreateProject
(
req
*
apiModel
.
CreateProjectRequest
)
(
resp
*
apiModel
.
CreateProjectResponse
,
err
error
)
{
resp
=
&
apiModel
.
CreateProjectResponse
{}
twitterUserId
,
twitterHandle
,
twitterName
,
err
:=
s
.
d
.
CreateTwitterProject
(
req
.
TwitterAPIKey
,
req
.
TwitterAPISecret
,
req
.
TwitterAccessToken
,
req
.
TwitterAccessSecret
,
req
.
TwitterToken
,
req
.
ProjectName
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"create twitter project error"
)
return
}
tgTitle
,
tgUsername
,
err
:=
s
.
d
.
GetTGGroupInfo
(
req
.
TelegramChatId
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"get telegram group info error"
)
return
}
p
:=
&
dbModel
.
Project
{
Id
:
util
.
GenFlakeID
(),
Name
:
req
.
ProjectName
,
Description
:
req
.
Description
,
TweeterAPIKey
:
req
.
TweeterAPIKey
,
TweeterAPISecret
:
req
.
TweeterAPISecret
,
TweeterAccessToken
:
req
.
TweeterAccessToken
,
TweeterAccessSecret
:
req
.
TweeterAccessSecret
,
TweeterToken
:
req
.
TweeterToken
,
TweeterHandle
:
tweetHandle
,
TweeterName
:
tweetName
,
TweeterUserId
:
tweetId
,
TelegramChatId
:
req
.
TelegramChatId
,
Id
:
util
.
GenFlakeID
(),
Name
:
req
.
ProjectName
,
Description
:
req
.
Description
,
TwitterAPIKey
:
req
.
TwitterAPIKey
,
TwitterAPISecret
:
req
.
TwitterAPISecret
,
TwitterAccessToken
:
req
.
TwitterAccessToken
,
TwitterAccessSecret
:
req
.
TwitterAccessSecret
,
TwitterToken
:
req
.
TwitterToken
,
TwitterHandle
:
twitterHandle
,
TwitterName
:
twitterName
,
TwitterUserId
:
twitterUserId
,
TelegramChatId
:
req
.
TelegramChatId
,
TelegramChatTitle
:
tgTitle
,
TelegramChatUsername
:
tgUsername
,
}
err
=
s
.
d
.
CreateProject
(
p
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"create project error"
)
return
}
return
p
.
Id
,
nil
resp
.
TelegramChatUsername
=
tgUsername
resp
.
TelegramChatTitle
=
tgTitle
resp
.
TwitterName
=
twitterName
resp
.
TwitterHandle
=
twitterHandle
resp
.
ProjectId
=
p
.
Id
return
}
func
(
s
*
Service
)
GetProjectList
(
page
,
pageSize
int
)
(
resp
[]
*
apiModel
.
GetProjectResponse
,
err
error
)
{
list
,
err
:=
s
.
d
.
GetProjectList
(
page
,
pageSize
)
func
(
s
*
Service
)
GetProjectList
(
page
,
pageSize
int
)
(
resp
*
apiModel
.
GetProjectListResponse
,
err
error
)
{
resp
=
&
apiModel
.
GetProjectListResponse
{}
list
,
count
,
err
:=
s
.
d
.
GetProjectList
(
page
,
pageSize
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"get project list error"
)
return
}
resp
=
make
([]
*
apiModel
.
GetProjectResponse
,
0
)
resp
.
TotalCount
=
count
resp
.
Items
=
make
([]
*
apiModel
.
GetProjectResponse
,
0
)
for
_
,
v
:=
range
list
{
resp
=
append
(
resp
,
&
apiModel
.
GetProjectResponse
{
TelegramChatId
:
v
.
TelegramChatId
,
TwitterHandle
:
v
.
TweeterHandle
,
TweeterName
:
v
.
TweeterName
,
TweeterUserId
:
v
.
TweeterUserId
,
Description
:
v
.
Description
,
resp
.
Items
=
append
(
resp
.
Items
,
&
apiModel
.
GetProjectResponse
{
ProjectId
:
v
.
Id
,
TelegramChatId
:
v
.
TelegramChatId
,
TwitterHandle
:
v
.
TwitterHandle
,
TwitterName
:
v
.
TwitterName
,
TwitterUserId
:
v
.
TwitterUserId
,
Description
:
v
.
Description
,
TelegramChatTitle
:
v
.
TelegramChatTitle
,
TelegramChatUsername
:
v
.
TelegramChatUsername
,
ProjectName
:
v
.
Name
,
})
}
return
...
...
@@ -68,16 +89,18 @@ func (s *Service) GetProject(pid int) (resp *apiModel.GetProjectResponse, err er
}
return
&
apiModel
.
GetProjectResponse
{
TelegramChatId
:
p
.
TelegramChatId
,
TwitterHandle
:
p
.
TweeterHandle
,
TweeterName
:
p
.
TweeterName
,
TweeterUserId
:
p
.
TweeterUserId
,
ProjectName
:
p
.
Name
,
Description
:
p
.
Description
,
// TweeterAPIKey: p.TweeterAPIKey,
// TweeterAPISecret: p.TweeterAPISecret,
// TweeterAccessToken: p.TweeterAccessToken,
// TweeterAccessSecret: p.TweeterAccessSecret,
// TweeterToken: p.TweeterToken,
TelegramChatId
:
p
.
TelegramChatId
,
TelegramChatUsername
:
p
.
TelegramChatUsername
,
TelegramChatTitle
:
p
.
TelegramChatTitle
,
TwitterHandle
:
p
.
TwitterHandle
,
TwitterName
:
p
.
TwitterName
,
TwitterUserId
:
p
.
TwitterUserId
,
ProjectName
:
p
.
Name
,
Description
:
p
.
Description
,
// TwitterAPIKey: p.TwitterAPIKey,
// TwitterAPISecret: p.TwitterAPISecret,
// TwitterAccessToken: p.TwitterAccessToken,
// TwitterAccessSecret: p.TwitterAccessSecret,
// TwitterToken: p.TwitterToken,
},
nil
}
service/task.go
View file @
2a47dede
...
...
@@ -19,6 +19,7 @@ func (s *Service) CheckTask(taskId int, userId string) (exist, done bool, expire
exist
=
false
return
}
log
.
Debugf
(
"task: %+v"
,
task
)
// 超出时间后只查询不再更新状态
if
int64
(
task
.
Start
)
>
time
.
Now
()
.
Unix
()
||
int64
(
task
.
End
)
<
time
.
Now
()
.
Unix
()
{
...
...
@@ -90,9 +91,9 @@ func (s *Service) SyncTask(taskId int, userId string) (done bool, err error) {
switch
task
.
Action
{
case
constant
.
TaskActionFollow
:
followed
,
err
:=
s
.
d
.
CheckTw
eeterFollow
(
task
.
Twee
terUserId
,
twitterUserId
)
followed
,
err
:=
s
.
d
.
CheckTw
itterFollow
(
task
.
Twit
terUserId
,
twitterUserId
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"check tw
ee
ter follow error"
)
log
.
WithError
(
err
)
.
Error
(
"check tw
it
ter follow error"
)
return
false
,
err
}
if
!
followed
{
...
...
@@ -107,12 +108,12 @@ func (s *Service) SyncTask(taskId int, userId string) (done bool, err error) {
case
constant
.
TaskActionLike
,
constant
.
TaskActionRetweet
,
constant
.
TaskActionReply
:
var
taskDone
bool
if
task
.
Action
==
constant
.
TaskActionLike
{
taskDone
,
err
=
s
.
d
.
CheckTw
ee
terLike
(
task
.
TweetId
,
twitterUserId
,
0
,
0
)
taskDone
,
err
=
s
.
d
.
CheckTw
it
terLike
(
task
.
TweetId
,
twitterUserId
,
0
,
0
)
}
else
{
taskDone
,
err
=
s
.
d
.
CheckTw
ee
terRetweet
(
task
.
TweetId
,
twitterUserId
,
0
,
0
)
taskDone
,
err
=
s
.
d
.
CheckTw
it
terRetweet
(
task
.
TweetId
,
twitterUserId
,
0
,
0
)
}
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Errorf
(
"check tw
ee
ter %s error"
,
task
.
Action
)
log
.
WithError
(
err
)
.
Errorf
(
"check tw
it
ter %s error"
,
task
.
Action
)
return
false
,
err
}
if
!
taskDone
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment