forked from git.klmp200.net/ALFRED
Limit Chaos to once an hour
This commit is contained in:
parent
368ac57b04
commit
31c4a24de0
@ -2,7 +2,7 @@
|
|||||||
* @Author: Bartuccio Antoine
|
* @Author: Bartuccio Antoine
|
||||||
* @Date: 2018-07-25 18:51:38
|
* @Date: 2018-07-25 18:51:38
|
||||||
* @Last Modified by: klmp200
|
* @Last Modified by: klmp200
|
||||||
* @Last Modified time: 2018-07-26 22:35:14
|
* @Last Modified time: 2018-07-26 22:52:51
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package commands
|
package commands
|
||||||
@ -15,9 +15,17 @@ import (
|
|||||||
tb "gopkg.in/tucnak/telebot.v2"
|
tb "gopkg.in/tucnak/telebot.v2"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type sjw struct {
|
||||||
|
usable bool
|
||||||
|
mutex sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
var client *twitter.Client
|
var client *twitter.Client
|
||||||
|
var sjw_usable sjw
|
||||||
|
|
||||||
func initTwitter() {
|
func initTwitter() {
|
||||||
config := oauth1.NewConfig(
|
config := oauth1.NewConfig(
|
||||||
@ -31,6 +39,7 @@ func initTwitter() {
|
|||||||
|
|
||||||
http_client := config.Client(oauth1.NoContext, token)
|
http_client := config.Client(oauth1.NoContext, token)
|
||||||
client = twitter.NewClient(http_client)
|
client = twitter.NewClient(http_client)
|
||||||
|
sjw_usable = sjw{usable: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testOrInitTwitter() {
|
func testOrInitTwitter() {
|
||||||
@ -43,6 +52,13 @@ func twitterCommunicationError(m *tb.Message) {
|
|||||||
shared.Bot.Send(m.Chat, "Désolé, les serveurs de twitter sont injoignables.")
|
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) {
|
func LastTrumpTweet(m *tb.Message) {
|
||||||
testOrInitTwitter()
|
testOrInitTwitter()
|
||||||
user, _, err := client.Users.Show(&twitter.UserShowParams{ScreenName: "realDonaldTrump"})
|
user, _, err := client.Users.Show(&twitter.UserShowParams{ScreenName: "realDonaldTrump"})
|
||||||
@ -85,6 +101,13 @@ func TwitterTrends(m *tb.Message) {
|
|||||||
|
|
||||||
func TwitterSJW(m *tb.Message) {
|
func TwitterSJW(m *tb.Message) {
|
||||||
testOrInitTwitter()
|
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
|
||||||
|
}
|
||||||
|
sjw_usable.usable = false
|
||||||
tweets, _, err := client.Search.Tweets(&twitter.SearchTweetParams{
|
tweets, _, err := client.Search.Tweets(&twitter.SearchTweetParams{
|
||||||
Query: "#SJW",
|
Query: "#SJW",
|
||||||
})
|
})
|
||||||
@ -95,4 +118,5 @@ func TwitterSJW(m *tb.Message) {
|
|||||||
for _, tweet := range tweets.Statuses {
|
for _, tweet := range tweets.Statuses {
|
||||||
shared.Bot.Send(m.Chat, tweet.Text)
|
shared.Bot.Send(m.Chat, tweet.Text)
|
||||||
}
|
}
|
||||||
|
go unlockSjw()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user