Class CommandSender


  • public class CommandSender
    extends Object
    This class present an executor to execute command. We can use it to distinguish different permissions.
    • Field Detail

      • CONSOLE

        public static final CommandSender CONSOLE
        Present CONSOLE or we call it Terminate
    • Constructor Detail

      • CommandSender

        public CommandSender​(@NonNull net.mamoe.mirai.contact.Friend friend)
        Present Friend
        Parameters:
        friend - the Mirai Friend instance
      • CommandSender

        public CommandSender​(@NonNull net.mamoe.mirai.contact.Member member)
        Present Member in Group
        Parameters:
        member - The Mirai Member Instance
      • CommandSender

        public CommandSender​(@NonNull net.mamoe.mirai.contact.Stranger stranger)
        Present Stranger
        Parameters:
        stranger - The Mirai Stranger Instance
    • Method Detail

      • getFriend

        public @Nullable net.mamoe.mirai.contact.Friend getFriend()
        Get the Mirai Friend instance, or null if this CommandSender does not present a Mirai Friend instance.
        Returns:
        the Mirai Friend instance
      • isFriend

        @EnsuresNonNullIf(expression="getFriend()",
                          result=true)
        public boolean isFriend()
        Indicate whether this is a Mirai Friend instance
        Returns:
        true if this CommandSender presents a Mirai Friend instance, false otherwise
      • hasPermission

        public boolean hasPermission​(CommandPermission permission)
        Indicate whether this CommandSender owns the permission
        Parameters:
        permission - the compared permission
        Returns:
        true if the permission of this CommandSender is higher or equivalent to the compared permission, false otherwise
      • getMember

        public @Nullable net.mamoe.mirai.contact.Member getMember()
        Get the Mirai Member instance, or null if this CommandSender does not present a Mirai Member instance.
        Returns:
        the Mirai Member instance
      • isMember

        @EnsuresNonNullIf(expression="getMember()",
                          result=true)
        public boolean isMember()
        Indicate whether this is a Mirai Member instance
        Returns:
        true if this CommandSender presents a Mirai Member instance, false otherwise
      • isAdministrator

        public boolean isAdministrator()
        Indicate whether this is an Administrator
        Returns:
        true if this CommandSender presents its id is equal to the id of the Administrator, false otherwise
      • getPermission

        public @NonNull CommandPermission getPermission()
        Get permission
        Returns:
        permission of this sender
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • isConsole

        public boolean isConsole()
        Indicate whether it is CONSOLE
        Returns:
        true if it is CONSOLE, false otherwise
      • getIOHandler

        public IOHandler getIOHandler()
        Get the receiver by this CommandSender
        Returns:
        the receiver by this CommandSender
      • getSession

        public Session getSession()
        Get Session of a special CommandSender. It can be used to store some data for future using. But the data it stored will be lost after Bot exiting.
        Returns:
        Session of sender
      • getBot

        public @Nullable Bot getBot()
        Get the bot
        Returns:
        the bot
      • isStranger

        public boolean isStranger()
        Indicate whether this is a Mirai Stranger instance
        Returns:
        true if this CommandSender presents a Mirai Stranger instance, false otherwise