Skip to content

Commit

Permalink
添加多平台编译,应用程序信息和图标
Browse files Browse the repository at this point in the history
  • Loading branch information
kagurazakayashi committed Jun 26, 2023
1 parent 35007e2 commit 03e7a5f
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 16 deletions.
35 changes: 26 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- 当传送的内容为视频时,自动在正文前面添加 `#视频` 标签。可以在配置文件中禁用或自定义此功能。
- 输入 `/chatid` 命令时,将返回当前会话和用户的名称和 ID 。该命令仅在配置文件中启用调试模式时有效,并且无视使用者白名单限制。可用于使用者加入白名单之前获取自己的 用户/群组/频道 的 ID 。

## 部署
## 编译

开发时所用 golang 版本: `1.19.5`

Expand All @@ -29,16 +29,33 @@ go get
go build
```

然后创建配置文件 `config.json` ,和编译出来的可执行文件 `rbq_anonymous_bot` 放一起。
### 跨平台编译

在 Windows x64 中也可以通过批处理一键生成全平台二进制文件:

```bat
go build
MKDIR bin
build.bat
```

批处理脚本最后会调用 `MAKECAB``7z` 命令进行压缩。

## 部署

1. 创建配置文件 `config.json` ,和编译出来的可执行文件放一起。
2. Linux 或 macOS 需要使用 `chmod +x [可执行文件名]` 给予权限。
3. 运行可执行文件。

### 使用 Docker 部署

1. 使用 `build_linux.bat` 或参考里面的操作生成可执行文件压缩档 `bin/rbq_anonymous_bot.xz`
2. 修改 `./docker.sh` 为需要的 Docker 操作。
3.`bin/rbq_anonymous_bot.xz` + `config.json` + `Dockerfile` + `docker.sh` 复制到服务器中的同一个文件夹中。
4. 进入服务器中的该文件夹,执行 `chmod +x docker.sh``./docker.sh` 即可运行
5. 让 bot 转发一条消息,等待大约一分钟,该 Docker 容器状态会显示为 `healthy`
6. 如果没有出现停止问题,可以将 RESTART POLICIES 设置为 `Always`
1. 创建配置文件 `config.json`
2. 使用 `build_linux.bat` 或参考里面的操作生成可执行文件压缩档 `bin/rbq_anonymous_bot.xz`
3. 修改 `./docker.sh` 为需要的 Docker 操作。
4.`bin/rbq_anonymous_bot.xz` + `config.json` + `Dockerfile` + `docker.sh` 复制到服务器中的同一个文件夹中。
5. 进入服务器中的该文件夹,执行 `chmod +x docker.sh``./docker.sh` 即可运行
6. 让 bot 转发一条消息,等待大约一分钟,该 Docker 容器状态会显示为 `healthy`
7. 如果没有出现停止问题,可以将 RESTART POLICIES 设置为 `Always`

### 配置文件示例

Expand Down Expand Up @@ -75,7 +92,7 @@ go build
- `debug` 调试模式。显示所有通信日志,并将无命令的内容直接返回。
- `proxy` 是代理服务器,支持 `http``socks5`,不需要时留空字符串。
- `apikey` Telegram 的会话令牌(去问 [BotFather](https://t.me/BotFather) 要)。
- `healthcheck` Docker 健康检查用会话文件名,需要和 `Dockerfile` 中的 `HEALTHCHECK` 想对应
- `healthcheck` Docker 健康检查用会话文件名,需要和 `Dockerfile` 中的 `HEALTHCHECK` 相对应
- `timezone` GMT 时间偏移量,用于显示时间时所用的时区。
- `whitelist` 是白名单,只允许这些 UID 使用这个 BOT 。
- `to` 是会话代号(预定义的发送目标)。
Expand Down
36 changes: 36 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
SET NAME=rbq_anonymous_bot_v1.1.0_
DEL /Q bin\*
SET CGO_ENABLED=0
SET GOARCH=amd64
go generate
SET GOOS=windows
go build -o bin\%NAME%Windows64.exe .
DEL /Q *.syso
SET GOOS=linux
go build -o bin\%NAME%Linux64 .
SET GOOS=darwin
go build -o bin\%NAME%macOS64 .
SET GOARCH=386
go generate
SET GOOS=windows
go build -o bin\%NAME%Windows32.exe .
DEL /Q *.syso
SET GOOS=linux
go build -o bin\%NAME%Linux32 .
CD bin
MAKECAB /d compressiontype=lzx /d compressionmemory=21 %NAME%Windows32.exe
RENAME %NAME%Windows32.ex_ %NAME%Windows32.exe.cab
MAKECAB /d compressiontype=lzx /d compressionmemory=21 %NAME%Windows64.exe
RENAME %NAME%Windows64.ex_ %NAME%Windows64.exe.cab
DEL /Q *.exe
7z a -txz -mx9 %NAME%Linux64.xz %NAME%Linux64
DEL /Q %NAME%Linux64
7z a -txz -mx9 %NAME%Linux32.xz %NAME%Linux32
DEL /Q %NAME%Linux32
7z a -tzip -mx9 %NAME%macOS64.zip %NAME%macOS64
DEL /Q %NAME%macOS64
CD ..
SET NAME=
SET CGO_ENABLED=
SET GOARCH=
SET GOOS=
6 changes: 0 additions & 6 deletions build_linux.bat

This file was deleted.

2 changes: 2 additions & 0 deletions desktop.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[.ShellClassInfo]
IconResource=rc.ico,0
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ require (
)

require (
github.com/akavel/rsrc v0.10.2 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/josephspurrier/goversioninfo v1.4.0 // indirect
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
)
32 changes: 32 additions & 0 deletions main.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
type="win32"
name="com.github.rbqgroup.rbq_anonymous_bot"
version="1.0.0.0"
processorArchitecture="*"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True</dpiAware>
</windowsSettings>
</application>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows Vista , Windows Server 2008 -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!-- Windows 7 , Windows Server 2008 R2 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows 8 , Windows Server 2012 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Windows 8.1 , Windows Server 2012 R2 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 10 , Windows 11 , Windows Server 2016 , Windows server 2019 , Windows server 2022 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:generate goversioninfo -icon=rc.ico -manifest=main.exe.manifest
package main

import (
Expand All @@ -18,7 +19,7 @@ type ChatObj struct {
}

func main() {
fmt.Println("絨!")
fmt.Println("rbq_anonymous_bot v1.1.0")
if !loadConfig() {
return
}
Expand Down
Binary file added rc.icns
Binary file not shown.
Binary file added rc.ico
Binary file not shown.
43 changes: 43 additions & 0 deletions versioninfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"FixedFileInfo": {
"FileVersion": {
"Major": 1,
"Minor": 0,
"Patch": 0,
"Build": 0
},
"ProductVersion": {
"Major": 1,
"Minor": 0,
"Patch": 0,
"Build": 0
},
"FileFlagsMask": "3f",
"FileFlags ": "00",
"FileOS": "040004",
"FileType": "01",
"FileSubType": "00"
},
"StringFileInfo": {
"Comments": "绒布球频道更新姬",
"CompanyName": "神楽坂雅詩",
"FileDescription": "绒布球频道更新姬",
"FileVersion": "v1.1.0.0",
"InternalName": "rbq_anonymous_bot",
"LegalCopyright": "2022, rbqgroup.",
"LegalTrademarks": "",
"OriginalFilename": "main.exe",
"PrivateBuild": "",
"ProductName": "绒布球频道 BOT",
"ProductVersion": "v1.1.0.0",
"SpecialBuild": ""
},
"VarFileInfo": {
"Translation": {
"LangID": "0804",
"CharsetID": "04B0"
}
},
"IconPath": "rc.ico",
"ManifestPath": "main.exe.manifest"
}

0 comments on commit 03e7a5f

Please sign in to comment.