Jump to content

Basic chat tab API


Parenthesis

Recommended Posts

Better Alternative - liverare's API

 

Old API

 

Couldn't really find anything in the OSBot API that covers this, so I've made a simple API.
 

import org.osbot.script.Script;

public class ChatTabManager {
	
	private Script context;
	
	public ChatTabManager(Script context) {
		this.context = context;
	}
	
	public int getTabState(int tab) {
		return context.client.getInterface(548).getChild(tab).getSpriteIndex1();
	}
	
	public String getTabFilter(int tab) {
		String processedString = "{ERROR}";
		
		if(tab != ChatTab.GAME || tab != ChatTab.ALL) {
			String rawMessage = context.client.getInterface(548).getChild(tab + 2).getMessage();
			if(rawMessage.contains(">")) {
				processedString = rawMessage.substring(rawMessage.indexOf('>') + 1);
			} else {
				processedString = rawMessage;
			}
		}
		return processedString;
	}
	
	public boolean isTabOpen(int tab) {
		int tabState = this.getTabState(tab);
		if(tabState == TabState.OPEN || tabState == TabState.OPEN_HOVERED)
			return true;
		return false;
	}
	
	public int getCurrentTab() {
		int[] tabIDs = { 3, 6, 9, 13, 17, 21 };
		for(int id : tabIDs) {
			if(isTabOpen(id)) {
				return id;
			}
		}
		return 0;
	}
	
	public String getTabName(int tab) {
		return context.client.getInterface(548).getChild(tab + 1).getMessage();
	}
	
	public interface ChatTab {
		public final int ALL = 3;
		public final int GAME = 6;
		public final int PUBLIC = 9;
		public final int PRIVATE = 13;
		public final int CLAN = 17;
		public final int TRADE = 21;
	}
	
	public interface TabState {
		public final int STANDARD = 1019;
		public final int HOVERED = 1020;
		public final int UNREAD = 1021;
		public final int OPEN = 1022;
		public final int OPEN_HOVERED = 1023;
	}
}

For reference:
gueEr1m.png
Usage:

		ChatTabManager tabManager = new ChatTabManager(this);
		
		/* getTabFilter (<Integer ChatTab ID>) -- Returns 'On', 'Friends', 'Hide' etc. */
		String filterText = tabManager.getTabFilter(ChatTabManager.ChatTab.PUBLIC);
		
		/* getTabState (<Integer ChatTab ID>) -- Returns integer of the chat state */
		boolean isOpen = tabManager.getTabState(ChatTabManager.ChatTab.PUBLIC) == ChatTabManager.TabState.OPEN;
		
		/* isTabOpen (<Integer ChatTab ID>) -- Returns whether or not the specified tab is open */
		boolean isGameTabOpen = tabManager.isTabOpen(ChatTabManager.ChatTab.GAME);
		
		/* getCurrentTab () -- Returns the ID of the tab that is currently open */
		int currentTab = tabManager.getCurrentTab();
		
		/* getTabName (<Integer ChatTab ID>) -- Returns String value of that tab (eg. 'Private') */
		tabManager.getTabName(ChatTabManager.ChatTab.PRIVATE);

A thank you to Cyro for assisting me while creating this.

Edited by Parenthesis
  • Like 1
Link to comment
Share on other sites

if(tab != ChatTab.GAME || tab != ChatTab.ALL)

I believe you were supposed to use "&&". smile.png

 

I got to work on making a fully working API you can use.

 

Edited the API to make it not require Client to be a constant parameter for methods. However, an enum couldn't be used to achieve this.

Edited by liverare
  • Like 1
Link to comment
Share on other sites

if(tab != ChatTab.GAME || tab != ChatTab.ALL)

I believe you were supposed to use "&&". smile.png

 

I got to work on making a fully working API you can use.

 

Example of use:

        if (!ChatTab.TRADE.isFilterSetToFriends(client))
            ChatTab.interact(client, ChatTab.TRADE, ChatTab.ACTION_FRIENDS);
        else if (!ChatTab.PUBLIC.isSelected(client))
            ChatTab.interact(client, ChatTab.PUBLIC, ChatTab.ACTION_VIEW);

-Check to see if trade tab's filter is not set to friends.

--Set the trade tab's filter to friends.

-Else check to see if the public tab's filter is not set to selected.

--Select the public tab.

 

Enjoy. smile.png

 

 

You're right on those conditional operators, don't know how I missed that.

 

That's an amazing API! way more useful than my current one. I'll put it up in the main post.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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