Skip to content

Commit

Permalink
Rename --book to --grimoire, fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ginger51011 committed Feb 2, 2024
1 parent 1b8de3d commit 0a3cc6d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Clients (hopefully bots) that disregard `robots.txt` and connect to your instanc

HellPot will send an infinite stream of data that is *just close enough* to being a real website that they might just stick around until their soul is ripped apart and they cease to exist.

Under the hood of this eternal suffering is a markov engine that chucks bits and pieces of [The Birth of Tragedy (Hellenism and Pessimism)](https://www.gutenberg.org/files/51356/51356-h/51356-h.htm) by Friedrich Nietzsche at the client using [fasthttp](https://github.com/valyala/fasthttp), or optionally your (least?) favorite text using the `-b`/`--book` flag.
Under the hood of this eternal suffering is a markov engine that chucks bits and pieces of [The Birth of Tragedy (Hellenism and Pessimism)](https://www.gutenberg.org/files/51356/51356-h/51356-h.htm) by Friedrich Nietzsche at the client using [fasthttp](https://github.com/valyala/fasthttp), or optionally you may synchronize HellPot with your nightmares by using the `-g`/`--grimoire` flag

## Building From Source

Expand Down
2 changes: 1 addition & 1 deletion cmd/HellPot/HellPot.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func init() {

extra.Banner()

log.Info().Str("caller", "config").Str("file", config.ConfigFilename).Msg(config.ConfigFilename)
log.Info().Str("caller", "config").Str("file", config.Filename).Msg(config.Filename)
log.Info().Str("caller", "logger").Msg(config.CurrentLogFile)
log.Debug().Str("caller", "logger").Msg("debug enabled")
log.Trace().Str("caller", "logger").Msg("trace enabled")
Expand Down
6 changes: 3 additions & 3 deletions internal/config/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func argParse() {
os.Exit(1)
}
loadCustomConfig(os.Args[i+1])
case "-b", "--book":
case "-g", "--grimoire":
if len(os.Args) < i+2 {
println("missing book file after -b/--book")
println("missing source of suffering file after -g/--grimoire")
os.Exit(1)
}
BookFilename = os.Args[i+1]
Grimoire = os.Args[i+1]
UseCustomHeffalump = true
default:
continue
Expand Down
24 changes: 12 additions & 12 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ var (
Trace bool
// Debug is the value of our debug (verbose) on/off toggle as per the current configuration.
Debug bool
// ConfigFilename returns the current location of our toml config file.
ConfigFilename string
// Filename returns the current location of our toml config file.
Filename string
// UseCustomHeffalump decides if a custom Heffalump is to be used
UseCustomHeffalump = false
// BookFilename returns the current location of a possible book file
BookFilename string
// Grimoire returns the current location of a possible source of suffering file
Grimoire string
)

func writeConfig() {
Expand All @@ -44,9 +44,9 @@ func writeConfig() {
os.Exit(1)
}
}
ConfigFilename = prefConfigLocation + "/" + "config.toml"
if err := snek.SafeWriteConfigAs(ConfigFilename); err != nil {
fmt.Println("Failed to write new configuration file to '" + ConfigFilename + "': " + err.Error())
Filename = prefConfigLocation + "/" + "config.toml"
if err := snek.SafeWriteConfigAs(Filename); err != nil {
fmt.Println("Failed to write new configuration file to '" + Filename + "': " + err.Error())
os.Exit(1)
}
}
Expand Down Expand Up @@ -75,8 +75,8 @@ func Init() {
writeConfig()
}

if len(ConfigFilename) < 1 {
ConfigFilename = snek.ConfigFileUsed()
if len(Filename) < 1 {
Filename = snek.ConfigFileUsed()
}

snek.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_"))
Expand Down Expand Up @@ -106,9 +106,9 @@ func loadCustomConfig(path string) {
os.Exit(1)
}

ConfigFilename, err = filepath.Abs(path)
if len(ConfigFilename) < 1 || err != nil {
ConfigFilename = path
Filename, err = filepath.Abs(path)
if len(Filename) < 1 || err != nil {
Filename = path
}

defer func(f *os.File) {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func gen(memfs afero.Fs) {
println(err.Error())
os.Exit(1)
}
print("default configuration successfully written to " + target)
println("default configuration successfully written to " + target)
os.Exit(0)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/config/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var CLI = help{
1: {0: "--nocolor", 1: "disable color and banner"},
2: {0: "--banner", 1: "show banner + version and exit"},
3: {0: "--genconfig", 1: "write default config to " + Title + ".toml then exit"},
4: {0: "-b, --book", 1: "<file>", 2: "Specify a custom file used for text generation"},
5: {0: "-h, --help", 1: "show this help and exit"},
4: {0: "-g, --grimoire", 1: "<file>", 2: "Specify a custom file used for text generation"},
5: {0: "-h,--help", 1: "show this help and exit"},
},
out: os.Stdout,
}
Expand Down
11 changes: 6 additions & 5 deletions internal/http/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,23 @@ func getSrv(r *router.Router) fasthttp.Server {
func Serve() error {
log = config.GetLogger()

if config.UseCustomHeffalump {
content, err := os.ReadFile(config.BookFilename)
switch config.UseCustomHeffalump {
case true:
content, err := os.ReadFile(config.Grimoire)
if err != nil {
panic(err)
}
// Wasteful, but only done once at startup
src := string(content)
log.Info().Msgf("Using custom book file '%s'", config.BookFilename)
log.Info().Msgf("Using custom grimoire file '%s'", config.Grimoire)

if len(src) < 1 {
panic("book file was empty!")
panic("grimoire file was empty!")
}

markovMap := heffalump.MakeMarkovMap(strings.NewReader(src))
hellpotHeffalump = heffalump.NewHeffalump(markovMap, heffalump.DefaultBuffSize)
} else {
default:
log.Info().Msg("Using default source text")
hellpotHeffalump = heffalump.NewDefaultHeffalump()
}
Expand Down

0 comments on commit 0a3cc6d

Please sign in to comment.