当前位置: 首页>>代码示例>>Java>>正文


Java SlackSession类代码示例

本文整理汇总了Java中com.ullink.slack.simpleslackapi.SlackSession的典型用法代码示例。如果您正苦于以下问题:Java SlackSession类的具体用法?Java SlackSession怎么用?Java SlackSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SlackSession类属于com.ullink.slack.simpleslackapi包,在下文中一共展示了SlackSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLastWeeksMessages

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
private List<SlackMessagePosted> getLastWeeksMessages() {
    SlackSession slackSession = getSlackSession();

    SlackChannel slackChannel = slackSession.findChannelByName("publicaties");

    ChannelHistoryModule channelHistoryModule = ChannelHistoryModuleFactory.createChannelHistoryModule(slackSession);

    List<SlackMessagePosted> lastWeeksMesages = IntStream.of(7, 6, 5, 4, 3, 2, 1)
            .mapToObj(daysAgo -> LocalDate.now().minus(daysAgo, ChronoUnit.DAYS))
            .flatMap(date -> getMessagesOfDay(slackChannel, channelHistoryModule, date))
            .collect(toList());

    try {
        slackSession.disconnect();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    return lastWeeksMesages;
}
 
开发者ID:bobvandenberge,项目名称:publicaties-generator,代码行数:21,代码来源:SlackAPI.java

示例2: processUserMessage

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
private void processUserMessage(String messageContent, SlackUser messageSender, SlackSession session, SlackChannel channel) {
    // TODO change it to be processed asynchronously
    // Parse the message content
    String parsedMessage = parseMessage(messageContent);

    if (parsedMessage != null) {
        logger.info("=> Received message from amigo bot:" + parsedMessage);
        try {
            // Some unique job name
            String jobName = "SLACK-MESG-JOB-" + UUID.randomUUID().toString();
            String groupName = JOB_GRP_SLACKBOT;
            JobDataMap params = new JobDataMap();
            params.put(JOB_PARAM_MESSAGE, parsedMessage);
            params.put(JOB_PARAM_MSG_SENDER, messageSender);
            params.put(JOB_PARAM_SLACK_SESSION, session);
            params.put(JOB_PARAM_SLACK_CHANNEL, channel);
            params.put(JOB_PARAM_BOT_TOK, System.getenv("SLACK_BOT_TOKEN"));
            logger.info("Processing message async with params: " + params);
            JobManager.getInstance().scheduleJob(SlackMessageProcessorJob.class, jobName, groupName, params);

        } catch (Exception e) {
            logger.log(Level.SEVERE, "Error in processing message", e);
        }
    }
}
 
开发者ID:sjsucohort6,项目名称:amigo-chatbot,代码行数:26,代码来源:MessageListener.java

示例3: run

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
@Override
public void run(WatchWordBot bot, SlackMessagePosted event,
		LinkedList<String> args, SlackSession session) {
	if (args.isEmpty()) {
		fireIncorrectUsage();
		return;
	}

	String banishedWord = args.pop();

	boolean match = bot.getWordGenerator().isWordPresent(banishedWord);

	if (!match) {
		session.sendMessage(event.getChannel(), "'" + banishedWord
				+ "' not found in wordlist.");
		return;
	}

	session.sendMessage(event.getChannel(),
			"Banish command not implemented.");

}
 
开发者ID:eraether,项目名称:WatchWordBot,代码行数:23,代码来源:BanishCommand.java

示例4: run

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
@Override
public void run(WatchWordBot bot, SlackMessagePosted event,
		LinkedList<String> args, SlackSession session) {
	SlackUser newUser = event.getSender();
	if (!bot.getLobby().hasUser(newUser)) {
		bot.getLobby().addUser(newUser);
		session.sendMessage(bot.getCurrentChannel(),
				WatchWordBot.getUsernameString(event.getSender())
						+ " has joined the game!");
		session.sendMessage(bot.getCurrentChannel(), bot.printFactions());
		bot.printMatchQuality();

	} else {
		session.sendMessage(event.getChannel(),
				WatchWordBot.getUsernameString(event.getSender())
						+ ", you're already in the game!");
	}
}
 
开发者ID:eraether,项目名称:WatchWordBot,代码行数:19,代码来源:JoinCommand.java

示例5: run

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
@Override
public void run(WatchWordBot bot, SlackMessagePosted event,
		LinkedList<String> args, SlackSession session) {
	int penaltyAmount = 0;

	if (!args.isEmpty()) {
		try {
			penaltyAmount = Integer.parseInt(args.pop());
			if (penaltyAmount < 0) {
				throw new IllegalArgumentException(
						"Penalty severity must be >= 0");
			}
		} catch (Exception e) {
			bot.printUsage(event.getChannel(), this.getPrimaryAlias()
					+ " <severity(0+)>");
			return;
		}
	}

	bot.penalizeCurrentFaction(penaltyAmount);
}
 
开发者ID:eraether,项目名称:WatchWordBot,代码行数:22,代码来源:PenaltyCommand.java

示例6: run

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
@Override
public void run(WatchWordBot bot, SlackMessagePosted event,
		LinkedList<String> args, SlackSession session) {
	if (bot.getGameState() == GameState.GAME) {
		session.sendMessage(
				bot.getCurrentChannel(),
				"Game has been canceled by "
						+ WatchWordBot.getUsernameString(event.getSender()));
		bot.partialGameReset();
		session.sendMessage(bot.getCurrentChannel(), bot.printFactions());
	} else {
		session.sendMessage(
				bot.getCurrentChannel(),
				"Lobby has been canceled by "
						+ WatchWordBot.getUsernameString(event.getSender()));
		bot.fullGameReset();
	}
}
 
开发者ID:eraether,项目名称:WatchWordBot,代码行数:19,代码来源:CancelCommand.java

示例7: run

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
@Override
public void run(WatchWordBot bot, SlackMessagePosted event,
		LinkedList<String> args, SlackSession session) {
	if (args.isEmpty()) {
		bot.printUsage(event.getChannel(),
				"[kick|remove] <player1, player2, ...>");
		return;
	}
	while (!args.isEmpty()) {
		String username = args.pop();
		SlackUser user = bot.getLobby().findUserByUsername(username);
		if (user != null) {
			bot.getLobby().removeUser(user);
			session.sendMessage(bot.getCurrentChannel(),
					event.getSender().getUserName() + " removed "
							+ WatchWordBot.getUsernameString(user));
		} else {
			session.sendMessage(bot.getCurrentChannel(),
					"Could not find user already in game with username '"
							+ username + "'.");
		}
	}
	session.sendMessage(bot.getLobby().getChannel(), bot.printFactions());
	bot.printMatchQuality();
}
 
开发者ID:eraether,项目名称:WatchWordBot,代码行数:26,代码来源:KickCommand.java

示例8: run

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
@Override
public void run(WatchWordBot bot, SlackMessagePosted event,
		LinkedList<String> args, SlackSession session) {

	if (bot.getGame().getActingFaction() == null) {
		session.sendMessage(event.getChannel(),
				"Game is currently in an invalid state, there is currently no acting faction!");
		return;
	}
	CompetitiveTime time = bot.getGame().getRemainingTime();
	if (time == null) {
		session.sendMessage(event.getChannel(),
				"There is currently no timer enabled for the "
						+ bot.getGame().getActingFaction().getName()
						+ " team.");
		return;
	}
	session.sendMessage(event.getChannel(),
			"Remaining time for the "
					+ bot.getGame().getActingFaction().getName()
					+ " team: " + time.getTime(TimeUnit.SECONDS)
					+ " secs. (" + time.getOvertime(TimeUnit.SECONDS)
					+ " secs. of overtime)");
}
 
开发者ID:eraether,项目名称:WatchWordBot,代码行数:25,代码来源:TimeCommand.java

示例9: run

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
@Override
public void run(WatchWordBot bot, SlackMessagePosted event,
		LinkedList<String> args, SlackSession session) {
	if (bot.getLobby().getPlayer(event.getSender()) == null) {
		session.sendMessage(event.getChannel(),
				WatchWordBot.getUsernameString(event.getSender())
						+ ", you are currently not in this game!");
		return;
	}
	if (args.isEmpty()) {
		bot.printUsage(event.getChannel(), "guess <word>");
		return;
	}

	String wordBeingGuessed = args.pop();
	bot.makeGuess(wordBeingGuessed, session, event.getChannel(),
			event.getSender());
}
 
开发者ID:eraether,项目名称:WatchWordBot,代码行数:19,代码来源:GuessCommand.java

示例10: handleCommand

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
private synchronized void handleCommand(SlackMessagePosted event,
		SlackSession session) {
	updateLastIssuedCommandTime();
	LinkedList<String> args = new LinkedList<String>();
	args.addAll(Arrays.asList(event.getMessageContent().split("\\s+")));// event.getMessageContent().split(" ");

	boolean matchingPrefix = true;
	if (DEBUG) {
		String debugPrefix = args.pop().toLowerCase();
		matchingPrefix = debugPrefix.equals("d");
	}

	if (matchingPrefix) {
		String commandText = args.pop().toLowerCase();
		List<Command> commands = generateCommands(event, args, session);
		Command matchingCommand = findMatchingCommand(commandText, args,
				commands, event.getChannel());
		if (matchingCommand != null) {
			matchingCommand.run(this, event, args, session);
		}
	} else {
		handlePlainTextMessage(event, session);
	}
}
 
开发者ID:eraether,项目名称:WatchWordBot,代码行数:25,代码来源:WatchWordBot.java

示例11: generateCommands

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
public List<Command> generateCommands(final SlackMessagePosted event,
		final LinkedList<String> args, final SlackSession session) {
	List<Command> commands = new ArrayList<Command>();
	commands.add(new BanishCommand());
	commands.add(new BotCommand());
	commands.add(new CancelCommand());
	commands.add(new ClueCommand());
	commands.add(new DefineCommand());
	commands.add(new EndCommand());
	commands.add(new FeatCommand());
	commands.add(new GridCommand());
	commands.add(new GuessCommand());
	commands.add(new HelpCommand());
	commands.add(new JoinCommand());
	commands.add(new KickCommand());
	commands.add(new ListCommand());
	commands.add(new LobbyCommand());
	commands.add(new PenaltyCommand());
	commands.add(new StartCommand());
	commands.add(new SwapCommand());
	commands.add(new SyncCommand());
	commands.add(new TimeCommand());
	commands.add(new WinCommand());
	return commands;
}
 
开发者ID:eraether,项目名称:WatchWordBot,代码行数:26,代码来源:WatchWordBot.java

示例12: onEvent

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
@Override
public void onEvent(
    final SlackMessagePosted event, final SlackSession session
) {
    final String channel = event.getChannel().getId();
    if (this.channel.equals(channel)) {
        final User user = new User.UserBuilder().withSlackNick(
            event.getSender().getUserName()
        ).build();
        final List<String> codes = Stream.of(
            event.getMessageContent().split("\n")
        ).filter(
            code -> this.progress.codes().contains(code)
        ).collect(Collectors.toList());
        if (!codes.isEmpty()) {
            this.progress.markProgressDone(user, codes.toArray(
                new String[codes.size()])
            );
            this.progress.reactToUserCodes(event.getTimeStamp(), channel);
        }
    }
}
 
开发者ID:JujaLabs,项目名称:microservices,代码行数:23,代码来源:ProgressSlackChannel.java

示例13: marksProgressDoneIfMatchesCodes

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
/**
 * ProgressSlackChannel can mark codes done with service.
 */
@Test
public void marksProgressDoneIfMatchesCodes() throws Exception {
    final ProgressService service = Mockito.mock(ProgressService.class);
    final String id = "D0FUQEQUF";
    final ProgressSlackChannel channel = new ProgressSlackChannel(
        id, service
    );
    Mockito.when(service.codes()).thenReturn(
        new HashSet<>(Arrays.asList(
            "+code1", "+code2"
        ))
    );
    final String user = "juja";
    final SlackMessagePosted message = this.createMessageWithUserAndChannel(
        id, user, "+code2\n+code3\n+code1"
    );
    channel.onEvent(message, Mockito.mock(SlackSession.class));
    Mockito.verify(service).markProgressDone(
        new User.UserBuilder().withSlackNick(user).build(),
        "+code2", "+code1"
    );
}
 
开发者ID:JujaLabs,项目名称:microservices,代码行数:26,代码来源:ProgressSlackChannelTest.java

示例14: filtersChannel

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
/**
 * ProgressSlackChannel can filter channel.
 */
@Test
public void filtersChannel() throws Exception {
    final ProgressService service = Mockito.mock(ProgressService.class);
    final ProgressSlackChannel channel = new ProgressSlackChannel(
        "D0FUQEQUF", service
    );
    Mockito.when(service.codes()).thenReturn(
        new HashSet<>(Arrays.asList(
            "+code1", "+code2"
        ))
    );
    final String user = "juja";
    final SlackMessagePosted message = this.createMessageWithUserAndChannel(
        "AnotherChannelId", user, "+code2\n+code3\n+code1"
    );
    channel.onEvent(message, Mockito.mock(SlackSession.class));
    Mockito.verify(service, Mockito.never()).markProgressDone(
        new User.UserBuilder().withSlackNick(user).build(),
        "+code2", "+code1"
    );
}
 
开发者ID:JujaLabs,项目名称:microservices,代码行数:25,代码来源:ProgressSlackChannelTest.java

示例15: reactsToMessage

import com.ullink.slack.simpleslackapi.SlackSession; //导入依赖的package包/类
/**
 * ProgressSlackChannel can reacts to user messages.
 */
@Test
public void reactsToMessage() throws Exception {
    final ProgressService service = Mockito.mock(ProgressService.class);
    final String chnl = "ProgressChannel";
    final ProgressSlackChannel channel = new ProgressSlackChannel(
        chnl, service
    );
    Mockito.when(service.codes()).thenReturn(
        new HashSet<>(Arrays.asList(
            "+code1", "+code2"
        ))
    );
    final String user = "juja";
    final SlackMessagePosted message = this.createMessageWithUserAndChannel(
        chnl, user, "+code2\n+code3\n+code1"
    );
    final String msg = "messageId";
    Mockito.when(message.getTimeStamp()).thenReturn(msg);
    channel.onEvent(message, Mockito.mock(SlackSession.class));
    Mockito.verify(service).reactToUserCodes(msg, chnl);
}
 
开发者ID:JujaLabs,项目名称:microservices,代码行数:25,代码来源:ProgressSlackChannelTest.java


注:本文中的com.ullink.slack.simpleslackapi.SlackSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。