diff --git a/djpianalto.com/goff/exts/init.go b/djpianalto.com/goff/exts/init.go index cd49783..4527caa 100644 --- a/djpianalto.com/goff/exts/init.go +++ b/djpianalto.com/goff/exts/init.go @@ -157,4 +157,13 @@ func AddCommandHandlers(h *disgoman.CommandManager) { RequiredPermissions: disgoman.PermissionBanMembers, Invoke: unbanUserCommand, }) + _ = h.AddCommand(&disgoman.Command{ + Name: "remind", + Aliases: nil, + Description: "Remind me at a later time", + OwnerOnly: false, + Hidden: false, + RequiredPermissions: 0, + Invoke: addReminderCommand, + }) } diff --git a/djpianalto.com/goff/exts/tasks.go b/djpianalto.com/goff/exts/tasks.go new file mode 100644 index 0000000..779c086 --- /dev/null +++ b/djpianalto.com/goff/exts/tasks.go @@ -0,0 +1,41 @@ +package exts + +import ( + "djpianalto.com/goff/djpianalto.com/goff/utils" + "errors" + "github.com/dustinpianalto/disgoman" + "github.com/olebedev/when" + "github.com/olebedev/when/rules/common" + "github.com/olebedev/when/rules/en" + "strings" + "time" +) + +func addReminderCommand(ctx disgoman.Context, args []string) { + w := when.New(nil) + w.Add(en.All...) + w.Add(common.All...) + + text := strings.Join(args, " ") + r, err := w.Parse(text, time.Now()) + if err != nil { + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "Error parsing time", + Error: err, + } + return + } + if r == nil { + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "You need to include a valid time", + Error: errors.New("no time found"), + } + return + } + content := strings.Replace(text, r.Text, "", 1) + query := "INSERT INTO tasks (type, content, guild_id, channel_id, user_id, trigger_time) " + + "VALUES ('Reminder', $1, $2, $3, $4, $5)" + utils.Database.Exec(query, content, ctx.Guild.ID, ctx.Channel.ID, ctx.User.ID, r.Time) +} diff --git a/go.mod b/go.mod index 1422f41..ae0b77e 100644 --- a/go.mod +++ b/go.mod @@ -7,4 +7,5 @@ require ( github.com/dustinpianalto/disgoman v0.0.0-20200420065246-662acb500b0c github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/lib/pq v1.3.0 + github.com/olebedev/when v0.0.0-20190311101825-c3b538a97254 ) diff --git a/go.sum b/go.sum index e76a2df..f6e61ce 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,10 @@ +github.com/AlekSi/pointer v1.0.0 h1:KWCWzsvFxNLcmM5XmiqHsGTTsuwZMsLFwWF9Y+//bNE= +github.com/AlekSi/pointer v1.0.0/go.mod h1:1kjywbfcPFCmncIxtk6fIEub6LKrfMz3gc5QKVOSOA8= github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= -github.com/dustinpianalto/disgoman v0.0.0-20200407073246-017a13d2f100 h1:yKyt6EakVkopZRdOYXa5AOQVRl2QgRRDaTPZerpgoCI= -github.com/dustinpianalto/disgoman v0.0.0-20200407073246-017a13d2f100/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g= -github.com/dustinpianalto/disgoman v0.0.0-20200420005144-c3143ea66130 h1:J967RgBA9J1nBJrNdVxpYeRNYAoA2h5XOc0ndD6zhQQ= -github.com/dustinpianalto/disgoman v0.0.0-20200420005144-c3143ea66130/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g= -github.com/dustinpianalto/disgoman v0.0.0-20200420022152-4729d2c5ee3e h1:EeLjjVHZNa9DCpOftoKDZalSwO7usn9yhRwXXz2RSdA= -github.com/dustinpianalto/disgoman v0.0.0-20200420022152-4729d2c5ee3e/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g= -github.com/dustinpianalto/disgoman v0.0.0-20200420041406-a10b5cdbec0d h1:nVmxBFiOB/okyXp31ka5DSP+OnwpZF2CJDopRsM8c9E= -github.com/dustinpianalto/disgoman v0.0.0-20200420041406-a10b5cdbec0d/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g= -github.com/dustinpianalto/disgoman v0.0.0-20200420064112-dd8cd312d4d2 h1:hSAwrJi3E2SVbWXnb45JjdbAoN6d08OcsgU6nRwbLXk= -github.com/dustinpianalto/disgoman v0.0.0-20200420064112-dd8cd312d4d2/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g= -github.com/dustinpianalto/disgoman v0.0.0-20200420064814-3537b1e12501 h1:vnk1KQySNbsLTfKuUNiYFlgtNQm3EgPVta1pBYueFCc= -github.com/dustinpianalto/disgoman v0.0.0-20200420064814-3537b1e12501/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dustinpianalto/disgoman v0.0.0-20200420065246-662acb500b0c h1:o2XsDNNwRPosS26VNcuNgVczGzQARWiW9J3nf1Kmzjk= github.com/dustinpianalto/disgoman v0.0.0-20200420065246-662acb500b0c/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= @@ -20,5 +13,14 @@ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNU github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/olebedev/when v0.0.0-20190311101825-c3b538a97254 h1:JYoQR67E1vv1WGoeW8DkdFs7vrIEe/5wP+qJItd5tUE= +github.com/olebedev/when v0.0.0-20190311101825-c3b538a97254/go.mod h1:DPucAeQGDPUzYUt+NaWw6qsF5SFapWWToxEiVDh2aV0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=