1
1
import { CacheType , ChatInputCommandInteraction , Interaction , User } from "discord.js" ;
2
- import { Flags } from "../interface/model.interface" ;
2
+ import { Contest , Flags } from "../interface/model.interface" ;
3
3
import FlagModel from "../model/flag.model" ;
4
4
import scoreModel from "../model/score.model" ;
5
5
import playerModel from "../model/player.model" ;
@@ -17,10 +17,13 @@ export const saveFlag = async (
17
17
mode : Boolean | null ,
18
18
url : String | null ,
19
19
category : String | null ,
20
+ status : String | null ,
21
+ publicMode : Boolean | null ,
22
+ password : String | null ,
20
23
interaction : ChatInputCommandInteraction < CacheType > ) =>
21
24
{
22
25
try {
23
- const newFlag = new FlagModel ( { idChall, nameAuthor, nameChall, point, level, description, flag, mode, url, category } ) ;
26
+ const newFlag = new FlagModel ( { idChall, nameAuthor, nameChall, point, level, description, flag, mode, url, category, status , public : publicMode , password , createdBy : interaction . user . id } ) ;
24
27
await newFlag . save ( ) ;
25
28
await interaction . reply ( "Thêm thành công!" ) ;
26
29
} catch ( error ) {
@@ -55,41 +58,48 @@ export const checkFlag = async (flag: String | null, players: User, interaction:
55
58
}
56
59
57
60
58
- export const getAllChallenge = async ( admin : Boolean , category : String | null , idContest : String | null , interaction : ChatInputCommandInteraction < CacheType > ) => {
61
+ export const getAllChallenge = async ( admin : Boolean , category : String | null , idContest : String | null , password : String | null , interaction : ChatInputCommandInteraction < CacheType > ) => {
62
+ let contest : Contest | null = null ;
63
+ if ( idContest != null ) {
64
+ contest = await contestModel . findOne ( { idContest : idContest } ) ;
65
+ if ( contest == null ) {
66
+ return await interaction . reply ( "Không tìm thấy contest này!" ) ;
67
+ }
59
68
60
- const contest = await contestModel . findOne ( { idContest : idContest } ) ;
69
+ // Testing
70
+ const checkUser = contest . teams . find ( team => team . team . members . find ( member => member . idUser == interaction . user . id ) ) ;
71
+ if ( ! checkUser ) {
72
+ return await interaction . reply ( "Bạn không tham gia contest này!" ) ;
73
+ }
74
+ }
61
75
62
- if ( contest == null ) {
63
- await interaction . reply ( "Không tìm thấy contest này!" ) ;
64
- } else {
65
- let challenges : Array < Flags > = [ ] ;
66
- challenges = await FlagModel . find ( {
67
- mode : ! admin ,
68
- category : category ?? { $regex : / .* / } ,
69
- idContest : idContest
70
- } , "idChall nameAuthor nameChall point level description mode url category" ) ;
76
+ let challenges : Array < Flags > = [ ] ;
77
+ challenges = await FlagModel . find ( {
78
+ mode : ! admin ,
79
+ category : category ?? { $regex : / .* / } ,
80
+ idContest : idContest
81
+ } , "idChall nameAuthor nameChall point level description mode url category" ) ;
71
82
72
- if ( challenges . length == 0 ) {
73
- await interaction . reply ( `Các challenge của contest ***${ contest . nameContest } *** chưa được cập nhập hoặc public!` ) ;
74
- }
75
- else {
76
- let infoChallenges = "" ;
77
- challenges . map ( ( challenge : Flags , index : number ) => {
78
- infoChallenges += `${ index + 1 } . ***Tên thử thách:*** ` + challenge . nameChall +
79
- "***\n\tID:*** " + challenge . idChall +
80
- "***\n\tTác giả:*** " + challenge . nameAuthor +
81
- "***\n\tLoại:*** " + challenge . category +
82
- "***\n\tMô tả:*** " + challenge . description +
83
- "***\n\tĐiểm:*** " + challenge . point +
84
- "***\n\tĐộ khó:*** " + challenge . level +
85
- "***\n\tLink thử thách:*** " + challenge . url + "\n" ;
86
- if ( admin ) {
87
- infoChallenges += "***\n\tTrạng thái:*** " + ( challenge . mode ? "Public" : "Private" ) + "***\tID Challenge:*** " + challenge . idChall + "\n" + "***\n\tID Contest:*** " + challenge . idContest ?? "Không" + "\n" ;
88
- }
89
- } ) ;
90
- const embed = createEmbed ( "Danh sách thử thách" + ( category ? ` thuộc loại ${ category } ` : "" ) , infoChallenges ) ;
91
- await interaction . reply ( { embeds : [ embed ] } ) ;
92
- }
83
+ if ( challenges . length == 0 && contest != null ) {
84
+ await interaction . reply ( `Các challenge của contest ***${ contest . nameContest } *** chưa được cập nhập hoặc public!` ) ;
85
+ }
86
+ else {
87
+ let infoChallenges = "" ;
88
+ challenges . map ( ( challenge : Flags , index : number ) => {
89
+ infoChallenges += `${ index + 1 } . ***Tên thử thách:*** ` + challenge . nameChall +
90
+ "***\n\tID:*** " + challenge . idChall +
91
+ "***\n\tTác giả:*** " + challenge . nameAuthor +
92
+ "***\n\tLoại:*** " + challenge . category +
93
+ "***\n\tMô tả:*** " + challenge . description +
94
+ "***\n\tĐiểm:*** " + challenge . point +
95
+ "***\n\tĐộ khó:*** " + challenge . level +
96
+ "***\n\tLink thử thách:*** " + challenge . url + "\n" ;
97
+ if ( admin ) {
98
+ infoChallenges += "***\n\tTrạng thái:*** " + ( challenge . mode ? "Public" : "Private" ) + "***\tID Challenge:*** " + challenge . idChall + "\n" + "***\n\tID Contest:*** " + challenge . idContest ?? "Không" + "\n" ;
99
+ }
100
+ } ) ;
101
+ const embed = createEmbed ( "Danh sách thử thách" + ( category ? ` thuộc loại ${ category } ` : "" ) , infoChallenges ) ;
102
+ await interaction . reply ( { embeds : [ embed ] } ) ;
93
103
}
94
104
}
95
105
0 commit comments