Jump to content

Check if user is in clan.


Recommended Posts

Posted (edited)

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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