From 0919398edc23e70ce7caaaf892b24082ca15014f Mon Sep 17 00:00:00 2001 From: Hamcha Date: Fri, 21 Apr 2017 10:18:57 +0200 Subject: [PATCH] unsplash: Try to strip unreadable characters --- mods/unsplash.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mods/unsplash.go b/mods/unsplash.go index dba2976..1ba99ca 100644 --- a/mods/unsplash.go +++ b/mods/unsplash.go @@ -41,6 +41,13 @@ func initunsplash() { log.Println("[unsplash] Loaded!") } +func stripUnreadable(r rune) rune { + if r < 32 || r >= 0x1f000 { + return -1 + } + return r +} + func unsplash(broker *tg.Broker, update tg.APIMessage) { if isCommand(update, "unsplash") { text := "" @@ -59,6 +66,9 @@ func unsplash(broker *tg.Broker, update tg.APIMessage) { } } + // Cleanup chars + text = strings.Map(stripUnreadable, text) + author := user.FirstName if user.LastName != "" { author = user.FirstName + " " + user.LastName