<commit_before>package main

import (
	"fmt"
	"github.com/jyggen/pingu/pingu"
	"github.com/nlopes/slack"
	"github.com/spf13/viper"
	"net/http"
	"regexp"
	"strconv"
	"strings"
	"sync"
	"time"
)

type plugin struct {
	channel      string
	client       *client
	global       *leaderboard
	leaderboards leaderboardList
}

var leaderboardRegex *regexp.Regexp
var version string

func init() {
	leaderboardRegex = regexp.MustCompile("^!leaderboard(?: ([\\d]{4}))?$")
}

func New(c *viper.Viper) pingu.Plugin {
	return pingu.Plugin(&plugin{
		channel: c.GetString("aoc.channel"),
		client: &client{
			httpClient: &http.Client{
				Timeout: c.GetDuration("aoc.timeout") * time.Second,
			},
			ownerId: c.GetInt("aoc.owner"),
			session: c.GetString("aoc.session"),
		},
		global: &leaderboard{},
	})
}

func (pl *plugin) Author() pingu.Author {
	return pingu.Author{
		Email: "<EMAIL>",
		Name:  "<NAME>",
	}
}

func (pl *plugin) Commands() pingu.Commands {
	return pingu.Commands{
		&pingu.Command{
			Description: "Prints either the global leaderboard, or the leaderboard for a specific year.",
			Func:        pl.postLeaderboard,
			Trigger:     leaderboardRegex,
		},
		&pingu.Command{
			Description: "Forces a refresh of all leaderboards.",
			Func: func(pi *pingu.Pingu, ev *slack.MessageEvent) {
				if ev.Channel != pl.channel {
					pi.Reply(ev, fmt.Sprintf("Noot! Noot! That command is only available in <#%s>!", pl.channel))
					return
				}

				pl.refreshLeaderboards(pi)
			},
			Trigger: regexp.MustCompile("^!refresh$"),
		},
	}
}

func (pl *plugin) Name() string {
	return "Advent of Code"
}

func (pl *plugin) Tasks() pingu.Tasks {
	return pingu.Tasks{
		&pingu.Task{
			Func:     pl.refreshLeaderboards,
			Interval: time.Minute * 15,
		},
		&pingu.Task{
			Func: pl.announceNewDay,
			Spec: "0 6 1-25 DEC *",
		},
	}
}

func (pl *plugin) Version() string {
	return version
}

func (pl *plugin) announceJoined(pi *pingu.Pingu, a leaderboard, b leaderboard) {
	availableStars := calculateAvailableStars(time.Now(), b.Year)

Loop:
	for _, our := range b.Members {
		for _, their := range a.Members {
			if our.Id == their.Id {
				continue Loop<commit_msg>Fix schedule<commit_after>package main

import (
	"fmt"
	"github.com/jyggen/pingu/pingu"
	"github.com/nlopes/slack"
	"github.com/spf13/viper"
	"net/http"
	"regexp"
	"strconv"
	"strings"
	"sync"
	"time"
)

type plugin struct {
	channel      string
	client       *client
	global       *leaderboard
	leaderboards leaderboardList
}

var leaderboardRegex *regexp.Regexp
var version string

func init() {
	leaderboardRegex = regexp.MustCompile("^!leaderboard(?: ([\\d]{4}))?$")
}

func New(c *viper.Viper) pingu.Plugin {
	return pingu.Plugin(&plugin{
		channel: c.GetString("aoc.channel"),
		client: &client{
			httpClient: &http.Client{
				Timeout: c.GetDuration("aoc.timeout") * time.Second,
			},
			ownerId: c.GetInt("aoc.owner"),
			session: c.GetString("aoc.session"),
		},
		global: &leaderboard{},
	})
}

func (pl *plugin) Author() pingu.Author {
	return pingu.Author{
		Email: "<EMAIL>",
		Name:  "<NAME>",
	}
}

func (pl *plugin) Commands() pingu.Commands {
	return pingu.Commands{
		&pingu.Command{
			Description: "Prints either the global leaderboard, or the leaderboard for a specific year.",
			Func:        pl.postLeaderboard,
			Trigger:     leaderboardRegex,
		},
		&pingu.Command{
			Description: "Forces a refresh of all leaderboards.",
			Func: func(pi *pingu.Pingu, ev *slack.MessageEvent) {
				if ev.Channel != pl.channel {
					pi.Reply(ev, fmt.Sprintf("Noot! Noot! That command is only available in <#%s>!", pl.channel))
					return
				}

				pl.refreshLeaderboards(pi)
			},
			Trigger: regexp.MustCompile("^!refresh$"),
		},
	}
}

func (pl *plugin) Name() string {
	return "Advent of Code"
}

func (pl *plugin) Tasks() pingu.Tasks {
	return pingu.Tasks{
		&pingu.Task{
			Func:     pl.refreshLeaderboards,
			Interval: time.Minute * 15,
		},
		&pingu.Task{
			Func: pl.announceNewDay,
			Spec: "0 0 6 1-25 DEC *",
		},
	}
}

func (pl *plugin) Version() string {
	return version
}

func (pl *plugin) announceJoined(pi *pingu.Pingu, a leaderboard, b leaderboard) {
	availableStars := calculateAvailableStars(time.Now(), b.Year)

Loop:
	for _, our := range b.Members {
		for _, their := range a.Members {
			if our.Id == their.Id {
				continue Loop
{'fraction_non_alphanumeric': 0.15072597372666513, 'fraction_numerical': 0.004839824844434202, 'mean_word_length': 3.5636172450052577, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '467962', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1594, 'n_words': 373}