Skip to content

Commit

Permalink
pokfpskfp
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed May 8, 2020
1 parent 6ffc4e9 commit 55ad493
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.settings/
/libs/
/bin/
/.classpath
/.project
Expand Down
12 changes: 6 additions & 6 deletions src/main/groovy/hlaaftana/discordg/Client.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Client extends User {
beAnAsshole ? customUserAgent : "$DiscordG.USER_AGENT $customUserAgent"
}

String tokenPrefix
String tokenPrefix = 'Bot'
String rawToken
boolean botField
String email, emailField
Expand Down Expand Up @@ -256,7 +256,7 @@ class Client extends User {
}

void setToken(String newToken) {
rawToken = newToken
rawToken = newToken.startsWith('Bot ') ? newToken.substring(4) : newToken
}

void setConfirmedBot(boolean ass) {
Expand Down Expand Up @@ -485,8 +485,8 @@ class Client extends User {

Member member(t) { (Member) findNested(guildCache, "memberCache", t) }
List<Member> members(t) { findAllNested(guildCache, "memberCache", t) }
Member member(s, u) { find(guildCache[Snowflake.from(s)].memberCache, u) }
List<Member> members(s, u) { findAll(guildCache[Snowflake.from(s)].memberCache, u) }
Member member(s, u) { this.<Member>find(guildCache[Snowflake.from(s)].memberCache, u) }
List<Member> members(s, u) { this.<Member>findAll(guildCache[Snowflake.from(s)].memberCache, u) }

User user(u) { (User) (member(u)?.user ?:
findNested(privateChannelCache, 'recipientCache', u) ?:
Expand All @@ -510,8 +510,8 @@ class Client extends User {

Role role(r) { (Role) findNested(guildCache, "roleCache", r) }
List<Role> roles(r) { findAllNested(guildCache, "roleCache", r) }
Role role(s, r) { find(guildCache[Snowflake.from(s)].roleCache, r) }
List<Role> roles(s, r) { findAll(guildCache[Snowflake.from(s)].roleCache, r) }
Role role(s, r) { this.<Role>find(guildCache[Snowflake.from(s)].roleCache, r) }
List<Role> roles(s, r) { this.<Role>findAll(guildCache[Snowflake.from(s)].roleCache, r) }

Call ongoingCall(c) { calls[Snowflake.from(c)] }

Expand Down
2 changes: 2 additions & 0 deletions src/main/groovy/hlaaftana/discordg/DiscordObject.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ abstract class DiscordObject implements Comparable {
if (null == map) return
def f = map.id
if (f instanceof String) jsonField('id', (String) f)
def auth = map.author
if (auth instanceof Map) jsonField('author', (Map) auth)
for (e in map.entrySet()) if (e.key instanceof String) jsonField((String) e.key, e.value)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import static groovy.lang.Closure.DELEGATE_FIRST
@CompileStatic
class ClientBuilder {
Map options
@Delegate(excludes = ['client', 'toString', 'getClass', 'sendFile']) Client client
@Delegate(excludes = ['toString', 'getClass', 'sendFile']) Client client

ClientBuilder(Map options = [:]) {
client = new Client()
Expand Down
1 change: 1 addition & 0 deletions src/main/groovy/hlaaftana/discordg/net/HTTPClient.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class HTTPClient {

HttpURLConnection headerUp(HttpURLConnection req) {
if (null != client.token) req.setRequestProperty('Authorization', client.token)
println client.token
if (req.requestMethod != 'GET') req.setRequestProperty('Content-Type', 'application/json')
req.setRequestProperty('User-Agent', null != client ? client.fullUserAgent : DiscordG.USER_AGENT)
req
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/hlaaftana/discordg/net/WSClient.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class WSClient extends WebSocketAdapter {
else if (type.contains('CHANNEL'))
data.channel = client.channel(data.id) ?: new Channel(client, data)
else if (type.contains('MESSAGE'))
data.message = ((Channel) data.channel).message(data.id, false) ?: new Message(client, data)
data.message = client.channel(data.channel_id).message(data.id, false) ?: new Message(client, data)
}
if (data.channel_id) data.channel = client.channel(data.channel_id)
if (data.guild_id) data.guild = client.guild(data.guild_id)
Expand Down
8 changes: 4 additions & 4 deletions src/main/groovy/hlaaftana/discordg/objects/Guild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ class Guild extends DiscordObject {

@InheritConstructors
static class Ban extends DiscordObject {
@Delegate(excludes = ['getClient', 'getClass', 'toString']) User user
@Delegate(excludes = ['getClass', 'toString']) User user
String reason

void jsonField(String name, value) {
Expand Down Expand Up @@ -751,7 +751,7 @@ class Role extends DiscordObject {
class Member extends DiscordObject {
Snowflake guildId
Set<Snowflake> roleIds
@Delegate(excludes = ['getClient', 'getClass', 'toString']) User user
@Delegate(excludeTypes = [Client]) User user
String rawNick, rawJoinedAt
boolean mute, deaf

Expand All @@ -762,14 +762,14 @@ class Member extends DiscordObject {
void jsonField(String name, value) {
final field = FIELDS.get(name)
if (null != field) jsonField(field, value)
else client.log.warn("Unknown field $name for ${this.class}")
else super.getClient().log.warn("Unknown field $name for ${this.class}")
}

void jsonField(Integer field, value) {
if (null == field) return
int f = field.intValue()
if (f == 1) {
if (null == user) user = new User(client)
if (null == user) user = new User(super.getClient())
user.fill((Map) value)
} else if (f == 2) {
roleIds = Snowflake.swornStringSet(value)
Expand Down
1 change: 1 addition & 0 deletions src/main/groovy/hlaaftana/discordg/objects/Message.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Message extends DiscordObject {
final map = (Map) value
if (null != guildIdField) {
def mem = new Member(client)
mem.user = author
mem.guildId = guildIdField
mem.fill(map)
client.guildCache[guildIdField].memberCache[mem.id] = mem
Expand Down
4 changes: 2 additions & 2 deletions src/main/groovy/hlaaftana/discordg/objects/User.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class Application extends DiscordObject {
@InheritConstructors
class Profile extends DiscordObject {
Snowflake id
@Delegate(excludes = ['getClient', 'getClass', 'toString', 'getId', 'setId']) User user
@Delegate(excludes = ['getClass', 'toString', 'getId']) User user
boolean premium
List<Map> accounts
Set<Snowflake> mutualGuildIds
Expand Down Expand Up @@ -283,7 +283,7 @@ class Profile extends DiscordObject {
@CompileStatic
@InheritConstructors
class Relationship extends DiscordObject {
@Delegate(excludes = ['getClient', 'getClass', 'toString']) User user
@Delegate(excludes = ['getClass', 'toString']) User user
int type

void jsonField(String name, value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ConversionUtil {
}

static byte[] getBytes(thing) {
try { (byte[]) invokeMethod('getBytes$', [thing] as Object[]) }
try { (byte[]) this.class.invokeMethod('getBytes$', [thing] as Object[]) }
catch (MissingMethodException ignore) { try { getBytesProperty(thing) }
catch (ex) { throw new UnsupportedOperationException("Cannot get byte array of $thing", ex) } }
}
Expand Down

0 comments on commit 55ad493

Please sign in to comment.