本文整理汇总了Java中org.pircbotx.hooks.events.PrivateMessageEvent类的典型用法代码示例。如果您正苦于以下问题:Java PrivateMessageEvent类的具体用法?Java PrivateMessageEvent怎么用?Java PrivateMessageEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PrivateMessageEvent类属于org.pircbotx.hooks.events包,在下文中一共展示了PrivateMessageEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPrivateMessage
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
public void onPrivateMessage(PrivateMessageEvent<Bot> event){
String command = event.getMessage().split(" ")[0];
if(Utils.arrayContains(Reference.ignoredUsers, event.getUser().getNick()) || !event.getMessage().startsWith(Reference.commandPrefix)){ return; }
for(ICommand cmd : Reference.commands){
for(String s : cmd.getAliases()){
if(command.equalsIgnoreCase(Reference.commandPrefix + s)){
try{
cmd.exePrivate(event, Utils.getArgsFromCommand(event.getMessage()));
}catch(Exception e){
e.printStackTrace();
}
return;
}
}
}
}
示例2: onPrivateMessage
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
public void onPrivateMessage(PrivateMessageEvent<MyPircBotX> event) throws Exception{
String message = event.getMessage().toUpperCase();
String user = event.getUser().getNick().toLowerCase();
String admin = event.getBot().getSettings().getAdmin().toLowerCase();
if (user.equals(admin)){
if (message.startsWith("SET DAD JOKE")){
int dadJokeChance = Integer.parseInt(message.substring(12));
event.getBot().getSettings().setDadjokeChance(dadJokeChance);
logger.info("Dad Joke Updated to: " + dadJokeChance + " on bot "
+ event.getBot().getNick());
}
if(message.startsWith("QUIT")){
event.getBot().stopBotReconnect();
event.getBot().sendIRC().quitServer("Daisy, Daisy...");
}
if(message.startsWith("MESSAGE")){
String dest = message.substring(message.indexOf(" "));
dest = dest.substring(0, dest.indexOf(" "));
String reply = message.substring(message.indexOf(dest));
event.getBot().sendIRC().message(dest,reply);
}
}
}
示例3: exe
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
@Override
public void exe(PrivateMessageEvent event, String cmdName, String[] args) throws Exception
{
String msg = "";
if(!args[0].startsWith("#"))
args[0] = "#" + args[0];
for(int i = 1; i < args.length; i++)
{
msg += args[i] + " ";
}
msg = msg.substring(0, msg.length() - 1);
Core.bot.action(args[0], msg);
}
示例4: run
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
@Override
public String run(String[] params, Event<SlyBot> event) {
if (!(event instanceof PrivateMessageEvent)) return "false";
if (params.length == 2) {
//Check if no password is set
if (Settings.operatorpass.equals("")) {
event.getBot().getConfig().updateSetting(Reference.CONFIG_BOTPASS, params[1]);
event.getBot().reply(event, "Sucessfully updated password.");
return "true";
}
} else if (params.length == 3){
if (Settings.operatorpass.equals(params[1])) {
event.getBot().getConfig().updateSetting("operatorpass", params[2]);
event.getBot().reply(event, "Sucessfully updated password.");
return "true";
}
}
return "false";
}
示例5: onPrivateMessage
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
public void onPrivateMessage(PrivateMessageEvent<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(), message.indexOf(" ", youtubes.start()));
try {
youtube.parseVideoInfo(url, pircBotXEvent);
} catch (IllegalArgumentException e) {
pircBotXEvent.getBot().reply(pircBotXEvent, "Sorry, your youtube URL gave me no results");
}
}
}
示例6: handleOpt
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
boolean handleOpt(PrivateMessageEvent<PircBotX> event, String message, OsuUser user,
PersistenceManager pm) throws UserException, IOException {
if (message.equalsIgnoreCase(OPTOUT)) {
user.setAllowsSpectating(false);
log.debug("{} opted out. removing from queue", user.getUserName());
QueuedPlayer oldPlayer = spectator.getCurrentPlayer(pm);
QueuedPlayer newPlayer = spectator.removeFromQueue(pm, user);
if (oldPlayer != null && newPlayer != null) {
twitch.announceAdvance(null, oldPlayer.getPlayer(), newPlayer.getPlayer());
}
respond(event, String.format(OsuResponses.OPTOUT));
return true;
}
if (message.equalsIgnoreCase(OPTIN)) {
user.setAllowsSpectating(true);
respond(event, String.format(OsuResponses.OPTIN));
return true;
}
return false;
}
示例7: handlePosition
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
void handlePosition(PrivateMessageEvent<PircBotX> event, String message, OsuUser user,
PersistenceManager pm) throws UserException, IOException {
OsuUser requestedUser = osuApi.getUser(message, pm, 60 * 60 * 1000);
if (requestedUser == null) {
return;
}
int position = spectator.getQueuePosition(pm, requestedUser);
if (position != -1) {
respond(event, String.format(OsuResponses.POSITION,
requestedUser.getUserName(), position));
} else {
respond(event, String.format(OsuResponses.NOT_IN_QUEUE,
requestedUser.getUserName()));
}
}
示例8: handleGameMode
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
void handleGameMode(PrivateMessageEvent<PircBotX> event, String message, OsuUser user,
PersistenceManager pm) throws UserException, IOException {
if (message.equalsIgnoreCase("osu")) {
user.setGameMode(GameModes.OSU);
} else if (message.equalsIgnoreCase("taiko")) {
user.setGameMode(GameModes.TAIKO);
} else if (message.equalsIgnoreCase("ctb")) {
user.setGameMode(GameModes.CTB);
} else if (message.equalsIgnoreCase("mania")) {
user.setGameMode(GameModes.MANIA);
} else {
throw new UserException("Unknown game mode.");
}
respond(event, Responses.GAME_MODE_CHANGED);
}
示例9: handleLink
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
void handleLink(PrivateMessageEvent<PircBotX> event, String message, OsuUser user,
PersistenceManager pm) throws UserException, IOException {
final TwitchUser userObject =
JdoQueryUtil.getUnique(pm, twitchUser, twitchUser.linkString.eq(message)).orElseThrow(
() -> new UserException(OsuResponses.UNKNOWN_LINK));
if (JdoQueryUtil.getUnique(pm, twitchUser, twitchUser.osuUser.eq(user)).isPresent()) {
throw new UserException(OsuResponses.ALREADY_LINKED);
}
// the twitch side makes sure that a twitch account can't be linked twice.
pm.currentTransaction().begin();
try {
userObject.setOsuUser(user);
userObject.setLinkString(null);
pm.currentTransaction().commit();
} finally {
if (pm.currentTransaction().isActive()) {
pm.currentTransaction().rollback();
}
}
respond(event, String.format(OsuResponses.LINKED,
userObject.getUser().getDisplayName()));
}
示例10: testSelfQueue
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
@Test
public void testSelfQueue() throws Exception {
when(spectator.enqueue(any(), any(), eq(true), any(), eq(true))).thenReturn(EnqueueResult.SUCCESS);
ircBot.onPrivateMessage(new PrivateMessageEvent<PircBotX>(bot, user, "!spec"));
ArgumentCaptor<QueuedPlayer> captor = ArgumentCaptor.forClass(QueuedPlayer.class);
verify(spectator, only()).enqueue(any(), captor.capture(), eq(true),
eq("osu:" + osuApi.getUser("osuIrcUser", pm, 0L).getUserId()), eq(true));
QueuedPlayer request = captor.getValue();
assertEquals("osuIrcUser", request.getPlayer().getUserName());
assertEquals(true, request.isNotify());
verify(outputUser, only()).message(Responses.SELF_QUEUE_SUCCESSFUL);
}
示例11: testGameMode
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
@Test
public void testGameMode() throws Exception {
ircBot.onPrivateMessage(new PrivateMessageEvent<PircBotX>(bot, user, "!gamemode ctb"));
assertEquals(GameModes.CTB, osuApi.getUser("osuIrcUser", pmf.getPersistenceManager(), 0)
.getGameMode());
ircBot.onPrivateMessage(new PrivateMessageEvent<PircBotX>(bot, user, "!gamemode taiko"));
assertEquals(GameModes.TAIKO, osuApi.getUser("osuIrcUser", pmf.getPersistenceManager(), 0)
.getGameMode());
ircBot.onPrivateMessage(new PrivateMessageEvent<PircBotX>(bot, user, "!gamemode mania"));
assertEquals(GameModes.MANIA, osuApi.getUser("osuIrcUser", pmf.getPersistenceManager(), 0)
.getGameMode());
ircBot.onPrivateMessage(new PrivateMessageEvent<PircBotX>(bot, user, "!gamemode osu"));
assertEquals(GameModes.OSU, osuApi.getUser("osuIrcUser", pmf.getPersistenceManager(), 0)
.getGameMode());
}
示例12: testBanchoBotStatusHandler
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
@Test
public void testBanchoBotStatusHandler() throws Exception {
OsuUser tillerino = osuApi.getUser("Tillerino", pm, 0);
PollStatusConsumer consumer = mock(PollStatusConsumer.class);
ircBot.pollIngameStatus(tillerino, consumer);
assertSame(consumer, ircBot.statusConsumers.get(tillerino.getUserId()).peek().getValue());
String osuCommandUser = settings.getOsuCommandUser();
when(user.getNick()).thenReturn(osuCommandUser);
ircBot.onPrivateMessage(new PrivateMessageEvent<PircBotX>(bot, user,
"Stats for (Tillerino)[https://osu.ppy.sh/u/" + tillerino.getUserId() + "] is Playing:"));
verifyNoMoreInteractions(spectator);
verify(consumer).accept(any(), any());
assertTrue(ircBot.statusConsumers.get(tillerino.getUserId()).isEmpty());
}
示例13: onPrivateMessage
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
@Override
public void onPrivateMessage(PrivateMessageEvent e) {
final String command = RUtils.getFirstWord(e.getMessage());
if (!command.equalsIgnoreCase("raw")) return;
final User u = e.getUser();
if (!PermissionHandler.isAuthedOrAdmin(u.getNick(), u.getServer())) {
e.respond("You are not allowed to do this.");
return;
}
String[] args = e.getMessage().trim().split(" ");
args = (String[]) ArrayUtils.subarray(args, 1, args.length);
if (args.length < 1) {
e.respond("Usage: raw [command]");
return;
}
String rawCommand = StringUtils.join(args, " ");
e.getBot().sendRaw().rawLine(rawCommand);
e.respond("Attempted to send raw IRC line: " + rawCommand);
}
示例14: onPrivateMessage
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
@Override
public void onPrivateMessage(PrivateMessageEvent e) {
final String command = RUtils.getFirstWord(e.getMessage());
if (!command.equalsIgnoreCase("command")) return;
final User u = e.getUser();
if (!PermissionHandler.isAuthedOrAdmin(u.getNick(), u.getServer())) {
e.respond("You are not allowed to do this.");
return;
}
String[] args = e.getMessage().split(" ");
args = (String[]) ArrayUtils.subarray(args, 1, args.length);
if (args.length < 1) {
e.respond("Usage: command [command]");
return;
}
final String commandToSend = StringUtils.join(args, " ").trim();
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), commandToSend);
e.respond("Sent command to server: /" + commandToSend);
}
示例15: onPrivateMessage
import org.pircbotx.hooks.events.PrivateMessageEvent; //导入依赖的package包/类
@Override
public void onPrivateMessage(PrivateMessageEvent e) {
final String command = RUtils.getFirstWord(e.getMessage());
if (!command.equalsIgnoreCase("privmsg")) return;
final User u = e.getUser();
if (!PermissionHandler.isAuthedOrAdmin(u.getNick(), u.getServer())) {
e.respond("You are not allowed to do this.");
return;
}
String[] args = e.getMessage().split(" ");
args = (String[]) ArrayUtils.subarray(args, 1, args.length);
if (args.length < 2) {
e.respond("Usage: privmsg [user] [message]");
return;
}
String sendTo = args[0];
String message = StringUtils.join(args, " ", 1, args.length);
final User t = e.getBot().getUserChannelDao().getUser(sendTo);
t.send().message(message);
e.respond("Sent message \"" + message + "\" to " + t.getNick() + ".");
}