1 import bancho.irc; 2 3 void main() 4 { 5 BanchoBot banchoConnection = new BanchoBot("WebFreak", ""); 6 bool running = true; 7 auto botTask = runTask(() @safe nothrow { 8 while (running) 9 { 10 banchoConnection.connect(); 11 logDiagnostic("Got disconnected from bancho..."); 12 13 if (waitForInterrupt(2.seconds)) 14 break; 15 } 16 }); 17 sleep(3.seconds); 18 auto users = ["WebFreak", "Node"]; 19 OsuRoom room = banchoConnection.createRoom("bob"); 20 sleep(7.seconds); 21 room.password = "123456"; 22 runTask(() @safe nothrow { 23 // repeats code until bancho responded to everything (didn't throw) 24 // aborts when room is closed 25 room.repeatUntilRespondedOrFatalExit({ 26 room.size = 8; 27 room.mods = [Mod.Hidden, Mod.DoubleTime]; 28 room.map = "1158325"; 29 }); 30 }); 31 runTask(() @safe nothrow { 32 foreach (user; users) 33 room.repeatUntilRespondedOrFatalExit({ 34 room.invite(user); 35 }); 36 }); 37 runTask(() @safe nothrow { 38 int joined; 39 while (true) 40 { 41 string user = room.tryWaitForJoin(30.seconds); 42 if (user.length) 43 { 44 joined++; 45 room.trySendMessage("yay welcome " ~ user ~ "!"); 46 } 47 else 48 { 49 if (joined == 0) 50 { 51 // forever alone 52 room.close(); 53 return; 54 } 55 else 56 { 57 break; 58 } 59 } 60 } 61 62 room.trySendMessage("Referees: " ~ room.tryListRefs.join(", ")); 63 room.trySendMessage( 64 "This is an automated test, this room will close in 10 seconds on timer (three times)"); 65 room.trySetTimer(10.seconds); 66 room.trySetTimer(10.seconds); 67 room.trySetTimer(10.seconds); 68 room.waitForTimer(15.seconds).orTimeout({ 69 room.trySendMessage("Timer didn't trigger :("); 70 room.trySendMessage("closing the room in 5s"); 71 waitForInterrupt(5.seconds); 72 }); 73 room.close(); 74 }).join(); 75 running = false; 76 banchoConnection.disconnect(); 77 botTask.join(); 78 }
Returns the value given in first parameter or executes the callback if evaluating it threw a WaitTimeoutException. If any other exception is thrown, an AssertError will be triggered.