Jump to content

Check if user is in clan.


Mocro

Recommended Posts

I made a little class that will hopefully deal with this ( not properly tested )

import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.Script;

import java.util.Random;

public class ClanChatter{

    private Script script;

    public ClanChatter(Script script){
        this.script = script;
    }

    public boolean notInClanChat(){
        RS2Widget notInChat = script.getWidgets().getWidgetContainingText("Not in chat");
        return (notInChat != null && notInChat.isVisible());
    }

    public void openClanChatTab(){
        script.getTabs().open(Tab.CLANCHAT);
    }

    public boolean isClanChatTabOpen(){
        return Tab.CLANCHAT.isOpen(script.getBot());
    }

    public boolean isInClanChat(){
        RS2Widget talkingIn = script.getWidgets().getWidgetContainingText("Talking in:");
        return (talkingIn != null && talkingIn.isVisible() && !talkingIn.getMessage().contains("Not in chat"));
    }

    public void joinClanChat(String name){

        //RS2Widget enterName = getWidgets().getWidgetContainingText("Enter the player name whose channel you wish to join:");
        RS2Widget enterName = script.getWidgets().get(162, 32);
        RS2Widget joinChat = script.getWidgets().getWidgetContainingText("Join Chat");

        if (enterName != null && enterName.isVisible()){
            script.getKeyboard().typeString(name);
            sleep(4000, 5000);
        }
        else if (joinChat != null && joinChat.isVisible()) clickOnWidget(joinChat);
    }

    public void leaveClanChat(){
        RS2Widget leaveWidget = script.getWidgets().getWidgetContainingText("Leave Chat");
        if (leaveWidget != null && leaveWidget.isVisible()) clickOnWidget(leaveWidget);
    }

    public boolean isInClan(String name){
       RS2Widget talkingIn = script.getWidgets().getWidgetContainingText("Talking in:");
       return talkingIn.getMessage().contains(name);
    }

    public boolean isOwner(String name){
       RS2Widget owner = script.getWidgets().getWidgetContainingText("Owner:");
       return owner.getMessage().contains(name);
    }

    public void talkInClanChat(String output){
        script.getKeyboard().typeString(String.format("/%s", output));
        sleep(1500, 2000);
    }

    private void clickOnWidget(RS2Widget widget){
        widget.hover();
        script.getMouse().click(false);
        sleep(1500, 2000);
    }

    private void sleep(int min, int max){

        try{
            script.sleep(new Random().nextInt(max-min) + min);
        } catch(Exception e){
            script.log(e);
        }
    }
}

Edited by Explv
  • Like 4
  • Heart 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...