BanchoBot

Represents a Bancho IRC connection.

@safe
class BanchoBot {}

Constructors

this
this(string username, string password, string host, ushort port)

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

Destructor

~this
~this()
Undocumented in 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)

Removes a channel from the managed channels.

fetchOldMembershipLog
MembershipEvent[] fetchOldMembershipLog(bool delegate(MembershipEvent) @(safe) nothrow check, bool returnIt)

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

fetchOldMessageLog
Message[] fetchOldMessageLog(bool delegate(Message) @(safe) nothrow check, bool returnIt)
fetchOldQuitLog
Quit[] fetchOldQuitLog(bool delegate(Quit) @(safe) nothrow check, bool returnIt)
fetchOldTopicLog
TopicChange[] fetchOldTopicLog(bool delegate(TopicChange) @(safe) nothrow check, bool returnIt)

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

fromUnmanaged
OsuRoom fromUnmanaged(string room, string game)

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)

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

processNumeric
void processNumeric(int num, string line, string relevantPart)
Undocumented in source. Be warned that the author may not have intended to support it.
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)
ratelimitNothrow
bool ratelimitNothrow(string channel, bool put)

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

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

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

tryWaitForMembership
bool tryWaitForMembership(bool delegate(MembershipEvent) @(safe) nothrow check, Duration timeout, MembershipEvent result)

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

tryWaitForMessage
bool tryWaitForMessage(bool delegate(Message) @(safe) nothrow check, Duration timeout, Message result)
tryWaitForQuit
bool tryWaitForQuit(bool delegate(Quit) @(safe) nothrow check, Duration timeout, Quit result)
tryWaitForTopic
bool tryWaitForTopic(bool delegate(TopicChange) @(safe) nothrow check, Duration timeout, TopicChange result)

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

unmanageRoom
void unmanageRoom(OsuRoom room)

internal function to remove a room from the managed rooms list

waitForMembership
MembershipEvent waitForMembership(bool delegate(MembershipEvent) @(safe) nothrow check, Duration timeout)
waitForMessage
Message waitForMessage(bool delegate(Message) @(safe) nothrow 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) @(safe) nothrow check, Duration timeout, Duration totalTimeout, Duration inbetweenTimeout)

Waits for multiple messages sent at once and returns them.

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

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

waitUntilLoggedIn
void waitUntilLoggedIn()
Undocumented in source. Be warned that the author may not have intended to support it.

Mixins

__anonymous
mixin Processor!("Message", Message, 256, 5.seconds)
Undocumented in source.
__anonymous
mixin Processor!("Quit", Quit, 256, 20.seconds)
Undocumented in source.
__anonymous
mixin Processor!("Topic", TopicChange, 8, 30.seconds)
Undocumented in source.
__anonymous
mixin Processor!("Membership", MembershipEvent, 8, 20.seconds)
Undocumented in source.

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.

onAuthenticated
NothrowEvent!() onAuthenticated;

Event emitted on a successful login.

onDirectMessage
NothrowEvent!Message onDirectMessage;

Event emitted on a private message to the bot.

onMotdLine
NothrowEvent!string onMotdLine;

Event emitted for every motd line.

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

BanchoBot bot = new BanchoBot("User", "hunter2");
runTask({
  while (true)
  {
    bot.connect();
    logDiagnostic("Got disconnected from bancho...");
    sleep(2.seconds);
  }
});

Meta