First Run

This commit is contained in:
Pratyush Desai 2022-07-19 07:13:57 +05:30
parent 1ac062af33
commit f0418ea7f7
Signed by: pratyush
GPG Key ID: DBA5BB7505946FAD
3 changed files with 22 additions and 12 deletions

5
go.mod
View File

@ -2,4 +2,7 @@ module pratyush/wutbot
go 1.18 go 1.18
require github.com/ergochat/irc-go v0.2.0 require (
github.com/ergochat/irc-go v0.2.0
github.com/joho/godotenv v1.4.0
)

2
go.sum
View File

@ -1,2 +1,4 @@
github.com/ergochat/irc-go v0.2.0 h1:3vHdy4c56UTY6+/rTBrQc1fmt32N5G8PrEZacJDOr+E= github.com/ergochat/irc-go v0.2.0 h1:3vHdy4c56UTY6+/rTBrQc1fmt32N5G8PrEZacJDOr+E=
github.com/ergochat/irc-go v0.2.0/go.mod h1:2vi7KNpIPWnReB5hmLpl92eMywQvuIeIIGdt/FQCph0= github.com/ergochat/irc-go v0.2.0/go.mod h1:2vi7KNpIPWnReB5hmLpl92eMywQvuIeIIGdt/FQCph0=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=

27
irc.go
View File

@ -9,6 +9,7 @@ import (
"github.com/ergochat/irc-go/ircevent" "github.com/ergochat/irc-go/ircevent"
"github.com/ergochat/irc-go/ircmsg" "github.com/ergochat/irc-go/ircmsg"
"github.com/joho/godotenv"
) )
type empty struct{} type empty struct{}
@ -93,24 +94,28 @@ func ownerMatches(e ircmsg.Message, owner string) bool {
} }
func newBot() *Bot { func newBot() *Bot {
err := godotenv.Load(".env")
if err != nil {
log.Fatalf("Some error occured. Err: %s", err)
}
// required: // required:
nick := os.Getenv("TITLEBOT_NICK") nick := os.Getenv("WUTBOT_NICK")
server := os.Getenv("TITLEBOT_SERVER") server := os.Getenv("WUTBOT_SERVER")
// required (comma-delimited list of channels) // required (comma-delimited list of channels)
channels := os.Getenv("TITLEBOT_CHANNELS") channels := os.Getenv("WUTBOT_CHANNELS")
// SASL is optional: // SASL is optional:
saslLogin := os.Getenv("TITLEBOT_SASL_LOGIN") saslLogin := os.Getenv("WUTBOT_SASL_LOGIN")
saslPassword := os.Getenv("TITLEBOT_SASL_PASSWORD") saslPassword := os.Getenv("WUTBOT_SASL_PASSWORD")
// owner is optional (if unset, titlebot won't accept any owner commands) // owner is optional (if unset, WUTBOT won't accept any owner commands)
owner := os.Getenv("TITLEBOT_OWNER_ACCOUNT") owner := os.Getenv("WUTBOT_OWNER_ACCOUNT")
// more optional settings // more optional settings
version := os.Getenv("TITLEBOT_VERSION") version := os.Getenv("WUTBOT_VERSION")
if version == "" { if version == "" {
version = "github.com/ergochat/irc-go" version = "github.com/ergochat/irc-go"
} }
debug := os.Getenv("TITLEBOT_DEBUG") != "" debug := os.Getenv("WUTBOT_DEBUG") != ""
insecure := os.Getenv("TITLEBOT_INSECURE_SKIP_VERIFY") != "" insecure := os.Getenv("WUTBOT_INSECURE_SKIP_VERIFY") != ""
userAgent := os.Getenv("TITLEBOT_USER_AGENT") userAgent := os.Getenv("WUTBOT_USER_AGENT")
if userAgent == "" { if userAgent == "" {
userAgent = defaultUserAgent userAgent = defaultUserAgent
} }