父節點
c0b8b27489
當前提交
6946f42517
147
src/main.go
147
src/main.go
|
@ -1,147 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
//Patrons sets caches for the various user vices
|
||||
type Patrons struct {
|
||||
// alcohol
|
||||
Drunks *cache.Cache
|
||||
// weed
|
||||
Trees *cache.Cache
|
||||
// uppers
|
||||
Sonics *cache.Cache
|
||||
// opis
|
||||
Junkies *cache.Cache
|
||||
// empathogens
|
||||
Ravers *cache.Cache
|
||||
// psychedelics
|
||||
Trippers *cache.Cache
|
||||
}
|
||||
|
||||
var p *Patrons
|
||||
|
||||
//init the go-cache expiration times for each vice
|
||||
func init() {
|
||||
p = &Patrons{
|
||||
Drunks: cache.New(240*time.Minute, cache.DefaultExpiration),
|
||||
Trees: cache.New(60*time.Minute, cache.DefaultExpiration),
|
||||
Sonics: cache.New(45*time.Minute, cache.DefaultExpiration),
|
||||
Junkies: cache.New(120*time.Minute, cache.DefaultExpiration),
|
||||
Trippers: cache.New(240*time.Minute, cache.DefaultExpiration),
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func soSober(nick string){
|
||||
Patrons.Set(nick, 1, cache.NoExpiration)
|
||||
|
||||
//return slice string of sober nicks
|
||||
}
|
||||
*/
|
||||
|
||||
// takes the user nick and user vice aka "poison" outputs int val
|
||||
func (p *Patrons) getFaded(nick string, poison string) int {
|
||||
// var count int
|
||||
// var faded bool = false
|
||||
|
||||
var target *cache.Cache
|
||||
|
||||
switch poison {
|
||||
case "drink":
|
||||
target = p.Drunks
|
||||
case "smoke":
|
||||
target = p.Trees
|
||||
case "speed":
|
||||
target = p.Sonics
|
||||
case "nod":
|
||||
target = p.Junkies
|
||||
case "trip":
|
||||
target = p.Trippers
|
||||
default:
|
||||
fmt.Println("Wtf?!")
|
||||
panic("!??!!?!?")
|
||||
}
|
||||
|
||||
cacheresult, faded := target.Get(nick)
|
||||
|
||||
if !faded {
|
||||
target.Set(nick, 1, cache.DefaultExpiration)
|
||||
return 1
|
||||
}
|
||||
|
||||
count := cacheresult.(int)
|
||||
|
||||
endresult, err := target.IncrementInt(nick, count)
|
||||
if err != nil {
|
||||
panic("you're fucked bud")
|
||||
}
|
||||
|
||||
return endresult
|
||||
}
|
||||
|
||||
func art(poison string) string {
|
||||
|
||||
switch poison {
|
||||
default:
|
||||
fmt.Printf("┎┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┒\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┖┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┚\n")
|
||||
case "drink":
|
||||
color.Red("┎┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┒\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┖┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┚\n")
|
||||
|
||||
case "smoke":
|
||||
color.Red("┎┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┒\n")
|
||||
color.Red("┋ ``; \n")
|
||||
color.Red("┋ ▓▓▓▓▓▓▒░\n")
|
||||
color.Red("┋this\n")
|
||||
color.Red("┖┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┚\n")
|
||||
|
||||
case "speed":
|
||||
fmt.Printf("┎┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┒\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┖┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┚\n")
|
||||
|
||||
case "nod":
|
||||
fmt.Printf("┎┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┒\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┖┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┚\n")
|
||||
|
||||
case "trip":
|
||||
fmt.Printf("┎┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┒\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┋this\n")
|
||||
fmt.Printf("┖┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┚\n")
|
||||
|
||||
}
|
||||
|
||||
return "nil"
|
||||
}
|
||||
|
||||
func main() {
|
||||
var howmanybeers int
|
||||
fmt.Println("totally a real program here")
|
||||
howmanybeers = p.getFaded("bob", "drink")
|
||||
fmt.Println("bob has drank " + strconv.Itoa(howmanybeers) + "brews")
|
||||
fmt.Println("another round pls")
|
||||
howmanybeers = p.getFaded("bob", "drink")
|
||||
fmt.Println("bob has drank " + strconv.Itoa(howmanybeers) + "brews")
|
||||
art("smoke")
|
||||
}
|
載入中…
新增問題並參考