conn.Privmsgf(targetChannel,"Thanks for inviting me, %s! I am %s, the friendly bot that shows information about links posted in this channel. I hope I can be of great help for everyone here in %s! :)",sourceNick,conn.GetNick(),targetChannel)
log.Printf("WARNING: Timed out waiting for us to join %s as we got invited",targetChannel)
breakjoinWaitLoop
}
}
}(e.Nick,e.Arguments[1])
conn.Join(e.Arguments[1])
})
conn.AddCallback("PRIVMSG",func(e*irc.Event){
gofunc(event*irc.Event){
//sender := event.Nick
target:=event.Arguments[0]
isChannel:=true
ifstrings.EqualFold(target,conn.GetNick()){
// Private message to us!
target=event.Nick
isChannel=false
}
ifstrings.EqualFold(target,conn.GetNick()){
// Emergency switch to avoid endless loop,
// dropping all messages from the bot to the bot!
log.Printf("BUG - Emergency switch, caught message from bot to bot: %s",event.Arguments)
return
}
msg:=stripIrcFormatting(event.Message())
log.Printf("<%s @ %s> %s",event.Nick,target,msg)
urlStr:=xurls.Relaxed.FindString(msg)
switch{
case!isChannel:
// Explain who we are and what we do
conn.Privmsgf(target,"Hi, I parse links people post to chat rooms to give some information about them. I also allow people to search for YouTube videos and SoundCloud sounds straight from IRC. If you have questions or got any bug reports, please direct them to Icedream in #MediaLink, thank you!")
caselen(urlStr)>0:// URL?
// Parse URL!
u,err:=url.ParseRequestURI(urlStr)
iferr!=nil{
u,err=url.ParseRequestURI("http://"+urlStr)
}
iferr!=nil{
log.Print(err)
break
}
// Check if this URL has been recently parsed before (antiflood)
shouldIgnore:=m.TrackUrl(target,u)
ifshouldIgnore{
log.Printf("WARNING: URL antiflood triggered, dropping URL for %s: %s",target,u)