importosu_irc_sdkfromosu_irc_sdkimportmodelsbot=osu_irc_sdk.OsuBot("your name", "your password", debug=True) # see: https://osu.ppy.sh/p/irc@bot.receiver(models.Codes.run_after_start)defrrr():
# Create a game room immediately after startupbot.logger("create room", bot.api.room_create("my test room", "114514", True, 4), test=True)
@bot.receiver(models.Codes.someone_joined_room)defjoin(event: models.Message):
bot.logger(f"{event.name} joined: {event.message}", test=True)
@bot.receiver(models.Codes.private_message)defpmessage(event: models.Message):
bot.logger(f"Get private chat: {event.name} - {event.message}")
# bot.api.send_private_message(event.name, f"我是复读机: {event.message}")@bot.receiver(models.Codes.channel_message)defcmessage(event: models.Message):
bot.logger(f"Message from {event.channel_id} :{event.name} - {event.message}")
# bot.api.send_private_message(event.channel_id, f"{event.message}")@bot.receiver(models.Codes.someone_joined_slot)defjoin_slot(event: models.Message):
bot.logger(f"{event.name} joined {event.channel_id} - {event.message} slot", test=True)
ifbot.name==event.name:
bot.api.room_set_host(event.channel_id, event.name)
@bot.receiver(models.Codes.someone_changed_slot)defchange_slot(event: models.Message):
bot.logger(f"{event.name} in {event.channel_id}, moved to {event.message} slot", test=True)
@bot.receiver(models.Codes.changed_song)defcs(event: models.Message):
bot.logger(f"room: {event.channel_id} changed song: {event.message}", test=True)
@bot.receiver(models.Codes.someone_left_room)deflft(event: models.Message):
bot.logger(f"{event.name} left: {event.channel_id}", test=True)
@bot.receiver(models.Codes.changed_host)defchst(event: models.Message):
bot.logger(f"{event.name} became the host of {event.channel_id}", test=True)
@bot.receiver(models.Codes.match_closed)defclst(event: models.Message):
bot.logger(f"room {event.channel_id} closed", test=True)
@bot.receiver(models.Codes.all_players_are_ready)defrdy(event: models.Message):
bot.logger(f"room: {event.channel_id} all players are ready", test=True)
@bot.receiver(models.Codes.user_finished_playing)deffsh(event: models.UserGrade):
bot.logger(f"room: {event.channel_id} player: {event.name} completed game, score: {event.score}, is_pass: {event.is_pass}",
test=True)
@bot.receiver(models.Codes.host_is_changing_map)defcmp(event: models.Message):
bot.logger(f"room: {event.channel_id} is revising map", test=True)
@bot.receiver(models.Codes.match_has_started)defstt(event: models.Message):
bot.logger(f"room: {event.channel_id} started the match", test=True)
@bot.receiver(models.Codes.match_finished)defstf(event: models.Message):
bot.logger(f"room: {event.channel_id} - match has finished", test=True)
bot.strat()
Events
models.Codes
run_after_start# This is a special event that will be executed immediately after successfully connecting to Bancho.channel_message# messages from roomprivate_message# private messagesomeone_joined_room# triggered only when a room is createdsomeone_joined_slot# someone joined roomsomeone_changed_slotchanged_songchanged_hostsomeone_left_roommatch_closed# room closedall_players_are_readyuser_finished_playing# someone finished playinghost_is_changing_mapmatch_has_startedmatch_finished# all players complete
API
OsuBot.api
send_private_message(username, message)
send_channel_message(room_id, message) # commands are also okroom_create(room_name, passwd="", free_mods=False, max_member="") # it will return the room_idroom_set_passwd(room_id, passwd)
room_set_max_member(room_id, max_member)
room_set_host(room_id, host_name)
room_set_mods(room_id, mods)
room_strat_game(room_id)
room_change_map(room_id, map_id, mode="") # mode:0/1/2/3