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

Node.js 写的一个真随机数机器人 - 适用于瀑布 IM 服务拓展

  •  1
     
  •   imdjh · Oct 25, 2015 · 6319 views
    This topic created in 3841 days ago, the information mentioned may be changed or developed.

    前些时间尝试了瀑布 IM - 一个团队协作办公平台(我更喜欢自己给的这个定义,它集合了各种团队协作服务于一聊天室)

    喜人的是,我看到了 hackable 的服务拓展,于是做了这么一个功能演示主题的聊天 bot 。

    先来看看效果吧 ;)

    chat showbox

    使用基于关键词激发的服务, 使用基于关键词激发的服务,监听关键词,发送 RESTful 请求到 API

    怎么用?

    1. 在服务器上直接安装&运行

    npm install trbot-pubuim -g
    

    2. 使用方便快速的 docker 镜像

    docker pull imdjh/trbot-pubuim
    docker run --name MyTrueRandomBot -d imdjh/trbot-pubuim
    

    3. 我没有服务器

    你真的很幸运,遇上免费 docker PaaS 的时代,而且本项目已 docker 镜像化。

    如何使用服务商 DaoCloud ,参见这个v2ex 帖子

    将 hub 镜像名设置为 imdjh/trbot-pubuim 。hub link

    4. 我不想用 docker , show me your prod.

    setting pubuim service

    将示例站点http://imdjh-true-number-bot.daoapp.io/输入回调地址

    配置机器人

    这个项目可以高度定制化(中二化)

    通过传递环境变量给守护进程完成。

    支持的环境变量以及对应解释如下。
    - BOT_AVATAR # [ life.glider ] 机器人在桌面提示时的头像, URL 字符串。
    - BOT_MSGPREFIX # [ I choose ] 机器人在返回随即数之前说的话,字符串。
    - BOT_NAME # [ True Random Dice ] 机器人在聊天室里显示的名字,字符串。
    - PULL_DELAY # [ 5000 ] 启动时检测随即池是否被填充的延时,单位毫秒
    - TR_BUFFER # [ 50 ] 每次从 random.org 提取随机数的数量,数字。
    - TR_BUFFER_CHECKLENGTH # [ 5 ] 每当随即池里的数少于此时,触发从 random.org 取随机数,数字
    - TR_END # [ 6 ] 随机数的截止(包含),数字。
    - TR_START # [ 1 ] 随机数的开始(包含),数字。

    - VERBOSE # [] 除非设置为 yes ,否则不再 log 中输出 DEBUG 信息,任意。

    配置示例

    config example
    这个是http://imdjh-true-number-bot.daoapp.io/示例站点的的配置

    Supplement 1  ·  Oct 25, 2015

    使用npm install -g trbot-pubuim后,用trbot-pubuim启动服务器,前面可以加环境变量。如:

    VERBOSE=yes BOT_NAME=gud trbot-pubuim

    Supplement 2  ·  Oct 25, 2015

    RANDOM.ORG offers true random numbers to anyone on the Internet. The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs.

    这个 Bot 原理是用了 random.org 的 API 放到自己的缓冲池里面,只要 random.org 是真随机的,那么结果就是真随机的。

    Supplement 3  ·  Oct 25, 2015

    刚才创建了一个瀑布 IM 的团队,大家可以用这个内部链接注册到团队里调戏 TR 机器人:
    https://true-rnd.pubu.im/reg/d32zrergp87gc6b

    或者嫌麻烦的话,用 [email protected]/321321a登录到团队开 ROLL !

    Supplement 4  ·  Oct 25, 2015

    感谢 @matsuijurina 提出,把大神的名字打错了,已在演示服务器中改正,再次谢谢!
    演示服务器 Update: 增加中二度,使语句通畅。

    update demo API shot

    14 replies    2015-10-27 12:19:35 +08:00
    Moker
        1
    Moker  
       Oct 25, 2015
    demo 404 了
    风格是自己喜欢的 先收藏下
    luoway
        2
    luoway  
       Oct 25, 2015   ❤️ 1
    > RANDOM.ORG offers true random numbers to anyone on the Internet. The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs.

    That's cool !
    imdjh
        3
    imdjh  
    OP
       Oct 25, 2015
    @Moker 你好,可能是 daocloud 抽了?我现在测了,演示服务器`http://imdjh-true-number-bot.daoapp.io/`没问题
    Moker
        4
    Moker  
       Oct 25, 2015
    @imdjh 我福建电信 还是不行。。
    matsuijurina
        5
    matsuijurina  
       Oct 25, 2015   ❤️ 2
    达扎克:我经历了亿万年的岁月,穷尽世间真理,追寻宇宙本源,终于在这个上帝不掷骰子的世界里找到了产生真随机数的方法,成为了多维宇宙的随机之神....然而....你居然把“随机”两个字打错了????!
    trigged
        6
    trigged  
       Oct 25, 2015
    怒赞
    chairuosen
        7
    chairuosen  
       Oct 25, 2015
    没明白,哪写着怎么真随机的原理了?
    imdjh
        8
    imdjh  
    OP
       Oct 25, 2015
    @chairuosen 这个 Bot 用了 random.org 的 API 放到自己的缓冲池里面,只要 random.org 是真随机的,那么结果就是真随机的。
    imdjh
        9
    imdjh  
    OP
       Oct 25, 2015
    @Moker 你好,刚才创建了一个瀑布 IM 的团队(聊天室),你可以试试看用这个内部链接注册:
    https://true-rnd.pubu.im/reg/d32zrergp87gc6b

    或者用这个测试帐号直接玩起(privileged)
    [email protected]/321321a
    imdjh
        10
    imdjh  
    OP
       Oct 25, 2015
    shyrock
        11
    shyrock  
       Oct 26, 2015
    进来看真随机数。。。
    aksoft
        12
    aksoft  
       Oct 26, 2015
    真·草薙京
    Kabie
        13
    Kabie  
       Oct 26, 2015
    ...我就是来看看真随机实现。。。结果你告诉我用服务。。。
    CYKun
        14
    CYKun  
       Oct 27, 2015
    RANDOM.ORG offers true random numbers to anyone on the Internet. The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs.

    用背景噪声生成随机数。。。总觉得好像不太靠谱
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2416 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 03:40 · PVG 11:40 · LAX 20:40 · JFK 23:40
    ♥ Do have faith in what you're doing.