public virtual IAsyncResult BeginSendDirectMessage(SendDirectMessageOptions options) { var text = options.Text; var user_id = options.UserId; var screen_name = options.ScreenName; return BeginWithHammock<TwitterDirectMessage>(WebMethod.Post, "direct_messages/new", FormatAsString, "?text=", text, "&user_id=", user_id, "&screen_name=", screen_name); }
public virtual void SendDirectMessage(SendDirectMessageOptions options, Action<TwitterDirectMessage, TwitterResponse> action) { var text = options.Text; var user_id = options.UserId; var screen_name = options.ScreenName; WithHammock(WebMethod.Post, action, "direct_messages/new", FormatAsString, "?text=", text, "&user_id=", user_id, "&screen_name=", screen_name); }
public virtual Task<TwitterResponse<TwitterDirectMessage>> SendDirectMessageAsync(SendDirectMessageOptions options) { var text = options.Text; var user_id = options.UserId; var screen_name = options.ScreenName; return ExecuteRequest<TwitterDirectMessage>(HttpMethod.Post, "direct_messages/new", FormatAsString, "?text=", text, "&user_id=", user_id, "&screen_name=", screen_name); }
/// <summary> /// Replies to a tweet without mentioning the other participants /// </summary> private void ReplyQuiet(string command) { if (User.IsMissingArgs(command) == false) /* Checks if arguments are missing from the command */ { if (command.Split(' ')[1].Length != 2) { ScreenDraw.ShowMessage("Wrong syntax. Use /rn [id] [reply]"); } else { char[] splitter = { ' ' }; string message = command.Split(splitter, 3)[2]; SendTweetOptions replyOpts = new SendTweetOptions(); Int64 tweetID = (Int64)TweetIdentification.GetTweetID(command.Split(' ')[1]).InReplyToStatusId; InteractiveTweet twit = TweetIdentification.FindTweet(tweetID); if (twit.IsDirectMessage) { SendDirectMessageOptions dmOpts = new SendDirectMessageOptions(); dmOpts.Text = message; dmOpts.ScreenName = twit.AuthorScreenName; User.Account.SendDirectMessage(dmOpts); if (User.Account.Response.Error != null) { TwitterError error = User.Account.Response.Error; ScreenDraw.ShowMessage(error.Code + ": " + error.Message); } } else { replyOpts.InReplyToStatusId = tweetID; replyOpts.Status = message; User.Account.BeginSendTweet(replyOpts); if (User.Account.Response.Error != null) { TwitterError error = User.Account.Response.Error; ScreenDraw.ShowMessage(error.Code + ": " + error.Message); } } } } }
/// <summary> /// Posts a reply to a tweet /// </summary> /// <param name="command">the full command used</param> /// <returns>should the program ask for more input from the user?</returns> private void ReplyGeneric(string command) { if (User.IsMissingArgs(command) == false) /* It's just an exception catching method, don't mind it */ { if (command.Split(' ')[1].Length != 2) { ScreenDraw.ShowMessage("Wrong syntax. Use /r [id] [reply]"); } else { char[] splitter = { ' ' }; string message = ""; try { message = command.Split(splitter, 3)[2]; } catch (Exception) { ScreenDraw.ShowMessage("The command was missing arguments"); return; } SendTweetOptions replyOpts = new SendTweetOptions(); Int64 tweetID = 0; try { tweetID = (Int64)TweetIdentification.GetTweetID(command.Split(' ')[1]).InReplyToStatusId; } catch (InvalidOperationException) { ScreenDraw.ShowMessage("Such an update does not exist"); return; } InteractiveTweet tweetReplyingTo = TweetIdentification.FindTweet(tweetID); if (tweetReplyingTo.IsDirectMessage) { SendDirectMessageOptions dmOpts = new SendDirectMessageOptions(); dmOpts.Text = message; dmOpts.ScreenName = tweetReplyingTo.AuthorScreenName; User.Account.SendDirectMessage(dmOpts); if (User.Account.Response.Error != null) { TwitterError error = User.Account.Response.Error; ScreenDraw.ShowMessage(error.Code + ": " + error.Message); } } else { string[] words = tweetReplyingTo.Contents.Split(' '); string userScreenName = GetUpdates.userScreenName.ToLower(); for (int index = 0; index < words.Length; index++) /* This checks for extra people mentioned in the tweet */ { if (words[index].StartsWith("@") && words[index].CompareTo("@") != 0) { if (words[index].ToLower().CompareTo("@" + userScreenName) != 0) { replyOpts.Status = replyOpts.Status + words[index] + " "; } } } replyOpts.InReplyToStatusId = tweetID; replyOpts.Status = replyOpts.Status + message; User.Account.BeginSendTweet(replyOpts); } } } }
/// <summary> /// Replies only to the tweet author, not mentioning everyone else the author mentioned /// </summary> private void ReplyClean(string command) { if (User.IsMissingArgs(command) == false) /* It's just an exception catching method, don't mind it */ { if (command.Split(' ')[1].Length != 2) { ScreenDraw.ShowMessage("Wrong syntax. Use /r [id] [reply]"); } else { char[] splitter = { ' ' }; /* Because why not? */ string message = ""; try { message = command.Split(splitter, 3)[2]; } catch (Exception) { ScreenDraw.ShowMessage("Wrong syntax. Use /r [id] [reply]"); return; } SendTweetOptions replyOpts = new SendTweetOptions(); Int64 tweetID = (Int64)TweetIdentification.GetTweetID(command.Split(' ')[1]).InReplyToStatusId; InteractiveTweet twit = TweetIdentification.FindTweet(tweetID); if (twit.IsDirectMessage) { SendDirectMessageOptions dmOpts = new SendDirectMessageOptions(); dmOpts.Text = message; dmOpts.ScreenName = twit.AuthorScreenName; User.Account.SendDirectMessage(dmOpts); if (User.Account.Response.Error != null) { TwitterError error = User.Account.Response.Error; ScreenDraw.ShowMessage(error.Code + ": " + error.Message); } } else { replyOpts.InReplyToStatusId = tweetID; replyOpts.Status = replyOpts.Status + " "; replyOpts.Status = replyOpts.Status + message; User.Account.BeginSendTweet(replyOpts); if (User.Account.Response.Error != null) { TwitterError error = User.Account.Response.Error; ScreenDraw.ShowMessage(error.Code + ": " + error.Message); } } } } }
/// <summary> /// Sends a direct message to someone /// </summary> /// <param name="command">The entire command to pass on</param> private void DirectMessage(string command) { char[] splitter = { ' ' }; if (User.IsMissingArgs(command) == false) /* Checks if arguments are missing from the command */ { if (command.Split(' ')[1].Length != 2 && command.Split(' ')[1].StartsWith("@") == false) { ScreenDraw.ShowMessage("Wrong syntax. Use /dm [id] or /dm @[name]"); return; } string screenName = ""; if (command.Split(' ')[1].StartsWith("@")) { screenName = command.Split(' ')[1].Remove(0, 1); } else { try { long tweetID = Convert.ToInt64(TweetIdentification.GetTweetID(command.Split(' ')[1]).InReplyToStatusId); InteractiveTweet tweet = TweetIdentification.FindTweet(tweetID); screenName = tweet.AuthorScreenName; } catch (KeyNotFoundException exIn) { ScreenDraw.ShowMessage(exIn.Message); } } SendDirectMessageOptions dmOpts = new SendDirectMessageOptions(); dmOpts.ScreenName = screenName; try { dmOpts.Text = command.Split(splitter, 3)[2]; } catch (Exception) { ScreenDraw.ShowMessage("Wrong syntax. Use /dm [id] or /dm @[name]"); return; } User.Account.SendDirectMessage(dmOpts); if (User.Account.Response.Error != null) { TwitterError error = User.Account.Response.Error; ScreenDraw.ShowMessage(error.Code + ": " + error.Message); } } }