]> jfr.im git - irc/rizon/acid.git/blob - vizon/src/main/java/net/rizon/acid/plugins/vizon/commands/CheckCommand.java
ff9b091e5add73ae11b46fb4ce0ad0048c0937bd
[irc/rizon/acid.git] / vizon / src / main / java / net / rizon / acid / plugins / vizon / commands / CheckCommand.java
1 /*
2 * Copyright (c) 2017, orillion <orillion@rizon.net>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
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.
13 *
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.
25 */
26 package net.rizon.acid.plugins.vizon.commands;
27
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;
40
41 /**
42 *
43 * @author orillion <orillion@rizon.net>
44 */
45 public class CheckCommand extends Command
46 {
47 public CheckCommand()
48 {
49 super(1, 1);
50 }
51
52 @Override
53 public void Run(User source, AcidUser to, Channel c, String[] args)
54 {
55 if (!source.hasMode("r"))
56 {
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");
59 return;
60 }
61
62 int drawingId;
63
64 try
65 {
66 drawingId = Integer.parseInt(args[0]);
67 }
68 catch (NumberFormatException e)
69 {
70 Acidictive.reply(source, to, c, "Please specify the number of the drawing you wish to check");
71 return;
72 }
73
74 VizonDrawing drawing = Vizon.getVizonDatabase().getDrawingById(drawingId);
75
76 if (drawing == null)
77 {
78 Acidictive.reply(source, to, c, String.format("Drawing with id %d does not exist", drawingId));
79 return;
80 }
81
82 VizonUser user = Vizon.getVizonDatabase().findOrCreateUser(source.getNick());
83
84 if (user == null)
85 {
86 // Should not happen, but just in case.
87 Acidictive.reply(source, to, c, "Unable to find your name in the database");
88 return;
89 }
90
91 VizonBet bet = Vizon.getVizonDatabase().findBetForUserAndDrawing(user, drawing);
92
93 if (drawing.getDate().isAfter(LocalDateTime.now()))
94 {
95 if (bet == null)
96 {
97 Acidictive.reply(source, to, c, String.format(
98 "Drawing No.%d did not happen yet!",
99 drawingId));
100 }
101 else
102 {
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",
105 drawingId,
106 bet.getBet().getFirst(),
107 bet.getBet().getSecond(),
108 bet.getBet().getThird(),
109 bet.getBet().getFourth(),
110 bet.getBet().getFifth(),
111 bet.getBet().getSixth()));
112 }
113
114 return;
115 }
116
117 List<Integer> bets = drawing.getDraws();
118 Collections.sort(bets);
119
120 if (bet == null)
121 {
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",
124 drawing.getId(),
125 bets.get(0),
126 bets.get(1),
127 bets.get(2),
128 bets.get(3),
129 bets.get(4),
130 bets.get(5)));
131 }
132 else
133 {
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());
137
138 switch (correct)
139 {
140 case 6:
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",
143 drawing.getId(),
144 bets.get(0),
145 bets.get(1),
146 bets.get(2),
147 bets.get(3),
148 bets.get(4),
149 bets.get(5),
150 bet.getBet().getFirst(),
151 bet.getBet().getSecond(),
152 bet.getBet().getThird(),
153 bet.getBet().getFourth(),
154 bet.getBet().getFifth(),
155 bet.getBet().getSixth()));
156 break;
157 case 5:
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",
160 drawing.getId(),
161 bets.get(0),
162 bets.get(1),
163 bets.get(2),
164 bets.get(3),
165 bets.get(4),
166 bets.get(5),
167 bet.getBet().getFirst(),
168 bet.getBet().getSecond(),
169 bet.getBet().getThird(),
170 bet.getBet().getFourth(),
171 bet.getBet().getFifth(),
172 bet.getBet().getSixth()));
173 break;
174 case 4:
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",
177 drawing.getId(),
178 bets.get(0),
179 bets.get(1),
180 bets.get(2),
181 bets.get(3),
182 bets.get(4),
183 bets.get(5),
184 bet.getBet().getFirst(),
185 bet.getBet().getSecond(),
186 bet.getBet().getThird(),
187 bet.getBet().getFourth(),
188 bet.getBet().getFifth(),
189 bet.getBet().getSixth()));
190 break;
191 case 3:
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",
194 drawing.getId(),
195 bets.get(0),
196 bets.get(1),
197 bets.get(2),
198 bets.get(3),
199 bets.get(4),
200 bets.get(5),
201 bet.getBet().getFirst(),
202 bet.getBet().getSecond(),
203 bet.getBet().getThird(),
204 bet.getBet().getFourth(),
205 bet.getBet().getFifth(),
206 bet.getBet().getSixth()));
207 break;
208 default:
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",
211 drawing.getId(),
212 bets.get(0),
213 bets.get(1),
214 bets.get(2),
215 bets.get(3),
216 bets.get(4),
217 bets.get(5),
218 bet.getBet().getFirst(),
219 bet.getBet().getSecond(),
220 bet.getBet().getThird(),
221 bet.getBet().getFourth(),
222 bet.getBet().getFifth(),
223 bet.getBet().getSixth()));
224 break;
225 }
226 }
227 }
228 }