I need some help with arrays for admins and stuff. I'm using this API to make a server bot. You can find all the classes, constructors, and methods there.
Here's my current code:
import org.jibble.pircbot.*;
public class MyBot extends PircBot {
public MyBot() {
this.setName("DevilBot");
}
String owner = "Evan";
public void onMessage(String channel, String sender,
String login, String hostname, String message) {
if (message.equalsIgnoreCase("!time")) {
String time = new java.util.Date().toString();
sendMessage(channel, sender + ": The time is now " + time);
}
if (message.equalsIgnoreCase("!owner")) {
if(sender.equals(owner))
{
sendMessage(channel, Colors.NORMAL + "You're my owner silly!");
}
if (!sender.equals(owner))
{
sendMessage(channel, Colors.NORMAL + sender + ": " + owner + " is my owner!");
}
}
if (message.equalsIgnoreCase("!ban")) {
if(sender.equals(owner))
{
ban(channel, message);
sendMessage(channel, "Banned " + message);
}
else
{
kick(channel, sender);
sendMessage(channel, "You aren't my mother!");
}
}
if (message.equalsIgnoreCase("!version")) {
sendMessage(channel, "Version 0.1");
sendMessage(channel, "PircBot API v1.5.0");
}
if (message.equalsIgnoreCase("!aelux")) {
sendMessage(channel, "ALL HAIL AELUX!");
}
if (message.equalsIgnoreCase("!hates")){
sendMessage(channel, message + ", " + sender + " hates you!");
}
if (message.equalsIgnoreCase("!op")){
if(sender.equals(owner))
{
sendMessage(channel, "Opping " + message);
}
else
{
ban(channel, sender);
kick(channel, sender);
sendMessage(channel, "GTFO! Banned.");
}
}
}
}
It compiles and runs fine. And it's still in Alpha Stages, but for some reason it won't read my command. Like:
!kick user
Yields no response.
The API is quick and easy to understand. If you CAN help me, that would be awesome!
Right now in your code you are only using equalsIgnoreCase
This method requires both strings to match perfectly apart from the case.
So the reason "!ban user" would not work is because of the following.
"!ban".equalsIgnoreCase("!bAn") == true
"!ban".equalsIgnoreCase("!BaN") == true
but
"!ban".equalsIgnoreCase("!ban username") == false
"!ban".equalsIgnoreCase("!ban ") == false
This following piece of code would result in you being able to ban people by typing "!ban username". However it will be case sensitive.
if (message.startsWith("!ban")) {
if(sender.equals(owner))
{
String userToBan = message.split(" ")[1];
ban(channel, userToBan);
sendMessage(channel, "Banned " + userToBan);
}
else
{
kick(channel, sender);
sendMessage(channel, "You aren't my mother!");
}
}
If you don't want it to be just split the incoming command on a separator (usually space), and convert the first string and match them with equalsIgnoreCase.
String[] messageParts = string.split();
String command = messageParts[0];
if("!ban".equalsIgnoreCase(command){
ban(channel,messageParts[1])
if(messageParts[2].isEmpty()){
sendMessage(channel, "Banned " + messageParts[1]);
}else{
sendMessage(channel, "Banned " + messageParts[1] + " Reason: " + messageParts[2]);
}
}
Hope this helps
Related
my dependency file here
implementation 'com.payumoney.sdkui:plug-n-play:1.6.1'
payUmoney code
private fun startPay() {
builder.setAmount(amount) // Payment amount
.setTxnId(txnid) // Transaction ID
.setPhone(phone) // User Phone number
.setProductName(prodname) // Product Name or description
.setFirstName(firstname) // User First name
.setEmail(email) // User Email ID
.setsUrl("https://www.payumoney.com/mobileapp/payumoney/success.php") // Success URL (surl)
.setfUrl("https://www.payumoney.com/mobileapp/payumoney/failure.php") //Failure URL (furl)
.setUdf1("")
.setUdf2("")
.setUdf3("")
.setUdf4("")
.setUdf5("")
.setUdf6("")
.setUdf7("")
.setUdf8("")
.setUdf9("")
.setUdf10("")
.setIsDebug(true) // Integration environment - true (Debug)/ false(Production)
.setKey(pro_merchantkey) // Merchant key
.setMerchantId(pro_merchantId);
try {
paymentParam = builder.build()
getHashkey()
} catch (e: Exception) {
Log.d("afkafbakabkab", " errors $e")
}
}
payment flow stating from here
private fun getHashkey() {
paymentParam!!.setMerchantHash(CreateHash())
PayUmoneyFlowManager.startPayUMoneyFlow(paymentParam, this as PaymentGateways, R.style.AppTheme_default, true);
}
generating hash key from this code
private fun CreateHash(): String {
var hashSequence: String = pro_merchantkey + "|" + txnid + "|" + amount + "|" + prodname + "|" + firstname + "|" + email + "|" +
udf1 + "|" + udf2 + "|" + udf3 + "|" + udf4 + "|" + udf5 +"||||||"+ pro_salt;
val hash = hashcal("SHA-512", hashSequence)
return hash
}
note :- i am getting only one payment option i want to get multiple payment options like netbanking ,Upi
you have set setIsDebug() true; for some resaons PayU have only provided test cards for testing purposes.
So, the release build will have all the options.
in simple words set setIsDebug(false) and you will get all the options.
Title is self-explanatory.
Instead of using:
if (link.contains(".com") || (link.contains(".net") || (link.contains(".org") || (link.contains(".info") || ("etc there are many domain names")) {
webView.loadUrl("https://www." + link);
} else {
webView.loadUrl("https://www." + link + ".com");
}
I want to do it this way if possible by declaring the String's values globally.
if (link.contains(domainNames)) {
webView.loadUrl("https://www." + link);
} else {
webView.loadUrl("https://www." + link + ".com");
}
Build a regex with the domain names, then test it, e.g.
private static final Pattern DOMAIN_NAMES = Pattern.compile("\\.(?i:com|net|org|info)$");
if (DOMAIN_NAMES.matcher(link).find()) {
webView.loadUrl("https://www." + link);
} else {
webView.loadUrl("https://www." + link + ".com");
}
Another mannual approach could be :
Domainnamelist.contains(substring from link that contains domain ending)
I am trying to read the data from CSV file. everything works fine but when i try to read the data for longitude and latitude. it gives me an below error message.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.yogi.guestlogix/com.example.yogi.guestlogix.MainActivity}: java.lang.NumberFormatException: Invalid double: "EVE"
Caused by: java.lang.NumberFormatException: Invalid double: "EVE"**
MainActivity.java
//Airports data begin
InputStream isss = getResources().openRawResource(R.raw.airports);
BufferedReader readerss = new BufferedReader(
new InputStreamReader(isss, Charset.forName("UTF-8"))
);
String liness = "";
//for airports.csv
try {
readerss.readLine();
while ((liness = readerss.readLine()) != null) {
//split by ',' first
String[] airport = liness.split(",");
//Read the data
AirportsData airdata = new AirportsData();
airdata.setAirportname(airport[0]);
airdata.setAirportcity(airport[1]);
airdata.setAirportcountry(airport[2]);
airdata.setAirportIATAcode(airport[3]);
//airdata.setAirportlang(Double.parseDouble(airport[4]));
//airdata.setAirportlat(Double.parseDouble(airport[5]));
AirportsDatas.add(airdata);
}
} catch (IOException e) {
Log.wtf("My Activity", "Reading data file error " + liness, e);
e.printStackTrace();
}
Log.d("Airline", "name is " + AirportsDatas);
AirportsData.java
public double getAirportlang(double airportlang) {
return airportlang;
}
public void setAirportlang(double airportlang) {
this.airportlang = airportlang;
}
public double getAirportlat( ) {
return airportlat;
}
public void setAirportlat(double airportlat) {
this.airportlat = airportlat;
}
#Override
public String toString() {
return "AirportsData{" +
"airportname='" + airportname + '\'' +
", airportcity='" + airportcity + '\'' +
", airportcountry='" + airportcountry + '\'' +
", airportIATAcode='" + airportIATAcode + '\'' +
", airportlang=" + airportlang +
", airportlat=" + airportlat +
'}';
}
**Any solution for this problem would be greatly appreciated....
The problem with CSV files is, that users (and other programmers) can pretty much write into the file what they want.
In your case, somebody entered a non-number into a CSV cell where you were expecting a double floating point number. Java correctly complains that this cannot be parsed to double. You have two approaches, to treat such situations:
A) Design by Contract
First, you could resolve that by relying on design by contract. You could have a parseLat method:
public Double parseLat(String[] csvRow) {
final String lat= csvRow[4];
assertIsNumeric(lat);
}
private void assertIsNumeric(String lat) {
if(!isNumeric(lat)) {
throw new IllegalArgumentException("Lattitude '" + lat + "' is not numeric");
}
}
There are countless options to implement an isNumeric method, some are discussed here. This will still stop the execution, but it will give a clearer message to users.
B) Defensive Design
A second option, is to provide a parseLAttitude method, that replaces non numeric value with null:
public Double parseLattitude(String[] csvRow) {
final String lattitude = csvRow[4];
if(!isNumeric(lattitude)) {
System.out.println("Could not parse lattitude '" + lat + "'");
return null;
}
return Double.parseDouble(lat);
}
I think the problem is that airport[4] & airport[5] might not be the lon and lat of the airport. If these field contain alpha characters [a-z] you will get an numberFormatException. Can you add the the output when you print airport like:
System.out.println(Arrays.asList(airport));
to the question? Than we will be better able to help you
I am working on an assignment with an online Udacity course, where we have been asked to develop a method that recognizes the last letter of the noun and then based on the letter, out put a "La", "el", or "?" + the noun.
The complete instructions are You are to complete the method fixNoun in the SpanishWord class so that it returns the noun preceded by:
// "la " if the noun ends in "a",
// "el " if it ends in "o"
// "? " if it ends in some other letter.
I seem to keep getting all failures when compiling. Can someone please help me understand what I am doing wrong?
public String fixNoun(String noun) {
String determinenet= noun.substring(noun.length() - 1);
if(determinenet.equals("a")) {
System.out.println("la" + " "+noun );
}
else if ( determinenet.equals("o")) {
System.out.println( "el"+ " "+noun);
}
else {
System.out.println("?"+ " "+noun);
}
return noun;
}
you don't return the altered noun but the old one. In your code you have to change the
System.out.println("la" + " "+noun );
to
return("la " + noun);
and so on.
The fixed code looks like this:
public String fixNoun(String noun) {
String determinenet= noun.substring(noun.length() - 1);
if(determinenet.equals("a")) {
return("la" + " "+noun );
}
else if ( determinenet.equals("o")) {
return( "el"+ " "+noun);
}
else {
return("?"+ " "+noun);
}
}
}
P.S.: The String class has a method endsWith() that gives you the last character of the string.
So you also could write your code like this:
public String fixNoun(String noun) {
if(noun.endsWith("a")) {
return("la " + noun);
else if(noun.endsWith("o")) {
return("el " + noun);
else {
return("? " + noun);
}
}
Good luck with your assignment :)
I don't know maybe i'm wrong. how about this?
String de=noun.charAt(noun.length()-1)
if(de.equalsIgnoreCase("a"))
return "la" + " "+noun ;
I'm writing something similar to smarterChild (that automated AOL Instant Messenger chat program from back in the day) and was curious about my method of determining sentence structure and response.
Currently, the bare bones design is to use 5 main methods which collectively determine the appropriate response given the user input:
1) Read(): initially accepts user input, then calls first of many methods: sentenceType()
2) getSentenceType(): User sentence type: Question, statement, directive, suggestion, etc…
3) getWho(): If question is about the computer, or about someone else…
4) getCategory(): What category the question is about (weather, sports…)
5) getResponse(): finally, form a response
These methods will query a database to determine if the user input contains key words...
Example of getSentenceType():
public String getSentenceType(String sentence) {
String type = null;
for (String s : db.getQuestions()) {
if (sentence.contains(s)) {
type = "question";
break;
}
else {
type = "statement";
}
}
return getWho(type, sentence);
}
Example of the final method which returns sentence structure:
//final call...
public String getResponse(String cat, String who, String type) {
String response = new String();
String auxVerb, subject, mainVerb, noun;
auxVerb = "do";
subject = who;
mainVerb = "like";
noun = cat;
//question structure: auxiliary verb + subject + main verb + noun/pronoun
// DO YOU LIKE MARY?
if (type.equals("question")) {
response = subject + " " + auxVerb + " " + mainVerb + " " + noun + ". ";
}
else {
response = auxVerb + " " + subject + " " + mainVerb + " " + noun + "?";
}
return response;
}
Sample database methods:
public String[] getQuestions() {
String[] questions = new String[] {"why", "?"};
return questions;
}
public String[] getWeather() {
String[] weather = new String[] {"cold", "hot", "rainy", "weather"};
return weather;
}
It will then progressively concatenate all the method results into a coherent response… then send that result back to Read(), which will print out the result to the user...
Is this an inefficient way to go about this? I know that if I continue down this path... to make a robust system, it will take tons of if else checks and a massive database to determine every possible type of response for user input.
Are there any suggested methods?
Thank you