private bool TestHelpMessage(ISummonable middleware, IChatServiceConnection chatServiceConnection, ChatMessageModel message) { // expect exactly 1 instance of the action verb var helpMatchPattern = string.Concat(middleware.GetSummonVerb(), "{1}\\s?help\\s*"); // match for message format "<bot mention> <verb> *rest of message*" and return *rest of message* to middleware Regex testRegex = new Regex(helpMatchPattern, RegexOptions.IgnoreCase); Match match = testRegex.Match(message.Body); return(match.Success); }
private async void channelsUpdated(IChatServiceConnection chatServiceConnection, ICollection <ChannelModel> channels) { // TODO: mutex var relays = _relays.Where(c => c.RelayAttendance && (c.FromChatService == chatServiceConnection)); foreach (var relay in relays) { if (relay.ToChannelId != null) { var channelUpdate = channels.SingleOrDefault(c => (c.Id == relay.FromChannelId)); if (channelUpdate != null) { await processAttendanceUpdateAsync(relay, channelUpdate); } } } }
private async void chatServiceConnected(object sender, EventArgs e) { IChatServiceConnection chatServiceConnection = sender as IChatServiceConnection; var relays = _relays.Where(r => (r.ToChatService == chatServiceConnection) || (r.FromChatService == chatServiceConnection)) .Distinct(); foreach (var relay in relays) { // Update channel IDs if (relay.FromChatService == chatServiceConnection) { relay.FromChannelId = await chatServiceConnection .GetChannelIdFromChannelNameAsync(relay.FromChannelName); } if (relay.ToChatService == chatServiceConnection) { relay.ToChannelId = await chatServiceConnection .GetChannelIdFromChannelNameAsync(relay.ToChannelName); } // Are both services ready to roll? if (!(relay.IsActive) && (relay.FromChatService.IsConnected && relay.ToChatService.IsConnected)) { if (relay.RelayAttendance) { // Send first update channelsUpdated(relay.FromChatService, relay.FromChatService.Channels); // Subscribe to future updates relay.FromChatService.ChannelsUpdated += (_, channels) => channelsUpdated(relay.FromChatService, channels); } relay.IsActive = true; } } }
private string ProcessSummonMessage(ISummonable middleware, IChatServiceConnection chatServiceConnection, ChatMessageModel message) { // expect exactly 1 instance of the action verb var verbMatchPattern = string.Concat(middleware.GetSummonVerb(), "{1}\\s?("); // match for message format "<bot mention> <verb> *rest of message*" and return *rest of message* to middleware var testPattern = string.Concat(verbMatchPattern, middleware.MentionRegex, ")"); Regex testRegex = new Regex(testPattern, RegexOptions.IgnoreCase); Match match = testRegex.Match(message.Body); if (!match.Success) { return(null); } var strippedMessageMatchGroup = match.Groups[1]; return(strippedMessageMatchGroup.Value == null ? string.Empty : strippedMessageMatchGroup.Value); }
private void onChatServiceConnectionInterruption( IChatServiceConnection connection, Exception exception, (uint retryNumber, uint nextRetrySeconds) retries)