Telegram: Send messages via telegram

Most messages are now sent as plaintext via telegram when suitable.
This commit is contained in:
Harvey Tindall
2021-05-07 16:06:47 +01:00
parent 72bf280e2d
commit 716d6a931a
10 changed files with 118 additions and 112 deletions
+10 -9
View File
@@ -71,9 +71,10 @@ func (app *appContext) checkUsers() {
mode = "delete"
termPlural = "Deleting"
}
email := false
if emailEnabled && app.config.Section("user_expiry").Key("send_email").MustBool(true) {
email = true
contact := false
if (emailEnabled && app.config.Section("user_expiry").Key("send_email").MustBool(true)) ||
app.config.Section("telegram").Key("enabled").MustBool(false) {
contact = true
}
// Use a map to speed up checking for deleted users later
userExists := map[string]bool{}
@@ -114,18 +115,18 @@ func (app *appContext) checkUsers() {
}
delete(app.storage.users, id)
app.jf.CacheExpiry = time.Now()
if email {
address, ok := app.storage.emails[id]
if contact {
if !ok {
continue
}
name := app.getAddressOrName(user.ID)
msg, err := app.email.constructUserExpired(app, false)
if err != nil {
app.err.Printf("Failed to construct expiry email for \"%s\": %s", user.Name, err)
} else if err := app.email.send(msg, address.(string)); err != nil {
app.err.Printf("Failed to send expiry email to \"%s\": %s", user.Name, err)
app.err.Printf("Failed to construct expiry message for \"%s\": %s", user.Name, err)
} else if err := app.sendByID(msg, user.ID); err != nil {
app.err.Printf("Failed to send expiry message to \"%s\": %s", name, err)
} else {
app.info.Printf("Sent expiry notification to \"%s\"", address.(string))
app.info.Printf("Sent expiry notification to \"%s\"", name)
}
}
}