diff --git a/build.gradle.example b/build.gradle.example new file mode 100644 index 0000000..e21b784 --- /dev/null +++ b/build.gradle.example @@ -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" \ No newline at end of file diff --git a/src/main/groovy/ml/hlaaftana/discordg/objects/API.groovy b/src/main/groovy/ml/hlaaftana/discordg/objects/API.groovy index 011e780..697a48d 100644 --- a/src/main/groovy/ml/hlaaftana/discordg/objects/API.groovy +++ b/src/main/groovy/ml/hlaaftana/discordg/objects/API.groovy @@ -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 } } @@ -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(' ', '_') } diff --git a/src/main/groovy/ml/hlaaftana/discordg/objects/Client.groovy b/src/main/groovy/ml/hlaaftana/discordg/objects/Client.groovy index 70cd62e..c10079c 100644 --- a/src/main/groovy/ml/hlaaftana/discordg/objects/Client.groovy +++ b/src/main/groovy/ml/hlaaftana/discordg/objects/Client.groovy @@ -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. @@ -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