use of discord4j.core.object.entity.User in project KaellyBot by Kaysoro.
the class MessageListener method onReady.
public Mono<MessageChannel> onReady(MessageCreateEvent event) {
return event.getMessage().getChannel().doOnSuccess(channel -> {
Language lg = Translator.getLanguageFrom(channel);
String prefixe = AbstractCommand.getPrefix(event.getMessage());
// If the authorId is a bot, message get ignored
if (!event.getMessage().getAuthor().map(User::isBot).orElse(true)) {
List<Command> commandsAvailable = new ArrayList<>();
for (Command command : CommandManager.getCommands()) if (event.getMessage().getContent().startsWith(prefixe + command.getName()))
commandsAvailable.add(command);
if (!commandsAvailable.isEmpty()) {
commandsAvailable.sort((cmd1, cmd2) -> cmd2.getName().length() - cmd1.getName().length());
Command command = commandsAvailable.get(0);
try {
command.request(event, event.getMessage());
} catch (Exception e) {
BasicDiscordException.UNKNOWN_ERROR.throwException(event.getMessage(), command, lg);
Reporter.report(e, null, channel, event.getMessage().getAuthor().orElse(null), event.getMessage());
LOG.error("onReady", e);
}
}
}
});
}
use of discord4j.core.object.entity.User in project symja_android_library by axkr.
the class SymjaBot method main.
public static void main(String[] args) {
if (args.length > 0) {
Locale.setDefault(Locale.US);
ParserConfig.PARSER_USE_LOWERCASE_SYMBOLS = true;
ToggleFeature.COMPILE = false;
Config.JAVA_UNSAFE = true;
Config.SHORTEN_STRING_LENGTH = 512;
Config.USE_VISJS = true;
Config.FILESYSTEM_ENABLED = false;
Config.FUZZY_PARSER = true;
Config.UNPROTECT_ALLOWED = false;
Config.USE_MANIPULATE_JS = true;
Config.JAS_NO_THREADS = true;
Config.MATHML_TRIG_LOWERCASE = false;
Config.MAX_AST_SIZE = 10000;
Config.MAX_OUTPUT_SIZE = 10000;
Config.MAX_BIT_LENGTH = 200000;
Config.MAX_POLYNOMIAL_DEGREE = 100;
Config.MAX_INPUT_LEAVES = 100L;
Config.MAX_MATRIX_DIMENSION_SIZE = 100;
Config.PRIME_FACTORS = new BigIntegerPrimality();
EvalEngine.get().setPackageMode(true);
String theDiscordToken = args[0];
GatewayDiscordClient client = DiscordClientBuilder.create(theDiscordToken).build().login().block();
client.getEventDispatcher().on(ReadyEvent.class).subscribe(event -> {
LocalDateTime now = LocalDateTime.now();
final User self = event.getSelf();
System.out.println(String.format(TIME_FORMATTER.format(now) + ": Logged in as %s#%s", self.getUsername(), self.getDiscriminator()));
});
client.on(MessageCreateEvent.class).subscribe(event -> {
final Message message = event.getMessage();
if (filterMessage(message)) {
createMessage(message);
}
});
client.onDisconnect().block();
} else {
System.out.println("The discord bot token has to be set as the first argument.");
}
}
use of discord4j.core.object.entity.User in project S-argo by Expugn.
the class MessageListener method messageReceived.
public static void messageReceived(Message message) {
if (message.getAuthor().isPresent()) {
if (!message.getAuthor().get().isBot()) {
// DIRECT MESSAGING IS NOT SUPPORTED
if (message.getChannel().block() instanceof PrivateChannel) {
User user = message.getAuthor().orElse(null);
String username = user.getUsername() + "#" + user.getDiscriminator();
String receivedMessage = message.getContent().orElse(null);
LOGGER.info("Direct Message received from " + username + " (" + user.getId().asString() + "): \"" + receivedMessage + "\"");
try {
if (receivedMessage.startsWith(CommandManager.getCommandPrefix())) {
Sargo.replyToMessage_Warning(message, "ERROR", "Using commands via **Direct Messaging** is not supported.");
}
} catch (NullPointerException e) {
// IGNORED
}
} else {
String messageChannelName = message.getChannel().cast(TextChannel.class).block().getName();
Long messageChannelID = message.getChannelId().asLong();
// IF THERE IS NOT A MAIN CHANNEL SET...
if (CommandSettingsParser.getMainChannel().isEmpty()) {
// CHECK IF CHANNEL IS BLACKLISTED (NAME OR CHANNEL ID)
boolean isInBlacklistedChannel = CommandSettingsParser.getBlacklistedChannels().contains(messageChannelName) || CommandSettingsParser.getBlacklistedChannels().contains(messageChannelID);
// IF NOT IN BLACKLIST, CONTINUE
if (!isInBlacklistedChannel) {
new CommandManager(message);
}
} else {
// A MAIN CHANNEL IS SET... CHECK IF THE MESSAGE IS SENT FROM THE MAIN CHANNEL.
boolean isInMainChannel;
try {
isInMainChannel = (messageChannelID == Long.parseLong(CommandSettingsParser.getMainChannel()));
} catch (NumberFormatException e) {
isInMainChannel = (messageChannelName.equalsIgnoreCase(CommandSettingsParser.getMainChannel()));
}
// CHECK IF THE MESSAGE IS FROM A WHITELISTED CHANNEL AS WELL.
boolean isInWhitelistedChannel = CommandSettingsParser.getWhitelistedChannels().contains(messageChannelName) || CommandSettingsParser.getWhitelistedChannels().contains(messageChannelID);
// IF MESSAGE IS IN MAIN CHANNEL OR A WHITELISTED ONE, CONTINUE...
if (isInMainChannel || isInWhitelistedChannel) {
new CommandManager(message);
}
}
}
}
}
}
Aggregations