@@ -23,25 +23,21 @@ local consoleCommands = {
23
23
" Syntax: sw_tags add <identifier> <tag> <color> <name_color> <msg_color> <scoreboard (0/1)>" )
24
24
end
25
25
26
-
27
- local addRowQuery =
28
- " INSERT INTO @tablename VALUES ('@identifier', '@tag', '@color', '@name_color', '@msg_color', @scoreboard)"
29
- local addRowParams = {
30
- [" tablename" ] = config :Fetch (" tags.database.tablesname.tags" ),
31
- [" identifier" ] = identifier ,
32
- [" tag" ] = tag ,
33
- [" color" ] = color ,
34
- [" name_color" ] = name_color ,
35
- [" msg_color" ] = msg_color ,
36
- [" scoreboard" ] = scoreboard
37
- }
38
-
39
- db :QueryParams (addRowQuery , addRowParams , function (err , result )
26
+ db :QueryBuilder ():Table (tostring (config :Fetch (" tags.database.tablesname.tags" ) or " sw_tags" )):Insert (
27
+ {
28
+ identifier = identifier ,
29
+ tag = tag ,
30
+ color = color ,
31
+ name_color = name_color ,
32
+ msg_color = msg_color ,
33
+ scoreboard = scoreboard
34
+ }
35
+ ):Execute (function (err , result )
40
36
if # err > 0 then
41
37
return print (" {DARKRED} ERROR: {DEFAULT}" .. err )
42
38
end
43
39
ReplyToCommand (playerid , config :Fetch (" tags.prefix" ), FetchTranslation (" tags.added" ):gsub (" {ID}" , identifier ))
44
- ReloadTags ()
40
+ ReloadTags ()
45
41
end )
46
42
end ,
47
43
@@ -58,19 +54,13 @@ local consoleCommands = {
58
54
FetchTranslation (" tags.not_exists" ):gsub (" {ID}" , identifier ))
59
55
end
60
56
61
- local removeRowQuery = " DELETE FROM @tablename WHERE identifier = '@identifier' LIMIT 1;"
62
- local removeRowParams = {
63
- [" tablename" ] = config :Fetch (" tags.database.tablesname.tags" ),
64
- [" identifier" ] = identifier
65
- }
66
-
67
- db :QueryParams (removeRowQuery , removeRowParams , function (err , result )
57
+ db :QueryBuilder ():Table (tostring (config :Fetch (" tags.database.tablesname.tags" ) or " sw_tags" )):Delete ():Where (' identifier' , ' =' , identifier ):Execute (function (err , result )
68
58
if # err > 0 then
69
59
return print (" {DARKRED} ERROR: {DEFAULT}" .. err )
70
60
end
71
61
ReplyToCommand (playerid , config :Fetch (" tags.prefix" ),
72
62
FetchTranslation (" tags.removed" ):gsub (" {ID}" , identifier ))
73
- ReloadTags ()
63
+ ReloadTags ()
74
64
end )
75
65
end ,
76
66
@@ -89,28 +79,39 @@ local consoleCommands = {
89
79
90
80
local option = args [3 ]
91
81
92
- if option = = " tag" and option ~= " color" and option ~= " name_color" and option ~= " msg_color" and option ~= " scoreboard" then
82
+ if option ~ = " tag" and option ~= " color" and option ~= " name_color" and option ~= " msg_color" and option ~= " scoreboard" then
93
83
return ReplyToCommand (playerid , config :Fetch (" tags.prefix" ),
94
84
" Syntax: sw_tags edit <identifier> <tag/color/name_color/msg_color/scoreboard> <value>)" )
95
85
end
96
86
local value = args [4 ]
97
87
88
+ local qb = db :QueryBuilder ():Table (tostring (config :Fetch (" tags.database.tablesname.tags" ) or " sw_tags" )):Where (' identifier' , ' =' , identifier )
98
89
99
- local updateRowQuery = " UPDATE @tablename SET @option = '@value' WHERE identifier = '@identifier'" ;
100
- local updateRowParams = {
101
- [" tablename" ] = config :Fetch (" tags.database.tablesname.tags" ),
102
- [" option" ] = option ,
103
- [" value" ] = value ,
104
- [" identifier" ] = identifier
105
- }
90
+ switch (option , {
91
+ [" tag" ] = function ()
92
+ qb :Update ({tag = value })
93
+ end ,
94
+ [" color" ] = function ()
95
+ qb :Update ({color = value })
96
+ end ,
97
+ [" name_color" ] = function ()
98
+ qb :Update ({name_color = value })
99
+ end ,
100
+ [" msg_color" ] = function ()
101
+ qb :Update ({msg_color = value })
102
+ end ,
103
+ [" scoreboard" ] = function ()
104
+ qb :Update ({scoreboard = value })
105
+ end ,
106
+ })
106
107
107
- db : QueryParams ( updateRowQuery , updateRowParams , function (err , result )
108
+ qb : Execute ( function (err , result )
108
109
if # err > 0 then
109
110
return print (" {DARKRED} ERROR: {DEFAULT}" .. err )
110
111
end
111
112
ReplyToCommand (playerid , config :Fetch (" tags.prefix" ),
112
113
FetchTranslation (" tags.updated" ):gsub (" {ID}" , identifier ))
113
- ReloadTags ()
114
+ ReloadTags ()
114
115
end )
115
116
end ,
116
117
@@ -194,7 +195,6 @@ local playerCommands = {
194
195
end
195
196
}
196
197
197
-
198
198
commands :Register (" tags" , function (playerid , args , argc , silent , prefix )
199
199
if playerid < 0 then
200
200
if argc < 1 then
0 commit comments