Created
October 19, 2018 14:52
-
-
Save ladydascalie/e170ea965763524acd102465fdf6df27 to your computer and use it in GitHub Desktop.
;)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
#### BEFORE YOU RUN THIS #### | |
Make sure you got everything you need, and run this: | |
go get github.com/nlopes/slack | |
go get github.com/fatih/color | |
go get github.com/davecgh/go-spew/spew | |
THEN FILL IN THE VARIABLES AT THE BEGINING OF MAIN. | |
*/ | |
package main | |
import ( | |
"fmt" | |
"log" | |
"time" | |
"github.com/davecgh/go-spew/spew" | |
"github.com/fatih/color" | |
"github.com/nlopes/slack" | |
) | |
var g = color.HiGreenString | |
var r = color.HiRedString | |
var y = color.HiYellowString | |
func main() { | |
// click on your photo twice in any DMs to open your profile on the side bar then | |
// you should see an url like this: | |
// exmaple: https://lushglobal.slack.com/messages/{CHANNEL ID}/team/{USER ID}/ | |
// your user id, used for filtering, get it from your url | |
userID := "" | |
// the dm conversation id you wanna delete (get it from the url) | |
channel := "" | |
// your api token, get it from: https://api.slack.com/custom-integrations/legacy-tokens | |
token := "" | |
api := slack.New(token) | |
params := slack.HistoryParameters{ | |
Oldest: "0", | |
Latest: "", | |
Inclusive: false, | |
Count: 1000, | |
Unreads: true, | |
} | |
// prepare a func | |
call := func() (*slack.History, error) { | |
color.Green("New call made") | |
return api.GetIMHistory(channel, params) | |
} | |
history, err := call() | |
if err != nil { | |
log.Fatal(err) | |
} | |
var iter int | |
loop: // I'm lazy, so heck off | |
spew.Dump(len(history.Messages)) | |
for key, msg := range history.Messages { | |
if msg.User == userID { | |
retry: // I'm lazy, so heck off | |
_, _, err := api.DeleteMessage(channel, msg.Timestamp) | |
if err != nil { | |
fmt.Println(err) | |
fmt.Println(y("retrying:"), msg.Text) | |
time.Sleep(10 * time.Second) | |
goto retry // I'm lazy, so heck off | |
} | |
fmt.Println(r("deleted:"), g(msg.Text)) | |
time.Sleep(100 * time.Millisecond) | |
iter++ | |
if iter%15 == 0 { | |
time.Sleep(2 * time.Second) | |
} | |
} | |
if key == len(history.Messages)-1 && history.HasMore { | |
color.HiYellow(msg.Timestamp) | |
params.Latest = msg.Timestamp | |
history, err = call() | |
goto loop // I'm lazy, so heck off | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment