[smuxi] Engine-Twitter: implemented /delete command to delete tweets



commit 55bd63dda5e56f2f619417d7e26a1b0aa7debbf9
Author: Mirco Bauer <meebey meebey net>
Date:   Sun Jan 11 21:23:09 2015 +0100

    Engine-Twitter: implemented /delete command to delete tweets

 .../Protocols/Twitter/TwitterProtocolManager.cs    |   40 +++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)
---
diff --git a/src/Engine-Twitter/Protocols/Twitter/TwitterProtocolManager.cs 
b/src/Engine-Twitter/Protocols/Twitter/TwitterProtocolManager.cs
index faab1ff..16b035e 100644
--- a/src/Engine-Twitter/Protocols/Twitter/TwitterProtocolManager.cs
+++ b/src/Engine-Twitter/Protocols/Twitter/TwitterProtocolManager.cs
@@ -1,6 +1,6 @@
 // Smuxi - Smart MUltipleXed Irc
 // 
-// Copyright (c) 2009-2014 Mirco Bauer <meebey meebey net>
+// Copyright (c) 2009-2015 Mirco Bauer <meebey meebey net>
 // 
 // Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
 // 
@@ -675,6 +675,11 @@ namespace Smuxi.Engine
                             CommandSay(command);
                             handled = true;
                             break;
+                        case "del":
+                        case "delete":
+                            CommandDelete(command);
+                            handled = true;
+                            break;
                     }
                 }
                 switch (command.Command) {
@@ -729,6 +734,7 @@ namespace Smuxi.Engine
                 "search keyword",
                 "retweet/rt index-number|tweet-id",
                 "reply index-number|tweet-id message",
+                "delete/del index-number|tweet-id",
             };
 
             foreach (string line in help) {
@@ -1195,6 +1201,38 @@ namespace Smuxi.Engine
             PostUpdate(text, options);
         }
 
+        public void CommandDelete(CommandModel cmd)
+        {
+            if (cmd.DataArray.Length < 2) {
+                NotEnoughParameters(cmd);
+                return;
+            }
+
+            TwitterStatus status = null;
+            int indexId;
+            if (Int32.TryParse(cmd.Parameter, out indexId)) {
+                status = GetStatusFromIndex(indexId);
+            }
+
+            decimal statusId;
+            if (status == null) {
+                if (!Decimal.TryParse(cmd.Parameter, out statusId)) {
+                    return;
+                }
+            } else {
+                statusId = status.Id;
+            }
+            var response = TwitterStatus.Delete(f_OAuthTokens, statusId, f_OptionalProperties);
+            CheckResponse(response);
+            status = response.ResponseObject;
+
+            var msg = CreateMessageBuilder().
+                AppendEventPrefix().
+                AppendFormat(_("Successfully deleted tweet {0}."), cmd.Parameter).
+                ToMessage();
+            Session.AddMessageToFrontend(cmd, msg);
+        }
+
         private List<TwitterDirectMessage> SortTimeline(TwitterDirectMessageCollection timeline)
         {
             var sortedTimeline = new List<TwitterDirectMessage>(timeline.Count);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]