CTF2021/irc_bot
Archived
4
0

Rename env variables

This commit is contained in:
Denis Zheleztsov 2021-01-17 12:50:12 +03:00
parent 19950face6
commit 0d6e2457b5
2 changed files with 45 additions and 25 deletions

View File

@ -1,15 +1,17 @@
# irc_bot
About a cats
About cats
Inspired from https://github.com/go-chat-bot/plugins/blob/master/catfacts/catfacts.go
```go
go build
```
```sh
export CTF2021NICK="HaX0r666"
export CTF2021PASS="passw0rd"
export CTF2021URL="localhost:6667"
./ctf2021_ircbot
export IRC_NICK="HaX0r666"
export IRC_USER="mamin_simpotyaga"
export IRC_PASS="passw0rd"
export IRC_URL="localhost:6667"
./ctf2021_ircbot | tee bot.log
```

56
main.go
View File

@ -17,7 +17,7 @@ import (
)
var channel = "#ctf"
var sendWelcome = ""
var sendHi = ""
const (
pattern = "(?i)\\b(cat|gato|miau|meow|garfield|lolcat|кот|кошк)[s|z]{0,1}\\b"
@ -26,6 +26,16 @@ const (
gifPrefix = "Meow! Here's a gif: %s ^_^"
)
// environment variables
const (
userEnv = "IRC_USER"
nickEnv = "IRC_NICK"
himsgEnv = "IRC_SEY_HI"
passEnv = "IRC_PASS"
chanEnv = "IRC_CHAN"
urlEnv = "IRC_URL"
)
type catFact struct {
Fact string `json:"fact"`
Length int `json:"length"`
@ -81,25 +91,20 @@ func (s *stats) printStats(e *irc.Event) {
s.realStats(e)
}
func main() {
nick := os.Getenv("CTF2021NICK")
irccon := irc.IRC(nick, os.Getenv("CTF2021USER"))
s := newStats()
irccon.VerboseCallbackHandler = false
irccon.Debug = false
irccon.UseTLS = false
func addCallbacks(irccon *irc.Connection, s *stats) {
irccon.AddCallback("001", func(e *irc.Event) {
log.Println("Welcome message:", e.Message())
e.Connection.Privmsg("nickserv", "identify "+os.Getenv("CTF2021PASS"))
// Login
e.Connection.Privmsg("nickserv", "identify "+os.Getenv(passEnv))
if sendWelcome != "" {
e.Connection.Join(channel)
e.Connection.Privmsg(channel, `I'm a cat bot!`)
e.Connection.Privmsg(channel, `Inspired from https://github.com/go-chat-bot/plugins/blob/master/catfacts/catfacts.go`)
// Join to channel
e.Connection.Join(channel)
// Greetings
if sendHi != "" {
e.Connection.Privmsg(channel, `Hi!`)
e.Connection.Privmsg(channel, `I'm a cat facts bot!`)
e.Connection.Privmsg(channel, `Try cat /etc/passwd :p`)
e.Connection.Privmsg(channel, `Source code and issue tracker: https://gitea.difrex.ru/CTF2021/irc_bot`)
e.Connection.Privmsg(channel, `Now with gifs! ^_^`)
@ -111,8 +116,21 @@ func main() {
s.addUser(e.Nick)
doCommand(e.Message(), e, s)
})
}
err := irccon.Connect(os.Getenv("CTF2021URL"))
func main() {
nick := os.Getenv(nickEnv)
irccon := irc.IRC(nick, os.Getenv(userEnv))
s := newStats()
irccon.VerboseCallbackHandler = false
irccon.Debug = false
irccon.UseTLS = false
addCallbacks(irccon, s)
err := irccon.Connect(os.Getenv(urlEnv))
if err != nil {
fmt.Printf("Err %s", err)
return
@ -195,10 +213,10 @@ func catFacts(con *irc.Connection) (string, error) {
}
func init() {
ch := os.Getenv("CTF2021CHANNEL")
ch := os.Getenv(chanEnv)
if ch != "" {
channel = ch
}
sendWelcome = os.Getenv("CTF2021WC")
sendHi = os.Getenv(himsgEnv)
}