This repository was archived by the owner on Jan 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbotinit.lua
More file actions
154 lines (138 loc) · 4.61 KB
/
Copy pathbotinit.lua
File metadata and controls
154 lines (138 loc) · 4.61 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
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
-- Initialization of functions and variables used by the other .lua files. --
local discordia = require("discordia")
local json = require("json")
local PRC = process.env
local getPRC = require("./botvars.lua") -- Loads our .ENV function in case the bot isn't ran through Heroku.
return function(ENV)
setfenv(1, ENV) -- Connects the main environment from botmain.lua into this file.
local self = {} -- init_table
self.commands = require("./botcmds.lua")(ENV) -- Loads in the commands into the table so that it can get loaded into the main environment later.
self.datastore = require("./botdata.lua")(ENV) -- Loads in the botdata module into the table.
self.client = discordia.Client()
self.prefix = PRC.PREFIX or getPRC("PREFIX") or ";"
self.adminsOnly = (PRC.ADMINS_ONLY or getPRC("ADMINS_ONLY")) == "true"
self.isInvisible = (PRC.INVISIBLE or getPRC("INVISIBLE")) == "true"
self.silentStartup = (PRC.SILENT_STARTUP or getPRC("SILENT_STARTUP")) == "true"
self.status = PRC.STATUS or getPRC("STATUS") or ""
self.main_channel = PRC.MAIN_CHANNEL or getPRC("MAIN_CHANNEL") or ""
self.dest_channel = PRC.DEST_CHANNEL or getPRC("DEST_CHANNEL") or ""
self.data_storage = PRC.DATA_CHANNEL or getPRC("DATA_CHANNEL") or ""
self.ownerOverride = PRC.OWNER_OVERRIDE or getPRC("OWNER_OVERRIDE") or "OWNER_ID"
local ran, returns = pcall(function() return json.decode(PRC.ADMINS or getPRC("ADMINS")) end)
self.admins = (ran == true and returns) or {}
-- Below are temporary until serverdata is fully developed. --
self.coalToRub = 8 -- PRC.CV_COAL
self.payType = 1 -- Add an option between [1] random (current), [2] percentages (amount worked), and [3] static (based on the goal amount)
-- Above are temporary until serverdata is fully developed. --
self.statusList = {}
self.coalOperation = function(serverId)
local data = dataCheck(serverId, "serverdata")
statusList[serverId] = {
reached = false,
workers = {},
coal = 0,
goal = math.random(data.mingoal, data.maxgoal)
}
end
self.sleep = function(n) -- In seconds
local t0 = os.clock()
while os.clock() - t0 <= n do end
return true -- For loops
end
self.waitForNextMessage = function(message)
local author = message.author.id
local channel = message.channel.id
local returned
repeat
local _, newmsg = client:waitFor("messageCreate")
if newmsg.author.id == author and newmsg.channel.id == channel then
returned = newmsg
end
until returned ~= nil
return returned
end
self.dataCheck = function(id, datatype)
local returns = datastore.Cache[id]
if returns ~= nil then
return returns
elseif datatype ~= nil then
return datastore:Save(id, {}, datatype)
else
print("[WARN] Attempt to data-check a new ID without providing a datatype!")
return false
end
end
self.getLevel = function(message)
local userId = message.author.id
local level = 1
for _, id in pairs(admins) do
if userId == id then
level = 3 -- Usually 2 (3 is operator-level)
end
end
if message.member:getPermissions():has("administrator", "manageGuild", "manageChannels") then
level = 2
end
if userId == owner then
level = 3
end
return level
end
self.isCoalMine = function(message)
local data = dataCheck(message.guild.id, "serverdata")
if message.channel.id == data.coalmine then
return true
elseif data.coalmine ~= "" then
message:reply("Invalid channel! Go-to: <#".. tostring(data.coalmine) ..">.")
message:addReaction("❌")
return false
else
message:reply("No coalmine channel has been set on this server yet!")
message:addReaction("❌")
return false
end
end
self.getBalance = function(userId)
local data = dataCheck(userId, "userdata")
if data ~= nil then
return data.balance
else
return 0
end
end
self.addBalance = function(userId, amount)
local data = dataCheck(userId, "userdata")
datastore:Save(userId, {balance = data.balance + amount})
end
self.getCoal = function(message)
local data = statusList[message.guild.id]
if data ~= nil then
local worker = data.workers[message.author.id]
if worker ~= nil then
return worker.mined
else
return 0
end
else
print("[WARN] Attempt to GET coal value from a non-initalized server!")
return 0
end
end
self.addCoal = function(message, amount)
local data = statusList[message.guild.id]
if data ~= nil then
local worker = data.workers[message.author.id]
if worker ~= nil then
worker.mined = worker.mined + amount
else
data.workers[message.author.id] = {
mined = amount,
paid = false
}
end
else
print("[WARN] Attempt to ADD coal value from a non-initalized server!")
end
end
return self
end;