forked from git.klmp200.net/ALFRED
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
/*
|
|
* @Author: Bartuccio Antoine
|
|
* @Date: 2018-07-25 18:51:38
|
|
* @Last Modified by: klmp200
|
|
* @Last Modified time: 2018-07-25 22:51:50
|
|
*/
|
|
|
|
package commands
|
|
|
|
import (
|
|
"../settings"
|
|
"../shared"
|
|
"github.com/dghubble/go-twitter/twitter"
|
|
"github.com/dghubble/oauth1"
|
|
tb "gopkg.in/tucnak/telebot.v2"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
var client *twitter.Client
|
|
|
|
func initTwitter() {
|
|
config := oauth1.NewConfig(
|
|
settings.Settings["twitter consumer key"].(string),
|
|
settings.Settings["twitter consumer secret"].(string),
|
|
)
|
|
token := oauth1.NewToken(
|
|
settings.Settings["twitter access token"].(string),
|
|
settings.Settings["twitter access secret"].(string),
|
|
)
|
|
|
|
http_client := config.Client(oauth1.NoContext, token)
|
|
client = twitter.NewClient(http_client)
|
|
}
|
|
|
|
func testOrInitTwitter() {
|
|
if client == nil {
|
|
initTwitter()
|
|
}
|
|
}
|
|
|
|
func LastTrumpTweet(m *tb.Message) {
|
|
testOrInitTwitter()
|
|
user, _, err := client.Users.Show(&twitter.UserShowParams{ScreenName: "realDonaldTrump"})
|
|
if err != nil {
|
|
shared.Bot.Send(m.Chat, "Désolé, les serveurs de twitter sont injoignables.")
|
|
return
|
|
}
|
|
timeline, _, err := client.Timelines.UserTimeline(&twitter.UserTimelineParams{ScreenName: "realDonaldTrump"})
|
|
if err != nil {
|
|
shared.Bot.Send(m.Chat, "Désolé, les serveurs de twitter sont injoignables.")
|
|
return
|
|
}
|
|
response := []string{
|
|
user.Name,
|
|
"\nFollowers : ",
|
|
strconv.Itoa(user.FollowersCount),
|
|
"\nStatus : ",
|
|
user.Description,
|
|
"\n ---",
|
|
"\n" + timeline[0].Text,
|
|
"\n ---",
|
|
"\n" + timeline[0].Source,
|
|
}
|
|
shared.Bot.Send(m.Chat, strings.Join(response, " "))
|
|
}
|