-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTAROT.lua
162 lines (140 loc) · 4.59 KB
/
TAROT.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
local log = require("log")
local Api = require("coreApi")
local json = require("json")
local http = require("http")
local tarot = {
[0] = "愚者(The Fool,0)" ,
[1] = "魔术师(The Magician,I)" ,
[2] = "女祭司(The High Priestess,II)" ,
[3] = "女皇(The Empress,III)" ,
[4] = "皇帝(The Emperor,IV)" ,
[5] = "教皇(The Hierophant,or the Pope,V)" ,
[6] = "恋人(The Lovers,VI)" ,
[7] = "战车(The Chariot,VII)" ,
[8] = "力量(Strength,VIII)" ,
[9] = "隐者(The Hermit,IX)" ,
[10] = "命运之轮(The Wheel of Fortune,X)" ,
[11] = "正义(Justice,XI)" ,
[12] = "倒吊人(The Hanged Man,XII)" ,
[13] = "死神(Death,XIII)" ,
[14] = "节制(Temperance,XIV)" ,
[15] = "恶魔(The Devil ,XV)" ,
[16] = "塔(The Tower,XVI)" ,
[17] = "星星(The Star,XVII)" ,
[18] = "月亮(The Moon,XVIII)" ,
[19] = "太阳(The Sun,XIX)" ,
[20] = "审判(Judgement,XX)" ,
[21] = "世界(The World,XXI)"
}
local inverse = {"正" , "逆" }
function ReceiveFriendMsg(CurrentQQ, data)
if string.find(data.Content, "塔罗牌") == 1 and data.Content:gsub("塔罗牌", "")=="" then
Send_friendmsg(CurrentQQ, data,"正在虔诚洗牌...")
shuffle(tarot)
os.execute("sleep " .. 3)
result1,result2,result3= getrandomint(21)
result1 = tarot[result1]
result2 = tarot[result2]
result3 = tarot[result3]
math.randomseed(os.time()+assert(tonumber(tostring({}):sub(7))))
inverse1 = inverse[math.random(1 , 2)]
inverse2 = inverse[math.random(1 , 2)]
inverse3 = inverse[math.random(1 , 2)]
Send_friendmsg(CurrentQQ, data,"你抽出了\n"..
inverse1.."位 "..result1.."\n"..
inverse2.."位 "..result2.."\n"..
inverse3.."位 "..result3)
end
return 1
end
function ReceiveGroupMsg(CurrentQQ, data)
if string.find(data.Content, "塔罗牌") == 1 then
Send_msg(CurrentQQ, data,"正在虔诚洗牌...")
shuffle(tarot)
os.execute("sleep " .. 3)
result1,result2,result3= getrandomint(21)
result1 = tarot[result1]
result2 = tarot[result2]
result3 = tarot[result3]
--print(result1.."\n")
--print(result2.."\n")
--print(result3.."\n")
math.randomseed(os.time()+assert(tonumber(tostring({}):sub(7))))
inverse1 = inverse[math.random(1 , 2)]
inverse2 = inverse[math.random(1 , 2)]
inverse3 = inverse[math.random(1 , 2)]
Send_msg(CurrentQQ, data,"你抽出了\n"..
inverse1.."位 "..result1.."\n"..
inverse2.."位 "..result2.."\n"..
inverse3.."位 "..result3)
end
return 1
end
function shuffle(t)
local randomnum = 0
local temp = ""
math.randomseed(os.time()+assert(tonumber(tostring({}):sub(7))))
for i=#t,1,-1 do
randomnum = math.random(0 , i-1)
--print(randomnum.."-rand\n")
temp = t[randomnum]
t[randomnum] = t[i]
t[i] = temp
end
randomnum = nil
temp = nil
return t
end
function getrandomint(n)
local bodytable = {
jsonrpc= "2.0",
method= "generateIntegers",
params= {
apiKey= "aaaa-bbb-ccccc", ---需要自己申请 apikey https://api.random.org/dashboard/details
n= 3,
min= 0,
max= n,
replacement= false,
base= 10
},
id=math.random(1 , n)
}
response, error_message = http.request
(
"POST",
"https://api.random.org/json-rpc/2/invoke",
{
query = "",
headers = {["Content-Type"] = "application/json"},
body = json.encode( bodytable)
}
)
local html = response.body
local res=json.decode(html)
return res.result.random.data[1],res.result.random.data[2],res.result.random.data[3]
end
function Send_msg(CurrentQQ, data,resultstr)
Api.Api_SendMsg( -- 调用发消息的接口
CurrentQQ, {
toUser = data.FromGroupId, -- 回复当前消息的来源群ID
sendToType = 2, -- 2发送给群1发送给好友3私聊
sendMsgType = "TextMsg", -- 进行文本复读回复
groupid = 0, -- 不是私聊自然就为0咯
content = resultstr, -- 回复内容
atUser = data.FromUserId -- 是否 填上data.FromUserId就可以复读给他并@了
})
end
function Send_friendmsg(CurrentQQ, data,resultstr)
luaMsg =
Api.Api_SendMsg(--调用发消息的接口
CurrentQQ,
{
toUser = data.FromUin, --回复当前消息的来源群ID
sendToType = 1, --2发送给群1发送给好友3私聊
sendMsgType = "TextMsg", --进行文本复读回复
groupid = 0, --不是私聊自然就为0咯
content = resultstr, --回复内容
}
)
end
function ReceiveEvents(CurrentQQ, data, extData) return 1 end