Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
adds ability to login using a token
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Winkler committed Aug 19, 2016
1 parent e0170df commit c8ce0c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 11 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ func main() {
cfg = ini.Empty()
}

if !cfg.Section("auth").HasKey("email") ||
!cfg.Section("auth").HasKey("password") {
if (!cfg.Section("auth").HasKey("email") ||
!cfg.Section("auth").HasKey("password")) &&
!cfg.Section("auth").HasKey("token") {
cfg.Section("auth").NewKey("email", "your@email.com")
cfg.Section("auth").NewKey("password", "yourpassword")
cfg.Section("channels").NewKey("channelid1", "C:\\full\\path\\1")
Expand Down Expand Up @@ -86,9 +87,14 @@ func main() {
return
}

dg, err := discordgo.New(
cfg.Section("auth").Key("email").String(),
cfg.Section("auth").Key("password").String())
var dg *discordgo.Session
if cfg.Section("auth").HasKey("token") {
dg, err = discordgo.New(cfg.Section("auth").Key("token").String())
} else {
dg, err = discordgo.New(
cfg.Section("auth").Key("email").String(),
cfg.Section("auth").Key("password").String())
}
if err != nil {
fmt.Println("error creating Discord session,", err)
return
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ This is a simple tool which downloads pictures posted in discord channels of you
## How to use?
When you run the tool for the first time it creates an `config.ini` file with example values. Edit these values and run the tool for a second time. It should connect to discords api and wait for new messages.

In case you are using two-factor authentication you have to login using your token. Remove the the email and password lines under the auth section in the config file and instead put in `token = <your token>`. You can acquire your token from the developer tools in your browser (`localStorage.token`).

### Where do I get the channel id?
Open discord in your browser and go to the channel you want to monitor. In your adress bar should be an URL like `https://discordapp.com/channels/1234/5678`. The number after the last slash is the channel id, in this case `5678`.

0 comments on commit c8ce0c9

Please sign in to comment.