From cea0ee09384395992d408f70a26eafd70507ac6a Mon Sep 17 00:00:00 2001 From: gutmet Date: Thu, 17 Sep 2020 21:30:51 +0200 Subject: [PATCH] reply functionality --- Readme.md | 12 ++++++++++-- drivel.go | 24 +++++++++++++++++++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Readme.md b/Readme.md index 3821cda..5d34cb0 100644 --- a/Readme.md +++ b/Readme.md @@ -1,7 +1,7 @@ drivel ======== -drivel is a Twitter command line interface for status updates, media upload and mentions. +drivel is a Twitter command line interface for status updates, media upload, mentions and replies. My personal opinion is that you shouldn't be on Twitter in the first place, but anyway... @@ -27,13 +27,21 @@ To get your last 100 mentions: drivel mentions ``` -To update your status with optional media upload: +To update your status with optional media upload... ``` drivel status STATUS [FILE1, FILE2, ...] ``` +...or reply to a tweet with a specific ID: + + +``` +drivel reply TWEET_ID MESSAGE [FILE1, FILE2, ...] +``` + + with any number of files, as long as they are .jpg, .png, .gif or .mp4 and smaller than 5 MB each. On first use, drivel will ask you to go to [https://apps.twitter.com/app/new](https://apps.twitter.com/app/new), register a new app and create an access token. Those values will be stored in HOME/.drivel/ for later use. drivel will automatically split large status messages and multiple files into separate tweets belonging to the same thread. diff --git a/drivel.go b/drivel.go index 5d7b0f5..3a58b5e 100644 --- a/drivel.go +++ b/drivel.go @@ -324,11 +324,10 @@ func (d *data) uploadVideo(client *http.Client, i int) []ObjectID { return uploadAll(client, []string{vid}) } -func (d *data) push(client *http.Client) { +func (d *data) push(client *http.Client, previous ObjectID) { if d == nil { return } - var previous ObjectID = "" empty := false i, g, v := 0, 0, 0 for !empty { @@ -359,20 +358,25 @@ func (d *data) push(client *http.Client) { } } -func status(args []string) error { +func updateStatus(args []string, previous ObjectID) { d := splitArguments(args) httpClient := getClient() - d.push(httpClient) + d.push(httpClient, previous) +} + +func status(args []string) error { + updateStatus(args, "") return nil } type Mention struct { Full_text string + Id_str string User MentionUser } func (m Mention) String() string { - return m.User.Name + ":\n" + m.Full_text + return m.User.Name + " " + "(" + m.Id_str + ")" + ":\n" + m.Full_text } type MentionUser struct { @@ -393,10 +397,20 @@ func mentions(args []string) error { return nil } +func reply(args []string) error { + if len(args) < 2 { + fmt.Fprintln(os.Stderr, "Usage: drivel reply TWEET_ID MESSAGE [FILE1, FILE2, ...]") + os.Exit(-1) + } + updateStatus(args[1:], ObjectID(args[0])) + return nil +} + func main() { commands := []goutil.Command{ goutil.NewCommand("status", status, "post a status with message and/or media"), goutil.NewCommand("mentions", mentions, "get your mentions"), + goutil.NewCommand("reply", reply, "reply to a tweet with a specific ID"), } err := goutil.Execute(commands) if err != nil {