Added preliminary announcement code.
This commit is contained in:
parent
84e624a91b
commit
3fafe8455a
4 changed files with 95 additions and 12 deletions
|
|
@ -43,6 +43,56 @@ func main() {
|
|||
},
|
||||
},
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "announcements",
|
||||
Description: "Announcement management",
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "add",
|
||||
Description: "Adds an announcement to the queue.",
|
||||
Action: cmdHost.Announcements().AddAnnouncement,
|
||||
Flags: []cli.Flag{
|
||||
&cli.Int64Flag{
|
||||
Name: "chatid",
|
||||
Aliases: []string{"c"},
|
||||
Usage: "Specifies the chat ID. Required.",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "reminders",
|
||||
Aliases: []string{"r"},
|
||||
Usage: "Enables reminders for this announcement. Reminders will be triggered one week prior and one day prior by default.",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "title",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "Announcement title (optional).",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "content",
|
||||
Aliases: []string{"a"},
|
||||
Usage: "Announcement content (required).",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "weekly",
|
||||
Description: "Lists this week's announcements.",
|
||||
Action: cmdHost.Announcements().ListThisWeeksAnnouncements,
|
||||
},
|
||||
{
|
||||
Name: "today",
|
||||
Description: "Lists the announcements for today.",
|
||||
Action: cmdHost.Announcements().ListTodaysAnnouncements,
|
||||
Flags: []cli.Flag{
|
||||
&cli.Int64Flag{
|
||||
Name: "chatid",
|
||||
Aliases: []string{"c"},
|
||||
Usage: "Specifies the chat ID. Required.",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "birthdays",
|
||||
Description: "Birthday management",
|
||||
|
|
|
|||
|
|
@ -94,8 +94,6 @@ func (a *App) loadEnv() error {
|
|||
}
|
||||
|
||||
func (a *App) daily() {
|
||||
fmt.Println("daily trigger")
|
||||
|
||||
chats, err := a.db.Chats().ListChats()
|
||||
if err != nil {
|
||||
a.logger.Error("unable to retrieve chats:", err)
|
||||
|
|
@ -125,6 +123,22 @@ func (a *App) daily() {
|
|||
a.logger.Error("could not retrieve this week's birthdays:", err)
|
||||
}
|
||||
}
|
||||
announce, err := a.db.Announcements().AnnouncementsToday(chat.ID)
|
||||
if err == nil && len(announce) > 0 {
|
||||
sb.WriteString("**<u>📢 Today's Announcements 📢</u>**\n\n")
|
||||
for _, ann := range announce {
|
||||
if ann.Title != "" {
|
||||
sb.WriteString("**")
|
||||
sb.WriteString(ann.Title)
|
||||
sb.WriteString("**")
|
||||
sb.WriteString("\n\n")
|
||||
}
|
||||
sb.WriteString(" * ")
|
||||
sb.WriteString(ann.Content)
|
||||
sb.WriteByte('\n')
|
||||
}
|
||||
sb.WriteByte('\n')
|
||||
}
|
||||
bdays, err := a.db.Birthdays().BirthdaysToday(chat.ID)
|
||||
if err == nil && len(bdays) > 0 {
|
||||
sb.WriteString("**<u>Today's Birthday")
|
||||
|
|
|
|||
|
|
@ -10,13 +10,14 @@ import (
|
|||
)
|
||||
|
||||
type commands struct {
|
||||
ctx context.Context
|
||||
root vfs.VFS
|
||||
birthday *birthday
|
||||
chats *chats
|
||||
meta *metadata
|
||||
verse *verse
|
||||
settings *settings.Settings
|
||||
ctx context.Context
|
||||
root vfs.VFS
|
||||
announcement *announcement
|
||||
birthday *birthday
|
||||
chats *chats
|
||||
meta *metadata
|
||||
verse *verse
|
||||
settings *settings.Settings
|
||||
}
|
||||
|
||||
func NewCommandHost(ctx context.Context, root vfs.VFS) (*commands, error) {
|
||||
|
|
@ -56,6 +57,16 @@ func (c *commands) Initalizer() *installer {
|
|||
return i
|
||||
}
|
||||
|
||||
func (c *commands) Announcements() *announcement {
|
||||
if c.announcement == nil {
|
||||
c.announcement = &announcement{
|
||||
fs: c.root,
|
||||
settings: c.settings,
|
||||
}
|
||||
}
|
||||
return c.announcement
|
||||
}
|
||||
|
||||
func (c *commands) Birthdays() *birthday {
|
||||
if c.birthday == nil {
|
||||
c.birthday = &birthday{
|
||||
|
|
|
|||
|
|
@ -20,9 +20,10 @@ type Database struct {
|
|||
db *sqlx.DB
|
||||
conf *settings.Settings
|
||||
|
||||
birthdays *BirthdayModel
|
||||
chats *ChatModel
|
||||
verses *VerseModel
|
||||
announcements *AnnouncementModel
|
||||
birthdays *BirthdayModel
|
||||
chats *ChatModel
|
||||
verses *VerseModel
|
||||
}
|
||||
|
||||
func OpenDatabase(ctx context.Context, conf *settings.Settings) *Database {
|
||||
|
|
@ -60,6 +61,13 @@ func (d *Database) Migrate(migrations vfs.VFS) error {
|
|||
return migrator.Up()
|
||||
}
|
||||
|
||||
func (d *Database) Announcements() *AnnouncementModel {
|
||||
if d.announcements == nil {
|
||||
d.announcements = NewAnnouncementModel(d.ctx, d.db)
|
||||
}
|
||||
return d.announcements
|
||||
}
|
||||
|
||||
func (d *Database) Birthdays() *BirthdayModel {
|
||||
if d.birthdays == nil {
|
||||
d.birthdays = NewBirthdayModel(d.ctx, d.db)
|
||||
|
|
|
|||
Loading…
Reference in a new issue