File tree 2 files changed +65
-0
lines changed
2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ func init() {
56
56
RootCmd .AddCommand (commands .UpdateStripePriceId )
57
57
RootCmd .AddCommand (commands .ClanRecalculateCommand )
58
58
RootCmd .AddCommand (commands .RemoveUnrankedClanScores )
59
+ RootCmd .AddCommand (commands .BadgePlayerGiveCmd )
59
60
60
61
// Migrations
61
62
RootCmd .AddCommand (migrations .MigrationPlaylistMapsetCmd )
Original file line number Diff line number Diff line change
1
+ package commands
2
+
3
+ import (
4
+ "github.com/Quaver/api2/db"
5
+ "github.com/sirupsen/logrus"
6
+ "github.com/spf13/cobra"
7
+ "strconv"
8
+ )
9
+
10
+ var BadgePlayerGiveCmd = & cobra.Command {
11
+ Use : "badge:player:give" ,
12
+ Short : "Gives a player a badge" ,
13
+ Run : func (cmd * cobra.Command , args []string ) {
14
+ if len (args ) < 2 {
15
+ logrus .Error ("You must provide a badge id and a player id" )
16
+ return
17
+ }
18
+
19
+ badgeId , err := strconv .Atoi (args [0 ])
20
+
21
+ if err != nil {
22
+ logrus .Error (err )
23
+ return
24
+ }
25
+
26
+ playerId , err := strconv .Atoi (args [1 ])
27
+
28
+ if err != nil {
29
+ logrus .Error (err )
30
+ return
31
+ }
32
+
33
+ _ , err = db .GetUserById (playerId )
34
+
35
+ if err != nil {
36
+ logrus .Error ("Error retrieving player: " , err )
37
+ return
38
+ }
39
+
40
+ hasBadge , err := db .UserHasBadge (playerId , badgeId )
41
+
42
+ if err != nil {
43
+ logrus .Error ("Error checking user has badge: " , err )
44
+ return
45
+ }
46
+
47
+ if hasBadge {
48
+ logrus .Info ("User already has badge" )
49
+ return
50
+ }
51
+
52
+ badge := & db.UserBadge {
53
+ UserId : playerId ,
54
+ BadgeId : badgeId ,
55
+ }
56
+
57
+ if err := badge .Insert (); err != nil {
58
+ logrus .Error ("Error inserting badge: " , err )
59
+ return
60
+ }
61
+
62
+ logrus .Info ("Done!" )
63
+ },
64
+ }
You can’t perform that action at this time.
0 commit comments