]>
jfr.im git - irc/rizon/acid.git/blob - vizon/src/main/java/net/rizon/acid/plugins/vizon/commands/CheckCommand.java
ff9b091e5add73ae11b46fb4ce0ad0048c0937bd
2 * Copyright (c) 2017, orillion <orillion@rizon.net>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
26 package net
.rizon
.acid
.plugins
.vizon
.commands
;
28 import java
.time
.LocalDateTime
;
29 import java
.util
.Collections
;
30 import java
.util
.List
;
31 import net
.rizon
.acid
.core
.AcidUser
;
32 import net
.rizon
.acid
.core
.Acidictive
;
33 import net
.rizon
.acid
.core
.Channel
;
34 import net
.rizon
.acid
.core
.Command
;
35 import net
.rizon
.acid
.core
.User
;
36 import net
.rizon
.acid
.plugins
.vizon
.Vizon
;
37 import net
.rizon
.acid
.plugins
.vizon
.VizonBet
;
38 import net
.rizon
.acid
.plugins
.vizon
.db
.VizonDrawing
;
39 import net
.rizon
.acid
.plugins
.vizon
.db
.VizonUser
;
43 * @author orillion <orillion@rizon.net>
45 public class CheckCommand
extends Command
53 public void Run(User source
, AcidUser to
, Channel c
, String
[] args
)
55 if (!source
.hasMode("r"))
57 // User has not identified to NickServ.
58 Acidictive
.reply(source
, to
, c
, "You need to register your nickname before you can use this command");
66 drawingId
= Integer
.parseInt(args
[0]);
68 catch (NumberFormatException e
)
70 Acidictive
.reply(source
, to
, c
, "Please specify the number of the drawing you wish to check");
74 VizonDrawing drawing
= Vizon
.getVizonDatabase().getDrawingById(drawingId
);
78 Acidictive
.reply(source
, to
, c
, String
.format("Drawing with id %d does not exist", drawingId
));
82 VizonUser user
= Vizon
.getVizonDatabase().findOrCreateUser(source
.getNick());
86 // Should not happen, but just in case.
87 Acidictive
.reply(source
, to
, c
, "Unable to find your name in the database");
91 VizonBet bet
= Vizon
.getVizonDatabase().findBetForUserAndDrawing(user
, drawing
);
93 if (drawing
.getDate().isAfter(LocalDateTime
.now()))
97 Acidictive
.reply(source
, to
, c
, String
.format(
98 "Drawing No.%d did not happen yet!",
103 Acidictive
.reply(source
, to
, c
, String
.format(
104 "Drawing No.%d did not happen yet! Your bet is: %d %d %d %d %d %d",
106 bet
.getBet().getFirst(),
107 bet
.getBet().getSecond(),
108 bet
.getBet().getThird(),
109 bet
.getBet().getFourth(),
110 bet
.getBet().getFifth(),
111 bet
.getBet().getSixth()));
117 List
<Integer
> bets
= drawing
.getDraws();
118 Collections
.sort(bets
);
122 Acidictive
.reply(source
, to
, c
, String
.format(
123 "The result of VIzon No.%d was: %d %d %d %d %d %d, you did not place a bet for this drawing",
134 // @TODO: Figure out how to recover Grand Prize info, perhaps
135 // store in the database or something.
136 int correct
= drawing
.checkCorrect(bet
.getBet());
141 Acidictive
.reply(source
, to
, c
, String
.format(
142 "The result of VIzon No.%d was: %d %d %d %d %d %d, you won first prize for this drawing! Your bet was: %d %d %d %d %d %d",
150 bet
.getBet().getFirst(),
151 bet
.getBet().getSecond(),
152 bet
.getBet().getThird(),
153 bet
.getBet().getFourth(),
154 bet
.getBet().getFifth(),
155 bet
.getBet().getSixth()));
158 Acidictive
.reply(source
, to
, c
, String
.format(
159 "The result of VIzon No.%d was: %d %d %d %d %d %d, you won second prize for this drawing! Your bet was: %d %d %d %d %d %d",
167 bet
.getBet().getFirst(),
168 bet
.getBet().getSecond(),
169 bet
.getBet().getThird(),
170 bet
.getBet().getFourth(),
171 bet
.getBet().getFifth(),
172 bet
.getBet().getSixth()));
175 Acidictive
.reply(source
, to
, c
, String
.format(
176 "The result of VIzon No.%d was: %d %d %d %d %d %d, you won third prize for this drawing! Your bet was: %d %d %d %d %d %d",
184 bet
.getBet().getFirst(),
185 bet
.getBet().getSecond(),
186 bet
.getBet().getThird(),
187 bet
.getBet().getFourth(),
188 bet
.getBet().getFifth(),
189 bet
.getBet().getSixth()));
192 Acidictive
.reply(source
, to
, c
, String
.format(
193 "The result of VIzon No.%d was: %d %d %d %d %d %d, you won the consolation prize for this drawing! Your bet was: %d %d %d %d %d %d",
201 bet
.getBet().getFirst(),
202 bet
.getBet().getSecond(),
203 bet
.getBet().getThird(),
204 bet
.getBet().getFourth(),
205 bet
.getBet().getFifth(),
206 bet
.getBet().getSixth()));
209 Acidictive
.reply(source
, to
, c
, String
.format(
210 "The result of VIzon No.%d was: %d %d %d %d %d %d, you did not win any prize for this drawing. Your bet was: %d %d %d %d %d %d",
218 bet
.getBet().getFirst(),
219 bet
.getBet().getSecond(),
220 bet
.getBet().getThird(),
221 bet
.getBet().getFourth(),
222 bet
.getBet().getFifth(),
223 bet
.getBet().getSixth()));