コード例 #1
0
ファイル: TechBotIrcService.cs プロジェクト: MShaffar19/irc
 private string GetMessageSource(MessageContext context)
 {
     if (context is ChannelMessageContext)
     {
         ChannelMessageContext channelContext = context as ChannelMessageContext;
         return(String.Format("#{0}",
                              channelContext.Channel.Name));
     }
     else if (context is UserMessageContext)
     {
         UserMessageContext userContext = context as UserMessageContext;
         return(userContext.User.Nickname);
     }
     else
     {
         throw new InvalidOperationException(String.Format("Unhandled message context '{0}'",
                                                           context.GetType()));
     }
 }
コード例 #2
0
ファイル: TechBotIrcService.cs プロジェクト: MShaffar19/irc
 public void WriteLine(MessageContext context,
                       string message)
 {
     if (context is ChannelMessageContext)
     {
         Thread.Sleep(500);
         ChannelMessageContext channelContext = context as ChannelMessageContext;
         channelContext.Channel.Talk(message);
     }
     else if (context is UserMessageContext)
     {
         UserMessageContext userContext = context as UserMessageContext;
         userContext.User.Talk(message);
     }
     else
     {
         throw new InvalidOperationException(String.Format("Unhandled message context '{0}'",
                                                           context.GetType()));
     }
 }
コード例 #3
0
ファイル: TechBotIrcService.cs プロジェクト: MShaffar19/irc
 private bool ShouldAcceptMessage(IrcMessage message,
                                  out MessageContext context)
 {
     if (message.Command.ToUpper().Equals("PRIVMSG"))
     {
         string channelName;
         string nickname;
         if (GetChannelName(message,
                            out channelName))
         {
             foreach (IrcChannel channel in channels)
             {
                 if (String.Equals(channel.Name, channelName, StringComparison.OrdinalIgnoreCase))
                 {
                     context = new ChannelMessageContext(channel);
                     return(true);
                 }
             }
         }
         else if (GetTargetNickname(message,
                                    out nickname))
         {
             IrcUser targetUser = new IrcUser(m_IrcClient,
                                              nickname);
             if (String.Compare(targetUser.Nickname, botname, true) == 0)
             {
                 IrcUser sourceUser = new IrcUser(m_IrcClient,
                                                  message.PrefixNickname);
                 context = new UserMessageContext(sourceUser);
                 return(true);
             }
         }
     }
     context = null;
     return(false);
 }