Skip to content

Commit

Permalink
build.gradle example and tweak to Client.editProfile and avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Feb 5, 2016
1 parent 228d845 commit 1a9d6e6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
32 changes: 32 additions & 0 deletions build.gradle.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apply plugin: 'groovy'

String discordGVersion = "2.0.0"

def downloadDiscordG = {
return new File("libs/${discordGVersion}.jar").with {
createNewFile()
mkdirs()
delegate
}.withOutputStream { out ->
out << new URL("https://github.com/hlaaftana/DiscordG/releases/download/${discordGVersion}/DiscordG-${discordGVersion}.jar").openStream()
delegate
}
}

jar {
from { configurations.compile.findAll { !it.path.contains("groovy") }.collect { it.directory ? it : zipTree(it) } }
}

repositories {
mavenCentral()
}

dependencies {
downloadDiscordG
compile 'org.codehaus.groovy:groovy-all:2.4.5'
compile files("libs/DiscordG-${discordGVersion}.jar")
}

version = "1"
group = "my.cool.program"
archivesBaseName = "AwesomeStuff"
4 changes: 2 additions & 2 deletions src/main/groovy/ml/hlaaftana/discordg/objects/API.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class API{
void removeListenersFor(String event){
for (e in listeners.entrySet()){
if (e.key == parseEventType(event)){
listeners.remove(e.key, e.value)
listeners[e.key] = []
return
}
}
Expand All @@ -208,7 +208,7 @@ class API{
* @param str - the string.
* @return the event name.
*/
String parseEventType(String str){
static String parseEventType(String str){
return str.toUpperCase().replace("CHANGE", "UPDATE").replace("SERVER", "GUILD").replace(' ', '_')
}

Expand Down
9 changes: 8 additions & 1 deletion src/main/groovy/ml/hlaaftana/discordg/objects/Client.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ml.hlaaftana.discordg.objects
import java.util.List
import java.util.Map

import ml.hlaaftana.discordg.util.JSONUtil
import ml.hlaaftana.discordg.util.*

/**
* The Discord client.
Expand Down Expand Up @@ -306,6 +306,13 @@ class Client{
*/
User editProfile(Map data){
Map map = ["avatar": this.user.avatarHash, "email": api.email, "password": api.password, "username": this.user.username]
if (data["avatar"] != null){
if (data["avatar"] instanceof String && !(data["avatar"].startsWith("data"))){
data["avatar"] = ConversionUtil.encodeToBase64(data["avatar"] as File)
}else if (data["avatar"] instanceof File){
data["avatar"] = ConversionUtil.encodeToBase64(data["avatar"])
}
}
Map response = JSONUtil.parse api.requester.patch("https://discordapp.com/api/users/@me", map << data)
api.email = response.email
api.password = (data["new_password"] != null && data["new_password"] instanceof String) ? data["new_password"] : api.password
Expand Down

0 comments on commit 1a9d6e6

Please sign in to comment.