Skip to content

Commit

Permalink
http://pastebin.com/VcK2NvFM
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Jan 17, 2016
1 parent ce05e49 commit 2129ede
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/ml/hlaaftana/discordg/objects/API.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class API{
// if you want to use global variables through the API object. mostly for utility
Map<String, Object> fields = [:]
boolean cacheTokens = true
int eventThreadCount = 3
int eventThreadCount = 3 // if your bot is on tons of big servers, this might help however take up some CPU
boolean ignorePresenceUpdate = false // if your bot is on tons of big servers, this might help you lose some CPU

/**
* Builds a new API object. This is safe to do.
Expand Down
8 changes: 6 additions & 2 deletions src/ml/hlaaftana/discordg/objects/Member.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ml.hlaaftana.discordg.objects

import java.text.SimpleDateFormat
import java.util.List
import java.net.URL

Expand Down Expand Up @@ -31,8 +32,11 @@ class Member extends User{
/**
* @return a timestamp of when the member joined the server.
*/
String getJoinDate(){ return object["joined_at"] }

String getJoinDateRaw(){ return object["joined_at"] }
/**
* @return a Date object of when the member joined the server.
*/
Date getJoinDate(){ return new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSSSSXXX").parse(this.joinDateRaw) }
/**
* @return the roles this member has.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/ml/hlaaftana/discordg/objects/Server.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class Server extends Base {
List array = JSONUtil.parse(api.requester.get("https://discordapp.com/api/guilds/${this.getId()}/bans"))
List<User> bans = new ArrayList<User>()
for (o in array){
bans.add(new User(api, o))
bans.add(new User(api, o["user"]))
}
return bans
}
Expand Down
7 changes: 6 additions & 1 deletion src/ml/hlaaftana/discordg/objects/TextChannel.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ml.hlaaftana.discordg.objects

import groovy.json.JsonException
import java.util.List

import ml.hlaaftana.discordg.util.JSONUtil
Expand Down Expand Up @@ -39,7 +40,11 @@ class TextChannel extends Channel {
*/
Message sendMessage(String content, boolean tts=false) {
if (content.length() > 2000) throw new Exception("You tried to send a message longer than 2000 characters.")
return new Message(api, JSONUtil.parse(api.requester.post("https://discordapp.com/api/channels/${this.id}/messages", ["content": content, "tts": tts, "channel_id": this.id])))
try{
return new Message(api, JSONUtil.parse(api.requester.post("https://discordapp.com/api/channels/${this.id}/messages", ["content": content, "tts": tts, "channel_id": this.id])))
}catch (JsonException ex){
throw new Exception("You need to enter the chill zone.")
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/ml/hlaaftana/discordg/request/WSClient.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class WSClient{
@OnWebSocketMessage
void onMessage(Session session, String message) throws IOException{
def clos = {
if (api.ignorePresenceUpdate) return
Map content = JSONUtil.parse(message)
String type = content["t"]
Map data = content["d"]
Expand Down
14 changes: 14 additions & 0 deletions src/ml/hlaaftana/discordg/util/RandomUtil.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,18 @@ class RandomUtil {
}
return returnThis
}

static registerDiscordStringMethods(){
String.metaClass.removeFormatting = {
return delegate.replace("~", "\u200b~").replace("_", "\u200b_").replace("*", "\u200b*")
.replace("`", "\u200b`").replace(":", "\u200b:").replace(" ", "\u200b`").replace("/", "\u200b/")
.replace("@", "\u200b@").replace("<", "\u200b<").replace(">", "\u200b>")

}
String.metaClass.bold = { return "**$delegate**" }
String.metaClass.italic = { return "*$delegate*" }
String.metaClass.underline = { return "__${delegate}__" }
String.metaClass.code = { return "`$delegate`" }
String.metaClass.block = { String language="" -> return "```$language\n$delegate```" }
}
}

0 comments on commit 2129ede

Please sign in to comment.