@@ -4,48 +4,63 @@ use diesel::prelude::*;
44
55/// Remove a key value pair from the tags.
66pub fn delete ( args : Args ) -> Result < ( ) , Error > {
7- if api:: is_wg_and_teams ( & args) ? {
8- let conn = DB . get ( ) ?;
9- let key = args
10- . params
11- . get ( "key" )
12- . ok_or ( "Unable to retrieve param: key" ) ?;
13-
14- match diesel:: delete ( tags:: table. filter ( tags:: key. eq ( key) ) ) . execute ( & conn) {
15- Ok ( _) => args. msg . react ( args. cx , "✅" ) ?,
16- Err ( _) => api:: send_reply ( & args, "A database error occurred when deleting the tag." ) ?,
17- }
7+ let conn = DB . get ( ) ?;
8+ let key = args
9+ . params
10+ . get ( "key" )
11+ . ok_or ( "Unable to retrieve param: key" ) ?;
12+
13+ match diesel:: delete ( tags:: table. filter ( tags:: key. eq ( key) ) ) . execute ( & conn) {
14+ Ok ( _) => args. msg . react ( args. cx , "✅" ) ?,
15+ Err ( _) => api:: send_reply ( & args, "A database error occurred when deleting the tag." ) ?,
1816 }
1917 Ok ( ( ) )
2018}
2119
2220/// Add a key value pair to the tags.
2321pub fn post ( args : Args ) -> Result < ( ) , Error > {
24- if api:: is_wg_and_teams ( & args) ? {
25- let conn = DB . get ( ) ?;
26-
27- let key = args
28- . params
29- . get ( "key" )
30- . ok_or ( "Unable to retrieve param: key" ) ?;
31-
32- let value = args
33- . params
34- . get ( "value" )
35- . ok_or ( "Unable to retrieve param: value" ) ?;
36-
37- match diesel:: insert_into ( tags:: table)
38- . values ( ( tags:: key. eq ( key) , tags:: value. eq ( value) ) )
39- . execute ( & conn)
40- {
41- Ok ( _) => args. msg . react ( args. cx , "✅" ) ?,
42- Err ( _) => api:: send_reply ( & args, "A database error occurred when creating the tag." ) ?,
43- }
44- } else {
45- api:: send_reply (
46- & args,
47- "Please reach out to a Rust team/WG member to create a tag." ,
48- ) ?;
22+ let conn = DB . get ( ) ?;
23+
24+ let key = args
25+ . params
26+ . get ( "key" )
27+ . ok_or ( "Unable to retrieve param: key" ) ?;
28+
29+ let value = args
30+ . params
31+ . get ( "value" )
32+ . ok_or ( "Unable to retrieve param: value" ) ?;
33+
34+ match diesel:: insert_into ( tags:: table)
35+ . values ( ( tags:: key. eq ( key) , tags:: value. eq ( value) ) )
36+ . execute ( & conn)
37+ {
38+ Ok ( _) => args. msg . react ( args. cx , "✅" ) ?,
39+ Err ( _) => api:: send_reply ( & args, "A database error occurred when creating the tag." ) ?,
40+ }
41+ Ok ( ( ) )
42+ }
43+
44+ /// Update an existing tag.
45+ pub fn update ( args : Args ) -> Result < ( ) , Error > {
46+ let conn = DB . get ( ) ?;
47+
48+ let key = args
49+ . params
50+ . get ( "key" )
51+ . ok_or ( "Unable to retrieve param: key" ) ?;
52+
53+ let value = args
54+ . params
55+ . get ( "value" )
56+ . ok_or ( "Unable to retrieve param: value" ) ?;
57+
58+ match diesel:: update ( tags:: table. filter ( tags:: key. eq ( key) ) )
59+ . set ( tags:: value. eq ( value) )
60+ . execute ( & conn)
61+ {
62+ Ok ( _) => args. msg . react ( args. cx , "✅" ) ?,
63+ Err ( _) => api:: send_reply ( & args, "A database error occurred when updating the tag." ) ?,
4964 }
5065
5166 Ok ( ( ) )
@@ -97,6 +112,7 @@ pub fn get_all(args: Args) -> Result<(), Error> {
97112pub fn help ( args : Args ) -> Result < ( ) , Error > {
98113 let help_string = "```
99114?tags create {key} value... Create a tag. Limited to WG & Teams.
115+ ?tags update {key} value... Update a tag. Limited to WG & Teams.
100116?tags delete {key} Delete a tag. Limited to WG & Teams.
101117?tags help This menu.
102118?tags Get all the tags.
0 commit comments