本文整理汇总了Java中org.pircbotx.hooks.events.MessageEvent.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java MessageEvent.getMessage方法的具体用法?Java MessageEvent.getMessage怎么用?Java MessageEvent.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.pircbotx.hooks.events.MessageEvent
的用法示例。
在下文中一共展示了MessageEvent.getMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
/**
* Honestly, I haven't figured out the difference between OnGenericMessage and OnMessage yet
* A MessageEvent seems to be more useful though, because I can tell what channel it came from
* @param event MessageEvent given when someone says something on a channel the bot is in
*/
@Override
public void onMessage(MessageEvent event){
parseInvite(event);
parseRemind(event);
parsePing(event);
parseSource(event);
parsePart(event);
String message = event.getMessage();
if (message.toLowerCase().startsWith(bot_nick.toLowerCase())) {
String query = message;
if (!query.isEmpty()) {
query = Swiggityspeare_utils.trimNick(query, bot_nick); //trim off `swiggityspeare` from input
if(include_nick_in_query) query = event.getUser().getNick() + ": " + query;
String response = Swiggityspeare_utils.getString(query, neuralNetworkDirectory, neuralNetworkFile);
event.respond(response);
}
}
}
示例2: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的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);
}
}
示例3: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessage(MessageEvent<PircBotX> event) throws Exception {
String message = event.getMessage();
if (message.charAt(0) == config.getPrefix()) {
int spaceIdx = message.indexOf(' ');
String command = spaceIdx > -1 ? message.substring(1, spaceIdx) : message.substring(1);
Command c = Command.fromString(command);
if (c != null) {
c.handleCommand(event);
} else if (config.isSendNoSuchCommand()) {
event.respond("No such command");
}
} else {
String formatted = config.getPrivmsgFormatString()
.replace("{user}", jsonEscape(event.getUser().getNick()))
.replace("{message}", jsonEscape(message));
ObfuscationHelper.sendMessageFromJson(formatted);
}
}
示例4: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessage(final MessageEvent<MyPircBotX> event) {
DAD_JOKE_CHANCE = event.getBot().getSettings().getDadjokeChance();
try {
Random generator = new Random();
if (DAD_JOKE_CHANCE > 0) {
int r = generator.nextInt(DAD_JOKE_CHANCE);
if (r == (DAD_JOKE_CHANCE - 1)) {
String message = event.getMessage();
String response = parseDadJoke(message, event.getBot()
.getNick());
event.getChannel().getBot().sendIRC()
.message(event.getChannel().getName(), response);
}
}
} catch (Exception e) {
// It's okay, you'd make a terrible dad.
logger.error("Dad joke failed: " + e.getMessage());
}
}
示例5: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
public void onMessage(final MessageEvent<MyPircBotX> event) {
String message = event.getMessage();
String user = event.getUser().getNick();
if(isValid(message)&&isValidUser(user)){
RedditPreview rurl;
try {
rurl = new RedditPreview(message);
if(rurl!=null){
event.getBot().sendIRC().message(event.getChannel().getName(),rurl.getPreview());
}
} catch (BotException e) {
event.getBot().sendIRC().message(event.getBot().getSettings().getAdmin(),
"I have failed to parse json for " + event.getMessage());
e.printStackTrace();
}
}
}
示例6: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessage(MessageEvent<SlyBot> pircBotXEvent) {
//Extract the message
String message = pircBotXEvent.getMessage();
Matcher youtubes = Strings.youtube.matcher(message);
while (youtubes.find()) {
//Split start of url to
String url = message.substring(youtubes.end());
if (url.contains(" ")) url = url.substring(0, url.indexOf(" "));
try {
youtube.parseVideoInfo(url, pircBotXEvent);
} catch (IllegalArgumentException e) {
url = message.substring(youtubes.start());
if (url.contains(" ")) url = url.substring(0, url.indexOf(" "));
pircBotXEvent.getBot().reply(pircBotXEvent, "Sorry, your youtube URL (" + url + ") gave me no results");
}
}
}
示例7: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
public void onMessage(final MessageEvent event) {
try {
final String userNick = this.getUserName(event.getUser());
long count = this.ignore.stream()
.filter(s -> s.equals(userNick))
.count();
if (count > 0) {
logger.info("Ignoring message because nickname matches ignore list");
return;
}
FirehoseMessage firehoseMessage = new FirehoseMessage("irc",
"message",
this.getUserName(event.getUser()),
this.serverName,
event.getChannel().getName().replace("#", ""),
event.getMessage());
logger.info("Got event from service: " + firehoseMessage.toLogString());
callback.execute(firehoseMessage);
} catch (NullPointerException e) {
logger.error(MessageFormat.format("Error {0}",
e.getMessage()
));
}
}
示例8: channelCommand
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
public void channelCommand(MessageEvent<PircBotX> event) throws Exception {
message = event.getMessage();
command = message.split(" ")[0];
user = event.getUser().getNick();
args = event.getMessage().split(" ");
channel = event.getChannel();
}
示例9: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessage(MessageEvent event) throws Exception {
String msg = event.getMessage();
if (msg.startsWith(Helix.botPrefix + Commands.youTubeSearch) && ((msg.length() > (Commands.youTubeSearch.length()+2) && msg.charAt(Commands.youTubeSearch.length()+1) == ' ') || (msg.length() > (Commands.youTubeSearch.length()+3) && Arrays.asList(Helix.valid).contains(msg.charAt(Commands.youTubeSearch.length()+1)) && msg.charAt(Commands.youTubeSearch.length()+2) == ' '))){
String q = msg.split(" ", 2)[1];
String max = msg.charAt(3) == ' ' ? "1" : String.valueOf(msg.charAt(3));
String a = String.format("https://www.googleapis.com/youtube/v3/search?part=id&maxResults=%s®ionCode=br&type=video&q=%s&key=%s", max, URLEncoder.encode(q, "UTF-8"), Helix.properties.get("google.apikey"));
JSONObject v;
JSONObject snip;
String views;
String dislike;
String like;
String len;
String m;
try {
v = new JSONObject(Util.getHTTPResponse(String.format("https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,statistics&id=%s&key=%s", (new JSONObject(Util.getHTTPResponse(a))).getJSONArray("items").getJSONObject(Integer.valueOf(max) - 1).getJSONObject("id").getString("videoId"), Helix.properties.get("google.apikey")))).getJSONArray("items").getJSONObject(0);
snip = v.getJSONObject("snippet");
JSONObject stat = v.getJSONObject("statistics");
views = Helix.numberFormat.format(Long.parseLong(stat.getString("viewCount")));
dislike = Helix.numberFormat.format(Integer.parseInt(stat.getString("dislikeCount")));
like = Helix.numberFormat.format(Integer.parseInt(stat.getString("likeCount")));
len = v.getJSONObject("contentDetails").getString("duration");
m = Colors.BOLD + Colors.BLACK + ",00[You" + Colors.WHITE + ",04Tube]" + Colors.NORMAL + " " + snip.getString("title") + " [" + Colors.OLIVE + (len.equals("PT0S")? "Live" : Util.parseYouTubeTime(len)) + Colors.NORMAL + "] [" + Colors.TEAL + views + Colors.NORMAL + "] [" + Colors.DARK_GREEN + "+" + like + Colors.NORMAL + "] [" + Colors.RED + "-" + dislike + Colors.NORMAL + "] [" + Colors.MAGENTA + snip.getString("channelTitle") + Colors.NORMAL + "] http://youtu.be/" + v.getString("id");
} catch (JSONException e){
m = "Video not found! \"" + Colors.BOLD + q + Colors.NORMAL + "\"";
}
event.getChannel().send().message(m);
}
}
示例10: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessage(MessageEvent event) throws Exception {
if (!event.getMessage().startsWith(COMMAND_PREFIX)) return;
String message = event.getMessage();
String username = event.getUser().getNick();
logger.info("Received command message '{}' from '{}'", message, username);
String command = message.split("\\s+")[0].toLowerCase();
if (command.equals(TIME_COMMAND)) {
logger.info("Recognized command '{}'", command);
if (commandThrottler.throttleCommand(command)) {
logger.info("Throttled command '{}'", command);
} else {
logger.info("Responding to command '{}'", command);
event.getChannel().send().message(getTimeString());
logger.info("Tracking usage of command '{}'", command);
commandThrottler.trackCommandUsage(command);
}
} else if (command.equals(VERSION_COMMAND)) {
logger.info("Recognized command '{}'", command);
if (commandThrottler.throttleCommand(command)) {
logger.info("Throttled command '{}'", command);
} else {
logger.info("Responding to command '{}'", command);
event.getChannel().send().action(getVersionString());
logger.info("Tracking usage of command '{}'", command);
commandThrottler.trackCommandUsage(command);
}
} else {
logger.info("Unrecognized command '{}'", command);
}
}
示例11: newGenericQuery
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
@Override
public void newGenericQuery(MessageEvent<MyPircBotX> event) {
QueryBO helper = new QueryBO();
Timestamp now = helper.getNow(event);
Timestamp start = helper.getDaysAgo(event,1);
// get message
String input = event.getMessage();
// cut "!query"
input = input.substring(input.indexOf(" "));
// sanitize input (removes start/end spaces
input = helper.sanitize(input);
// get report name
// Bandaid, and a bad one at that.
input = input+ " ";
String report = helper.sanitize(input.substring(0,input.indexOf(" ")+1));
try{
REPORT_LIST reports = REPORT_LIST.valueOf(report.toUpperCase());
switch(reports) {
case TRENDING:
String[][] reply = getTopWords(5,event.getChannel().getName(),start,now);
helper.displayTrendingList(reply,5,event);
break;
default:
event.getBot().sendIRC().message(event.getUser().toString(), "You have failed.");
}
}catch(Exception e){
//I'm not sure how I want to handle this yet
}
}
示例12: CustomQuery
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
public CustomQuery(MessageEvent<MyPircBotX> event) {
QueryBO helper = new QueryBO();
// get initial settings
this.channel = event.getChannel().getName();
this.event = event;
// read message
String input = event.getMessage();
// sanitize input
input = sanitize(input);
// create string array
String[] inArray = input.split(" ");
// [0] "!query" [1] REPORT
// parse input from array
// find report
report = Report.valueOf(inArray[1].toUpperCase());
// find nick
for (int i= 2;i<inArray.length;i++){
String test = inArray[i].trim();
// Get nick
if (test.equals("-n")){
nick = inArray[i+1];
}
// Get time
if (test.equals("-t")){
this.timeQuantity = Integer.parseInt(inArray[i+1]);
this.timePeriod = inArray[i+2];
this.start = helper.getPeriodsAgo(timeQuantity,timePeriod,event);
}
// Time end defaults to "now"
this.end = helper.getNow(event);
// Get quantity
if (test.equals("-q")){
this.resultsQuantity = Integer.parseInt(inArray[i+1]);
}
}
// verify input
verify();
}
示例13: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessage(MessageEvent e) throws Exception {
String messageRaw = e.getMessage();
if (messageRaw.equals("$")) {
return;
}
if (messageRaw.startsWith("$")) {
String[] arr = messageRaw.split(" ", 2);
String cmd = arr[0].substring(1).toLowerCase();
Aradiabot.getLogger().info(e.getUser().getNick() + " issused command: " + cmd);
if (CommandList.contains(cmd)) {
Command command = CommandList.get(cmd);
if (arr.length <= 1) {
Utils.dispatchEvent(e.getBot(), new CommandEvent(e, e.getUser(), e.getChannel(), command, new String[0]));
} else {
List<String> args = new ArrayList<String>();
Matcher m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(arr[1]);
while (m.find()) {
args.add(m.group().replaceAll("\"", "").trim());
}
Utils.dispatchEvent(e.getBot(), new CommandEvent(e, e.getUser(), e.getChannel(), command, args.toArray(new String[args.size()])));
}
}
}
}
示例14: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessage(MessageEvent<PircBotX> event) {
String message = event.getMessage();
// Search through for command calls
if (!message.startsWith(settings.getTwitchIrcCommand())) {
log.debug("Received Twitch message from {}: {}", event.getUser().getNick(), message);
return;
}
message = message.substring(settings.getTwitchIrcCommand().length());
PersistenceManager pm = pmf.getPersistenceManager();
try {
for (CommandHandler commandHandler : handlers) {
if (commandHandler.handle(event, message, event.getUser().getNick(), pm)) {
return;
}
}
log.debug("Received unknown twitch command from {}: {}", event.getUser().getNick(), message);
} catch (Exception e) {
Consumer<String> messager =
x -> whisperBot.whisper(event.getUser().getNick(), x);
UserException.handleException(log, e, messager);
} finally {
pm.close();
}
}
示例15: onMessage
import org.pircbotx.hooks.events.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessage(MessageEvent<PircBotX> event) {
final User user = event.getUser();
final Channel channel = event.getChannel();
final String message = event.getMessage();
if (user != plugin.getIrcBot().getUserBot()) {
if (!message.startsWith("!")) {
plugin.handleChat(user, channel, message);
}
}
}