BanchoBot

Represents a Bancho IRC connection.

class BanchoBot {}

Constructors

this
this(string username, string password, string host = "irc.ppy.sh", ushort port = 6667)

Prepares a bancho IRC connection with username & password (can be obtained from https://osu.ppy.sh/p/irc)

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

clear
void clear()

Clears all logs, called by connect

clearMembershipLog
void clearMembershipLog()

Clears all backlog & removes all event listeners for the object type.

clearMessageLog
void clearMessageLog()
clearQuitLog
void clearQuitLog()
clearTopicLog
void clearTopicLog()

Clears all backlog & removes all event listeners for the object type.

connect
bool connect()

Connects to this.host:this.port (irc.ppy.sh:6667) and authenticates with username & password. Blocks and processes all messages sent by the TCP socket. Recommended to be called in runTask. Cleans up on exit properly and is safe to be called again once returned.

createRoom
OsuRoom createRoom(string title)

Creates a new managed room with a title and returns it. Automatically gets room ID & game ID.

disconnect
void disconnect()

Disconnects & closes the TCP socket.

disownChannel
void disownChannel(string channel, bool gotClosed = false)

Removes a channel from the managed channels.

fetchOldMembershipLog
MembershipEvent[] fetchOldMembershipLog(bool delegate(MembershipEvent) check, bool returnIt = true)

Goes through the backlog and removes and optionally returns all matching objects.

fetchOldMessageLog
Message[] fetchOldMessageLog(bool delegate(Message) check, bool returnIt = true)
fetchOldQuitLog
Quit[] fetchOldQuitLog(bool delegate(Quit) check, bool returnIt = true)
fetchOldTopicLog
TopicChange[] fetchOldTopicLog(bool delegate(TopicChange) check, bool returnIt = true)

Goes through the backlog and removes and optionally returns all matching objects.

fromUnmanaged
OsuRoom fromUnmanaged(string room, string game = null)

Joins a room in IRC and creates the room object from it.

joinChannel
void joinChannel(string channel)

Sends a join command to a channel so messages can be sent in it.

preProcessMessage
void preProcessMessage(Message message)

Processes messages meant for mutliplayer rooms to update their state. called by mixin template

processMembership
void processMembership(MembershipEvent change)

Calls all event subscribers to try to match this object, otherwise replace the oldest element in the backlog with this.

processMessage
void processMessage(Message message)
processQuit
void processQuit(Quit quit)
processTopic
void processTopic(TopicChange change)

Calls all event subscribers to try to match this object, otherwise replace the oldest element in the backlog with this.

ratelimit
void ratelimit(string channel, bool put)

Manually wait until you can send a message again in a given channel.

sendMessage
void sendMessage(string channel, in char[] message)
void sendMessage(string channel, in char[] message, bool doRatelimit)

Sends a message to a username or channel (#channel).

unmanageRoom
void unmanageRoom(OsuRoom room)

internal function to remove a room from the managed rooms list

waitForMembership
MembershipEvent waitForMembership(bool delegate(MembershipEvent) check, Duration timeout)

Waits for an event or returns one which is in the backlog already. Removes matching backlog entries.

waitForMessage
Message waitForMessage(bool delegate(Message) check, Duration timeout)

Waits for an event or returns one which is in the backlog already. Removes matching backlog entries.

waitForMessageBunch
Message[] waitForMessageBunch(bool delegate(Message) check, Duration timeout, Duration totalTimeout = 5.seconds, Duration inbetweenTimeout = 300.msecs)

Waits for multiple messages sent at once and returns them.

waitForQuit
Quit waitForQuit(bool delegate(Quit) check, Duration timeout)
waitForTopic
TopicChange waitForTopic(bool delegate(TopicChange) check, Duration timeout)

Waits for an event or returns one which is in the backlog already. Removes matching backlog entries.

Variables

backlogsMembership
MembershipEvent[8] backlogsMembership;

list of backlog which hasn't been handled by any event subscribers, oldest one will always be replaced on new ones.

backlogsMessage
Message[256] backlogsMessage;
backlogsQuit
Quit[256] backlogsQuit;
backlogsTopic
TopicChange[8] backlogsTopic;

list of backlog which hasn't been handled by any event subscribers, oldest one will always be replaced on new ones.

client
TCPConnection client;
doRatelimit
bool doRatelimit;

Set to true to slow down message sending to the limit allowed on osu.

gotLine
bool gotLine;

true after the first line has been received.

host
string host;

IRC host to connect to.

onDirectMessage
Event!Message onDirectMessage;

Event emitted on a private message to the bot.

password
string password;

Credentials to use for authentication when connecting.

port
ushort port;

IRC port to use to connect.

processorsMembership
bool delegate(MembershipEvent)[] processorsMembership;

list of event subscribers. Gets removed automatically when called and returns true, otherwise caller has to remove it.

processorsMessage
bool delegate(Message)[] processorsMessage;
processorsQuit
bool delegate(Quit)[] processorsQuit;
processorsTopic
bool delegate(TopicChange)[] processorsTopic;

list of event subscribers. Gets removed automatically when called and returns true, otherwise caller has to remove it.

ratelimiter
BanchoRatelimiter!() ratelimiter;

Bancho ratelimiter instance.

rooms
OsuRoom[] rooms;
username
string username;

Credentials to use for authentication when connecting.

Examples

1 BanchoBot bot = new BanchoBot("User", "hunter2");
2 runTask({
3   while (true)
4   {
5     bot.connect();
6     logDiagnostic("Got disconnected from bancho...");
7     sleep(2.seconds);
8   }
9 });

Meta