LittlePaimon/LittlePaimon-install.ps1
2022-04-07 11:32:10 +08:00

293 lines
10 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# this file should be saved as "UTF-8 with BOM"
$ErrorActionPreference = "Stop"
function Expand-ZIPFile($file, $destination) {
$file = (Resolve-Path -Path $file).Path
$destination = (Resolve-Path -Path $destination).Path
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach ($item in $zip.items()) {
$shell.Namespace($destination).copyhere($item)
}
}
# 检查运行环境
if ($Host.Version.Major -lt 3) {
Write-Output 'powershell 版本过低,无法一键安装'
exit
}
if ((Get-ChildItem -Path Env:OS).Value -ine 'Windows_NT') {
Write-Output '当前操作系统不支持一键安装'
exit
}
if (![Environment]::Is64BitProcess) {
Write-Output '暂时不支持32位系统'
exit
}
if (Test-Path ./LittlePaimon-Bot) {
Write-Output '发现重复,是否删除旧文件并重新安装?'
$reinstall = Read-Host '请输入 y 或 n (y/n)'
Switch ($reinstall) {
Y { Remove-Item .\LittlePaimon-Bot -Recurse -Force }
N { exit }
Default { exit }
}
}
try {
py -3.8 --version
if ($LASTEXITCODE = '0') {
Write-Output 'python 3.8 已发现,跳过安装'
$install_git = $false
}
else {
$install_python = $true
Write-Output 'python 3.8 未发现,将自动安装'
}
}
catch [System.Management.Automation.CommandNotFoundException] {
$install_python = $true
Write-Output 'python 3.8 未发现,将自动安装'
}
try {
git --version
$install_git = $false
Write-Output 'git 已发现,跳过安装'
}
catch [System.Management.Automation.CommandNotFoundException] {
$install_git = $true
Write-Output 'git 未发现,将自动安装'
}
$qqid = Read-Host '请输入作为机器人的QQ号'
$qqpassword = Read-Host -AsSecureString '请输入作为机器人的QQ密码'
$qqsuperuser = Read-Host '请输入机器人管理员的QQ号'
$loop = $true
while ($loop) {
$loop = $false
Write-Output '请选择下载源'
Write-Output '1、中国大陆'
Write-Output '2、港澳台或国外'
$user_in = Read-Host '请输入 1 或 2'
Switch ($user_in) {
1 { $source_cn = $true }
2 { $source_cn = $false }
Default { $loop = $true }
}
}
if ($source_cn) {
# 中国大陆下载源
$python38 = 'https://mirrors.huaweicloud.com/python/3.8.6/python-3.8.6-amd64.exe'
$git = 'https://mirrors.huaweicloud.com/git-for-windows/v2.35.1.windows.1/Git-2.35.1-64-bit.exe'
$gocqhttp = 'https://download.fastgit.org/Mrs4s/go-cqhttp/releases/download/v1.0.0-rc1/go-cqhttp_windows_amd64.zip'
$LittlePaimongit = 'https://hub.fastgit.xyz/CMHopeSunshine/LittlePaimon.git'
$pypi = 'http://mirrors.aliyun.com/pypi/simple/'
}
else {
# 国际下载源
$python38 = 'https://www.python.org/ftp/python/3.8.6/python-3.8.6-amd64.exe'
$git = 'https://github.com/git-for-windows/git/releases/download/v2.35.1.windows.1/Git-2.35.1-64-bit.exe'
$gocqhttp = 'https://github.com/Mrs4s/go-cqhttp/releases/download/v1.0.0-rc1/go-cqhttp_windows_amd64.zip'
$LittlePaimongit = 'https://github.com/CMHopeSunshine/LittlePaimon.git'
$pypi = 'https://pypi.org/simple/'
}
# 创建运行目录
New-Item -Path .\LittlePaimon-Bot -ItemType Directory
Set-Location LittlePaimon-Bot
New-Item -ItemType Directory -Path .\go-cqhttp
# 下载安装程序
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if ($install_python) {
Write-Output "正在安装 python"
Invoke-WebRequest $python38 -OutFile .\python-3.8.6.exe
Start-Process -Wait -FilePath .\python-3.8.6.exe -ArgumentList "/quiet InstallAllUsers=1 PrependPath=1 Include_test=0"
Write-Output "python 安装成功"
Remove-Item python-3.8.6.exe
}
if ($install_git) {
Write-Output "正在安装 git"
Invoke-WebRequest $git -OutFile .\git-2.35.1.exe
Start-Process -Wait -FilePath .\git-2.35.1.exe -ArgumentList "/SILENT /SP-"
$env:Path += ";C:\Program Files\Git\bin" # 添加 git 环境变量
Write-Output "git 安装成功"
Remove-Item git-2.35.1.exe
}
Invoke-WebRequest $gocqhttp -O .\go-cqhttp.zip
Expand-ZIPFile go-cqhttp.zip -Destination .\go-cqhttp\
Remove-Item go-cqhttp.zip
# 下载源码
git clone $LittlePaimongit --depth=1
Set-Location LittlePaimon
python -m pip install -r requirements.txt -i $pypi
Copy-Item -Recurse hoshino\config_example hoshino\config
Set-Location ..
# 写入 gocqhttp 配置文件
$realpassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($qqpassword))
New-Item -Path .\go-cqhttp\config.yml -ItemType File -Value @"
# go-cqhttp
account: #
uin: ${qqid} # QQ
password: '${realpassword}' # 使
encrypt: false #
status: 0 # 线 https://docs.go-cqhttp.org/guide/config.html#线
relogin: #
delay: 3 # ,
interval: 3 #
max-times: 0 # , 0
# 使
# ,
use-sso-address: true
heartbeat:
# ,
# -1
interval: 5
message:
#
# : string,array
post-format: string
# CQ,
ignore-invalid-cqcode: false
#
#
#
force-fragment: true
# url
fix-url: false
#
proxy-rewrite: ''
#
report-self-message: false
# ReplyAt
remove-reply-at: false
# Reply
extra-reply-data: false
# Mime ,
skip-mime-scan: false
output:
# trace,debug,info,warn,error
log-level: warn
# . . 0 .
log-aging: 15
# . false
log-force-new: true
#
log-colorful: true
# DEBUG
debug: false #
#
default-middlewares: &default
# 访,
access-token: ''
#
filter: ''
# API
#
# cqhttp rate_limit ,
# , :
# https://baike.baidu.com/item/%E4%BB%A4%E7%89%8C%E6%A1%B6%E7%AE%97%E6%B3%95/6597000?fr=aladdin
rate-limit:
enabled: false #
frequency: 1 # ,
bucket: 1 #
database: #
leveldb:
# leveldb
# 10-20MB
# 使 get_msg
enable: true
# 使()
cache:
image: data/image.db
video: data/video.db
#
servers:
#
#- http: # http
#- ws: # Websocket
#- ws-reverse: # Websocket
#- pprof: #
# WS
- ws-reverse:
# WS Universal
#
universal: ws://127.0.0.1:6660/ws/
# WS API
api: ws://127.0.0.1:6660/api/
# WS Event
event: ws://127.0.0.1:6660/event/
#
reconnect-interval: 3000
middlewares:
<<: *default #
"@
# 写入 LittlePaimon 配置文件
Set-Content .\LittlePaimon\hoshino\config\__bot__.py -Value @"
# coding=gbk
# hoshinoip
PORT = 6660
HOST = '127.0.0.1' # 使QQbot
# HOST = '0.0.0.0' # 访使
DEBUG = False #
WHITE_LIST = []
SUPERUSERS = [${qqsuperuser}] # QQ","
GUILDADMIN = []
NICKNAME = ('','bot') # @bot
COMMAND_START = {''} #
COMMAND_SEP = set() # hoshinoset()
#
# http, file, base64
# QQbothttp
RES_PROTOCOL = 'file'
# windows
RES_DIR = r'./res/'
# 使httpurlRES_DIR
RES_URL = 'http://127.0.0.1:5000/static/'
#
#
#
#
MODULES_ON = {
'botmanage',
'dice',
'avatar_gif',
'codeonline',
'Paimonchat',
'Genshin_Paimon',
'myb_exchange'
}
"@
# 写启动程序
New-Item -Path .\启动.ps1 -ItemType File -Value @"
Start-Process powershell.exe -ArgumentList "Set-Location .\LittlePaimon ; python run.py"
Set-Location .\go-cqhttp
./go-cqhttp.exe
"@
Write-Output '安装完成用powershell运行"启动.ps1"来启动机器人吧!'