当前位置: 首页>>代码示例>>Java>>正文


Java Message.getAuthor方法代码示例

本文整理汇总了Java中net.dv8tion.jda.core.entities.Message.getAuthor方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getAuthor方法的具体用法?Java Message.getAuthor怎么用?Java Message.getAuthor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.dv8tion.jda.core.entities.Message的用法示例。


在下文中一共展示了Message.getAuthor方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doYaThing

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public void doYaThing(Message message) {
    MessageChannel channel = message.getChannel();
    User author = message.getAuthor();
    try {
        BufferedImage avatar = ReadImage.readImageFromURL(author.getAvatarUrl());
        BufferedImage triggered = ReadImage.readImageFromDisk("triggered.jpg");
        DrawOnImg.drawImg(avatar, triggered, 0, avatar.getHeight() - 20, avatar.getWidth(), 20);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(avatar, "png", baos);
        channel.sendFile(baos.toByteArray(), "triggered.png", null).complete();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        log.log("ERROR: " + e.getCause() + " " + e.getMessage());
    }
}
 
开发者ID:ExidCuter,项目名称:JDodoBot,代码行数:18,代码来源:Triggered.java

示例2: onCommand

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public boolean onCommand(Message message, String[] args) {
    User user = message.getAuthor();
    if (args.length > 0) {
        user = MentionableUtil.getUser(message, args);
    }

    if (user == null) {
        return sendErrorMessage(message, "I found no users with the name or ID of `%s`", args[0]);
    }

    MessageFactory.makeSuccess(message, ":id: of the user **:target** is `:targetid`")
        .set("target", user.getAsMention())
        .set("targetid", user.getId())
        .queue();
    return true;
}
 
开发者ID:avaire,项目名称:avaire,代码行数:18,代码来源:UserIdCommand.java

示例3: onCommand

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public boolean onCommand(Message message, String[] args) {
    User user = message.getAuthor();
    if (args.length > 0) {
        user = MentionableUtil.getUser(message, args);
    }

    if (user == null) {
        return sendErrorMessage(message, "I found no users with the name or ID of `%s`", args[0]);
    }

    String avatarUrl = generateAvatarUrl(user);
    MessageFactory.makeEmbeddedMessage(message.getChannel())
        .setTitle(user.getName() + "#" + user.getDiscriminator() + "'s Avatar", avatarUrl)
        .setImage(avatarUrl)
        .queue();

    return true;
}
 
开发者ID:avaire,项目名称:avaire,代码行数:20,代码来源:UserAvatarCommand.java

示例4: execute

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    Message message = parsedCommandInvocation.getMessage();
    User info;
    String[] args = parsedCommandInvocation.getArgs();
    if (args.length > 0) {
        if (message.getMentionedUsers().size() > 0)
            info = message.getMentionedUsers().get(0);
        else {
            return createHelpMessage();
        }
    } else {
        info = message.getAuthor();
    }

    Member user = message.getGuild().getMember(info);
    StringBuilder rawRoles = new StringBuilder();
    user.getRoles().forEach(r -> rawRoles.append(r.getName()).append(", "));
    StringBuilder roles = new StringBuilder(rawRoles.toString());
    if (!user.getRoles().isEmpty())
        roles.replace(rawRoles.lastIndexOf(","), roles.lastIndexOf(",") + 1, "");
    EmbedBuilder userinfo = new EmbedBuilder();
    userinfo.setColor(Colors.COLOR_PRIMARY);
    userinfo.setTitle("User information of " + user.getUser().getName());
    userinfo.setThumbnail(info.getAvatarUrl());
    userinfo.addField("Nickname", user.getEffectiveName(), false);
    userinfo.addField("User id", info.getId(), false);
    userinfo.addField("Status", user.getOnlineStatus().toString().replace("_", ""), false);
    if (user.getGame() != null)
        userinfo.addField("Game", user.getGame().toString(), false);
    userinfo.addField("Guild join date", formatDate(user.getJoinDate()), false);
    userinfo.addField("Roles", "`" + roles.toString() + "`", false);
    userinfo.addField("Discord join date", formatDate(info.getCreationTime()), false);
    userinfo.addField("Avatar url", info.getAvatarUrl(), true);
    userinfo.addField("--- RubiconBot Stats ---", "" +
            "Level: " + RubiconBot.getMySQL().getUserValue(user.getUser(), "level") + "\n" +
            "Ruby's: " + RubiconBot.getMySQL().getUserValue(user.getUser(), "money"), true);
    return new MessageBuilder().setEmbed(userinfo.build()).build();
}
 
开发者ID:Rubicon-Bot,项目名称:Rubicon,代码行数:40,代码来源:CommandUserInfo.java

示例5: onMessageReceived

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageReceivedEvent event) {
    if (event.getAuthor().isBot())
        return;
    Message message = event.getMessage();
    String content = message.getRawContent();
    User author = message.getAuthor();
    try {
        Stats temp = Stats.GetStats(author);
        if (temp != null) {
            temp.increase();
        }
        if (content.equals("Bot.stats(false);") && temp != null) {
            stats.remove(temp);
            message.addReaction("\u2705").complete();
        }
        if (message.getRawContent().equals("Bot.stats(true);") && temp == null) {
            stats.add(new Stats(author));
            message.addReaction("\u2705").complete();
            message.getTextChannel().sendMessage("Use `" + prefix + "stats` to check your stats").complete();
        }
        if (RandomGen.rndNm(10) == 3) {
            FileHandler.writeToFile(stats);
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
        log.log("ERROR: " + e.getCause() + " " + e.getMessage());
    }
}
 
开发者ID:ExidCuter,项目名称:JDodoBot,代码行数:30,代码来源:StatsListener.java

示例6: doYaThing

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public void doYaThing(Message message) {
    User author = message.getAuthor();
    MessageChannel channel = message.getChannel();

    BankAccount temp = new BankAccount("temp");
    boolean exists = false;
    for (BankAccount b : bankAccounts) {
        if (b.getID().equals(author.getId())) {
            exists = true;
            temp = b;
        }
    }
    try {
        if (exists && temp.lastPay.before(new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(23)))) {
            temp.setBalance(temp.getBalance() + 100.00);
            temp.lastPay = new Date();
            channel.sendMessage("You got 100.00 Dodos.\nNew balance: " + Double.toString(temp.getBalance())).complete();
            FileHandler.writeToFile(bankAccounts);
        } else {
            channel.sendMessage("You have already got your pay!").complete();
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
        log.log("ERROR: " + e.getCause() + " " + e.getMessage());
    }
}
 
开发者ID:ExidCuter,项目名称:JDodoBot,代码行数:28,代码来源:Payday.java

示例7: doYaThing

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public void doYaThing(Message message) {
    User author = message.getAuthor();
    String content = message.getRawContent();
    MessageChannel channel = message.getChannel();
    String commandNParameters[] = DodoStringHandler.getCommandNParameters(content);
    BankAccount temp = new BankAccount("temp");
    boolean exists = false;
    for (BankAccount b : bankAccounts) {
        if (b.getID().equals(author.getId())) {
            exists = true;
            temp = b;
        }
    }
    try {
        if (commandNParameters.length < 2)
            channel.sendMessage("```" + prefix + usage + "```").complete();
        else if (exists && temp.getBalance() >= Double.parseDouble(commandNParameters[1])) {
            if (Double.parseDouble(commandNParameters[1]) > -1)
                SlotMashina.slotMashinas(Double.parseDouble(commandNParameters[1]), channel, temp);
            else
                channel.sendMessage("Can't slot that!").complete();
        } else {
            if (!exists) {
                channel.sendMessage("You have to register! Use `" + prefix + "bank register`").complete();
            } else channel.sendMessage("You are too poor!").complete();
        }

    } catch (Exception e) {
        System.out.println(e.getMessage());
        log.log("ERROR: " + e.getCause() + " " + e.getMessage());
    }
}
 
开发者ID:ExidCuter,项目名称:JDodoBot,代码行数:34,代码来源:Slot.java

示例8: doYaThing

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public void doYaThing(Message message) {
    MessageChannel channel = message.getChannel();
    User author = message.getAuthor();
    try {
        BufferedImage avatar;
        List<User> users = message.getMentionedUsers();
        if (users.isEmpty()) avatar = ReadImage.readImageFromURL(author.getAvatarUrl());
        else avatar = ReadImage.readImageFromURL(users.get(0).getAvatarUrl());
        for (int i = 0; i < gif.length; i++) {
            gif[i] = ReadImage.readImageFromDisk("gif/"+String.valueOf(i)+".png");
        }

        GifImage img = new GifImage(gif[0].getWidth(),gif[0].getHeight(),GifImage.RESIZE_STRATEGY_SCALE_TO_FIT_IMAGE_SIZE);

        for (int i = 0; i < gif.length; i++) {
            if (i>21) DrawOnImg.drawImg(gif[i],avatar,30-(10*(i-20)),42+(11*(i-20)),110,98);
            else DrawOnImg.drawImg(gif[i],avatar,30,42,110,98);
            img.addGifFrame(new GifFrame(gif[i]));
        }
        img.setDefaultDelay(1);
        GifEncoder.encode(img, new File("hudio.gif"), true);
        Path fileLocation = Paths.get("hudio.gif");
        byte[] data = Files.readAllBytes(fileLocation);

        channel.sendFile(data, "shoot.gif", null).complete();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        log.log("ERROR: " + e.getCause() + " " + e.getMessage());
    }
}
 
开发者ID:ExidCuter,项目名称:JDodoBot,代码行数:33,代码来源:Shoot.java

示例9: doYaThing

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public void doYaThing(Message message) {
    User author = message.getAuthor();
    MessageChannel channel = message.getChannel();
    try {
        channel.sendMessage("Hello " + author.getAsMention()).complete();
    } catch (Exception e) {
        System.out.println(e.getMessage());
        log.log("ERROR: " + e.getCause() + " " + e.getMessage());
    }
}
 
开发者ID:ExidCuter,项目名称:JDodoBot,代码行数:12,代码来源:Hi.java

示例10: doYaThing

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public void doYaThing(Message message) {
    try {
        boolean exists = false;
        User author = message.getAuthor();
        String[] commandsNParameters = DodoStringHandler.getCommandNParameters(message.getRawContent());
        String strRole = DodoStringHandler.glueStringsBackTogether(commandsNParameters, " ", 1);
        if (AdminHandler.isAdmin(author, message.getGuild())) {
            if (commandsNParameters.length > 1) {
                List<Role> roles = message.getGuild().getRoles();
                for (Role role : roles) {
                    if (role.getName().equals(strRole)) {
                        for (dodo.bot.types.DefaultRole defaultRoleIn : Bot.defaultRoles) {
                            if (defaultRoleIn.getGuildID().equals(role.getGuild().getId())) {
                                Bot.defaultRoles.remove(defaultRoleIn);

                            }
                        }
                        Bot.defaultRoles.add(new dodo.bot.types.DefaultRole(role, role.getGuild()));
                        FileHandler.writeToFile(Bot.defaultRoles);
                        exists = true;
                        message.getTextChannel().sendMessage("Your default role is set to: `" + role.getName() + "`").complete();
                    }

                }
            } else {
                message.getTextChannel().sendMessage("```" + this.toString() + "```").complete();
            }
        } else {
            message.getTextChannel().sendMessage("Only admin can set the defaultRole").complete();
        }
        if (!exists) {
            message.getTextChannel().sendMessage("There is no `" + strRole + "` Role").complete();
        }

    } catch (Exception e) {
        e.printStackTrace();
        message.getTextChannel().sendMessage("```" + e.getMessage() + "```").complete();
    }
}
 
开发者ID:ExidCuter,项目名称:JDodoBot,代码行数:41,代码来源:DefaultRole.java

示例11: onCommand

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public boolean onCommand(Message message, String[] args) {
    GuildTransformer guildTransformer = GuildController.fetchGuild(avaire, message);
    if (guildTransformer == null || !guildTransformer.isLevels()) {
        return sendErrorMessage(message, "This command requires the `Levels & Experience` feature to be enabled for the server, you can ask a server admin if they want to enable it with `.level`");
    }

    User user = message.getAuthor();
    if (!message.getMentionedUsers().isEmpty() && !args[0].equals("---skip-mentions")) {
        user = message.getMentionedUsers().get(0);
    }
    final User author = user;

    if (author.isBot()) {
        MessageFactory.makeWarning(message, "Bots cannot receive xp and therefore can\'t be ranked, try and tag a user instead.").queue();
        return false;
    }

    loadProperties(message, author).thenAccept(properties -> {
        String score = properties.getScore().equals("Unranked") ?
            "Unranked" : properties.getScore() + " / " + message.getGuild().getMembers().size();

        long experience = properties.getPlayer().getExperience();
        long level = LevelUtil.getLevelFromExperience(experience);
        long current = LevelUtil.getExperienceFromLevel(level);

        long diff = LevelUtil.getExperienceFromLevel(level + 1) - current;
        double percentage = ((double) (experience - current) / diff) * 100;

        String levelBar = "";
        for (int i = 1; i <= 40; i++) {
            levelBar += ((i * 2.5) < percentage) ? "\u2592" : "\u2591";
        }

        MessageFactory.makeEmbeddedMessage(message.getChannel(), Color.decode("#E91E63"))
            .setAuthor(author.getName(), "https://avairebot.com/leaderboard/" + message.getGuild().getId(), author.getAvatarUrl())
            .setFooter("https://avairebot.com/leaderboard/" + message.getGuild().getId())
            .addField("Rank", score, true)
            .addField("Level", "" + level, true)
            .addField("Experience", (experience - 100 < 0 ? "0" : String.format("%s (Total: %s)",
                experience - 100, properties.getTotal()
            )), true)
            .addField("Experience needed to next Level", String.format("[%s] %s%s",
                levelBar, new DecimalFormat("#.##").format(percentage), '%'
            ), false)
            .queue();
    });

    return true;
}
 
开发者ID:avaire,项目名称:avaire,代码行数:51,代码来源:RankCommand.java

示例12: UIMessageGroup

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
public UIMessageGroup(Message message) {
    user = message.getAuthor();

    messages = new HashMap<>();
    UIMessageGroupText messageComponent = new UIMessageGroupText(message, this);
    messages.put(message.getId(), messageComponent);

    setMaximumSize(new Dimension(TransparentDiscord.UI_WIDTH, Integer.MAX_VALUE));

    mostRecentMessageTime   = message.getCreationTime();
    oldestMessageTime       = message.getCreationTime();

    setLayout(new BorderLayout());

    //Set up gridbag to add new messages20.

    c = new GridBagConstraints();
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;

    messagePanel = new JPanel();
    messagePanel.setLayout(new GridBagLayout());
    messagePanel.setBorder(new EmptyBorder(5,5,5,5));

    if (TransparentDiscord.isSelfUser(user)) {
        messagePanel.setBackground(Color.LIGHT_GRAY);
        setBorder(new EmptyBorder(15,50,15,5));

        messageInfo = new JLabel(getInfo());
        messageInfo.setFont(TransparentDiscord.defaultFont.deriveFont(Font.PLAIN, 12));
        messageInfo.setHorizontalAlignment(JLabel.RIGHT);
        messageInfo.setBorder(new EmptyBorder(0,0,0,5));

        add(messageInfo, BorderLayout.SOUTH);
    }
    else {
        messagePanel.setBackground(Color.WHITE);
        setBorder(new EmptyBorder(15,5,15,5));

        authorIcon = new JLabel(TransparentDiscord.getImage(message.getAuthor(),25,25));
        authorIcon.setBorder(new EmptyBorder(10,10,10,10));
        authorIcon.setVerticalAlignment(JLabel.TOP);

        messageInfo = new JLabel(getInfo());
        messageInfo.setFont(TransparentDiscord.defaultFont.deriveFont(Font.PLAIN, 12));
        messageInfo.setHorizontalAlignment(JLabel.LEFT);
        messageInfo.setBorder(new EmptyBorder(0,45,0,0));

        add(authorIcon, BorderLayout.WEST);
        add(messageInfo, BorderLayout.SOUTH);
    }

    messagePanel.add(new UIMessageGroupText(message, this),c,0);
    if (!message.getAttachments().isEmpty())
        messagePanel.add(new UIMessageGroupAttachment(message),c,0);

   add(messagePanel, BorderLayout.CENTER);
}
 
开发者ID:MCPlummet,项目名称:TransparentDiscord,代码行数:60,代码来源:UIMessageGroup.java

示例13: onGuildMessageReceived

import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
{
    //TODO: Automod!
    /*
    Want the following:
        * Configurable auto deleting of links and file uploads
        * Whitelist/Blacklist for links and bad words
        * Regex on bad words (print to the log what words were matched in the message
        * Configurable muting when someone's done bad enough things:
            * Posted too many bad words within X time (default 5mins?)
            * Posted too many messages (configurable) within X time (default 5 messages in 2s?)
            * Posted too many duplicate characters in a message (default >60% similar characters in a message?)
     */

    Message message = event.getMessage();
    User author = message.getAuthor();

    //Ignore Admins and Moderators
    if(MDCBot.isMemberBotModerator(event.getGuild().getMember(author)))
        return;

    String content = message.getContent();
    TextChannel channel = event.getChannel();
    String channelName = channel.getName();

    if(checkLinks(channelName, message))
        deleteMessage(message, "Deleted message containing link from member %s (%s) in %s (%s):%s", author.getAsMention(), author.getName(), channel.getAsMention(), channelName, content);

    if(checkFiles(channelName, message))
    {
        StringBuilder sb = new StringBuilder();
        for(Message.Attachment a : message.getAttachments())
            sb.append("\n").append(a.getUrl());
        deleteMessage(message, "Deleted file posted by member %s (%s) in %s (%s):%s", author.getAsMention(), author.getName(), channel.getAsMention(), channelName, sb.toString());
    }

    if(checkSpamCharacters(channelName, content))
        deleteMessage(message, "Deleted message containing spammed characters from member %s (%s) in %s (%s):%s", author.getAsMention(), author.getName(), channel.getAsMention(), channelName, content);

    if(checkSpamMessages(channelName, message))
        for(Message m : messageSpamCache.get(author.getIdLong()))
            deleteMessage(m, "Deleted message due to spam from member %s (%s) in %s (%s):%s", author.getAsMention(), author.getName(), channel.getAsMention(), channelName, m.getContent());

    if(checkBadWords(channelName, content))
        deleteMessage(message, "Deleted message due to bad words from member %s (%s) in %s (%s):%s", author.getAsMention(), author.getName(), channel.getAsMention(), channelName, content);
}
 
开发者ID:thebrightspark,项目名称:MDC-Discord-Bot,代码行数:48,代码来源:AutomodListener.java


注:本文中的net.dv8tion.jda.core.entities.Message.getAuthor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。