Rename env variables
This commit is contained in:
parent
19950face6
commit
0d6e2457b5
14
README.md
14
README.md
@ -1,15 +1,17 @@
|
|||||||
# irc_bot
|
# irc_bot
|
||||||
|
|
||||||
About a cats
|
About cats
|
||||||
|
|
||||||
|
Inspired from https://github.com/go-chat-bot/plugins/blob/master/catfacts/catfacts.go
|
||||||
|
|
||||||
```go
|
```go
|
||||||
go build
|
go build
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
export CTF2021NICK="HaX0r666"
|
export IRC_NICK="HaX0r666"
|
||||||
export CTF2021PASS="passw0rd"
|
export IRC_USER="mamin_simpotyaga"
|
||||||
export CTF2021URL="localhost:6667"
|
export IRC_PASS="passw0rd"
|
||||||
./ctf2021_ircbot
|
export IRC_URL="localhost:6667"
|
||||||
|
./ctf2021_ircbot | tee bot.log
|
||||||
```
|
```
|
||||||
|
|
||||||
|
54
main.go
54
main.go
@ -17,7 +17,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var channel = "#ctf"
|
var channel = "#ctf"
|
||||||
var sendWelcome = ""
|
var sendHi = ""
|
||||||
|
|
||||||
const (
|
const (
|
||||||
pattern = "(?i)\\b(cat|gato|miau|meow|garfield|lolcat|кот|кошк)[s|z]{0,1}\\b"
|
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 ^_^"
|
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 {
|
type catFact struct {
|
||||||
Fact string `json:"fact"`
|
Fact string `json:"fact"`
|
||||||
Length int `json:"length"`
|
Length int `json:"length"`
|
||||||
@ -81,25 +91,20 @@ func (s *stats) printStats(e *irc.Event) {
|
|||||||
s.realStats(e)
|
s.realStats(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func addCallbacks(irccon *irc.Connection, s *stats) {
|
||||||
nick := os.Getenv("CTF2021NICK")
|
|
||||||
irccon := irc.IRC(nick, os.Getenv("CTF2021USER"))
|
|
||||||
|
|
||||||
s := newStats()
|
|
||||||
|
|
||||||
irccon.VerboseCallbackHandler = false
|
|
||||||
irccon.Debug = false
|
|
||||||
irccon.UseTLS = false
|
|
||||||
|
|
||||||
irccon.AddCallback("001", func(e *irc.Event) {
|
irccon.AddCallback("001", func(e *irc.Event) {
|
||||||
log.Println("Welcome message:", e.Message())
|
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 != "" {
|
// Join to channel
|
||||||
e.Connection.Join(channel)
|
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`)
|
// 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, `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, `Source code and issue tracker: https://gitea.difrex.ru/CTF2021/irc_bot`)
|
||||||
e.Connection.Privmsg(channel, `Now with gifs! ^_^`)
|
e.Connection.Privmsg(channel, `Now with gifs! ^_^`)
|
||||||
@ -111,8 +116,21 @@ func main() {
|
|||||||
s.addUser(e.Nick)
|
s.addUser(e.Nick)
|
||||||
doCommand(e.Message(), e, s)
|
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 {
|
if err != nil {
|
||||||
fmt.Printf("Err %s", err)
|
fmt.Printf("Err %s", err)
|
||||||
return
|
return
|
||||||
@ -195,10 +213,10 @@ func catFacts(con *irc.Connection) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ch := os.Getenv("CTF2021CHANNEL")
|
ch := os.Getenv(chanEnv)
|
||||||
if ch != "" {
|
if ch != "" {
|
||||||
channel = ch
|
channel = ch
|
||||||
}
|
}
|
||||||
|
|
||||||
sendWelcome = os.Getenv("CTF2021WC")
|
sendHi = os.Getenv(himsgEnv)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user