博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
『转载』使用DotMSN 2.0开发MSN机器人
阅读量:6950 次
发布时间:2019-06-27

本文共 2274 字,大约阅读时间需要 7 分钟。

在网络上查阅了很多关于通过DotMSN开发包来开发MSN机器人的小程序,为了验证其正确性,本人亲自测试,发现了这样一篇文章,他写的很好,没有问题。下面就贴出源代码,和大家分享。请提前在项目引用中添加下载到的DotMSN.dll文件,再using DotMSN;

0.jpg 

 

ContractedBlock.gif
ExpandedBlockStart.gif
Code
using System;   
  
using System.Collections.Generic;   
  
using System.ComponentModel;   
  
using System.Data;   
  
using System.Drawing;   
  
using System.Text;   
  
using System.Windows.Forms;   
  
using DotMSN;   
  
  
  
namespace MSNBotTest   
  
{   
  
    
public partial class Form1 : Form   
  
    {   
  
        
public Form1()   
  
        {   
  
            InitializeComponent();   
  
        }   
  
        DotMSN.Messenger msn 
= new DotMSN.Messenger();//初始化一个Messenger对象用来登陆服务器   
  
        
private void button1_Click(object sender, EventArgs e)   
  
        {   
  
            
try  
  
            {   
  
  
  
                statusBar1.Text
="正在连接到服务器dot.gif";   
  
                msn.ConversationCreated 
+= new Messenger.ConversationCreatedHandler(ConversationCreated);   
  
                msn.Connect(textBox1.Text, textBox2.Text);
//前一个为用户名,后一个为密码   
  
                msn.SynchronizeList();初始化列表,用来显示在线用户   
  
                statusBar1.Text
="成功连接到服务器";   
  
                   
  
            }   
  
            
catch (DotMSN.MSNException me)   
  
            {   
  
                MessageBox.Show(me.ToString());   
  
            }   
  
  
  
        }   
  
        
private void ReadMsg(Conversation sender, DotMSN.MessageEventArgs e)   
  
        {   
  
            
//string content;   
  
            
string input = e.Message.Text;   
  
            
if (input.Equals("j"))   
  
            {   
  
                
string content = "你好,我是机器人小范";   
  
                sender.SendMessage(content);   
  
            }   
  
  
  
            
else if (input.StartsWith("H"))   
  
            {   
  
                
string content = "我很笨,很多功能还在开发哦";   
  
                sender.SendMessage(content);   
  
            }   
  
            
else  
  
            {   
  
                
string content = "你好啊,我不知道你说的是什么啊,有什么事情请输入H";   
  
                sender.SendMessage(content);   
  
            }   
  
  
  
        }   
  
        
private void ConversationCreated(Messenger sender, ConversationEventArgs e)   
  
        {   
  
               
  
            e.Conversation.MessageReceived 
+= new Conversation.MessageReceivedHandler(ReadMsg);   
  
        }   
  
  
  
        
private void button2_Click(object sender, EventArgs e)   
  
        {   
  
            
try  
  
            {   
  
                ShowAll();   
  
            }   
  
            
catch (Exception ex)   
  
            {   
  
                MessageBox.Show(ex.ToString());   
  
            }   
  
        }   
  
        
private void ShowAll()   
  
        {   
  
            
try  
  
            {   
  
                msn.SetStatus(MSNStatus.Online);   
  
                AllListView.Clear();   
  
                
foreach (Contact contact in msn.GetListEnumerator(MSNList.ForwardList))   
  
                {   
  
                    ListViewItem item 
= new ListViewItem(contact.Name);   
  
                    item.Tag 
= contact;   
  
                    
if (contact.Status != MSNStatus.Offline)   
  
                    {   
  
                        AllListView.Items.Add((item 
+ "在线").Remove(014));   
  
                    }   
  
                    
//                    if(contact.Status == MSNStatus.Busy)   
  
                    
//                    {   
  
                    
//                        AllListView.Items.Add(item+"忙碌");   
  
                    
//                    }   
  
                    
//                    if(contact.Status == MSNStatus.Away)   
  
                    
//                    {   
  
                    
//                        AllListView.Items.Add(item+"离开");   
  
                    
//                    }   
  
                    
else  
  
                    {   
  
                        AllListView.Items.Add((item 
+ "离线").Remove(014));   
  
                    }   
  
  
  
                }   
  
  
  
            }   
  
            
catch (Exception ex)   
  
            {   
  
                MessageBox.Show(ex.ToString());   
  
            }   
  
        }   
  
  
  
        
private void button3_Click(object sender, EventArgs e)//用来断开连接   
  
        {   
  
            msn.CloseConnection();   
  
        }   
  
    }   
  
}  
你可能感兴趣的文章
Vmware 安装 Fedora 18 注意事项
查看>>
《C++ Primer Plus(第6版)中文版》——1.2 C++简史
查看>>
使用git遇到的问题汇总
查看>>
《Python极客项目编程 》——第2章 万花尺 2.1 参数方程
查看>>
《C++游戏编程入门(第4版)》——1.2 编写第一个C++程序
查看>>
《黑客秘笈——渗透测试实用指南(第2版)》—第1章1.6学习
查看>>
SpringBoot多跨域请求的支持(JSONP)
查看>>
几个Cache方案的比较
查看>>
【云栖大会】创无止境 YunOS云栖大会诠释万物互联
查看>>
Python基础教程
查看>>
MySQL · 特性分析 · 执行计划缓存设计与实现
查看>>
Java基础知识回顾--正则表达式
查看>>
java NIO
查看>>
声音就是你的武器!这样的攻防大赛你一定没有见过!
查看>>
CUDA入门(六) 异步并行执行解析
查看>>
内容分发网络(CDN)关键技术、架构与应用(一)
查看>>
linux 添加链接与删除链接(ln命令的用法)
查看>>
HTTP中Get与Post的区别
查看>>
Dart基础-泛型和库
查看>>
Android中文API(114)——TabWidget
查看>>