Fix FSM storage and filter.

This commit is contained in:
Alex Root Junior 2018-06-27 01:13:53 +03:00
parent 3fb0a23db7
commit b4d8ac2c0a
4 changed files with 7 additions and 7 deletions

View file

@ -303,6 +303,8 @@ class RedisStorage2(BaseStorage):
async def update_data(self, *, chat: typing.Union[str, int, None] = None, user: typing.Union[str, int, None] = None,
data: typing.Dict = None, **kwargs):
if data is None:
data = {}
temp_data = await self.get_data(chat=chat, user=user, default={})
temp_data.update(data, **kwargs)
await self.set_data(chat=chat, user=user, data=temp_data)
@ -330,6 +332,8 @@ class RedisStorage2(BaseStorage):
async def update_bucket(self, *, chat: typing.Union[str, int, None] = None,
user: typing.Union[str, int, None] = None,
bucket: typing.Dict = None, **kwargs):
if bucket is None:
bucket = {}
temp_bucket = await self.get_data(chat=chat, user=user)
temp_bucket.update(bucket, **kwargs)
await self.set_data(chat=chat, user=user, data=temp_bucket)

View file

@ -133,6 +133,7 @@ class StateFilter(BaseFilter):
result = super(StateFilter, cls).validate(full_config)
if not result:
return {cls.key: None}
return result
async def check(self, obj):
if '*' in self.state:

View file

@ -88,7 +88,7 @@ class FilterRecord:
if self.event_handlers:
return event_handler in self.event_handlers
elif self.exclude_event_handlers:
return not event_handler in self.exclude_event_handlers
return event_handler not in self.exclude_event_handlers
return True

View file

@ -122,10 +122,5 @@ async def process_gender(message: types.Message):
await state.finish()
async def shutdown(dispatcher: Dispatcher):
await dispatcher.storage.close()
await dispatcher.storage.wait_closed()
if __name__ == '__main__':
executor.start_polling(dp, loop=loop, skip_updates=True, on_shutdown=shutdown)
executor.start_polling(dp, loop=loop, skip_updates=True)