From fc6aed71f513c83f0ae6aee74cc8410f0c4af0a9 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 15 Sep 2007 10:10:30 +0000 Subject: [PATCH] twitter plugin: don't update status if message length is > 160 characters, and give a warning when > 140 Twitter has a hard limit for message lengths at 160, and the recommended maximum length is 140 characters, so enforce the hard limit and warn when the soft limit is passed --- data/rbot/plugins/twitter.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/data/rbot/plugins/twitter.rb b/data/rbot/plugins/twitter.rb index 79d46619..25ceb63a 100644 --- a/data/rbot/plugins/twitter.rb +++ b/data/rbot/plugins/twitter.rb @@ -99,7 +99,18 @@ class TwitterPlugin < Plugin pass = URI.escape(@registry[m.sourcenick + "_password"]) uri = "http://#{user}:#{pass}@twitter.com/statuses/update.xml" - body = "status=#{CGI.escape(params[:status].to_s)}" + msg = params[:status].to_s + + if msg.length > 160 + m.reply "your status message update is too long, please keep it under 140 characters if possible, 160 characters maximum" + return + end + + if msg.length > 140 + m.reply "your status message is longer than 140 characters, which is not optimal, but I'm going to update anyway" + end + + body = "status=#{CGI.escape(msg)}" response = @bot.httputil.post(uri, body, :headers => @header) debug response -- 2.39.5