import{_ as n,o as e,c as s,e as a}from"./app-BvUYPzLF.js";const t={},o=a(`

liteyuki.dev.observer

说明: 此模块用于注册观察者函数,使用watchdog监控文件变化并重启bot 启用该模块需要在配置文件中设置dev_mode为True

var CALLBACK_FUNC

var FILTER_FUNC

def debounce(wait)

说明: 防抖函数

源代码在GitHub上查看
def debounce(wait):
    """
    防抖函数
    """

    def decorator(func):

        def wrapper(*args, **kwargs):
            nonlocal last_call_time
            current_time = time.time()
            if current_time - last_call_time > wait:
                last_call_time = current_time
                return func(*args, **kwargs)
        last_call_time = None
        return wrapper
    return decorator

class CodeModifiedHandler(FileSystemEventHandler)

@debounce(1)

def on_modified(self, event)

源代码在GitHub上查看
@debounce(1)
def on_modified(self, event):
    raise NotImplementedError('on_modified must be implemented')

def on_created(self, event)

源代码在GitHub上查看
def on_created(self, event):
    self.on_modified(event)

def on_deleted(self, event)

源代码在GitHub上查看
def on_deleted(self, event):
    self.on_modified(event)

def on_moved(self, event)

源代码在GitHub上查看
def on_moved(self, event):
    self.on_modified(event)

def on_any_event(self, event)

源代码在GitHub上查看
def on_any_event(self, event):
    self.on_modified(event)

def on_file_system_event(directories: tuple[str], recursive: bool = True, event_filter: FILTER_FUNC = None) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC]

说明: 注册文件系统变化监听器

参数:

返回: 装饰器,装饰一个函数在接收到数据后执行

源代码在GitHub上查看
def on_file_system_event(directories: tuple[str], recursive: bool=True, event_filter: FILTER_FUNC=None) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC]:
    """
    注册文件系统变化监听器
    Args:
        directories: 监听目录们
        recursive: 是否递归监听子目录
        event_filter: 事件过滤器, 返回True则执行回调函数
    Returns:
        装饰器,装饰一个函数在接收到数据后执行
    """

    def decorator(func: CALLBACK_FUNC) -> CALLBACK_FUNC:

        def wrapper(event: FileSystemEvent):
            if event_filter is not None and (not event_filter(event)):
                return
            func(event)
        code_modified_handler = CodeModifiedHandler()
        code_modified_handler.on_modified = wrapper
        for directory in directories:
            observer.schedule(code_modified_handler, directory, recursive=recursive)
        return func
    return decorator
`,27),i=[o];function l(p,c){return e(),s("div",null,i)}const d=n(t,[["render",l],["__file","observer.html.vue"]]),u=JSON.parse('{"path":"/dev/api/dev/observer.html","title":"liteyuki.dev.observer","lang":"zh-CN","frontmatter":{"title":"liteyuki.dev.observer","lastUpdated":false,"description":"liteyuki.dev.observer 说明: 此模块用于注册观察者函数,使用watchdog监控文件变化并重启bot 启用该模块需要在配置文件中设置dev_mode为True var CALLBACK_FUNC 说明: 位置1为FileSystemEvent 类型: TypeAlias 默认值: Callable[[FileSystemEvent...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/dev/observer.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/dev/observer.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki.dev.observer"}],["meta",{"property":"og:description","content":"liteyuki.dev.observer 说明: 此模块用于注册观察者函数,使用watchdog监控文件变化并重启bot 启用该模块需要在配置文件中设置dev_mode为True var CALLBACK_FUNC 说明: 位置1为FileSystemEvent 类型: TypeAlias 默认值: Callable[[FileSystemEvent..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:locale:alternate","content":"en-US"}],["meta",{"property":"og:updated_time","content":"2024-08-29T06:19:39.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:19:39.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"liteyuki.dev.observer\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"var CALLBACK_FUNC","slug":"var-callback-func","link":"#var-callback-func","children":[]},{"level":3,"title":"var FILTER_FUNC","slug":"var-filter-func","link":"#var-filter-func","children":[]},{"level":3,"title":"def debounce(wait)","slug":"def-debounce-wait","link":"#def-debounce-wait","children":[]},{"level":3,"title":"class CodeModifiedHandler(FileSystemEventHandler)","slug":"class-codemodifiedhandler-filesystemeventhandler","link":"#class-codemodifiedhandler-filesystemeventhandler","children":[]},{"level":3,"title":"def on_file_system_event(directories: tuple[str], recursive: bool = True, event_filter: FILTER_FUNC = None) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC]","slug":"def-on-file-system-event-directories-tuple-str-recursive-bool-true-event-filter-filter-func-none-callable-callback-func-callback-func","link":"#def-on-file-system-event-directories-tuple-str-recursive-bool-true-event-filter-filter-func-none-callable-callback-func-callback-func","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":6}]},"readingTime":{"minutes":1.85,"words":554},"filePathRelative":"dev/api/dev/observer.md","localizedDate":"2024年8月19日","autoDesc":true}');export{d as comp,u as data};