Skip to content

Commit

Permalink
Merge pull request #5 from SuperEgoKoishi/main
Browse files Browse the repository at this point in the history
fix:修复重启失败
  • Loading branch information
Ohdmire authored Nov 16, 2024
2 parents 2d481df + cd35895 commit 30cdee2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions irc_dlient.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from requests.exceptions import HTTPError

from datetime import datetime
from datetime import datetime, timedelta

import rosu_pp_py as rosu

Expand Down Expand Up @@ -84,12 +84,12 @@ def reset_all(self):
self.b.clear_cache()

def restart(self):
print(f'尝试重启...{datetime.now()+datetime.timedelta(hours=8)}')
print(f'尝试重启...{datetime.now()+timedelta(hours=8)}')
time.sleep(120)
self.reset_all()
self.r.create_room(self.server, "")
self.restarting_task = threading.Thread(target=(self.restart))
print(f'重启完成{datetime.now()+datetime.timedelta(hours=8)}')
print(f'重启完成{datetime.now()+timedelta(hours=8)}')

# 定义定时任务,每60s执行一次,检查房间状态
def start_periodic_task(self):
Expand Down
20 changes: 20 additions & 0 deletions tests/test_irc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,26 @@ def test_on_pubmsg_handle_room_host_changed_message(self, mock_print):
# 断言
self.assertEqual("BanchoBot114", self.client.p.room_host)

def test_on_pubmsg_handle_bancho_restart_message(self):
"""
测试处理来自BanchoBot的服务器重启消息
"""
# 模拟接收频道消息事件
mock_connection = MagicMock()
mock_event = MagicMock()
mock_event.arguments = ["Bancho will be right back!"]
mock_event.source = "[email protected]"

# 保存调用on_pubmsg前的restarting_task
restarting_task = self.client.restarting_task

# 调用on_pubmsg
self.client.on_pubmsg(mock_connection, mock_event)
time.sleep(125)

# 断言
self.assertNotEqual(restarting_task, self.client.restarting_task)

@patch('builtins.print')
def test_on_pubmsg_handle_player_joined_room(self, mock_print):
"""
Expand Down

0 comments on commit 30cdee2

Please sign in to comment.