mirror of
https://git.klmp200.net/ALFRED/ALFRED.git
synced 2025-01-18 18:46:44 +01:00
115 lines
2.6 KiB
Go
115 lines
2.6 KiB
Go
/*
|
|
* @Author: Bartuccio Antoine
|
|
* @Date: 2018-07-25 18:51:38
|
|
* @Last Modified by: klmp200
|
|
* @Last Modified time: 2018-07-27 16:49:59
|
|
*/
|
|
|
|
package commands
|
|
|
|
import (
|
|
"../settings"
|
|
"../shared"
|
|
"github.com/dghubble/go-twitter/twitter"
|
|
"github.com/dghubble/oauth1"
|
|
tb "gopkg.in/tucnak/telebot.v2"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
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 twitterCommunicationError(m *tb.Message) {
|
|
shared.Bot.Send(m.Chat, "Désolé, les serveurs de twitter sont injoignables.")
|
|
}
|
|
|
|
func LastTrumpTweet(m *tb.Message) {
|
|
testOrInitTwitter()
|
|
user, _, err := client.Users.Show(&twitter.UserShowParams{ScreenName: "realDonaldTrump"})
|
|
if err != nil {
|
|
twitterCommunicationError(m)
|
|
return
|
|
}
|
|
timeline, _, err := client.Timelines.UserTimeline(&twitter.UserTimelineParams{ScreenName: "realDonaldTrump"})
|
|
if err != nil {
|
|
twitterCommunicationError(m)
|
|
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, " "))
|
|
}
|
|
|
|
func TwitterTrends(m *tb.Message) {
|
|
testOrInitTwitter()
|
|
trends, _, err := client.Trends.Place(int64(615702), nil)
|
|
if err != nil {
|
|
twitterCommunicationError(m)
|
|
return
|
|
}
|
|
message := "Voici les dernières tendances en France"
|
|
for _, trend := range trends[0].Trends {
|
|
message += "\n" + trend.Name
|
|
}
|
|
shared.Bot.Send(m.Chat, message)
|
|
}
|
|
|
|
func TwitterSJW(m *tb.Message) {
|
|
testOrInitTwitter()
|
|
last_use, exists := shared.ChatData.Get(m.Chat.ID, "last chaos use")
|
|
if exists {
|
|
var date time.Time
|
|
if _, is_string := last_use.(string); is_string {
|
|
date, _ = time.Parse(time.RFC3339, last_use.(string))
|
|
} else {
|
|
date = last_use.(time.Time)
|
|
}
|
|
if time.Now().Before(date.Add(time.Hour * 24)) {
|
|
shared.Bot.Send(m.Chat, "Arioch ne répondra pas à votre appel.")
|
|
return
|
|
}
|
|
}
|
|
shared.ChatData.Set(m.Chat.ID, "last chaos use", time.Now())
|
|
|
|
tweets, _, err := client.Search.Tweets(&twitter.SearchTweetParams{
|
|
Query: "#SJW",
|
|
})
|
|
if err != nil {
|
|
twitterCommunicationError(m)
|
|
return
|
|
}
|
|
for _, tweet := range tweets.Statuses {
|
|
shared.Bot.Send(m.Chat, tweet.Text)
|
|
}
|
|
}
|