-
Notifications
You must be signed in to change notification settings - Fork 10
/
module_mention.lua
66 lines (56 loc) · 1.47 KB
/
module_mention.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
-- Copyright (C) 2018 Jérôme Leclercq
-- This file is part of the "Not a Bot" application
-- For conditions of distribution and use, see copyright notice in LICENSE
local client = Client
local discordia = Discordia
local bot = Bot
local enums = discordia.enums
Module.Name = "mention"
function Module:GetConfigTable()
return {
{
Name = "Emoji",
Description = "Emoji to add as a reaction",
Type = bot.ConfigType.Emoji,
Default = "mention"
},
{
Name = "ReactOnEveryoneOrHere",
Description = "Reacts on everyone or here mention?",
Type = bot.ConfigType.Boolean,
Default = true
}
}
end
function Module:OnEnable(guild)
local config = self:GetConfig(guild)
local mentionEmoji = bot:GetEmojiData(guild, config.Emoji)
if (not mentionEmoji) then
return false, "Emoji \"" .. config.Emoji .. "\" not found (check your configuration)"
end
return true
end
function Module:OnMessageCreate(message)
if (not bot:IsPublicChannel(message.channel)) then
return
end
local mention = false
local config = self:GetConfig(message.guild)
if (message.mentionsEveryone and config.ReactOnEveryoneOrHere) then
mention = true
else
for _, user in pairs(message.mentionedUsers) do
if (user.id == client.user.id) then
mention = true
break
end
end
end
if (mention) then
local mentionEmoji = bot:GetEmojiData(message.guild, config.Emoji)
if (not mentionEmoji) then
return
end
message:addReaction(mentionEmoji.Emoji or mentionEmoji.Id)
end
end