Fishroom安装记录

fishroom项目主页


安装过程(直接在服务器上部署,不使用docker)

采用的系统是ubuntu 16.04,debian记忆中安装时候有报错

下载项目

git clone https://github.com/tuna/fishroom
cd fishroom

安装redis

apt update
apt install redis-server

安装依赖

首先确认python最新的3.5版本已经安装

apt-get install -y python3-dev python3-pip libmagic1 libjpeg-dev libpng-dev libwebp-dev zlib1g-dev gcc
pip3 install --upgrade pip setuptools
pip3 install -r requirements.txt

编辑配置文件(重点)

mv fishroom/config.py.example fishroom/config.py
vim fishroom/config.py

这是一开始配置文件的内容:

config = {
    "debug": True,
    "timezone": "Asia/Shanghai",
    "baseurl": "http://fishroom.example.com",  # do not end with "/"
    "name": "teleboto",
    "cmd_me": "tg_bot",  # username of the telegram bot

    "redis": {
        # "unix_socket_path": "/var/run/redis/redis.sock"
        "host": "redis-host",  # hostname for redis server
        "port": 6379,
        "prefix": "fishroom",
    },

    "irc": {
        "server": "irc.freenode.net",
        "port": 6697,
        "nick": "XiaoT",       # IRC nick name
        "password": None,      # IRC account password, if nickname registered
        "ssl": True,
        "blacklist": [
            "[Olaf]",
        ],
    },

    # Uncomment these if you want telegram access
    # "telegram": {
    #     "token": "",  # get this from @BotFather
    #     "me": None,
    #     "admin": [],  # admin id (integer)
    # },

    # Uncomment these if you want XMPP-MUC access
    # "xmpp": {
    #     "server": "xmpp.jp",
    #     "port": 5222,
    #     "jid": "[email protected]/resource",
    #     "password": "",
    #     "nick": "XiaoT",
    # },

    # Uncomment these if you want gitter access
    # "gitter": {
    #     "token": "",
    #     "me": "",  # bot username
    # },

    # Uncomment these if you want Matrix access
    # "matrix": {
    #     "server": "https://matrixim.cc:8448",
    #     "user": "fishroom",
    #     "password": "",
    #     "nick": "bot_fishroom",
    #     "bot_msg_pattern": "^mubot|^!wikipedia",
    # },

    # Uncomment these if you want WeChat access
    # "wechat": {},

    # Optional, only if you use qiniu for file_store
    # Comment this out if you don"t use qiniu
    "qiniu": {
        "access_key": "",
        "secret_key": "",
        "bucket": "",
        "base_url": "",
    },

    "photo_store": {
        # set one in ("imgur", "vim-cn", "qiniu")
        "provider": "vim-cn",
        "options": {
            "client_id": "",
        }
    },

    # this is the web interface
    "chatlog": {
        "host": "tornado-host",  # hostname for web server
        "port": 8000,
        "default_channel": "teleboto-dev",
    },

    # Comment this out if you don"t use qiniu
    "file_store": {
        "provider": "qiniu",
    },

    "text_store": {
        "provider": "vinergy",
        "options": {
        },
    },

    "plugins": [
        "pia", "imglink", "vote", "hualao"
    ],

    "bindings": {
        "archlinux-cn": {
            "irc": "#archlinux-cn",
            "telegram": "-1001031857103",  # group id can be obtained using bot api
            "xmpp": "[email protected]",
            "matrix": "#archlinux:matrixim.cc"
        },
        "test": {
            # Use room nick name to identify a room
            # TODO: use Uins (https://itchat.readthedocs.io/zh/latest/intro/contact/#uins)
            # to identify a room, but currently I can"t get room Uins on login.
            "wechat": "xxx chat room"
        }
    }
}

# vim: ft=python

我的需求是使用web服务,然后用bot把irc和telegram互通起来

为了方便阅读,把配置文件拆开

config = {
    "debug": True,
    "timezone": "Asia/Shanghai",
    "baseurl": "http://irc.parrotsec-cn.org",  # do not end with "/"
    "name": "teleboto",
    "cmd_me": "ParrotSecCN_bot",  # username of the telegram bot

baseurl:设置成你web想要访问的url,如http://irc.parrotsec-cn.org ,需要注意的是这里会强制跳转,如果你这里写的是https,但是你并没有配置https,会导致web服务无法使用,如果你这里设置的是 http://www.baidu.com 那么通过ip访问你的web服务的时候,会跳转到百度, 如果你dns中还没有添加a记录解析域名到你服务器的ip,这里先填 http://你的服务器ip地址 即可
cmd_me:设置成你telegrambot的用户名,比如我的bot用户名是ParrotSecCN_bot

    "redis": {
        # "unix_socket_path": "/var/run/redis/redis.sock"
        "host": "127.0.0.1",  # hostname for redis server
        "port": 6379,
        "prefix": "fishroom",
    },

这里如果你和我一样是直接在服务器上部署,host请改为127.0.0.1

    "irc": {
        "server": "irc.freenode.net",
        "port": 6697,
        "nick": "ParrotSecCN_bot",       # IRC nick name
        "password": None,      # IRC account password, if nickname registered
        "ssl": True,
        "blacklist": [
            "[Olaf]",
        ],
    },

这里是设置irc频道,默认使用的服务器是freenode端口6697,你也可以设置为其他irc服务器
nick是你的bot在irc频道中的昵称,比如ParrotSecCN_bot

    # Uncomment these if you want telegram access
     "telegram": {
         "token": "11111111:XXXX-LgxxxxxxA6ueyN_xxxxxxxxxUY",  # get this from @BotFather
         "me": [123456789],
         "admin": [987654321],  # admin id (integer)
     },

我需要使用telegrambot去和irc互通,所以要把这条配置中的注释符删掉

token是telegram @BotFather给你创建的机器人的token,格式为数字:字母
me是你机器人的id,如果你不知道你机器人的id是多少,访问https://api.telegram.org/bot+token/getMe(把你的token加在bot后面没有’+’) 返回内容中的id即是你bot的id
admin:这是群组管理员的id,先把你的bot加到你想要添加的群组,然后使用管理员用户随便发句话,访问:https://api.telegram.org/bot+token/getUpdates即可看到新发的内容,找到username和管理员一样的那段前面的id即是管理员的id,注意这里还可以看到一个群组id,把它记录下来

    # Uncomment these if you want XMPP-MUC access
    # "xmpp": {
    #     "server": "xmpp.jp",
    #     "port": 5222,
    #     "jid": "[email protected]/resource",
    #     "password": "",
    #     "nick": "XiaoT",
    # },

    # Uncomment these if you want gitter access
    # "gitter": {
    #     "token": "",
    #     "me": "",  # bot username
    # },

    # Uncomment these if you want Matrix access
    # "matrix": {
    #     "server": "https://matrixim.cc:8448",
    #     "user": "fishroom",
    #     "password": "",
    #     "nick": "bot_fishroom",
    #     "bot_msg_pattern": "^mubot|^!wikipedia",
    # },

    # Uncomment these if you want WeChat access
    # "wechat": {},

这些我都不需要,不需要修改

    # Optional, only if you use qiniu for file_store
    # Comment this out if you don"t use qiniu
    #"qiniu": {
    #   "access_key": "",
    #    "secret_key": "",
    #    "bucket": "",
    #    "base_url": "",
    #},

把这里注释掉因为我不需要七牛来储存内容

    "photo_store": {
        # set one in ("imgur", "vim-cn", "qiniu")
        "provider": "vim-cn",
        "options": {
            "client_id": "",
        }
    },

不需要修改

    # this is the web interface
    "chatlog": {
        "host": "0.0.0.0",  # hostname for web server
        "port": 80,
        "default_channel": "parrotsec-cn",
    },

这里是web服务监听的地址,我想要外网访问,并且不想配置https,直接监听外网ip然后端口设置为80即可

default_channel是默认加入的irc频道,设置为你聊天使用的irc频道即可

    # Comment this out if you don"t use qiniu
    #"file_store": {
    #    "provider": "qiniu",
    #},

同样注释掉这里,不使用七牛

    "text_store": {
        "provider": "vinergy",
        "options": {
        },
    },

    "plugins": [
        "pia", "imglink", "vote", "hualao"
    ],

不需要修改

    "bindings": {
        "parrotsec-cn": {
            "irc": "#parrotsec-cn",
            "telegram": "-1001031857103",  # group id can be obtained using bot api
            #"xmpp": "[email protected]",
            #"matrix": "#archlinux:matrixim.cc"
        },
        #"test": {
            # Use room nick name to identify a room
            # TODO: use Uins (https://itchat.readthedocs.io/zh/latest/intro/contact/#uins)
            # to identify a room, but currently I can"t get room Uins on login.
            #"wechat": "xxx chat room"
        #}
    }
}

# vim: ft=python

最后这里,bindings和test是在网页右上角可以切换的频道,如果你只需要一个irc频道,把后面的test内容注释掉

irc:是irc频道
telegram:是tg群组的id,在通过之前的方法应该已经得到了
xmppmatrix我不需要使用,所以注释掉

启动

依次执行即可

# run fishroom core
python3 -m fishroom.fishroom

# start IM interfaces, select not all of them are needed
python3 -m fishroom.telegram
python3 -m fishroom.IRC
#python3 -m fishroom.gitter
#python3 -m fishroom.xmpp

python3 -m fishroom.web

你会发现需要多个窗口来执行,很麻烦,所以我写了一个脚本来批量启动并且记录log

start.sh:

#! /bin/bash

nohup python3 -m fishroom.fishroom > log/fishroom.txt 2>&1 &
nohup python3 -m fishroom.IRC > log/irc.txt 2>&1 &
nohup python3 -m fishroom.web > log/web.txt 2>&1 &
nohup python3 -m fishroom.telegram > log/telegram.txt 2>&1 &

保存后添加执行权限chmod +x start.sh

启动:./start.sh

log会保存到fishroom/log/目录下


*转载请注明来自AresX’s Blog

本博客采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议(CC BY-NC-SA 4.0) 发布.转载请注明出处
本文链接:https://ares-x.com/2018/01/15/Fishroom安装记录/