leet

package
v0.0.0-...-993cae5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2023 License: MIT Imports: 16 Imported by: 0

README

leet / 1337

This is a game where the point is to post !1337 as close to 13:37:00:000000000 as possible, on the positive side.

Installation

Import github.com/oddlid/dvdgbot/leet in main.go. Then, in entryPoint() in main.go, take the first return value from irc.SetUpConn(config) (the bot instance), and pass on to leet.SetParentBot(bot).

Config

The config for the game is done via both environment variables and in the JSON config files it needs.

Enviroment variables:
  • LEETBOT_HOUR - Defaults to 13. Useful to change to current hour during tests.
  • LEETBOT_MINUTE - Defaults to 37. Useful to change to current minute during tests.
  • LEETBOT_SCOREFILE - Defaults to /tmp/leetbot_scores.json. This is where The config for channels and their respective settings goes, and where the bot saves scores, times, tax and bonuses for each user.
  • LEETBOT_BONUSCONFIGFILE - Defaults to /tmp/leetbot_bonusconfigs.json. This is where you configure the bonus system. The bonus system is based on substring matching in the second and nanosecond fields of the timestamp when a user's post is registered.
JSON files:
  • $LEETBOT_SCOREFILE ( /tmp/leetbot_scores.json ) - Main configuration. Format:
{
  "botstart": "timestamp automatically set by bot",
  "channels": {
    "#channelname": {
      "channel_name": "#channelname",
      "users": {
        "Nick1": {
          "nick": "Nick1",
          "score": 0,
          "last_entry": "timestamp automatically set by bot",
          "best_entry": "timestamp automatically set by bot",
          "locked": false,
          "bonuses": {
            "times": 0,
            "total": 0
          },
          "taxes": {
            "times": 0,
            "total": 0
          }
        },
        "Nick2": { ... }
      },
      "inspect_always": false,
      "tax_loners": false,
      "post_tax_fail": false,
      "inspection_tax": 0,
      "overshoot_tax": 0
    }
  }
}

Most of the data in this file is generated automatically by the bot itself, used for keeping track of stats between restarts. The only values you should touch, are the ones at the bottom:

  • inspect_always: true/false
    • If set to true, Tax Inspection will be run after every round.
    • If set to false, Tax Inspection will only be run if a random int between 0 and 6 matches the current weekday.
  • tax_loners: true/false
    • If there is only one contestant on time in a given round, Tax Inspection will not run if this is set to false. inspect_always will override this, if set to true, though.
  • post_tax_fail: true/false
    • If set to true, the bot will post why taxation was not done to the channel. Usually, it's because the weekday doesn't match the random int.
  • inspection_tax: int
    • This is a percentage of the lowest score between the contestants that scored on time in a given round. So if the contestant with the higest total points have 1000 points, and the one with the lowest has 200, and inspection_tax is set to 10, then 20 points is the maximum tax for that round.
  • overshoot_tax: int
    • This is how many points will be the step value to deduct in a loop until a user is below the target score, if scoring past that value. The target score will be the concatenation of LEETBOT_HOUR and LEETBOT_MINUTE, so if set to defaults, the target score will be 1337 points. So if the overshoot tax is 10, a user has 1336 points, and gets 2 points in a round, it will be deducted 10 points and have 1328 points after the round. If the user overshoots with more points than the value of this tax, it will be decuted in a loop until the value is below.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetParentBot

func SetParentBot(b *bot.Bot)

SetParentBot sets the internal global reference to an instance of "github.com/go-chat-bot/bot". This reference is used to send messages outside of the registered callback (leet). The bot including this module must call this before using this module.

Types

type BonusConfig

type BonusConfig struct {
	SubString    string // string to search for in timestamp
	Greeting     string // Message from bot to user upon bonus hit
	StepPoints   int    // points to multiply substring position with
	NoStepPoints int    // points to return for match when UseStep == false

	PrefixChar rune // the char required as only prefix for max bonus, e.g. '0'
	UseStep    bool // if to multiply points for each position to the right in string
	// contains filtered or unexported fields
}

type BonusConfigs

type BonusConfigs []BonusConfig

type BonusReturn

type BonusReturn struct {
	Match  string
	Msg    string
	Points int
}

func (BonusReturn) String

func (br BonusReturn) String() string

type BonusReturns

type BonusReturns []BonusReturn

func (BonusReturns) String

func (brs BonusReturns) String() string

func (BonusReturns) TotalBonus

func (brs BonusReturns) TotalBonus() int

type Channel

type Channel struct {
	Users UserMap `json:"users"`                  // string key is nick
	Name  string  `json:"channel_name,omitempty"` // we need to duplicate this from the parent map key, so that the instance knows its own name

	InspectionTax float64 `json:"inspection_tax"` // percentage, but no check if outside of 0-100
	OvershootTax  int     `json:"overshoot_tax"`  // interval for how much to deduct if user scores past target

	InspectAlways bool `json:"inspect_always"` // if false, only inspect if random value between 0 and 6 matches current weekday
	TaxLoners     bool `json:"tax_loners"`     // If to inspect and tax when only one contestant in a round
	PostTaxFail   bool `json:"post_tax_fail"`  // If to post to channel why taxation does NOT happen
	// contains filtered or unexported fields
}

type ScoreData

type ScoreData struct {
	Channels map[string]*Channel `json:"channels"`

	BotStart time.Time `json:"botstart"`
	// contains filtered or unexported fields
}

type ScoreTracker

type ScoreTracker struct {
	Times int `json:"times"` // how many times have the user gotten a bonus or tax
	Total int `json:"total"` // the sum of all
}

type TimeCode

type TimeCode uint8

type TimeFrame

type TimeFrame struct {
	// contains filtered or unexported fields
}

type User

type User struct {
	LastEntry time.Time    `json:"last_entry"` // time of last !1337 post that resulted in a score, positive or negative
	BestEntry time.Time    `json:"best_entry"` // tightest to 1337, or whatever...
	Nick      string       `json:"nick"`       // duplicate of map key, but we need to have it here as well sometimes
	Taxes     ScoreTracker `json:"taxes"`      // hos much tax over time
	Bonuses   ScoreTracker `json:"bonuses"`    // how much bonuses over time
	Misses    ScoreTracker `json:"misses"`     // how many times have the user been early or late
	Points    int          `json:"score"`      // current points total

	Locked bool `json:"locked"` // true if the user has reached the target limit
	// contains filtered or unexported fields
}

type UserMap

type UserMap map[string]*User

type UserSlice

type UserSlice []*User

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL