del: Enable the previously dead code
[cacert-votebot.git] / src / org / cacert / votebot / CAcertVoteBot.java
1 package org.cacert.votebot;
2
3 import java.io.IOException;
4
5 import org.cacert.votebot.CAcertVoteMechanics.State;
6
7 public class CAcertVoteBot extends IRCBot implements Runnable {
8
9 public CAcertVoteBot(IRCClient c) {
10 super(c);
11
12 c.join(meetingChn);
13 c.join(voteAuxChn);
14
15 new Thread(this).start();
16 }
17
18 String meetingChn = System.getProperty("voteBot.meetingChn", "agm");
19
20 String voteAuxChn = System.getProperty("voteBot.voteChn", "vote");
21
22 long warn = Long.parseLong(System.getProperty("voteBot.warnSecs", "90"));
23
24 long timeout = Long.parseLong(System.getProperty("voteBot.timeoutSecs", "120"));
25
26 CAcertVoteMechanics mech = new CAcertVoteMechanics();
27
28 @Override
29 public synchronized void publicMessage(String from, String channel, String message) {
30 if (channel.equals(voteAuxChn)) {
31 sendPublicMessage(voteAuxChn, mech.evaluateVote(from, message));
32 }
33 }
34
35 @Override
36 public synchronized void privateMessage(String from, String message) {
37 if (message.startsWith("vote ")) {
38 String response = mech.callVote(from, message.substring(5));
39 sendPrivateMessage(from, response);
40
41 if (response.startsWith("Sorry,")) {
42 return;
43 }
44
45 anounce("New Vote: " + from + " has started a vote on \"" + mech.getTopic() + "\"");
46 sendPublicMessage(meetingChn, "Please cast your vote in #vote");
47 sendPublicMessage(voteAuxChn, "Please cast your vote in the next " + timeout + " seconds.");
48 }
49 }
50
51 private synchronized void anounce(String msg) {
52 sendPublicMessage(meetingChn, msg);
53 sendPublicMessage(voteAuxChn, msg);
54 }
55
56 public void run() {
57 try {
58 while (true) {
59 while (mech.getState() == State.IDLE) {
60 Thread.sleep(1000);
61 }
62
63 Thread.sleep(warn * 1000);
64 anounce("Voting on " + mech.getTopic() + " will end in " + (timeout - warn) + " seconds.");
65 Thread.sleep((timeout - warn) * 1000);
66 anounce("Voting on " + mech.getTopic() + " has closed.");
67 String[] res = mech.closeVote();
68 anounce("Results: for " + mech.getTopic() + ":");
69
70 for (int i = 0; i < res.length; i++) {
71 anounce(res[i]);
72 }
73 }
74 } catch (InterruptedException e) {
75 e.printStackTrace();
76 }
77 }
78
79 @Override
80 public synchronized void join(String cleanReferent, String chn) {
81
82 }
83
84 @Override
85 public synchronized void part(String cleanReferent, String chn) {
86
87 }
88
89 public static void main(String[] args) throws IOException, InterruptedException {
90 IRCClient ic = IRCClient.parseCommandLine(args, "dogcraft_de");
91 ic.setBot(new CAcertVoteBot(ic));
92 }
93
94 }