reply functionality

This commit is contained in:
gutmet 2020-09-17 21:30:51 +02:00
parent 838d6a85bf
commit cea0ee0938
2 changed files with 29 additions and 7 deletions

View File

@ -1,7 +1,7 @@
drivel 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 My personal opinion is that you shouldn't be on Twitter in the first place, but
anyway... anyway...
@ -27,13 +27,21 @@ To get your last 100 mentions:
drivel mentions drivel mentions
``` ```
To update your status with optional media upload: To update your status with optional media upload...
``` ```
drivel status STATUS [FILE1, FILE2, ...] 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. 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. drivel will automatically split large status messages and multiple files into separate tweets belonging to the same thread.

View File

@ -324,11 +324,10 @@ func (d *data) uploadVideo(client *http.Client, i int) []ObjectID {
return uploadAll(client, []string{vid}) return uploadAll(client, []string{vid})
} }
func (d *data) push(client *http.Client) { func (d *data) push(client *http.Client, previous ObjectID) {
if d == nil { if d == nil {
return return
} }
var previous ObjectID = ""
empty := false empty := false
i, g, v := 0, 0, 0 i, g, v := 0, 0, 0
for !empty { 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) d := splitArguments(args)
httpClient := getClient() httpClient := getClient()
d.push(httpClient) d.push(httpClient, previous)
}
func status(args []string) error {
updateStatus(args, "")
return nil return nil
} }
type Mention struct { type Mention struct {
Full_text string Full_text string
Id_str string
User MentionUser User MentionUser
} }
func (m Mention) String() string { 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 { type MentionUser struct {
@ -393,10 +397,20 @@ func mentions(args []string) error {
return nil 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() { func main() {
commands := []goutil.Command{ commands := []goutil.Command{
goutil.NewCommand("status", status, "post a status with message and/or media"), goutil.NewCommand("status", status, "post a status with message and/or media"),
goutil.NewCommand("mentions", mentions, "get your mentions"), goutil.NewCommand("mentions", mentions, "get your mentions"),
goutil.NewCommand("reply", reply, "reply to a tweet with a specific ID"),
} }
err := goutil.Execute(commands) err := goutil.Execute(commands)
if err != nil { if err != nil {