-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatBot.java
More file actions
51 lines (48 loc) · 2.09 KB
/
Copy pathChatBot.java
File metadata and controls
51 lines (48 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Name: Kota Naga Tejaswi LNU
* Class: 2336
* Assignment: Rest API Project
*/
import java.text.DecimalFormat;
import org.jibble.pircbot.*;
public class ChatBot extends PircBot {
public ChatBot(){
this.setName("MyChatBot");
}
//checks message and then does the following
public void onMessage(String channel, String sender, String login, String hostname, String message){
//for weather
if(message.equalsIgnoreCase("weather") || message.endsWith("weather")
|| message.contains("weather") || message.matches("weather") ||
message.startsWith("weather")){
//WeatherAPI weath = new WeatherAPI();
WeatherAPI.uCity = "Dallas";
//calling WeatherAPI's main method
WeatherAPI.main(null);
//to only display two decimal points
DecimalFormat df = new DecimalFormat("#.##");
String cur = df.format(WeatherAPI.parseTemp(WeatherAPI.result.toString()));
String min = df.format(WeatherAPI.parseMinTemp(WeatherAPI.result.toString()));
String max = df.format(WeatherAPI.parseMaxTemp(WeatherAPI.result.toString()));
sendMessage(channel, ": Dallas Weather:" + " Cur Temp: "+ cur + "°F" + " | Min Temp: " + min + "°F | Max Temp: " + max + "°F");
}
//if anyone says twitter or timeline
if(message.equalsIgnoreCase("twitter") || message.endsWith("twitter")
|| message.contains("twitter") || message.matches("twitter") ||
message.startsWith("twitter") || message.equalsIgnoreCase("timeline") || message.endsWith("timeline")
|| message.contains("timeline") || message.matches("timeline") ||
message.startsWith("timeline")){
TwitterAPI.main(null);
//sends message to the server with twitter names and statuses
sendMessage(channel, sender + " Timeline:");
for(int i = 0; i < TwitterAPI.names.size(); i++){
sendMessage(channel, sender + " @" + TwitterAPI.names.get(i) + " tweeted: " + TwitterAPI.stats.get(i));
}
}
//for time
if (message.equalsIgnoreCase("time")) {
String time = new java.util.Date( ).toString( );
sendMessage(channel, sender + ": The time is " + time);
}
}
}