forked from DigitalPulseSoftware/NotaBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_game.lua
54 lines (46 loc) · 1.02 KB
/
module_game.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
-- 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 bot = Bot
local client = Client
local discordia = Discordia
Module.Name = "game"
Module.Global = true
function Module:GetConfigTable()
return {
{
Array = true,
Global = true,
Name = "GameList",
Description = "List of games",
Type = bot.ConfigType.String,
Default = {},
Sensitive = true
},
}
end
function Module:OnLoaded()
self.Clock = discordia.Clock()
self.Counter = 0
self.Clock:on("min", function ()
self.Counter = self.Counter + 1
if (self.Counter >= 3) then
self:UpdateGame()
self.Counter = 0
end
end)
self.Clock:start()
self:UpdateGame()
return true
end
function Module:OnUnload()
self.Clock:stop()
end
function Module:UpdateGame()
local games = self.GlobalConfig.GameList
local newGame = games[math.random(1, #games)]
if (type(newGame) == "function") then
newGame = newGame()
end
client:setGame(newGame)
end