summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-15 10:10:30 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-15 10:10:30 +0000
commitfc6aed71f513c83f0ae6aee74cc8410f0c4af0a9 (patch)
treee16f6bbe0b766507118371b6e511b68a581b4138 /data
parente3931e43edf5b3c47fc94a1ae8405f1f213190cb (diff)
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
Diffstat (limited to 'data')
-rw-r--r--data/rbot/plugins/twitter.rb13
1 files changed, 12 insertions, 1 deletions
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