forked from saipo/astrbot_plugin_dajiao
Compare commits
91 Commits
Author | SHA1 | Date | |
---|---|---|---|
d35fa08ae9 | |||
e730e4f07d | |||
71d3fef258 | |||
3b7154c43c | |||
3081e27492 | |||
d1018dcb6b | |||
7011750868 | |||
3de65377c8 | |||
0eaec7a561 | |||
![]() |
c604a07c81 | ||
893bce1805 | |||
![]() |
d1d6307dc0 | ||
68f98f2b20 | |||
![]() |
8997b1ebb3 | ||
feee265119 | |||
![]() |
8cce90d4b4 | ||
22c2029103 | |||
![]() |
8f21c75592 | ||
fa5f1f5ad0 | |||
![]() |
3bb631114f | ||
4a4f151e64 | |||
71ee4c7bf8 | |||
f1bc92f73f | |||
979eb197d6 | |||
9391193e27 | |||
35d1939d0b | |||
49e1bb15a9 | |||
0be461c61e | |||
f4f40cd4aa | |||
6ff728b21f | |||
08f05ccaf9 | |||
f827007657 | |||
87a2ef7a1e | |||
60ae392ae3 | |||
31f82db044 | |||
612115f7fc | |||
895da59df9 | |||
![]() |
299d70c731 | ||
68e57cdc4b | |||
1005de3350 | |||
df152f1d8b | |||
a493233253 | |||
1bcee67180 | |||
![]() |
3612be8201 | ||
946f78a5a6 | |||
![]() |
cbb078eb4a | ||
a6944e856c | |||
![]() |
f5dc744507 | ||
aef43f0720 | |||
![]() |
306800bec1 | ||
66dc9e65fb | |||
![]() |
58b02cd42d | ||
dfd54bc96a | |||
![]() |
c769412f71 | ||
c176402f38 | |||
![]() |
5c6cec0d39 | ||
c4fb786d5a | |||
![]() |
263c2476fc | ||
09232b7bac | |||
![]() |
8f30dd73ec | ||
51cc7fc8ec | |||
9db0c3747b | |||
78fdda18cc | |||
920b098df6 | |||
45dcf35257 | |||
1653fb98e7 | |||
8b846255e2 | |||
405e2024cd | |||
675dc706d8 | |||
7d1331faa0 | |||
23669b399b | |||
74bbbacb94 | |||
53c26f8595 | |||
1f2f8e09db | |||
9d59f9f1c3 | |||
e06ce3931e | |||
0ccd9b482a | |||
7cf5e48eb4 | |||
8e6da4b569 | |||
ee3cfbecdb | |||
62064c3cc6 | |||
e693a02e51 | |||
f43310dd4a | |||
080270b0b9 | |||
ebec9ed323 | |||
09594360ad | |||
9a12b3c2a4 | |||
a53af94e9d | |||
f70cc6bdad | |||
a66a6817a8 | |||
9006c815ad |
72
TicTacToeGame.py
Normal file
72
TicTacToeGame.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import random
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
class TicTacToeGame:
|
||||||
|
def __init__(self):
|
||||||
|
self.board = [" "] * 9
|
||||||
|
self.player_symbol = "X"
|
||||||
|
self.computer_symbol = "O"
|
||||||
|
self.current_player = "X" # X先走
|
||||||
|
|
||||||
|
def print_board(self) -> str:
|
||||||
|
"""返回棋盘字符串"""
|
||||||
|
board_str = (
|
||||||
|
f"\n {self.board[0]} | {self.board[1]} | {self.board[2]} \n"
|
||||||
|
"-----------\n"
|
||||||
|
f" {self.board[3]} | {self.board[4]} | {self.board[5]} \n"
|
||||||
|
"-----------\n"
|
||||||
|
f" {self.board[6]} | {self.board[7]} | {self.board[8]} \n"
|
||||||
|
)
|
||||||
|
return board_str
|
||||||
|
|
||||||
|
def check_winner(self) -> Optional[str]:
|
||||||
|
"""检查是否有玩家获胜"""
|
||||||
|
win_combinations = [
|
||||||
|
[0, 1, 2], [3, 4, 5], [6, 7, 8], # 横向
|
||||||
|
[0, 3, 6], [1, 4, 7], [2, 5, 8], # 纵向
|
||||||
|
[0, 4, 8], [2, 4, 6] # 对角线
|
||||||
|
]
|
||||||
|
|
||||||
|
for combo in win_combinations:
|
||||||
|
if self.board[combo[0]] == self.board[combo[1]] == self.board[combo[2]] != " ":
|
||||||
|
return self.board[combo[0]]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def is_board_full(self) -> bool:
|
||||||
|
"""检查棋盘是否已满"""
|
||||||
|
return " " not in self.board
|
||||||
|
|
||||||
|
def computer_move(self) -> int:
|
||||||
|
"""电脑AI移动"""
|
||||||
|
for i in range(9):
|
||||||
|
if self.board[i] == " ":
|
||||||
|
self.board[i] = self.computer_symbol
|
||||||
|
if self.check_winner() == self.computer_symbol:
|
||||||
|
return i
|
||||||
|
self.board[i] = " "
|
||||||
|
|
||||||
|
for i in range(9):
|
||||||
|
if self.board[i] == " ":
|
||||||
|
self.board[i] = self.player_symbol
|
||||||
|
if self.check_winner() == self.player_symbol:
|
||||||
|
self.board[i] = self.computer_symbol
|
||||||
|
return i
|
||||||
|
self.board[i] = " "
|
||||||
|
|
||||||
|
move_order = [4, 0, 2, 6, 8, 1, 3, 5, 7]
|
||||||
|
for move in move_order:
|
||||||
|
if self.board[move] == " ":
|
||||||
|
return move
|
||||||
|
|
||||||
|
return -1
|
||||||
|
|
||||||
|
def make_move(self, position: int) -> bool:
|
||||||
|
"""玩家移动"""
|
||||||
|
if 0 <= position <= 8 and self.board[position] == " ":
|
||||||
|
self.board[position] = self.current_player
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def switch_player(self):
|
||||||
|
"""切换当前玩家"""
|
||||||
|
self.current_player = "O" if self.current_player == "X" else "X"
|
215
main.py
215
main.py
@ -5,7 +5,17 @@ from astrbot.api import logger
|
|||||||
import random
|
import random
|
||||||
from .back import time_long, volume, isUserExist, insertUser, seconds_to_hms, ml_to_l_ml, get_user_name
|
from .back import time_long, volume, isUserExist, insertUser, seconds_to_hms, ml_to_l_ml, get_user_name
|
||||||
import pymysql
|
import pymysql
|
||||||
|
import matplotlib
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import os
|
||||||
from .Tool import get_tool_name
|
from .Tool import get_tool_name
|
||||||
|
import astrbot.api.message_components as Comp
|
||||||
|
from astrbot.core.utils.session_waiter import (
|
||||||
|
session_waiter,
|
||||||
|
SessionController,
|
||||||
|
)
|
||||||
|
import aiohttp # 需要异步HTTP客户端
|
||||||
|
from .TicTacToeGame import TicTacToeGame
|
||||||
|
|
||||||
@register("helloworld", "YourName", "一个简单的 Hello World 插件", "1.0.0")
|
@register("helloworld", "YourName", "一个简单的 Hello World 插件", "1.0.0")
|
||||||
class MyPlugin(Star):
|
class MyPlugin(Star):
|
||||||
@ -37,7 +47,7 @@ class MyPlugin(Star):
|
|||||||
conn.close()
|
conn.close()
|
||||||
yield event.plain_result(f"Hello,{get_user_name(event.get_sender_id())}, 你坚持了{time}s哦,{a}.射出{V}ml,{b}!")
|
yield event.plain_result(f"Hello,{get_user_name(event.get_sender_id())}, 你坚持了{time}s哦,{a}.射出{V}ml,{b}!")
|
||||||
|
|
||||||
@filter.command("给我连打十次")
|
@filter.command("帮我连打十次")
|
||||||
async def dajiaoX(self, event: AstrMessageEvent):
|
async def dajiaoX(self, event: AstrMessageEvent):
|
||||||
if isUserExist(event.get_sender_id()) != True:
|
if isUserExist(event.get_sender_id()) != True:
|
||||||
insertUser(event.get_sender_id())
|
insertUser(event.get_sender_id())
|
||||||
@ -50,19 +60,20 @@ class MyPlugin(Star):
|
|||||||
,charset='utf8' # 字符编码
|
,charset='utf8' # 字符编码
|
||||||
)
|
)
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
time=[];V=[];a=[];b=[]
|
time = [];V = [];a = [];b = []
|
||||||
for i in range(0,10):
|
for i in range(0,10):
|
||||||
time.append(round(random.uniform(1, 600), 2))
|
time.append(round(random.uniform(1, 600), 2))
|
||||||
V.append(round(random.uniform(0.01,100), 2))
|
V.append(round(random.uniform(0.01,100), 2)) if i==0 else V.append(round(random.uniform(1, V[i-1]+1), 2))
|
||||||
a.append(time_long(time))
|
a.append(time_long(time[i]))
|
||||||
b.append(volume(V))
|
b.append(volume(V[i]))
|
||||||
sql = "INSERT INTO dajiao (openid, timelong, volume) VALUES (%s, %s, %s)"
|
sql = "INSERT INTO dajiao (openid, timelong, volume) VALUES (%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s),(%s, %s, %s)"
|
||||||
values = (user_name,time[i],V[i])
|
values = (user_name,time[0],V[0],user_name,time[1],V[1],user_name,time[2],V[2],user_name,time[3],V[3],user_name,time[4],V[4],user_name,time[5],V[5],user_name,time[6],V[6],user_name,time[7],V[7],user_name,time[8],V[8],user_name,time[9],V[9])
|
||||||
cur.execute(sql,values)
|
cur.execute(sql,values)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
cur.close()
|
cur.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
yield event.plain_result(f"Hello,{get_user_name(event.get_sender_id())}, 第一次你坚持了{time[0]}s哦,{a[0]}.射出{V[0]}ml,{b[0]}!\n第二次你坚持了{time[1]}s哦,{a[1]}.射出{V[1]}ml,{b[1]}!\n哎呀,一点也打不出来了!")
|
yield event.plain_result(f"Hello,{get_user_name(event.get_sender_id())},准备开始挑战十连咯!\n第一次你坚持了{time[0]}s哦,{a[0]}.射出{V[0]}ml,{b[0]}!\n第二次你坚持了{time[1]}s哦,{a[1]}.射出{V[1]}ml,{b[1]}!\n第三次你坚持了{time[2]}s哦,{a[2]}.射出{V[2]}ml,{b[2]}!\n第四次你坚持了{time[3]}s哦,{a[3]}.射出{V[3]}ml,{b[3]}!\n第五次你坚持了{time[4]}s哦,{a[4]}.射出{V[4]}ml,{b[4]}!\n第六次你坚持了{time[5]}s哦,{a[5]}.射出{V[5]}ml,{b[5]}!\n第七次你坚持了{time[6]}s哦,{a[6]}.射出{V[6]}ml,{b[6]}!\n第八次你坚持了{time[7]}s哦,{a[7]}.射出{V[7]}ml,{b[7]}!\n第九次你坚持了{time[8]}s哦,{a[8]}.射出{V[8]}ml,{b[8]}!\n第十次你坚持了{time[9]}s哦,{a[9]}.射出{V[9]}ml,{b[9]}!\n哎呀,一点也打不出来了!杂鱼!")
|
||||||
|
|
||||||
|
|
||||||
@filter.command("打打你的")
|
@filter.command("打打你的")
|
||||||
async def dajiao_other(self, event: AstrMessageEvent, message: str):
|
async def dajiao_other(self, event: AstrMessageEvent, message: str):
|
||||||
@ -296,6 +307,56 @@ class MyPlugin(Star):
|
|||||||
cur.close()
|
cur.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
@filter.command("我的日产量")
|
||||||
|
async def mydayvolume(self, event: AstrMessageEvent):
|
||||||
|
if isUserExist(event.get_sender_id()) != True:
|
||||||
|
insertUser(event.get_sender_id())
|
||||||
|
conn=pymysql.connect(host = '192.168.31.9' # 连接名称,默认
|
||||||
|
,user = 'saipo'
|
||||||
|
,passwd='Grasste0403' # 密码
|
||||||
|
,port= 3306 # 端口,默认为3306
|
||||||
|
,db='saipo' # 数据库名称
|
||||||
|
,charset='utf8' # 字符编码
|
||||||
|
)
|
||||||
|
cur = conn.cursor()
|
||||||
|
sql = "SELECT DAY(eventTime),round(sum(volume),2) FROM dajiao WHERE openid = %s and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(eventTime) GROUP BY DAY(eventTime);"
|
||||||
|
openid = event.get_sender_id()
|
||||||
|
cur.execute(sql,(openid,))
|
||||||
|
date = cur.fetchall()
|
||||||
|
if len(date) == 0:
|
||||||
|
cur.close()
|
||||||
|
conn.close()
|
||||||
|
yield event.plain_result(f"没有找到数据哦!")
|
||||||
|
day = []
|
||||||
|
volume = []
|
||||||
|
|
||||||
|
for i in range(len(date)):
|
||||||
|
day.append(date[i][0])
|
||||||
|
volume.append(date[i][1])
|
||||||
|
plt.plot(day, volume)
|
||||||
|
plt.title('dayvolume')
|
||||||
|
plt.xlabel('day')
|
||||||
|
plt.ylabel('volume')
|
||||||
|
plt.xticks(day)
|
||||||
|
#设置显示数据
|
||||||
|
for x, y in zip(day, volume):
|
||||||
|
plt.text(x, y, f'{y}', ha='center', va='bottom', fontsize=10)
|
||||||
|
plt.grid()
|
||||||
|
plt.savefig('dayvolume.png')
|
||||||
|
plt.close()
|
||||||
|
with open('dayvolume.png', 'rb') as f:
|
||||||
|
image_data = f.read()
|
||||||
|
image = Comp.Image.fromBytes(image_data)
|
||||||
|
chain = [
|
||||||
|
Comp.At(qq=event.get_sender_id()),
|
||||||
|
Comp.Plain("日产量折线图:"),
|
||||||
|
image,
|
||||||
|
]
|
||||||
|
yield event.chain_result(chain)
|
||||||
|
cur.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
testNumber = 0
|
testNumber = 0
|
||||||
@filter.command("测试")
|
@filter.command("测试")
|
||||||
@ -306,5 +367,143 @@ class MyPlugin(Star):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@filter.command("Dora")
|
||||||
|
async def Dora(self, event: AstrMessageEvent):
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
async with session.get('https://www.doro.asia/api/random-sticker') as resp:
|
||||||
|
if resp.status == 200:
|
||||||
|
data = await resp.json()
|
||||||
|
if data.get('success', False):
|
||||||
|
image_url = data['sticker']['url']
|
||||||
|
chain = [
|
||||||
|
Comp.At(qq=event.get_sender_id()), # At 消息发送者
|
||||||
|
Comp.Plain("来看这个图:"),
|
||||||
|
Comp.Image.fromURL(image_url), # 使用API返回的图片URL
|
||||||
|
]
|
||||||
|
yield event.chain_result(chain)
|
||||||
|
else:
|
||||||
|
yield "获取表情包失败"
|
||||||
|
else:
|
||||||
|
yield "API请求失败"
|
||||||
|
|
||||||
|
@filter.command("来句骚话")
|
||||||
|
async def lovelive(self, event: AstrMessageEvent):
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
async with session.get('https://api.lovelive.tools/api/SweetNothings') as resp:
|
||||||
|
if resp.status == 200:
|
||||||
|
text = await resp.text() # 获取返回的文本内容
|
||||||
|
chain = [
|
||||||
|
Comp.At(qq=event.get_sender_id()), # At 消息发送者
|
||||||
|
Comp.Plain(text) # 使用API返回的文本
|
||||||
|
]
|
||||||
|
yield event.chain_result(chain)
|
||||||
|
else:
|
||||||
|
yield "获取骚话失败"
|
||||||
|
|
||||||
|
@filter.command("部署")
|
||||||
|
async def bushutest(self, event: AstrMessageEvent):
|
||||||
|
yield event.plain_result("自动部署成功!!")
|
||||||
|
|
||||||
|
@filter.command("井字棋")
|
||||||
|
async def tic_tac_toe_handler(self, event: AstrMessageEvent):
|
||||||
|
"""井字棋游戏处理器"""
|
||||||
|
try:
|
||||||
|
# 初始化游戏
|
||||||
|
game = TicTacToeGame()
|
||||||
|
|
||||||
|
# 发送初始说明和空棋盘
|
||||||
|
instructions = (
|
||||||
|
"欢迎来到井字棋游戏!\n"
|
||||||
|
"输入1-9的数字来选择位置:\n"
|
||||||
|
" 1 | 2 | 3 \n"
|
||||||
|
"-----------\n"
|
||||||
|
" 4 | 5 | 6 \n"
|
||||||
|
"-----------\n"
|
||||||
|
" 7 | 8 | 9 \n"
|
||||||
|
"\n当前棋盘:" + game.print_board()
|
||||||
|
)
|
||||||
|
yield event.plain_result(instructions)
|
||||||
|
|
||||||
|
@session_waiter(timeout=60, record_history_chains=False)
|
||||||
|
async def game_waiter(controller: SessionController, event: AstrMessageEvent):
|
||||||
|
nonlocal game
|
||||||
|
idiom = event.message_str # 用户发来的成语,假设是 "一马当先"
|
||||||
|
# 玩家回合
|
||||||
|
if game.current_player == game.player_symbol:
|
||||||
|
move = int(idiom) - 1
|
||||||
|
if not game.make_move(move):
|
||||||
|
await event.send(event.make_result(chain=[Comp.Plain("无效移动,请重试。")]))
|
||||||
|
controller.keep(timeout=60, reset_timeout=True)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
# 电脑回合
|
||||||
|
move = game.computer_move()
|
||||||
|
game.board[move] = game.current_player
|
||||||
|
|
||||||
|
# 检查游戏状态
|
||||||
|
winner = game.check_winner()
|
||||||
|
if winner:
|
||||||
|
result = event.make_result()
|
||||||
|
result.chain = [
|
||||||
|
Comp.Plain(f"{game.print_board()}\n"),
|
||||||
|
Comp.Plain("恭喜你赢了!" if winner == game.player_symbol else "电脑赢了!")
|
||||||
|
]
|
||||||
|
await event.send(result)
|
||||||
|
controller.stop()
|
||||||
|
return
|
||||||
|
|
||||||
|
if game.is_board_full():
|
||||||
|
result = event.make_result()
|
||||||
|
result.chain = [
|
||||||
|
Comp.Plain(f"{game.print_board()}\n"),
|
||||||
|
Comp.Plain("平局!")
|
||||||
|
]
|
||||||
|
await event.send(result)
|
||||||
|
controller.stop()
|
||||||
|
return
|
||||||
|
|
||||||
|
# 切换玩家并继续游戏
|
||||||
|
game.switch_player()
|
||||||
|
|
||||||
|
# 发送更新后的棋盘
|
||||||
|
result = event.make_result()
|
||||||
|
if game.current_player == game.player_symbol:
|
||||||
|
result.chain = [
|
||||||
|
Comp.Plain(f"{game.print_board()}\n"),
|
||||||
|
Comp.Plain("轮到你走了,请输入1-9:")
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
result.chain = [
|
||||||
|
Comp.Plain(f"{game.print_board()}\n"),
|
||||||
|
Comp.Plain("电脑思考中...")
|
||||||
|
]
|
||||||
|
await event.send(result)
|
||||||
|
|
||||||
|
# 重置超时时间
|
||||||
|
controller.keep(timeout=60, reset_timeout=True)
|
||||||
|
|
||||||
|
try:
|
||||||
|
await game_waiter(event)
|
||||||
|
except TimeoutError:
|
||||||
|
yield event.plain_result("井字棋游戏超时结束!")
|
||||||
|
except Exception as e:
|
||||||
|
yield event.plain_result(f"游戏出错: {str(e)}")
|
||||||
|
finally:
|
||||||
|
event.stop_event()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"井字棋游戏错误: {str(e)}")
|
||||||
|
yield event.plain_result("游戏发生错误,请稍后再试。")
|
||||||
|
|
||||||
|
@filter.command("帮我清理")
|
||||||
|
async def clean(self, event: AstrMessageEvent):
|
||||||
|
if isUserExist(event.get_sender_id()) != True:
|
||||||
|
insertUser(event.get_sender_id())
|
||||||
|
|
||||||
|
V = round(random.uniform(0.01,100), 2)
|
||||||
|
b = volume(V)
|
||||||
|
|
||||||
|
if V>=10:
|
||||||
|
yield event.plain_result(f"让我帮你好好清理一下哦~哧溜哧溜,嗯嗯,又射了{V}ml,{b}!")
|
||||||
|
else:
|
||||||
|
yield event.plain_result(f"让我帮你好好清理一下哦~哧溜哧溜,哎呀,全都清理干净啦,杂鱼杂鱼!")
|
Loading…
x
Reference in New Issue
Block a user