Ejemplo n.º 1
0
func (plugin *Plugin) generateBan(nick string, hostmask string, reason string,
	duration time.Duration) tempban.TemporaryBan {
	return tempban.NewTemporaryBan(
		nick,
		hostmask,
		plugin.bot.Me().Name,
		reason,
		duration)
}
Ejemplo n.º 2
0
func (p *Plugin) dumpBans(target string) {
	num := 0

	// Fetch ban list
	banlist, err := p.mode.Bans(target)
	if err != nil {
		p.onDumpedBans(target, num, err)
		return
	}

	tbmgr := p.ensureTemporaryBanManager(target)

	// Save only bans from us
	for _, ban := range banlist {
		if ban.Nick != p.bot.Me().Nick {
			// Not a ban from us (going by the nickname at least)
			continue
		}

		if _, ok := tbmgr.Get(ban.Hostmask); ok {
			// We already have this ban saved
			continue
		}

		if err := tbmgr.Add(tempban.NewTemporaryBan(
			ban.Nick,
			ban.Hostmask,
			ban.Src,
			"Migrated old ban",
			48*time.Hour+ban.Timestamp.Sub(time.Now()))); err != nil {
			p.onDumpedBans(target, num, err)
			return
		}

		num++
	}

	p.syncBans(target)
	p.onDumpedBans(target, num, nil)
}