mirror of
https://git.klmp200.net/ALFRED/ALFRED.git
synced 2025-01-18 10:36:44 +01:00
Trump
This commit is contained in:
parent
f5c77bff99
commit
28a30c2d25
@ -2,7 +2,7 @@
|
||||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-23 15:24:22
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-24 20:55:53
|
||||
* @Last Modified time: 2018-07-25 19:27:21
|
||||
*/
|
||||
|
||||
package main
|
||||
@ -26,6 +26,7 @@ func main() {
|
||||
"/setgender": commands.SetGender,
|
||||
"/gender": commands.Gender,
|
||||
"/roll": commands.Dice,
|
||||
"/trump": commands.LastTrumpTweet,
|
||||
}
|
||||
|
||||
if err := settings.LoadSettings("settings.json", "settings_custom.json"); err != nil {
|
||||
|
66
commands/twitter.go
Normal file
66
commands/twitter.go
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* @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, " "))
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
{
|
||||
"token": "INSERT TOKEN HERE",
|
||||
"twitter access token": "INSERT TOKEN HERE",
|
||||
"twitter access secret": "INSERT TOKEN HERE",
|
||||
"twitter consumer key": "INSERT TOKEN HERE",
|
||||
"twitter consumer secret": "INSERT TOKEN HERE",
|
||||
"history size": 10,
|
||||
"history file": "history.json",
|
||||
"users file": "users.json"
|
||||
|
Loading…
Reference in New Issue
Block a user