本文整理汇总了Java中org.pircbotx.Colors类的典型用法代码示例。如果您正苦于以下问题:Java Colors类的具体用法?Java Colors怎么用?Java Colors使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Colors类属于org.pircbotx包,在下文中一共展示了Colors类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMessage
import org.pircbotx.Colors; //导入依赖的package包/类
@Override
public void onMessage(MessageEvent event) throws Exception
{
User user = event.getUser();
if (user == null)
return;
// Ignore own messages
if ( user.equals( bot.getUserBot() ) )
return;
// Don't bother with IRC formatting
String message = Colors.removeFormattingAndColors( event.getMessage() );
LOG.trace("Message from {}: {}", user.getNick(), message);
BRIDGE.onIRCMessage(user, message);
}
示例2: onAction
import org.pircbotx.Colors; //导入依赖的package包/类
@Override
public void onAction(ActionEvent event) throws Exception
{
User user = event.getUser();
if (user == null)
return;
// Ignore own messages
if ( user.equals( bot.getUserBot() ) )
return;
// Don't bother with IRC formatting
String action = Colors.removeFormattingAndColors( event.getAction() );
LOG.trace("Action from {}: {}", user.getNick(), action);
BRIDGE.onIRCAction(user, action);
}
示例3: initResponses
import org.pircbotx.Colors; //导入依赖的package包/类
private void initResponses() {
responses.add(Colors.GREEN + " Signs point to yes.");
responses.add(Colors.GREEN + " Yes.");
responses.add(Colors.YELLOW + " Reply hazy, try again.");
responses.add(Colors.GREEN + " Without a doubt.");
responses.add(Colors.RED + " My sources say no.");
responses.add(Colors.GREEN + " As I see it, yes.");
responses.add(Colors.GREEN + " You may rely on it.");
responses.add(Colors.YELLOW + " Concentrate and ask again.");
responses.add(Colors.RED + " Outlook not so good.");
responses.add(Colors.GREEN + " It is decidedly so.");
responses.add(Colors.YELLOW + " Better not tell you now.");
responses.add(Colors.RED + " Very doubtful.");
responses.add(Colors.GREEN + " Yes - definitely.");
responses.add(Colors.GREEN + " It is certain.");
responses.add(Colors.YELLOW + " Cannot predict now.");
responses.add(Colors.GREEN + " Most likely.");
responses.add(Colors.YELLOW + " Ask again later.");
responses.add(Colors.RED + " My reply is no.");
responses.add(Colors.GREEN + " Outlook good.");
responses.add(Colors.RED + " Do not count on it.");
}
示例4: onMessage
import org.pircbotx.Colors; //导入依赖的package包/类
@Override
public void onMessage(MessageEvent event) throws Exception {
String msg = event.getMessage();
if (msg.startsWith(Helix.botPrefix + Commands.googleSearch) && ((msg.length() > (Commands.googleSearch.length() + 2) && msg.charAt(Commands.googleSearch.length()+1) == ' ') || (msg.length() > (Commands.googleSearch.length()+3) && Arrays.asList(Helix.valid).contains(msg.charAt(Commands.googleSearch.length()+1)) && msg.charAt(Commands.googleSearch.length()+2) == ' '))) {
String q = msg.split(" ", 2)[1];
String max = msg.charAt(Commands.googleSearch.length()+1) == ' ' ? "1" : String.valueOf(msg.charAt(Commands.googleSearch.length()+1));
String a = "https://www.googleapis.com/customsearch/v1?fields=items(htmlTitle,link,htmlSnippet)&alt=json&key=" + Helix.properties.getProperty("google.apikey") + "&cx=" + Helix.properties.getProperty("google.searchengineid") + "&q=" + URLEncoder.encode(q, "UTF-8");
String m;
try {
JSONObject r = new JSONObject(Util.getHTTPResponse(a)).getJSONArray("items").getJSONObject(Integer.parseInt(max) - 1);
String title = StringEscapeUtils.unescapeHtml4(r.getString("htmlTitle").replace("<b>", Colors.BOLD).replace("</b>", Colors.NORMAL));
String link = r.getString("link");
String snip = StringEscapeUtils.unescapeHtml4(r.getString("htmlSnippet").replace("<b>", Colors.BOLD).replace("</b>", Colors.NORMAL).replace("\n", "").replace("<br>", ""));
m = "[" + title + "]" + snip + " " + link;
} catch (JSONException e) {
m = "No results found for \"" + Colors.BOLD + q + Colors.NORMAL + "\"";
}
event.getChannel().send().message(m);
}
}
示例5: onMessage
import org.pircbotx.Colors; //导入依赖的package包/类
@Override
public void onMessage(MessageEvent event) throws Exception {
if (event.getMessage().startsWith(Helix.botPrefix + Commands.addCmd + " ") && event.getMessage().length() > (Commands.addCmd.length() + 2) && admins.contains(Util.getLogin(event.getUser())) && Util.isVerified(event.getUser())) {
String s[] = event.getMessage().split(" ", 3);
if (Helix.hardCommands.contains(s[1].toLowerCase())) {
event.respond("Can't override hardcoded commands!");
return;
}
Helix.commands.put(s[1].toLowerCase(), s[2]);
try {
BufferedWriter wr = new BufferedWriter(new FileWriter("commands.json", false));
wr.write(Helix.commands.toString(4));
wr.flush();
wr.close();
} catch (IOException e) {
event.respond(Colors.BOLD + Colors.MAGENTA + "Warning! Failed to save commands.");
e.printStackTrace();
}
}
}
示例6: formatCoinRequest
import org.pircbotx.Colors; //导入依赖的package包/类
/**
* Handles the formatting for the bot's coin request.
*
* @param currency The list of currencies retrieved from the coinmarketcap API.
* @param nf The NumberFormat instance for formatting currencies.
* @return The bot's formatted response.
*/
private BotResponse formatCoinRequest(final List<CoinMarketCapResponse> currency, final NumberFormat nf) {
String dayChange = getColoredChangeText(currency.get(0).getPercentChange24h());
String hourChange = getColoredChangeText(currency.get(0).getPercentChange1h());
String weekChange = getColoredChangeText(currency.get(0).getPercentChange7d());
if (currency.get(0).getMarketCapUsd() != null) {
return new BotResponse(BotIntention.CHAT, null, Colors.CYAN + Colors.BOLD
+ currency.get(0).getName() + Colors.NORMAL + Colors.TEAL + ": "
+ nf.format(Double.valueOf(currency.get(0).getPriceUsd())) + " | Rank: "
+ currency.get(0).getRank() + Colors.TEAL + " | Market Cap: "
+ nf.format(Double.valueOf(currency.get(0).getMarketCapUsd())),
Colors.TEAL
+ "[Hour " + hourChange + "] | [Day " + dayChange + "] | [Week " + weekChange + "]");
} else {
return new BotResponse(BotIntention.CHAT, null, Colors.CYAN + Colors.BOLD
+ currency.get(0).getName() + Colors.NORMAL + Colors.TEAL + ": "
+ nf.format(Double.valueOf(currency.get(0).getPriceUsd()))
+ " | Rank: " + currency.get(0).getRank()
+ " | [" + dayChange + "] ",
"Market Cap: N/A");
}
}
示例7: executeCommand
import org.pircbotx.Colors; //导入依赖的package包/类
@Override
public BotResponse executeCommand(final IRCbutt butt, final GenericMessageEvent event, final String[] cmd) {
StringBuilder sb = new StringBuilder("Testing ");
sb.append(StringUtils.getArgs(cmd)).append(": ");
int random = MathUtils.getRandom(0, CHECK_MATH_MAX);
String result;
if (random < CHECK_MATH_PANIC) {
result = Colors.WHITE + "[" + Colors.YELLOW + "PANIC" + Colors.WHITE + "]";
} else if (random < CHECK_MATH_FAIL) {
result = Colors.WHITE + "[" + Colors.RED + "FAIL" + Colors.WHITE + "]";
} else {
result = Colors.WHITE + "[" + Colors.GREEN + "PASS" + Colors.WHITE + "]";
}
sb.append(result);
return new BotResponse(BotIntention.CHAT, event.getUser(), sb.toString());
}
示例8: onMessage
import org.pircbotx.Colors; //导入依赖的package包/类
@Override
public void onMessage(MessageEvent<?> event) {
if (Main.spamFilter.filtersEnabled(event.getChannel().getName())) {
for (String s : bannedWords) {
Matcher matcher = Pattern.compile("\\b(" + s + ")\\b", Pattern.CASE_INSENSITIVE).matcher(Colors.removeFormattingAndColors(event.getMessage()));
while (matcher.find()) {
String word = matcher.group();
if (word.equalsIgnoreCase(s)) {
PermLevel level = PermRegistry.INSTANCE.getPermLevelForUser(event.getChannel(), event.getUser());
if (!IRCUtils.isPermLevelAboveOrEqualTo(level, PermLevel.TRUSTED)) {
Main.spamFilter.finish(Main.spamFilter.timeout(event, CURSE) ? event.getUser() : null, CURSE, event.getMessage());
}
}
}
}
}
}
示例9: post
import org.pircbotx.Colors; //导入依赖的package包/类
/**
* Shows information about a selfpost, or linked post
* @param channel The channel to send the information in
* @param link The link to the post
*/
private void post(String channel, String link) throws IOException
{
Document doc = Jsoup.connect(link).userAgent(userAgent).get();
String gilded = doc.select(".gilded-icon").attr("data-count");
String votes = doc.select("div.score > span.number").text();
String percentage = doc.select(".score").get(0).text().split("\\(")[1].split("%")[0] + "%";
String title = doc.select("a.title").get(0).text();
String type = doc.select(".domain").get(0).text().contains("self.") ? "(Selfpost)" : doc.select(".domain").get(0).text();
String comments = doc.select(".comments[href=\"" + link +"\"]").text();
String author = doc.select("p.tagline > a.author").get(0).text();
String time = doc.select("p.tagline > time").get(0).text();
if(gilded.equals(""))
gilded = "0";
Utilities.sendMessage(channel, Colors.BROWN + "(" + gilded + ") " + Colors.GREEN + "[" + votes + " " + percentage + "] " + Colors.NORMAL + title + " " + Colors.ITALICS + Colors.LIGHT_GRAY + type + Colors.NORMAL + " - " + comments + " - " + Colors.MAGENTA + "/u/" + author + " posted " + time);
}
示例10: comment
import org.pircbotx.Colors; //导入依赖的package包/类
/**
* Shows information about a comment
* @param channel The channel to send the information in
* @param link The link to the comment
*/
private void comment(String channel, String link) throws IOException
{
Document doc = Jsoup.connect(link).userAgent(userAgent).get();
String gilded;
String author = doc.select("#thing_t1_" + link.substring(link.lastIndexOf('/') + 1) +" > div.entry > p.tagline > a.author").text();
String votes = doc.select("#thing_t1_" + link.substring(link.lastIndexOf('/') + 1) +" > div.entry > p.tagline > span.unvoted").text().split(" ")[0];
String time = doc.select("#thing_t1_" + link.substring(link.lastIndexOf('/') + 1) +" > div.entry > p.tagline > time").text();
try
{
gilded = doc.select(".gilded-icon").get(1).attr("data-count"); //for if the op has a gild
}
catch(IndexOutOfBoundsException e)
{
gilded = doc.select(".gilded-icon").attr("data-count"); //for it the op has no gild
}
if(gilded.equals(""))
gilded = "0";
Utilities.sendMessage(channel, Colors.BROWN + "(" + gilded + ") " + Colors.GREEN + "[" + votes + "] " + Colors.MAGENTA + "/u/" + author + " posted " + time);
}
示例11: exe
import org.pircbotx.Colors; //导入依赖的package包/类
@Override
public void exe(MessageEvent event, String cmdName, String[] args) throws Exception
{
String channel = event.getChannel().getName();
if(args.length == 2)
{
Document doc = Jsoup.connect("http://www.distance.to/" + args[0] + "/" + args[1]).get();
String directMI = doc.select(".info > li:nth-child(1) > span:nth-child(1)").get(0).text().replace(",", "");
String directKM = String.format("%.2f", Double.parseDouble(directMI.split(" ")[0]) * 1.621371).replace(",", ".");
Utilities.sendStarMsg(channel,
Colors.NORMAL + directKM + "km" + Colors.ITALICS + " (" + directMI + ")",
l10n.translate("credit", channel).replace("#link", Colors.NORMAL + "http://www.distance.to/"));
}
else
Utilities.sendHelp(module, event.getUser().getNick(), channel);
}
示例12: handleLink
import org.pircbotx.Colors; //导入依赖的package包/类
/**
* Takes actions when specific links are sent
* @param message The message containing links
* @param channel The channel the message got sent in
* @param user The user the message got sent by
*/
public static void handleLink(String message, String channel, String user) throws Exception
{
outer:
for(String s : message.split(" "))
{
s = Colors.removeFormattingAndColors(s);
if(s.contains("www.") || s.contains("http://") || s.contains("https://"))
{
for(LinkAction la : linkActions)
{
if(la.isValid(channel, s))
{
la.handle(channel, user, s);
continue outer;
}
}
}
}
}
示例13: raw
import org.pircbotx.Colors; //导入依赖的package包/类
/**
* Logs a raw line (without date) if logging is enabled and it hasn't failed setting up
* @param line The line
*/
private static void raw(String line)
{
if(enabled)
{
if(!failed)
{
try
{
writer.write(line + "\n");
writer.flush();
}
catch (IOException e)
{
e.printStackTrace(); //don't call Logging.stackTrace(e); here
}
}
System.out.println(Colors.removeFormattingAndColors(line));
}
System.gc();
}
示例14: log
import org.pircbotx.Colors; //导入依赖的package包/类
/**
* Logs a message
* @param message The message
*/
private static void log(String line)
{
if(enabled)
{
if(!failed)
{
try
{
writer.write(Utilities.getCurrentDate().toString() + " " + Colors.removeFormattingAndColors(line) + "\n");
writer.flush();
}
catch (IOException e)
{
e.printStackTrace(); //don't call Logging.stackTrace(e); here
}
}
System.out.println(Utilities.getCurrentDate().toString() + " " + Colors.removeFormattingAndColors(line));
}
System.gc();
}
示例15: run
import org.pircbotx.Colors; //导入依赖的package包/类
@Override
public String run(String[] parameters, Event<SlyBot> event) {
//Get the local version and build
String localVersion = event.getBot().getVersion();
String localBuild = localVersion.substring(localVersion.lastIndexOf(" ") + 1);
event.getBot().reply(event, "Currently running slybot version: " + Colors.BLUE + localVersion);
//Get upstream build version
String SHA = VersionUtil.getRemoteSHA("Balonbal", "slybot");
String remoteBuild = SHA.substring(0, localBuild.length());
if (!localBuild.equals(remoteBuild)) {
//Send a friendly reminder that a newer version exists
event.getBot().reply(event, "Newer version " + Colors.RED + remoteBuild + Colors.NORMAL + " was found, consider updating.");
event.getBot().reply(event, "Newest commit: " + Colors.DARK_BLUE + VersionUtil.getCommit("Balonbal", "slybot", SHA));
}
return localVersion;
}