A package of Discord related entities and classes for SqlSauce.
Current main purpose: Provide a framework to save settings for users / guilds combined with keeping some data on them, like names or avatar urls etc.
Make sure to include the core package SqlSauce in your project. This module can then be added through this additional dependency:
dependencies {
compile group: 'space.npstr.SqlSauce', name: 'discord-entities', version: '0.2.3'
}
<dependency>
<groupId>space.npstr.SqlSauce</groupId>
<artifactId>discord-entities</artifactId>
<version>0.2.3</version>
</dependency>
Make sure to read the documentation of SqlSauce as this package relies on many of its concepts.
Example class:
@Entity(name = "MyGuildSettings")
@Table(name = "guild_settings")
public class MyGuildSettings extends DiscordGuild<MyGuildSettings> {
@Column(name = "prefix")
private String prefix = "!";
//for JPA / SaucedEntity
public MyGuildSettings() {
}
public static String getPrefix(long guildId) throws DatabaseException {
return load(guildId, MyGuildSettings.class).getPrefix();
}
public static MyGuildSettings setPrefix(long guildId, String prefix) throws DatabaseException {
return load(guildId, MyGuildSettings.class)
.setPrefix(prefix)
.save();
}
public String getPrefix() {
return prefix;
}
public MyGuildSettings setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
}
Setting the entity up to be automatically cached with JDA:
JDABuilder jdaBuilder = new JDABuilder(AccountType.BOT)
[...]
.addEventListener(new GuildCachingListener<>(MyGuildSettings.class))
[...];
Omitted versions mean there were no changes to this module. It is still recommended to use the latest version as shown on the core module readme.
CacheableGuild
s andCacheableUser
s allow more genericCachingListener
s
- Support
AsyncDatabaseWrapper
contract in the providedCachingListener
implementations
- Expose the cache pump of
CachingListener
s, good for instrumenting.
- Delete deprecated code (mostly static SaucedEntity abuse)
- Deprecate static abuse of the entities
- Replaced deprecated events in the UserMemberCachingListener
- Add better named id getters for base discord entities
- Add missing package-info.java files
- Bintray publishing fix
- base user and base guild entities
- Add package wide nullability annotations
- testing and publishing to Bintray
- Composite ids
- Fix guilds not being cached on join / leave
- Caching happens on a worker thread now instead of the main JDA thread
- Some constants are now publicly accessible
- module was renamed 'sqlsauce-discord-entities' -> 'discord-entities'
- default values for non-null columns added, this should help with upgrading
- mass sync / cache methods (useful after downtime / restarts); performance isn't good yet, especially when using it for users
- Users of a guild are cached when the bot joins a guild
- Guilds are cached on reconnect
- More complete attempt at looking up a user name
- Initial release with Proof of Concept for Guilds and a JDA listener
- static getters should not load the entity and instead look up the field by a direct query
- indices?
- Java Discord API