Added reply convenience method for easy replying to message via inline replies; Changed allow api in ReplyBuilder by removing default values

This commit is contained in:
Szymon Uglis 2020-12-03 21:03:39 +01:00 committed by Szymon Uglis
parent 7850b5debd
commit f6d5dd82c6
No known key found for this signature in database
GPG key ID: 112376C5BEE91FE2
2 changed files with 39 additions and 8 deletions

View file

@ -37,6 +37,27 @@ class CommandContext {
static final _quotedTextRegex = RegExp('["\']([^"]*)["\']');
static final _codeBlocksRegex = RegExp(r"```(\w+)?(\s)?(((.+)(\s)?)+)```");
/// Creates inline reply for message
Future<Message> reply({
dynamic content,
EmbedBuilder? embed,
List<AttachmentBuilder>? files,
bool? tts,
AllowedMentions? allowedMentions,
MessageBuilder? builder,
bool mention = false,
}) async {
if (mention) {
if (allowedMentions != null) {
allowedMentions.allow(reply: true);
} else {
allowedMentions = AllowedMentions()..allow(reply: true);
}
}
return channel.sendMessage(content: content, embed: embed, tts: tts, allowedMentions: allowedMentions, builder: builder, replyBuilder: ReplyBuilder.fromMessage(this.message));
}
/// Reply to message. It allows to send regular message, Embed or both.
///
/// ```
@ -51,7 +72,7 @@ class CommandContext {
bool? tts,
AllowedMentions? allowedMentions,
MessageBuilder? builder,
ReplyBuilder? replyBuilder
ReplyBuilder? replyBuilder,
}) => channel.sendMessage(
content: content, embed: embed, tts: tts, files: files, builder: builder, allowedMentions: allowedMentions, replyBuilder: replyBuilder);
@ -62,7 +83,7 @@ class CommandContext {
/// await context.replyTemp(content: user.avatarURL());
/// }
/// ```
Future<Message> replyTemp(Duration duration, {
Future<Message> sendMessageTemp(Duration duration, {
dynamic content,
EmbedBuilder? embed,
List<AttachmentBuilder>? files,
@ -83,7 +104,7 @@ class CommandContext {
/// await context.replyDelayed(Duration(seconds: 2), content: user.avatarURL());
/// }
/// ```
Future<Message> replyDelayed(Duration duration,
Future<Message> sendMessageDelayed(Duration duration,
{dynamic content,
EmbedBuilder? embed,
List<AttachmentBuilder>? files,

View file

@ -16,11 +16,21 @@ class AllowedMentions implements Builder {
/// Allow @everyone and @here if [everyone] is true
/// Allow @user if [users] is true
/// Allow @role if [roles] is true
void allow({bool reply = false, bool everyone = false, bool users = false, bool roles = false}) {
this._allowEveryone = everyone;
this._allowUsers = users;
this._allowRoles = roles;
this._allowReply = reply;
void allow({bool? reply, bool? everyone, bool? users, bool? roles}) {
if (everyone != null) {
this._allowEveryone = everyone;
}
if (users != null) {
this._allowUsers = users;
}
if (roles != null) {
this._allowRoles = roles;
}
if (reply != null) {
this._allowReply = reply;
}
}
/// Suppress mentioning specific user by its id