Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DeleteReminderCommand = &dgc.Command{ Name: "deletereminder", Description: "Delete a reminder", Domain: "astral.integrations.reminders", Aliases: []string{"deletereminder", "delreminder", "delremind", "rmreminder", "rmremind"}, Category: "Reminders", Handler: func(ctx *dgc.Ctx) { database := db.New() id := ctx.Arguments.Get(0).Raw() wi, err := integrations.GetWorkspaceIntegrationForCommand(ctx, ReminderIntegrationID) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } iD, err := database.GetIntegrationDataForUser(ctx.Event.Author.ID, ReminderIntegrationID, wi.ID) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) } var reminders types.ReminderIntegrationData jsonStr, err := json.Marshal(iD.Data) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } err = json.Unmarshal(jsonStr, &reminders) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } for i, r := range reminders.Reminders { if r.MessageID == id { reminders.Reminders = append(reminders.Reminders[:i], reminders.Reminders[i+1:]...) } } err = database.SetIntegrationDataForUser(ctx.Event.Author.ID, ReminderIntegrationID, wi.ID, types.ReminderIntegrationData{ Reminders: reminders.Reminders, }) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } j, found := ctx.CustomObjects.Get(fmt.Sprintf("job-%s", id)) if found { job := j.(*scheduler.Job) job.Quit <- true } ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{ Title: "Reminder Deleted", Description: "Your reminder has been deleted. You may receive a notification if it's in the queue.", Color: 0x00ff00, })) }, }
View Source
var ListRemindersCommand = &dgc.Command{ Name: "listreminders", Description: "List all of your reminders", Domain: "astral.integrations.reminders", Aliases: []string{"listreminders", "listreminder", "listremind", "reminders", "reminderls", "remindls"}, Category: "Reminders", Handler: func(ctx *dgc.Ctx) { database := db.New() wi, err := integrations.GetWorkspaceIntegrationForCommand(ctx, ReminderIntegrationID) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } iD, err := database.GetIntegrationDataForUser(ctx.Event.Author.ID, ReminderIntegrationID, wi.ID) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } var reminders types.ReminderIntegrationData jsonStr, err := json.Marshal(iD.Data) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } err = json.Unmarshal(jsonStr, &reminders) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } embed := &discordgo.MessageEmbed{ Title: "Reminders", Description: "Here are all of your reminders", Color: 0x00ff00, Fields: []*discordgo.MessageEmbedField{}, } for _, r := range reminders.Reminders { valText := fmt.Sprintf("**Reminder:** %s\n**Time:** <t:%d>", r.Msg, r.Time.Unix()) if r.Repeating { valText = fmt.Sprintf("**Reminder:** %s\n**Every:** `%s`", r.Msg, r.RepeatInterval) } embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ Name: fmt.Sprintf("ID: %s", r.MessageID), Value: valText, Inline: false, }) } ctx.ReplyEmbed(embed) }, }
View Source
var RemindCommand = &dgc.Command{ Name: "remind", Description: "Remind yourself or someone else of something", Usage: "remind [@user or me] [time] [message]", Example: "remind me 1h to do something", Category: "Reminders", IntegrationID: ReminderIntegrationID, Domain: "astral.integrations.reminders", Aliases: []string{"remind", "reminder"}, Slash: true, SlashGuilds: []string{os.Getenv("DEV_GUILD")}, Handler: func(ctx *dgc.Ctx) { duration, err := utils.ParseDuration(ctx.Arguments.Get(1).Raw()) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } t := time.Now().Add(duration) a := ctx.Arguments.GetAll()[2:] msgArr := []string{} for _, v := range a { msgArr = append(msgArr, v.Raw()) } msg := strings.Join(msgArr, " ") user := ctx.Arguments.Get(0).Raw() if user == "me" { user = ctx.Event.Author.ID } else { user = ctx.Arguments.Get(0).AsUserMentionID() } database := db.New() wi, err := integrations.GetWorkspaceIntegrationForCommand(ctx, ReminderIntegrationID) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } iD, err := database.GetIntegrationDataForUser(ctx.Event.Author.ID, ReminderIntegrationID, wi.ID) if err != nil { } var reminders []types.Reminder re := types.Reminder{ Time: t, Msg: msg, UserID: user, Repeating: false, MessageID: ctx.Event.ID, CreatedAt: time.Now(), } if iD.Data != nil { jsonStr, err := json.Marshal(iD.Data) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } var d types.ReminderIntegrationData err = json.Unmarshal(jsonStr, &d) reminders = append(d.Reminders, re) } else { reminders = []types.Reminder{ re, } } err = database.SetIntegrationDataForUser(ctx.Event.Author.ID, ReminderIntegrationID, wi.ID, types.ReminderIntegrationData{ Reminders: reminders, }) s, _ := schedule.NewSchedule(time.RFC1123Z, t.Format(time.RFC1123Z), "Local") notifier := &integrations.DiscordNotifier{ UserID: user, Session: ctx.Session, Reminder: re, WiID: wi.ID, } rem := reminder.Reminder{ Schedule: s, Notifier: notifier, } go rem.Remind(user, msg) var fields []*discordgo.MessageEmbedField if err != nil { fields = append(fields, &discordgo.MessageEmbedField{ Name: "Error adding to database", Value: fmt.Sprintf("%s\n\nYour reminder is still set, however if the bot restarts, it will be lost.", err.Error()), Inline: false, }) } ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{ Title: "Reminder set!", Description: fmt.Sprintf("I'll remind you <t:%d:R>", t.Unix()), Color: 0x00ff00, Fields: fields, })) }, }
View Source
var RemindRepeatCommand = &dgc.Command{ Name: "remindrepeat", Description: "Remind yourself or someone else of something at a set interval", Domain: "astral.integrations.reminders", Usage: "remindrepeat [@user or me] [time] [message]", Example: "remindrepeat me 1h to do something", Category: "Reminders", Aliases: []string{"remindrepeat", "reminderrepeat", "rremind", "remindr"}, Slash: true, Handler: func(ctx *dgc.Ctx) { duration, err := utils.ParseDuration(ctx.Arguments.Get(1).Raw()) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } t := time.Now().Add(duration) a := ctx.Arguments.GetAll()[2:] msgArr := []string{} for _, v := range a { msgArr = append(msgArr, v.Raw()) } msg := strings.Join(msgArr, " ") user := ctx.Arguments.Get(0).Raw() if user == "me" { user = ctx.Event.Author.ID } else { user = ctx.Arguments.Get(0).AsUserMentionID() } database := db.New() wi, err := integrations.GetWorkspaceIntegrationForCommand(ctx, ReminderIntegrationID) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } iD, err := database.GetIntegrationDataForUser(ctx.Event.Author.ID, ReminderIntegrationID, wi.ID) if err != nil { } var reminders []types.Reminder re := types.Reminder{ Time: t, Msg: msg, UserID: user, Repeating: true, RepeatInterval: duration.String(), MessageID: ctx.Event.ID, CreatedAt: time.Now(), } if iD.Data != nil { jsonStr, err := json.Marshal(iD.Data) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } var d types.ReminderIntegrationData err = json.Unmarshal(jsonStr, &d) reminders = append(d.Reminders, re) } else { reminders = []types.Reminder{ re, } } err = database.SetIntegrationDataForUser(ctx.Event.Author.ID, ReminderIntegrationID, wi.ID, types.ReminderIntegrationData{ Reminders: reminders, }) notifier := &integrations.DiscordNotifier{ UserID: user, Session: ctx.Session, Reminder: re, WiID: wi.ID, } job, err := scheduler.Every(int(duration.Seconds())).Seconds().NotImmediately().Run(func() { notifier.Notify(user, msg) }) if err != nil { ctx.ReplyEmbed(utils.ErrorEmbed(*ctx, err)) return } ctx.CustomObjects.Set(fmt.Sprintf("job-%s", ctx.Event.ID), job) var fields []*discordgo.MessageEmbedField if err != nil { fields = append(fields, &discordgo.MessageEmbedField{ Name: "Error adding to database", Value: fmt.Sprintf("%s\n\nYour reminder is still set, however if the bot restarts, it will be lost.", err.Error()), Inline: false, }) } ctx.ReplyEmbed(utils.GenerateEmbed(*ctx, discordgo.MessageEmbed{ Title: "Reminder set!", Description: fmt.Sprintf("Okay! I'll remind you every `%s` to %s starting <t:%d>", duration.String(), msg, t.Unix()), Color: 0x00ff00, Fields: fields, })) }, }
View Source
var ReminderIntegrationID = "3dc87d39-a037-48fa-85b0-0243e6593883"
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.