2013-12-10 23:37:07 +00:00
|
|
|
// © 2013 the AlePale Authors under the WTFPL. See AUTHORS for the list of authors.
|
|
|
|
|
2013-06-02 01:59:55 +00:00
|
|
|
package bot
|
|
|
|
|
|
|
|
// User type stores user history. This is a vehicle that will follow the user for the active
|
|
|
|
// session
|
|
|
|
type User struct {
|
|
|
|
// Current nickname known
|
|
|
|
Name string
|
|
|
|
|
|
|
|
// LastSeen DateTime
|
|
|
|
|
|
|
|
// Alternative nicknames seen
|
|
|
|
Alts []string
|
|
|
|
Parent string
|
|
|
|
|
|
|
|
Admin bool
|
|
|
|
|
2013-09-02 17:34:20 +00:00
|
|
|
//bot *Bot
|
2013-06-02 01:59:55 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 06:12:26 +00:00
|
|
|
var users map[string]*User
|
2013-06-02 01:59:55 +00:00
|
|
|
|
|
|
|
func (b *Bot) GetUser(nick string) *User {
|
2016-01-15 06:12:26 +00:00
|
|
|
if _, ok := users[nick]; !ok {
|
|
|
|
users[nick] = &User{
|
|
|
|
Name: nick,
|
|
|
|
Admin: b.checkAdmin(nick),
|
2013-06-02 01:59:55 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-15 06:12:26 +00:00
|
|
|
return users[nick]
|
2013-06-02 01:59:55 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 06:12:26 +00:00
|
|
|
func (b *Bot) NewUser(nick string) *User {
|
|
|
|
return &User{
|
|
|
|
Name: nick,
|
|
|
|
Admin: b.checkAdmin(nick),
|
2013-06-02 01:59:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Bot) checkAdmin(nick string) bool {
|
|
|
|
for _, u := range b.Config.Admins {
|
|
|
|
if nick == u {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|