Fixed Review Comments, Cache & Entity Utility changes, Interaction changes
This commit is contained in:
parent
8e3f5b6a2f
commit
6d0c15fdaa
|
@ -1,3 +1,3 @@
|
|||
## 1.0.0
|
||||
## 1.1-dev.1
|
||||
|
||||
- Initial version, created by Stagehand
|
||||
- Initial version
|
||||
|
|
|
@ -2,11 +2,8 @@ library nyxx_interactions;
|
|||
|
||||
import "package:nyxx/nyxx.dart";
|
||||
|
||||
part "src/ExtendNyxx.dart";
|
||||
part "src/Interactions.dart";
|
||||
part "src/events/InteractionEvent.dart";
|
||||
part "src/models/CommandInteractionData.dart";
|
||||
part "src/models/CommandInteractionOption.dart";
|
||||
part "src/models/CommandInteractionOptionType.dart";
|
||||
part "src/models/Interaction.dart";
|
||||
part "src/models/InteractionType.dart";
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
part of nyxx_interactions;
|
||||
|
||||
extension on Nyxx {}
|
|
@ -2,7 +2,7 @@ part of nyxx_interactions;
|
|||
|
||||
class CommandInteractionOption {
|
||||
final String name;
|
||||
final CommandInteractionOptionType? value;
|
||||
final int? value;
|
||||
final List<CommandInteractionOption>? options;
|
||||
CommandInteractionOption._new(this.name, this.value, this.options);
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
part of nyxx_interactions;
|
||||
|
||||
enum CommandInteractionOptionType {
|
||||
SUB_COMMAND,
|
||||
SUB_COMMAND_GROUP,
|
||||
STRING,
|
||||
INTEGER,
|
||||
BOOLEAN,
|
||||
USER,
|
||||
CHANNEL,
|
||||
ROLE
|
||||
}
|
|
@ -4,45 +4,65 @@ class Interaction extends SnowflakeEntity implements Disposable {
|
|||
/// Reference to bot instance
|
||||
final Nyxx client;
|
||||
|
||||
late final InteractionType type;
|
||||
late final int type;
|
||||
|
||||
late final CommandInteractionData? data;
|
||||
|
||||
late final Snowflake guild_id;
|
||||
late final Cacheable<Snowflake, Guild> guild;
|
||||
|
||||
late final Snowflake channel_id;
|
||||
late final Cacheable<Snowflake, IChannel> channel;
|
||||
|
||||
late final User author;
|
||||
late final Member author;
|
||||
|
||||
late final String token;
|
||||
|
||||
late final int version;
|
||||
|
||||
CommandInteractionData? _generateData(Map<String, dynamic> raw) {
|
||||
return raw["data"] != null
|
||||
? CommandInteractionData._new(
|
||||
Snowflake(raw["data"]["id"]),
|
||||
raw["data"]["name"] as String,
|
||||
null, //TODO Add Tree Implimentation to show options
|
||||
)
|
||||
: null;
|
||||
}
|
||||
|
||||
Interaction._new(
|
||||
this.client,
|
||||
Map<String, dynamic> raw,
|
||||
) : super(Snowflake(raw["id"])) {
|
||||
switch (raw["type"] as int) {
|
||||
case 1:
|
||||
{
|
||||
this.type = InteractionType.Ping;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
this.type = InteractionType.ApplicationCommand;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
this.type = InteractionType.Unknown;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.type = raw["type"] as int;
|
||||
|
||||
this.guild_id = Snowflake(raw["guild_id"]);
|
||||
this.channel_id = Snowflake(raw["channel_id"]);
|
||||
this.author =
|
||||
this.data = _generateData(
|
||||
raw,
|
||||
);
|
||||
|
||||
this.guild = CacheUtility.createCacheableGuild(
|
||||
client,
|
||||
Snowflake(
|
||||
raw["guild_id"],
|
||||
),
|
||||
);
|
||||
|
||||
this.channel = CacheUtility.createCacheableChannel(
|
||||
client,
|
||||
Snowflake(
|
||||
raw["channel_id"],
|
||||
),
|
||||
);
|
||||
|
||||
this.author = EntityUtility.createGuildMember(
|
||||
client,
|
||||
Snowflake(
|
||||
raw["guild_id"],
|
||||
),
|
||||
raw["member"] as Map<String, dynamic>,
|
||||
);
|
||||
|
||||
this.token = raw["token"] as String;
|
||||
|
||||
this.version = raw["version"] as int;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
part of nyxx_interactions;
|
||||
|
||||
enum InteractionType {
|
||||
Ping,
|
||||
ApplicationCommand,
|
||||
Unknown
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
name: nyxx_interactions
|
||||
version: 0.0.0-dev.1
|
||||
version: 1.1.0-dev.1
|
||||
description: Interactions for Nyxx library
|
||||
homepage: https://github.com/l7ssha/nyxx
|
||||
repository: https://github.com/l7ssha/nyxx
|
||||
|
@ -21,4 +21,4 @@ dependency_overrides:
|
|||
git:
|
||||
url: git://github.com/dart-lang/http_parser.git
|
||||
nyxx:
|
||||
path: "../nyxx"
|
||||
path: "../nyxx"
|
||||
|
|
|
@ -13,64 +13,45 @@ class CacheUtility {
|
|||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Cacheable<Snowflake, User> cachedUser = CacheUtility.users(bot, Snowflake(''));
|
||||
/// Cacheable<Snowflake, User> cachedUser = CacheUtility.createCacheableUser(bot, Snowflake(''));
|
||||
/// }
|
||||
/// ```
|
||||
Cacheable<Snowflake, User> users(
|
||||
Nyxx client,
|
||||
Snowflake id,
|
||||
) =>
|
||||
_UserCacheable(
|
||||
client,
|
||||
id,
|
||||
);
|
||||
static Cacheable<Snowflake, User> createCacheableUser(
|
||||
Nyxx client, Snowflake id) =>
|
||||
_UserCacheable(client, id);
|
||||
|
||||
/// Retrieves a cached Guild.
|
||||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Cacheable<Snowflake, Guild> cachedGuild = CacheUtility.guilds(bot, Snowflake(''));
|
||||
/// Cacheable<Snowflake, Guild> cachedGuild = CacheUtility.createCacheableGuild(bot, Snowflake(''));
|
||||
/// }
|
||||
/// ```
|
||||
Cacheable<Snowflake, Guild> guilds(
|
||||
Nyxx client,
|
||||
Snowflake id,
|
||||
) =>
|
||||
_GuildCacheable(
|
||||
client,
|
||||
id,
|
||||
);
|
||||
static Cacheable<Snowflake, Guild> createCacheableGuild(
|
||||
Nyxx client, Snowflake id) =>
|
||||
_GuildCacheable(client, id);
|
||||
|
||||
/// Retrieves a cached Role.
|
||||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Cacheable<Snowflake, Guild> cachedGuild = CacheUtility.guilds(bot, Snowflake(''));
|
||||
/// Cacheable<Snowflake, Role> cachedRole = CacheUtility.roles(bot, Snowflake(''), cachedGuild);
|
||||
/// Cacheable<Snowflake, Role> cachedRole = CacheUtility.createCacheableRole(bot, Snowflake(''), cachedGuild);
|
||||
/// }
|
||||
/// ```
|
||||
Cacheable<Snowflake, Role> roles(
|
||||
Nyxx client,
|
||||
Snowflake id,
|
||||
Cacheable<Snowflake, Guild> guild,
|
||||
) =>
|
||||
_RoleCacheable(
|
||||
client,
|
||||
id,
|
||||
guild,
|
||||
);
|
||||
static Cacheable<Snowflake, Role> createCacheableRole(
|
||||
Nyxx client, Snowflake id, Cacheable<Snowflake, Guild> guild) =>
|
||||
_RoleCacheable(client, id, guild);
|
||||
|
||||
/// Retrieves a cached Role.
|
||||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Cacheable<Snowflake, IChannel> cachedChannel = CacheUtility.channels(bot, Snowflake(''));
|
||||
/// Cacheable<Snowflake, IChannel> cachedChannel = CacheUtility.createCacheableChannel(bot, Snowflake(''));
|
||||
/// }
|
||||
/// ```
|
||||
Cacheable<Snowflake, IChannel> channels(
|
||||
Nyxx client,
|
||||
Snowflake id,
|
||||
) =>
|
||||
static Cacheable<Snowflake, IChannel> createCacheableChannel(
|
||||
Nyxx client, Snowflake id) =>
|
||||
_ChannelCacheable(client, id);
|
||||
|
||||
/// Retrieves a cached Guild Member.
|
||||
|
@ -78,36 +59,22 @@ class CacheUtility {
|
|||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Cacheable<Snowflake, Guild> cachedGuild = CacheUtility.guilds(bot, Snowflake(''));
|
||||
/// Cacheable<Snowflake, Member> cachedMember = CacheUtility.members(bot, Snowflake(''), cachedGuild);
|
||||
/// Cacheable<Snowflake, Member> cachedMember = CacheUtility.createCacheableMember(bot, Snowflake(''), cachedGuild);
|
||||
/// }
|
||||
/// ```
|
||||
Cacheable<Snowflake, Member> members(
|
||||
Nyxx client,
|
||||
Snowflake id,
|
||||
Cacheable<Snowflake, Guild> guild,
|
||||
) =>
|
||||
_MemberCacheable(
|
||||
client,
|
||||
id,
|
||||
guild,
|
||||
);
|
||||
static Cacheable<Snowflake, Member> createCacheableMember(
|
||||
Nyxx client, Snowflake id, Cacheable<Snowflake, Guild> guild) =>
|
||||
_MemberCacheable(client, id, guild);
|
||||
|
||||
/// Retrieves a cached Guild Member.
|
||||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Cacheable<Snowflake, TextChannel> cachedChannel = CacheUtility.channels(bot, Snowflake(''));
|
||||
/// Cacheable<Snowflake, Member> cachedMember = CacheUtility.messages(bot, Snowflake(''), cachedChannel);
|
||||
/// Cacheable<Snowflake, Member> cachedMember = CacheUtility.createCacheableMessage(bot, Snowflake(''), cachedChannel);
|
||||
/// }
|
||||
/// ```
|
||||
Cacheable<Snowflake, Message> messages(
|
||||
Nyxx client,
|
||||
Snowflake id,
|
||||
Cacheable<Snowflake, TextChannel> channel,
|
||||
) =>
|
||||
_MessageCacheable(
|
||||
client,
|
||||
id,
|
||||
channel,
|
||||
);
|
||||
static Cacheable<Snowflake, Message> createCacheableMessage(Nyxx client,
|
||||
Snowflake id, Cacheable<Snowflake, TextChannel> channel) =>
|
||||
_MessageCacheable(client, id, channel);
|
||||
}
|
||||
|
|
|
@ -5,135 +5,101 @@ part of nyxx;
|
|||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Map<String, dynamic> json = /* JSON from the API */
|
||||
/// User user = EntityUtility.createUser(bot, json);
|
||||
/// Map<String, dynamic> rawJson = /* rawJson from the API */
|
||||
/// User user = EntityUtility.createUser(bot, rawJson);
|
||||
/// }
|
||||
/// ```
|
||||
class EntityUtility {
|
||||
/// Creates a User object, can be used for other classes where you have correct JSON data from the API.
|
||||
/// Creates a User object, can be used for other classes where you have correct rawJson data from the API.
|
||||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Map<String, dynamic> json = /* JSON from the API */
|
||||
/// User user = EntityUtility.createUser(bot, json);
|
||||
/// Map<String, dynamic> rawJson = /* rawJson from the API */
|
||||
/// User user = EntityUtility.createUser(bot, rawJson);
|
||||
/// }
|
||||
/// ```
|
||||
User createUser(
|
||||
Nyxx client,
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
User._new(
|
||||
client,
|
||||
json,
|
||||
);
|
||||
static User createUser(Nyxx client, Map<String, dynamic> rawJson) =>
|
||||
User._new(client, rawJson);
|
||||
|
||||
/// Creates a Guild object, can be used for other classes where you have correct JSON data from the API.
|
||||
/// Creates a Guild object, can be used for other classes where you have correct rawJson data from the API.
|
||||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Map<String, dynamic> json = /* JSON from the API */
|
||||
/// Guild guild = EntityUtility.createGuild(bot, json);
|
||||
/// Map<String, dynamic> rawJson = /* rawJson from the API */
|
||||
/// Guild guild = EntityUtility.createGuild(bot, rawJson);
|
||||
/// }
|
||||
/// ```
|
||||
Guild createGuild(
|
||||
Nyxx client,
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
Guild._new(
|
||||
client,
|
||||
json,
|
||||
);
|
||||
static Guild createGuild(Nyxx client, Map<String, dynamic> rawJson) =>
|
||||
Guild._new(client, rawJson);
|
||||
|
||||
/// Creates a Role object, can be used for other classes where you have correct JSON data from the API.
|
||||
/// Creates a Role object, can be used for other classes where you have correct rawJson data from the API.
|
||||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Map<String, dynamic> json = /* JSON from the API */
|
||||
/// Role role = EntityUtility.createRole(bot, json, Snowflake("81384788765712384"));
|
||||
/// Map<String, dynamic> rawJson = /* rawJson from the API */
|
||||
/// Role role = EntityUtility.createRole(bot, Snowflake("81384788765712384"), rawJson);
|
||||
/// }
|
||||
/// ```
|
||||
Role createRole(
|
||||
Nyxx client,
|
||||
Snowflake guildId,
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
Role._new(
|
||||
client,
|
||||
json,
|
||||
guildId,
|
||||
);
|
||||
static Role createRole(
|
||||
Nyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
|
||||
Role._new(client, rawJson, guildId);
|
||||
|
||||
/// Creates a CategoryGuildChannel object, can be used for other classes where you have correct JSON data from the API.
|
||||
/// Creates a CategoryGuildChannel object, can be used for other classes where you have correct rawJson data from the API.
|
||||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Map<String, dynamic> json = /* JSON from the API */
|
||||
/// CategoryGuildChannel category = EntityUtility.createCategoryGuildChannel(bot, json, Snowflake("81384788765712384"));
|
||||
/// Map<String, dynamic> rawJson = /* rawJson from the API */
|
||||
/// CategoryGuildChannel category = EntityUtility.createCategoryGuildChannel(bot, Snowflake("81384788765712384"), rawJson);
|
||||
/// }
|
||||
/// ```
|
||||
CategoryGuildChannel createCategoryGuildChannel(
|
||||
Nyxx client,
|
||||
Snowflake guildId,
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
CategoryGuildChannel._new(
|
||||
client,
|
||||
json,
|
||||
guildId,
|
||||
);
|
||||
static CategoryGuildChannel createCategoryGuildChannel(
|
||||
Nyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
|
||||
CategoryGuildChannel._new(client, rawJson, guildId);
|
||||
|
||||
/// Creates a VoiceGuildChannel object, can be used for other classes where you have correct JSON data from the API.
|
||||
/// Creates a VoiceGuildChannel object, can be used for other classes where you have correct rawJson data from the API.
|
||||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Map<String, dynamic> json = /* JSON from the API */
|
||||
/// VoiceGuildChannel voiceChannel = EntityUtility.createVoiceGuildChannel(bot, json, Snowflake("81384788765712384"));
|
||||
/// Map<String, dynamic> rawJson = /* rawJson from the API */
|
||||
/// VoiceGuildChannel voiceChannel = EntityUtility.createVoiceGuildChannel(bot, Snowflake("81384788765712384"), rawJson);
|
||||
/// }
|
||||
/// ```
|
||||
VoiceGuildChannel createVoiceGuildChannel(
|
||||
Nyxx client,
|
||||
Snowflake guildId,
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
VoiceGuildChannel._new(
|
||||
client,
|
||||
json,
|
||||
guildId,
|
||||
);
|
||||
static VoiceGuildChannel createVoiceGuildChannel(
|
||||
Nyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
|
||||
VoiceGuildChannel._new(client, rawJson, guildId);
|
||||
|
||||
/// Creates a Guild object, can be used for other classes where you have correct JSON data from the API.
|
||||
/// Creates a Guild object, can be used for other classes where you have correct rawJson data from the API.
|
||||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Map<String, dynamic> json = /* JSON from the API */
|
||||
/// TextGuildChannel textChannel = EntityUtility.createTextGuildChannel(bot, json, Snowflake("81384788765712384"));
|
||||
/// Map<String, dynamic> rawJson = /* rawJson from the API */
|
||||
/// TextGuildChannel textChannel = EntityUtility.createTextGuildChannel(bot, Snowflake("81384788765712384"), rawJson);
|
||||
/// }
|
||||
/// ```
|
||||
TextGuildChannel createTextGuildChannel(
|
||||
Nyxx client,
|
||||
Snowflake guildId,
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
TextGuildChannel._new(
|
||||
client,
|
||||
json,
|
||||
guildId,
|
||||
);
|
||||
static TextGuildChannel createTextGuildChannel(
|
||||
Nyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
|
||||
TextGuildChannel._new(client, rawJson, guildId);
|
||||
|
||||
/// Creates a Guild object, can be used for other classes where you have correct JSON data from the API.
|
||||
/// Creates a Guild object, can be used for other classes where you have correct rawJson data from the API.
|
||||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Map<String, dynamic> json = /* JSON from the API */
|
||||
/// DMChannel dmChannel = EntityUtility.createDMChannel(bot, json);
|
||||
/// Map<String, dynamic> rawJson = /* rawJson from the API */
|
||||
/// DMChannel dmChannel = EntityUtility.createDMChannel(bot, rawJson);
|
||||
/// }
|
||||
/// ```
|
||||
DMChannel createDMChannel(
|
||||
Nyxx client,
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
DMChannel._new(
|
||||
client,
|
||||
json,
|
||||
);
|
||||
static DMChannel createDMChannel(Nyxx client, Map<String, dynamic> rawJson) =>
|
||||
DMChannel._new(client, rawJson);
|
||||
|
||||
/// Creates a Guild Member object, can be used for other classes where you have correct rawJson data from the API.
|
||||
/// ```dart
|
||||
/// void main() {
|
||||
/// var bot = Nyxx("TOKEN");
|
||||
/// Map<String, dynamic> rawJson = /* rawJson from the API */
|
||||
/// DMChannel dmChannel = EntityUtility.createGuildMember(bot, Snowflake(''), rawJson);
|
||||
/// }
|
||||
/// ```
|
||||
static Member createGuildMember(
|
||||
Nyxx client, Snowflake guildId, Map<String, dynamic> rawJson) =>
|
||||
Member._new(client, rawJson, guildId);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue