forked from git.klmp200.net/ALFRED
Add specific chat data and pass chaos to an entire day
This commit is contained in:
parent
31c4a24de0
commit
b781ae9f53
5 changed files with 104 additions and 26 deletions
|
@ -2,7 +2,7 @@
|
|||
* @Author: Bartuccio Antoine
|
||||
* @Date: 2018-07-25 18:51:38
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2018-07-26 22:52:51
|
||||
* @Last Modified time: 2018-07-27 16:49:59
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
@ -15,17 +15,10 @@ import (
|
|||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type sjw struct {
|
||||
usable bool
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
var client *twitter.Client
|
||||
var sjw_usable sjw
|
||||
|
||||
func initTwitter() {
|
||||
config := oauth1.NewConfig(
|
||||
|
@ -39,7 +32,6 @@ func initTwitter() {
|
|||
|
||||
http_client := config.Client(oauth1.NoContext, token)
|
||||
client = twitter.NewClient(http_client)
|
||||
sjw_usable = sjw{usable: true}
|
||||
}
|
||||
|
||||
func testOrInitTwitter() {
|
||||
|
@ -52,13 +44,6 @@ func twitterCommunicationError(m *tb.Message) {
|
|||
shared.Bot.Send(m.Chat, "Désolé, les serveurs de twitter sont injoignables.")
|
||||
}
|
||||
|
||||
func unlockSjw() {
|
||||
time.Sleep(time.Hour)
|
||||
sjw_usable.mutex.Lock()
|
||||
sjw_usable.usable = true
|
||||
sjw_usable.mutex.Unlock()
|
||||
}
|
||||
|
||||
func LastTrumpTweet(m *tb.Message) {
|
||||
testOrInitTwitter()
|
||||
user, _, err := client.Users.Show(&twitter.UserShowParams{ScreenName: "realDonaldTrump"})
|
||||
|
@ -101,13 +86,21 @@ func TwitterTrends(m *tb.Message) {
|
|||
|
||||
func TwitterSJW(m *tb.Message) {
|
||||
testOrInitTwitter()
|
||||
sjw_usable.mutex.Lock()
|
||||
defer sjw_usable.mutex.Unlock()
|
||||
if !sjw_usable.usable {
|
||||
shared.Bot.Send(m.Chat, "Arioch ne répondra pas à votre appel.")
|
||||
return
|
||||
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
|
||||
}
|
||||
}
|
||||
sjw_usable.usable = false
|
||||
shared.ChatData.Set(m.Chat.ID, "last chaos use", time.Now())
|
||||
|
||||
tweets, _, err := client.Search.Tweets(&twitter.SearchTweetParams{
|
||||
Query: "#SJW",
|
||||
})
|
||||
|
@ -118,5 +111,4 @@ func TwitterSJW(m *tb.Message) {
|
|||
for _, tweet := range tweets.Statuses {
|
||||
shared.Bot.Send(m.Chat, tweet.Text)
|
||||
}
|
||||
go unlockSjw()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue