marvin

A simple and modular IRC bot

git clone https://git.8pit.net/marvin.git

 1// This program is free software: you can redistribute it and/or modify
 2// it under the terms of the GNU Affero General Public License as
 3// published by the Free Software Foundation, either version 3 of the
 4// License, or (at your option) any later version.
 5//
 6// This program is distributed in the hope that it will be useful, but
 7// WITHOUT ANY WARRANTY; without even the implied warranty of
 8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 9// Affero General Public License for more details.
10//
11// You should have received a copy of the GNU Affero General Public
12// License along with this program. If not, see <http://www.gnu.org/licenses/>.
13
14package time
15
16import (
17	"github.com/nmeum/marvin/irc"
18	"github.com/nmeum/marvin/modules"
19	"time"
20)
21
22type Module struct {
23	Format string `json:"format"`
24}
25
26func Init(moduleSet *modules.ModuleSet) {
27	moduleSet.Register(new(Module))
28}
29
30func (m *Module) Name() string {
31	return "time"
32}
33
34func (m *Module) Help() string {
35	return "USAGE: !time"
36}
37
38func (m *Module) Defaults() {
39	m.Format = time.RFC1123
40}
41
42func (m *Module) Load(client *irc.Client) error {
43	client.CmdHook("privmsg", m.timeCmd)
44	return nil
45}
46
47func (m *Module) timeCmd(client *irc.Client, msg irc.Message) error {
48	if msg.Data != "!time" {
49		return nil
50	}
51
52	now := time.Now().UTC()
53	return client.Write("NOTICE %s :%s",
54		msg.Receiver, now.Format(m.Format))
55}