Advertisement
Guest User

Untitled

a guest
Jan 20th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5. using agsXMPP;
  6. using agsXMPP.protocol.client;
  7. using agsXMPP.protocol.x.muc;
  8. using agsXMPP.protocol.x.muc.iq;
  9. using agsXMPP.protocol.x.muc.iq.admin;
  10. using agsXMPP.protocol.x.muc.iq.owner;
  11. using agsXMPP.protocol.x.data;
  12. using System.Net;
  13. using System.Collections.Specialized;
  14. using System.Linq;
  15. using System.Text.RegularExpressions;
  16.  
  17. namespace nyash_bot
  18. {
  19.     class Program
  20.     {
  21.         static XmppClientConnection xmpp;
  22.         static Jid Room;
  23.  
  24.         static void Main(string[] args)
  25.         {
  26.             xmpp = new XmppClientConnection();
  27.             xmpp.Server = "jabber.ru";
  28.             xmpp.ConnectServer = "jabber.ru";
  29.             xmpp.Username = "gamecoma";
  30.             xmpp.Password = "XXXXXX";
  31.             xmpp.Resource = "";
  32.            
  33.             xmpp.AutoPresence = true;
  34.             xmpp.AutoRoster = true;
  35.             xmpp.AutoAgents = true;
  36.  
  37.             xmpp.Priority = 0;
  38.            
  39.             xmpp.Open();
  40.  
  41.             xmpp.OnLogin += new ObjectHandler(OnLoginEvent);
  42.             xmpp.OnMessage += new MessageHandler(xmpp_OnMessage);
  43.             xmpp.OnError += new ErrorHandler(xmpp_OnError);
  44.  
  45.             string ConsoleLine = Console.ReadLine();
  46.             while (true)
  47.             {
  48.                 ConsoleLine = Console.ReadLine();
  49.                 int delay = 1000;
  50.                 switch (ConsoleLine)
  51.                 {
  52.                     case "exit": return;
  53.                     case "reconnect": xmpp.Close(); System.Threading.Thread.Sleep(delay); xmpp.Open(); continue;
  54.                 }
  55.                 xmpp.Send(new Message(Room, MessageType.groupchat, ConsoleLine));
  56.             }
  57.  
  58.  
  59.         }
  60.  
  61.         static void xmpp_OnError(object sender, Exception ex)
  62.         {
  63.             Console.WriteLine(ex.Message);
  64.         }
  65.  
  66.         static void xmpp_OnMessage(object sender, Message msg)
  67.         {
  68.             string SenderNickname = msg.From.ToString().Replace("gamecoma@conference.jabber.ru/", "");
  69.  
  70.  
  71.             Console.WriteLine(SenderNickname + ": " + msg.Body);
  72.             if (msg.XDelay != null) return;
  73.  
  74.             string pattern = "^![a-zA-Zа-яА-Я]+\\ ";
  75.             string pattern2 = "^![a-zA-Zа-яА-Я]";
  76.             string imgPattern = "\\.(jpeg|jpg|gif|png|bmp|ico|JPEG|JPG|GIF|PNG|BMP|ICO)$";
  77.             string replacement = "";
  78.  
  79.             Regex r = new Regex(pattern);
  80.             Regex r2 = new Regex(pattern2);
  81.             Regex imgr = new Regex(imgPattern);
  82.  
  83.             if (r.IsMatch(msg.Body))
  84.             {
  85.                 string[] result = Regex.Split(msg.Body, " ");
  86.                 string what = "";
  87.                 foreach(string newres in result)
  88.                 {
  89.                     if(!newres.Contains("!"))
  90.                         what += newres + " ";
  91.                 }
  92.                 xmpp.Send(new Message(Room, MessageType.groupchat, SenderNickname + ": " + GetFromSite(result[0], what)));
  93.             }
  94.             else if (r2.IsMatch(msg.Body))
  95.             { xmpp.Send(new Message(Room, MessageType.groupchat, SenderNickname + ": " + GetFromSite(msg.Body))); }
  96.  
  97.             else
  98.             {
  99.                 if (msg.Body.Contains("Няшка: "))
  100.                 {
  101.                     Regex rgx = new Regex("^Няшка: ");
  102.                     string result = rgx.Replace(msg.Body, replacement);
  103.  
  104.                     if (imgr.IsMatch(SenderNickname + ": " + msg.Body))
  105.                     {
  106.                        
  107.                         xmpp.Send(new Message(Room, MessageType.groupchat, SenderNickname + ": " + GetFromSite("image", result)));
  108.                     }
  109.                     else if (msg.Body.Contains("Няшка: "))
  110.                     {
  111.                         xmpp.Send(new Message(Room, MessageType.groupchat, SenderNickname + ": " + GetFromSite("talks", result)));
  112.                     }
  113.                 }
  114.             }
  115.         }
  116.  
  117.        
  118.        public static string GetFromSite(string cmd, string what = "")
  119.         {
  120.             ### cuted ###
  121.         }
  122.  
  123.         static void OnLoginEvent(object sender)
  124.         {
  125.             Console.ForegroundColor = ConsoleColor.White;
  126.             Console.WriteLine("Присоединён.");
  127.             xmpp.SendMyPresence();
  128.  
  129.             MucManager mucManager = new MucManager(xmpp);
  130.             Room = new Jid("gamecoma@conference.jabber.ru");
  131.  
  132.             mucManager.AcceptDefaultConfiguration(Room);
  133.             mucManager.JoinRoom(Room, "Няшка");
  134.         }
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement