-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgenerategive.lua
42 lines (35 loc) · 1.47 KB
/
generategive.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
local command = {}
function command.run(message, mt)
print(message.author.name .. " did !generategive")
local cmember = message.guild:getMember(message.author)
if not cmember:hasRole(privatestuff.modroleid) then
message.channel:send("haha no, nice try")
return
end
if not (#mt == 2 or #mt == 3) then
message.channel:send("Sorry, but the c!generategive command expects 2 or 3 arguments. Please see c!help for more details.")
return
end
local uj2f = usernametojson(mt[1])
if not uj2f then
message.channel:send("Sorry, but I could not find a user named " .. mt[1] .. " in the database. Make sure that you have spelled it right, and that they have at least pulled a card to register!")
return
end
local uj2 = dpf.loadjson(uj2f, defaultjson)
local curfilename = texttofn(mt[2])
if not curfilename then
message.channel:send("Sorry, but I could not find the " .. mt[2] .. " card in the database. Make sure that you spelled it right!")
return
end
local numcards = 1
if tonumber(mt[3]) then
if tonumber(mt[3]) > 1 then numcards = math.floor(mt[3]) end
end
uj2.inventory[curfilename] = uj2.inventory[curfilename] and uj2.inventory[curfilename] + numcards or numcards
dpf.savejson(uj2f,uj2)
print("saved user2 json with new card")
message.channel:send {
content = 'You have given ' .. numcards .. ' **' .. cdb[curfilename].name .. '** card' .. (numcards == 1 and "" or "s") .. ' to <@' .. uj2.id .. '> .'
}
end
return command