找到398个回复 (用户: 罐子)
@童真再见,可能是感觉是没有拉低短接点用万用表测一下,
一加8Pro
@童真再见,你在Arduino里面设置了串口的端口里没有
一加8Pro
@老虎会游泳,未命名那个代码应该在自定义数据列表public_22里
一加8Pro
hi
。
// 聊天框的CSS选择器 const chatBoxSelector = 'textarea.w-full.p-0'; // 发送按钮的CSS选择器 const sendButtonSelector = 'button.absolute.p-1'; // 正在输入动效(取代发送按钮)的CSS选择器 const replyNotReadySelector = 'div.text-2xl'; // 聊天回答的CSS选择器 const chatReplySelector = 'div.markdown'; // 用户自身的虎绿林uid const hu60MyUid = 19346; // 改成自己的uid // 用户的虎绿林sid const hu60Sid = '4JfOlTT3iHw58i1ITtpS0okksAAA'; // 带sid的虎绿林URL const hu60BaseUrl = 'https://hu60.cn/q.php/' + hu60Sid + '/'; ///////////////////////////////////////////////////////////// // 发送聊天信息 function sendText(text) { let chatBox = document.querySelector(chatBoxSelector); let sendButton = document.querySelector(sendButtonSelector); chatBox.value = text; sendButton.click(); } // 读取响应 function readReply() { let reply = Array.from(document.querySelectorAll(chatReplySelector)).at(-1); let lines = []; if (!reply.childNodes) { // 错误信息 return reply.innerText; } reply.childNodes.forEach(x => { if (x.tagName == 'PRE') { // 代码 lines.push("\n```\n" + x.querySelector('code').innerText + "\n```\n"); } else { // 正文 lines.push(x.innerText); } }); return lines.join("\n\n"); } // 判断响应是否结束 function isFinished() { return document.querySelector(replyNotReadySelector) == null; } // 读取@消息 async function readAtInfo() { let response = await fetch(hu60BaseUrl + 'msg.index.@.no.json?_origin=*&_content=json'); return await response.json(); } // 读取帖子内容 async function readTopicContent(path) { let url = hu60BaseUrl + path.replace('{$BID}', 'json').replace('?', '?_origin=*&_content=text&pageSize=1&'); let response = await fetch(url); return await response.json(); } // 回复帖子 async function replyTopic(uid, replyText, topicObject) { let content = "<!md>\n@#" + uid + "," + replyText; let url = null; if (topicObject.tMeta) { // 帖子 url = 'bbs.newreply.'+encodeURIComponent(topicObject.tContents[0].topic_id)+'.json'; } else { // 聊天室 url = 'addin.chat.'+encodeURIComponent(topicObject.chatRomName)+'.json'; } let formData = new FormData(); formData.append('content', content); formData.append('token', topicObject.token); formData.append('go', '1'); let response = await fetch(hu60BaseUrl + url + '?_origin=*', { body: formData, method: "post", redirect: "manual" // 不自动重定向 }); return response; } // 休眠指定的毫秒数 // 用法:await sleep(1000) const sleep = ms => new Promise(r => setTimeout(r, ms)); // 回复@信息 async function replyAtInfo(info) { try { let uid = info.byuid; let url = info.content[0].url; let floor = url.split('#')[1]; // 防止自己和自己对话 if (uid == hu60MyUid || uid < 1) { return; } console.log(info); let topicObject = await readTopicContent(url); let text = null; if (topicObject.tContents) { text = topicObject.tContents[0].content; } else { text = topicObject.chatList[0].content; } sendText(text); do { await sleep(500); } while (!isFinished()); let replyText = readReply(); let response = await replyTopic(uid, replyText, topicObject); console.log(response); } catch (ex) { console.error(ex); } } // 运行机器人 async function run() { console.log('虎绿林ChatGPT机器人已启动'); while (true) { try { // 浏览器用户可能直接输入了问题,等待回答完成 if (!isFinished()) { do { await sleep(500); } while (!isFinished()); } let atInfo = await readAtInfo(); console.log(new Date(), atInfo); for (let i=0; i<atInfo.msgList.length; i++) { await replyAtInfo(atInfo.msgList[i]); } await sleep(1000); } catch (ex) { console.error(ex); } } } run();
一加8Pro
asecyv@mailto.plus
package main//计算hex校验和
import (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
"strings"
)func main() {
fmt.Println("请输入要计算校验和的行:")
reader := bufio.NewReader(os.Stdin)
line, := reader.ReadString('\n')
line = strings.TrimSpace(line)
checksum, := strconv.ParseInt(line[len(line)-2:], 16, 64) //pattern := regexp.MustCompile(`.{2}`) parts := pattern.FindAllString(line[1:len(line)-2], -1) var nums []int for _, p := range parts { num, _ := strconv.ParseInt(p, 16, 64) nums = append(nums, int(num)) } newChecksum := 256 - reduce(nums) if checksum == int64(newChecksum) { fmt.Println("校验和匹配,该行无需修改") } else { fmt.Printf("校验和不匹配,原校验和:%d,应该改为:%d\n", checksum, newChecksum) fmt.Println("正确的行:") fmt.Printf("%s%02X\n", line[:len(line)-2], newChecksum) }
}
func reduce(nums []int) int {
return reduceHelper(nums, 0)
}
func reduceHelper(nums []int, acc int) int {
if len(nums) == 0 {
return acc % 256
}
return reduceHelper(nums[1:], (acc+nums[0])%256)
}This is a program written in Go to calculate the checksum of a given hex line and compare it to the last two digits of the input line. The program takes input from the user, removes whitespace characters, and extracts the last two digits as the expected checksum. Then, it extracts pairs of hex digits (two characters) from the remaining part of the input line and converts them to integers. The reduce function is called with the resulting list of integers as an argument, which recursively sums them and takes the result modulo 256. The calculated checksum is then compared to the expected checksum, and if they match, the program outputs that the line is correct. Otherwise, the program outputs the correct checksum and the modified line with the correct checksum appended at the end.
asecyv@mailto.plus
package main//计算hex校验和
import (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
"strings"
)func main() {
fmt.Println("请输入要计算校验和的行:")
reader := bufio.NewReader(os.Stdin)
line, := reader.ReadString('\n')
line = strings.TrimSpace(line)
checksum, := strconv.ParseInt(line[len(line)-2:], 16, 64) //pattern := regexp.MustCompile(`.{2}`) parts := pattern.FindAllString(line[1:len(line)-2], -1) var nums []int for _, p := range parts { num, _ := strconv.ParseInt(p, 16, 64) nums = append(nums, int(num)) } newChecksum := 256 - reduce(nums) if checksum == int64(newChecksum) { fmt.Println("校验和匹配,该行无需修改") } else { fmt.Printf("校验和不匹配,原校验和:%d,应该改为:%d\n", checksum, newChecksum) fmt.Println("正确的行:") fmt.Printf("%s%02X\n", line[:len(line)-2], newChecksum) }
}
func reduce(nums []int) int {
return reduceHelper(nums, 0)
}
func reduceHelper(nums []int, acc int) int {
if len(nums) == 0 {
return acc % 256
}
return reduceHelper(nums[1:], (acc+nums[0])%256)
}
改下添加按任意键退出
Sure, you can modify the code to add a prompt for the user to press any key to exit the program. You can use the function to wait for the user to input any text before exiting the program. Here's an example:fmt.Scanln()go
Copy code
package mainimport (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
"strings"
)func main() {
fmt.Println("请输入要计算校验和的行:")
reader := bufio.NewReader(os.Stdin)
line, := reader.ReadString('\n')
line = strings.TrimSpace(line)
checksum, := strconv.ParseInt(line[len(line)-2:], 16, 64)pattern := regexp.MustCompile(`.{2}`) parts := pattern.FindAllString(line[1:len(line)-2], -1) var nums []int for _, p := range parts { num, _ := strconv.ParseInt(p, 16, 64) nums = append(nums, int(num)) } newChecksum := 256 - reduce(nums) if checksum == int64(newChecksum) { fmt.Println("校验和匹配,该行无需修改") } else { fmt.Printf("校验和不匹配,原校验和:%d,应该改为:%d\n", checksum, newChecksum) fmt.Println("正确的行:") fmt.Printf("%s%02X\n", line[:len(line)-2], newChecksum) } fmt.Println("按任意键退出...") fmt.Scanln()
}
func reduce(nums []int) int {
return reduceHelper(nums, 0)
}func reduceHelper(nums []int, acc int) int {
if len(nums) == 0 {
return acc % 256
}
return reduceHelper(nums[1:], (acc+nums[0])%256)
}
With this modification, the program will wait for the user to press any key before exiting.asecyv@mailto.plus
fmt.Scanln()只能算是按回车键退出,不算是任意键退出
You are correct, waits for the user to input a complete line, which usually requires pressing the Enter key. If you want to wait for the user to press any key, you can use a platform-specific package like to read a single key without waiting for Enter to be pressed. Here's an example that uses this package to wait for the user to press any key:fmt.Scanln()github.com/eiannone/keyboardgo
Copy code
package mainimport (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
"strings""github.com/eiannone/keyboard"
)
func main() {
fmt.Println("请输入要计算校验和的行:")
reader := bufio.NewReader(os.Stdin)
line, := reader.ReadString('\n')
line = strings.TrimSpace(line)
checksum, := strconv.ParseInt(line[len(line)-2:], 16, 64)pattern := regexp.MustCompile(`.{2}`) parts := pattern.FindAllString(line[1:len(line)-2], -1) var nums []int for _, p := range parts { num, _ := strconv.ParseInt(p, 16, 64) nums = append(nums, int(num)) } newChecksum := 256 - reduce(nums) if checksum == int64(newChecksum) { fmt.Println("校验和匹配,该行无需修改") } else { fmt.Printf("校验和不匹配,原校验和:%d,应该改为:%d\n", checksum, newChecksum) fmt.Println("正确的行:") fmt.Printf("%s%02X\n", line[:len(line)-2], newChecksum) } fmt.Println("按任意键退出...") keyboard.GetSingleKey()
}
func reduce(nums []int) int {
return reduceHelper(nums, 0)
}func reduceHelper(nums []int, acc int) int {
if len(nums) == 0 {
return acc % 256
}
return reduceHelper(nums[1:], (acc+nums[0])%256)
}
In this example, we use the function from the package to wait for the user to press any key before exiting. Note that this package may not work on all platforms, so you should check the documentation and test the program on the platforms you plan to use it on.GetSingleKey()github.com/eiannone/keyboard
一加8Pro
C:\Users\Admin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
一加8Pro