-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheightball.lua
More file actions
88 lines (80 loc) · 2.75 KB
/
Copy patheightball.lua
File metadata and controls
88 lines (80 loc) · 2.75 KB
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
#!/usr/bin/env lua
--[[ shake-the-eightball addon for Hexchat
author: Moses Moore <moc.iazom@sesom>
date: 2018-09-08
config settings:
TRIGGER: what to listen for
matches start of string up to first whitespace
TIMEOUT: seconds between responses, per-channel
CHANNELS: which channels to listen for the command;
special channel name '*' means "listen on all channels"
ANSWERS: from the classic toy by Mattel; 10 yes, 5 no, 5 neutral
NAMES: what to call myself i.e. "The Obsidian Oracle," "Vriska's fetish"
]]
--[[ CONFIG ]]
local TRIGGER = "!8ball"
local TIMEOUT = 15
local CHANNELS = {"#farts", "#wetfish", "#test", "#botspam"}
local ANSWERS = {
'It is decidedly so', 'You may rely on it', 'Outlook good',
'Yes definitely', 'Signs point to yes', 'Most likely',
'Without a doubt', 'Yes', 'As I see it yes', 'It is certain',
'Very doubtful', 'Outlook not so good', 'My sources say no',
'Dont count on it', 'My reply is no', 'Better not tell you now',
'Concentrate and ask again', 'Reply hazy try again',
'Cannot predict now', 'Ask again later'
}
local NAMES = {
'magic Eight-ball\u{2122}', '8ball', 'eightball', '\u{277d}'
}
--[[ INIT ]]
local LASTBLEAT = { }
for _, i in pairs(CHANNELS) do LASTBLEAT[i] = 0 end
--[[ 31607 is the largest prime <= sqrt(1e7) ]]
math.randomseed((os.time() + (os.clock() * 1e6)) % 31607)
local function random_choice(intable)
local i, choice = 1, nil
for k, _ in pairs(intable) do
if math.random(i) == 1 then choice = k end
i = i + 1
end
return intable[choice]
end
local function eightball_answer()
return "The " .. random_choice(NAMES) .. " says: "
.. "\x02" .. random_choice(ANSWERS) .. "\x02"
end
local function cmd_8ball(word, eol)
print(eightball_answer())
end
local function msg_8ball(word, eol)
local chan = hexchat.get_info("channel")
if not (LASTBLEAT[chan] or LASTBLEAT['*']) then
return hexchat.EAT_NONE
end
local cmd = word[2]:match("^%s*(%S*)")
if not (cmd == TRIGGER) then
return hexchat.EAT_NONE
end
if os.difftime(os.time(), LASTBLEAT[chan]) > TIMEOUT then
LASTBLEAT[chan] = os.time()
hexchat.command("say " .. eightball_answer())
else
print("... staying quiet because " .. chan .. " timeout hasn't expired")
end
return hexchat.EAT_PLUGIN
end
--[[ MAIN ]]
if hexchat then
hexchat.register(
"eightball.lua",
"20180909",
"shake the eightball (/8ball, " .. TRIGGER .. ")"
)
hexchat.hook_print("Channel Message", msg_8ball)
hexchat.hook_print("Your Message", msg_8ball)
hexchat.hook_command("8BALL", cmd_8ball)
print("8ball.lua : /8ball or " .. TRIGGER .. " in configured channels")
else
cmd_8ball(nil, nil)
end