# bot4rocketchat **Repository Path**: percyc/bot4rocketchat ## Basic Information - **Project Name**: bot4rocketchat - **Description**: 一个对接了rocketchat的机器人 - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-03-26 - **Last Updated**: 2023-03-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: rocketchat, Bot ## README # bot4rocketchat #### 介绍 一个对接了rocketchat的机器人 #### 软件架构 软件架构说明 #### 安装教程 1. 下载代码 ```bash git clone https://gitee.com/percyc/bot4rocketchat.git ``` 2. 创建virtualenv ```bash cd bot4rocketchat virtualenv venv source venv/bin/activate ``` 3. 下载依赖 ```bash pip install rocketchat_API ``` 4. 在rocketchat注册一个用户,角色设置为bot。 5. 在当前文件夹创建一个文件,参照以下代码,填好rocketchat服务器、机器人帐号、密码,并运行即可。 #### 使用示例 ```python #!/usr/bin/env python3 # import os from bot4rocketchat import RocketchatBot import requests,re #username = os.environ.get('ROCKET_USERNAME') #password = os.environ.get('ROCKET_PASSWORD') #server_url = os.environ.get('ROCKET_SERVER_URL') username = '' password = '' server_url = "" #rocketchat server proxy_dict = { "http" : "http://127.0.0.1:2080", "https" : "https://127.0.0.1:2080", } bot = RocketchatBot(username, password, server_url,threading_updates=True) # 开启多线程 # 装饰器direct_command代表私聊,group_command是群聊,channel_command是频道。 # 其中装饰器里面内容为正则表达式,如果对应聊天中匹配到记录,则跳转到以下的程序进行处理,可以用match_list调用匹配到的内容 @bot.direct_command(r'(.*)') def directreply(message, match_list): bot.send_message(message['rid'], '%s'%(match_list[0]),alias='robot',emoji=':rabbit:') # alias和emoji为可选项,机器人回复时候的头像和名称 @bot.group_command(r'start') def start(message, match_list): bot.send_message(message['rid'], 'hi') @bot.channel_command(r'hi') def sayhello(message,match_list): bot.send_message(message['rid'],'hello') if __name__ == '__main__': print('机器人开始运行了。。。') bot.run(sleep=0.5) ``` #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)