V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
chuanwu

分享一个支持插件编程的微信 BOT

  •  
  •   chuanwu · Mar 31, 2017 · 2835 views
    This topic created in 3319 days ago, the information mentioned may be changed or developed.

    因为楼主是微信重度使用者,所以想着搞了一个微信机器人,来做一些 chatops 的事情。

    为了方便给 bot 开发更多的功能,我只暴露了一个注册函数的装饰器,其他全部整理到 bot 里。这样一来,开发新的功能就特别简单。 比如,我想添加一个探知服务是否存活的功能,只要编写如下代码,然后把文件放至 /plugin 目录下即可。

    from tinker import r
    
    
    @r.register('ping')
    def ping():
        return 'pong'
    
    

    这样一来,发送!ping给 bot , bot 就会返回一个pong作为回应,以此来测试 bot 是否正常运行(命令以!开头,是借鉴了公司内部 slack bot 的使用姿势)。

    Github 地址:Tinker

    BTW :这个项目本意是为了 chatops ,可惜这样的伟大愿景没有实现,我成了女票大人的专属开发....女票有啥需求,我就得实现啥.......为了更好更快地败家,现在已经沦落到在给女票写爬虫来提醒她购买各大品牌新推的产品。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2248 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 01:28 · PVG 09:28 · LAX 18:28 · JFK 21:28
    ♥ Do have faith in what you're doing.