Add helpful comments
This commit is contained in:
41
keyrcbot.go
41
keyrcbot.go
@ -12,21 +12,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dev = false
|
dev = false
|
||||||
k = keybase.NewKeybase()
|
k = keybase.NewKeybase()
|
||||||
channel keybase.Channel
|
channel keybase.Channel
|
||||||
irc *hbot.Bot
|
irc *hbot.Bot
|
||||||
linkName = "halium"
|
botNick = "keyrcbot" // Set this for IRC Nickname
|
||||||
botNick = "keyrcbot"
|
serv = flag.String("server", "chat.freenode.net:6667", "hostname and port") // Set this for whatever server you're using
|
||||||
serv = flag.String("server", "chat.freenode.net:6667", "hostname and port")
|
nick = flag.String("nick", botNick, "nickname for the bot")
|
||||||
nick = flag.String("nick", botNick, "nickname for the bot")
|
logOpts = loggy.LogOpts{
|
||||||
logOpts = loggy.LogOpts{
|
OutFile: "irc.log", // Set this for Logging output to file
|
||||||
OutFile: "irc.log",
|
KBTeam: "nightmarehaus.bots", // Set this for Logging output to Keybase team
|
||||||
KBTeam: "nightmarehaus.bots",
|
KBChann: "general", // Required for logging to Keybase Team, can be any channel
|
||||||
KBChann: "general",
|
ProgName: "irclink", // Also required for logging to Keybase team
|
||||||
ProgName: "irclink",
|
Level: 3, // 1 = Critical only, 2 = Errors, 3 = include Warnings, 4 = Debug, 5 = Info
|
||||||
Level: 3,
|
UseStdout: true, // Set to true to also display to stdout
|
||||||
UseStdout: true,
|
|
||||||
}
|
}
|
||||||
log = loggy.NewLogger(logOpts)
|
log = loggy.NewLogger(logOpts)
|
||||||
)
|
)
|
||||||
@ -37,8 +36,8 @@ func main() {
|
|||||||
log.LogPanic("You are not logged in.")
|
log.LogPanic("You are not logged in.")
|
||||||
}
|
}
|
||||||
channel.MembersType = keybase.TEAM
|
channel.MembersType = keybase.TEAM
|
||||||
channel.Name = "keyrc"
|
channel.Name = "keyrc" // The team you're linking to IRC
|
||||||
channel.TopicName = "general"
|
channel.TopicName = "general" // The control channel (will be ignored for all except commands)
|
||||||
sendChat("Link starting", "general")
|
sendChat("Link starting", "general")
|
||||||
go setupIRC()
|
go setupIRC()
|
||||||
k.Run(func(api keybase.ChatAPI) {
|
k.Run(func(api keybase.ChatAPI) {
|
||||||
@ -50,7 +49,7 @@ func setupIRC() {
|
|||||||
var err error
|
var err error
|
||||||
saslOption := func(bot *hbot.Bot) {
|
saslOption := func(bot *hbot.Bot) {
|
||||||
bot.SASL = true
|
bot.SASL = true
|
||||||
bot.Password = os.Getenv("IRC_PASS") // TODO: Set this
|
bot.Password = os.Getenv("IRC_PASS") // Set this to authenticate with IRC
|
||||||
}
|
}
|
||||||
hijackSession := func(bot *hbot.Bot) {
|
hijackSession := func(bot *hbot.Bot) {
|
||||||
bot.HijackSession = true
|
bot.HijackSession = true
|
||||||
@ -72,7 +71,7 @@ func setupKeybaseLinks() {
|
|||||||
log.LogError(fmt.Sprintf("Err was not nil from ChatList() in setupKeybaseLinks(), ```%+v```", err))
|
log.LogError(fmt.Sprintf("Err was not nil from ChatList() in setupKeybaseLinks(), ```%+v```", err))
|
||||||
}
|
}
|
||||||
for _, s := range api.Result.Conversations {
|
for _, s := range api.Result.Conversations {
|
||||||
if s.Channel.MembersType == keybase.TEAM && s.Channel.Name == channel.Name && s.Channel.TopicName != "general" {
|
if s.Channel.MembersType == keybase.TEAM && s.Channel.Name == channel.Name && s.Channel.TopicName != channel.TopicName {
|
||||||
addIrcTrigger(s.Channel.TopicName)
|
addIrcTrigger(s.Channel.TopicName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,14 +125,14 @@ func handleMessage(api keybase.ChatAPI) {
|
|||||||
if len(parts) == 3 {
|
if len(parts) == 3 {
|
||||||
if parts[0] == fmt.Sprintf("@%s", k.Username) {
|
if parts[0] == fmt.Sprintf("@%s", k.Username) {
|
||||||
if parts[1] == "join" {
|
if parts[1] == "join" {
|
||||||
if api.Msg.Channel.TopicName == "general" && parts[2] != "general" {
|
if api.Msg.Channel.TopicName == channel.TopicName && parts[2] != channel.TopicName {
|
||||||
addIrcTrigger(parts[2])
|
addIrcTrigger(parts[2])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if api.Msg.Channel.TopicName == "general" {
|
if api.Msg.Channel.TopicName == channel.TopicName {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
irc.Msg(fmt.Sprintf("#%s", api.Msg.Channel.TopicName), fmt.Sprintf("[%s]: %s", msgSender, msgBody))
|
irc.Msg(fmt.Sprintf("#%s", api.Msg.Channel.TopicName), fmt.Sprintf("[%s]: %s", msgSender, msgBody))
|
||||||
|
|||||||
Reference in New Issue
Block a user