Last active
February 29, 2016 18:10
-
-
Save Mutjake/0c66a1901d7abdee721d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/thoj/go-ircevent" | |
"strings" | |
"time" | |
"strconv" | |
) | |
var next_url = make(chan string) | |
var secret_token = "" | |
var timer_str = "" | |
var timer_count = 0 | |
func irc_loop() { | |
bot_nick := "" | |
bot_realname := "" | |
irc_server_and_port := "" | |
irc_channel := "" | |
ircobj := irc.IRC(bot_nick, bot_realname) | |
ircobj.Connect(irc_server_and_port) | |
ircobj.Join(irc_channel) | |
ircobj.AddCallback("PRIVMSG", func(event *irc.Event) { | |
if event.Arguments[0] == bot_nick { | |
payload := event.Message() | |
if strings.HasPrefix(payload, secret_token) { | |
next_url <- payload[len(secret_token):len(payload)] | |
} else if strings.HasPrefix(payload, timer_str) && strings.Contains(payload, " ") { | |
num_str := payload[len(timer_str):strings.Index(payload, " ")] | |
time_num, err2 := strconv.Atoi(num_str) | |
if err2 == nil && timer_count < 10 { | |
timer_count++ | |
go timed_paste(payload[strings.Index(payload, " ")+1:len(payload)], time_num) | |
} | |
} | |
} | |
}); | |
do_loop := true | |
for do_loop { | |
ircobj.Action(irc_channel, <- next_url) | |
} | |
} | |
func timed_paste(payload string, waitTime int) { | |
time.Sleep(time.Second * time.Duration(waitTime)) | |
next_url <- payload | |
timer_count-- | |
} | |
func main() { | |
irc_loop() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment