【发布时间】:2022-01-17 22:27:40
【问题描述】:
这是我的机器人,在游戏聊天中复制表情符号。
它复制的微笑保存在名为“表情”的表格中。如果有人写“:)”,机器人会写“:)”等等
循环内的代码是这样的:如果有人写,例如,>:)”,你必须复制脚本“>:)”,而不仅仅是“:)”
CreateFrame、RegisterEvent、SetScript 和 SendChatMessage 是游戏内置的 Lua API
local emoticons = {
":)", "(:", ":))", ">:)", "0:)", ":D", ":]", ":)))", "=]", "?_?", "+.+", ":P", ":3", "^^", "roar", ":V", "D:", ":C", ".D", ".)", "o_o",
"^-^", ":PPP", ":DDD", ":D:D:D", ":DDDD", ":D:D:D:D", ":DDDDD", ":d", ":L", "<O>_<O>", "o/", "+_+", "?_?", "*0*", ":}", ";)", ":))))", "o.o", "<.<''", ":|",
":-)", "^^^^", ":D:D:D:D:D:D", ":D :D :D", "^^^", ":c", ";]", ":9", ">:|", ">.<", ";3", ";P", "T_T", ":3c", ":)))))",
"^^^^^" }
local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_GUILD")
f:SetScript("OnEvent", function(self, event, text, playerName, _, channelName, playerName2, _, _, channelIndex)
local msg
local n = 0
for x, key in ipairs(emoticons) do
local l = string.len(emoticons[x])
if (string.sub(text, -l) == emoticons[x]) then
if (l > n) then
msg = emoticons[x]
n = l
end
end
end
if (msg) and (playerName ~= UnitName("player")) then
if (event == "CHAT_MSG_GUILD") then SendChatMessage(msg, "GUILD", nil, channelIndex) end
end
end)
有什么办法可以改善吗?例如,如果有人写
“^^^^^^”
机器人复制
“^^^^^”
这将与存储在表中的“^”少一个相同
我的目标是,如果有人写,例如“^^^^^^”,并且没有在表格中注册,脚本将不会响应
【问题讨论】:
-
还有为什么你有 ":D :D :D" ?简单地回应三个单曲似乎没有区别:D。这无缘无故地使事情复杂化
-
如何处理消息中的多个表情符号?你似乎回应了最后一场比赛
标签: string lua string-matching