use of com.denizenscript.ddiscordbot.objects.DiscordChannelTag in project dDiscordBot by DenizenScript.
the class DiscordMessageModifiedScriptEvent method getContext.
@Override
public ObjectTag getContext(String name) {
switch(name) {
case "channel":
return new DiscordChannelTag(botID, getEvent().getChannel());
case "group":
if (getEvent().isFromGuild()) {
return new DiscordGroupTag(botID, getEvent().getGuild());
}
break;
case "new_message":
return new DiscordMessageTag(botID, getEvent().getMessage());
case "old_message_valid":
return new ElementTag(oldMessage != null);
case "old_message":
return oldMessage == null ? null : new DiscordMessageTag(botID, oldMessage);
case "old_no_mention_message":
case "old_formatted_message":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return null;
case "message":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return new ElementTag(getEvent().getMessage().getContentRaw());
case "message_id":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return new ElementTag(getEvent().getMessage().getId());
case "no_mention_message":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return new ElementTag(DiscordMessageTag.stripMentions(getEvent().getMessage().getContentRaw()));
case "formatted_message":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return new ElementTag(getEvent().getMessage().getContentDisplay());
case "author":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return new DiscordUserTag(botID, getEvent().getMessage().getAuthor());
case "mentions":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
ListTag list = new ListTag();
for (User user : getEvent().getMessage().getMentionedUsers()) {
list.addObject(new DiscordUserTag(botID, user));
}
return list;
case "is_direct":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return new ElementTag(getEvent().getChannel() instanceof PrivateChannel);
}
return super.getContext(name);
}
use of com.denizenscript.ddiscordbot.objects.DiscordChannelTag in project dDiscordBot by DenizenScript.
the class DiscordCreateThreadCommand method execute.
// <--[command]
// @Name discordcreatethread
// @Syntax discordcreatethread [id:<id>] [name:<name>] [message:<message>/parent:<channel> (private)]
// @Required 3
// @Maximum 4
// @Short Creates a new Discord thread.
// @Plugin dDiscordBot
// @Guide https://guide.denizenscript.com/guides/expanding/ddiscordbot.html
// @Group external
//
// @Description
// Creates a new Discord thread.
//
// You must specify the bot object ID, and the thread name.
//
// You can either specify a full DiscordMessageTag instance to create a thread based on that message,
// OR specify a DiscordChannelTag parent and optionally mark it private (otherwise it's public).
//
// @Tags
// <entry[saveName].created_thread> returns the newly created thread.
//
// @Usage
// Use to create a new thread for a specific message and send a bot message to it.
// - ~discordcreatethread id:mybot "name:The bot's awesome thread" message:<context.message> save:thread
// - ~discordmessage id:mybot channel:<entry[thread].created_thread> "Here I made this thread just for you"
//
// @Usage
// Use to create a new thread in a channel and link to it in some channel.
// - ~discordcreatethread id:mybot "name:The bot's awesome thread" parent:<[some_channel]> save:thread
// - ~discordmessage id:mybot channel:<[some_channel]> "I created thread <<>#<entry[thread].created_thread.id><>>!"
//
// -->
@Override
public void execute(ScriptEntry scriptEntry) {
DiscordBotTag bot = scriptEntry.requiredArgForPrefix("id", DiscordBotTag.class);
ElementTag name = scriptEntry.requiredArgForPrefixAsElement("name");
DiscordMessageTag message = scriptEntry.argForPrefix("message", DiscordMessageTag.class, true);
DiscordChannelTag channel = scriptEntry.argForPrefix("parent", DiscordChannelTag.class, true);
boolean isPrivate = scriptEntry.argAsBoolean("private");
if (message != null) {
if (channel != null || isPrivate) {
throw new InvalidArgumentsRuntimeException("Cannot have both a 'message:' and channel/private");
}
if (message.channel_id == 0) {
throw new InvalidArgumentsRuntimeException("DiscordMessageTag not fully formed - missing channel ID.");
}
} else if (channel == null) {
throw new InvalidArgumentsRuntimeException("Missing message or channel argument!");
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), bot, name, message, channel, isPrivate ? db("private", true) : "");
}
Runnable runner = () -> {
if (message != null) {
DiscordMessageTag forMessage = message;
if (forMessage.bot == null || !forMessage.bot.equals(bot.bot)) {
forMessage = forMessage.duplicate();
forMessage.bot = bot.bot;
}
Message actualMessage = forMessage.getMessage();
if (actualMessage == null) {
handleError(scriptEntry, "Invalid message reference.");
return;
}
if (!(actualMessage.getChannel() instanceof GuildChannel)) {
handleError(scriptEntry, "Message referenced is not in a group (can't create threads in a DM).");
return;
}
if (actualMessage.getChannel() instanceof ThreadChannel) {
handleError(scriptEntry, "Message referenced is in a thread - you can't have threads inside threads.");
return;
}
try {
ThreadChannel created = ((TextChannel) actualMessage.getChannel()).createThreadChannel(name.asString(), actualMessage.getIdLong()).complete();
if (created != null) {
scriptEntry.addObject("created_thread", new DiscordChannelTag(bot.bot, created));
}
} catch (Throwable ex) {
handleError(scriptEntry, ex);
}
} else {
DiscordChannelTag forChannel = channel;
if (forChannel.bot == null || !forChannel.bot.equals(bot.bot)) {
forChannel = forChannel.duplicate();
forChannel.bot = bot.bot;
}
Channel actualChannel = forChannel.getChannel();
if (actualChannel == null) {
handleError(scriptEntry, "Invalid channel reference.");
return;
}
if (!(actualChannel instanceof GuildChannel)) {
handleError(scriptEntry, "Channel referenced is not in a group (can't create threads in a DM).");
return;
}
if (!(actualChannel instanceof TextChannel)) {
handleError(scriptEntry, "Channel referenced is not a text channel (can't create threads in a voice channel).");
return;
}
if (actualChannel instanceof ThreadChannel) {
handleError(scriptEntry, "Channel referenced is a thread - you can't have threads inside threads.");
return;
}
try {
ThreadChannel created = ((TextChannel) actualChannel).createThreadChannel(name.asString(), isPrivate).complete();
if (created != null) {
scriptEntry.addObject("created_thread", new DiscordChannelTag(bot.bot, created));
}
} catch (Throwable ex) {
handleError(scriptEntry, ex);
}
}
};
Bukkit.getScheduler().runTaskAsynchronously(DenizenDiscordBot.instance, () -> {
runner.run();
scriptEntry.setFinished(true);
});
}
use of com.denizenscript.ddiscordbot.objects.DiscordChannelTag in project dDiscordBot by DenizenScript.
the class DiscordMessageReceivedScriptEvent method getContext.
@Override
public ObjectTag getContext(String name) {
switch(name) {
case "channel":
return new DiscordChannelTag(botID, getEvent().getChannel());
case "group":
if (getEvent().isFromGuild()) {
return new DiscordGroupTag(botID, getEvent().getGuild());
}
break;
case "new_message":
return new DiscordMessageTag(botID, getEvent().getMessage());
case "message":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return new ElementTag(getEvent().getMessage().getContentRaw());
case "message_id":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return new ElementTag(getEvent().getMessage().getId());
case "no_mention_message":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return new ElementTag(DiscordMessageTag.stripMentions(getEvent().getMessage().getContentRaw()));
case "formatted_message":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return new ElementTag(getEvent().getMessage().getContentDisplay());
case "author":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return new DiscordUserTag(botID, getEvent().getMessage().getAuthor());
case "mentions":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
ListTag list = new ListTag();
for (User user : getEvent().getMessage().getMentionedUsers()) {
list.addObject(new DiscordUserTag(botID, user));
}
return list;
case "is_direct":
DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
return new ElementTag(getEvent().getChannel() instanceof PrivateChannel);
}
return super.getContext(name);
}
Aggregations