def test_joinChannel(self, mock_globals): mock_globals.channels = {} mock_globals.cluster = Mock(spec=connection.ConnectionHandler) self.assertIs(utils.joinChannel('botgotsthis', 0), True) self.assertIn('botgotsthis', mock_globals.channels) self.assertEqual(mock_globals.channels['botgotsthis'].joinPriority, 0) mock_globals.cluster.join_channel.assert_called_once_with( mock_globals.channels['botgotsthis'])
def test_joinChannel_existing_channel(self, mock_globals): mock_globals.cluster = Mock(spec=connection.ConnectionHandler) mock_globals.channels = { 'botgotsthis': Channel('botgotsthis', mock_globals.cluster, 1) } self.assertIs(utils.joinChannel('botgotsthis', 0), False) self.assertIn('botgotsthis', mock_globals.channels) self.assertEqual(mock_globals.channels['botgotsthis'].joinPriority, 0)
async def auto_join_add(db: DatabaseMain, channel: str, send: Send) -> bool: result: bool = await db.saveAutoJoin(channel, 0) priority: Union[int, float] = await db.getAutoJoinsPriority(channel) wasInChat: bool = not utils.joinChannel(channel, priority) if result and not wasInChat: send(f'''\ Auto join for {channel} is now enabled and joined {channel} chat''') elif not wasInChat: send(f'''\ Auto join for {channel} is already enabled but now joined {channel} chat''') else: send(f'''\ Auto join for {channel} is already enabled and already in chat''') return True
async def come(channel: str, send: Send) -> bool: bannedWithReason: Optional[str] priority: Union[float, int] db: DatabaseMain async with DatabaseMain.acquire() as db: bannedWithReason = await db.isChannelBannedReason(channel) if bannedWithReason is not None: send(f'Chat {channel} is banned from joining') return True priority = await db.getAutoJoinsPriority(channel) joinResult: bool = utils.joinChannel(channel, priority) if joinResult: send(f'Joining {channel}') else: send(f'I am already in {channel}') return True
async def join(channel: str, send: Send) -> bool: priority: Union[int, float] db: DatabaseMain async with DatabaseMain.acquire() as db: bannedWithReason: Optional[str] bannedWithReason = await db.isChannelBannedReason(channel) if bannedWithReason is not None: send(f'Chat {channel} is banned from joining') return True priority = await db.getAutoJoinsPriority(channel) if utils.joinChannel(channel, priority): send(f'Joining {channel}') else: send(f'Already joined {channel}') return True