Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- using agsXMPP;
- using agsXMPP.protocol.client;
- using agsXMPP.protocol.x.muc;
- using agsXMPP.protocol.x.muc.iq;
- using agsXMPP.protocol.x.muc.iq.admin;
- using agsXMPP.protocol.x.muc.iq.owner;
- using agsXMPP.protocol.x.data;
- using System.Net;
- using System.Collections.Specialized;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace nyash_bot
- {
- class Program
- {
- static XmppClientConnection xmpp;
- static Jid Room;
- static void Main(string[] args)
- {
- xmpp = new XmppClientConnection();
- xmpp.Server = "jabber.ru";
- xmpp.ConnectServer = "jabber.ru";
- xmpp.Username = "gamecoma";
- xmpp.Password = "XXXXXX";
- xmpp.Resource = "";
- xmpp.AutoPresence = true;
- xmpp.AutoRoster = true;
- xmpp.AutoAgents = true;
- xmpp.Priority = 0;
- xmpp.Open();
- xmpp.OnLogin += new ObjectHandler(OnLoginEvent);
- xmpp.OnMessage += new MessageHandler(xmpp_OnMessage);
- xmpp.OnError += new ErrorHandler(xmpp_OnError);
- string ConsoleLine = Console.ReadLine();
- while (true)
- {
- ConsoleLine = Console.ReadLine();
- int delay = 1000;
- switch (ConsoleLine)
- {
- case "exit": return;
- case "reconnect": xmpp.Close(); System.Threading.Thread.Sleep(delay); xmpp.Open(); continue;
- }
- xmpp.Send(new Message(Room, MessageType.groupchat, ConsoleLine));
- }
- }
- static void xmpp_OnError(object sender, Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- static void xmpp_OnMessage(object sender, Message msg)
- {
- string SenderNickname = msg.From.ToString().Replace("gamecoma@conference.jabber.ru/", "");
- Console.WriteLine(SenderNickname + ": " + msg.Body);
- if (msg.XDelay != null) return;
- string pattern = "^![a-zA-Zа-яА-Я]+\\ ";
- string pattern2 = "^![a-zA-Zа-яА-Я]";
- string imgPattern = "\\.(jpeg|jpg|gif|png|bmp|ico|JPEG|JPG|GIF|PNG|BMP|ICO)$";
- string replacement = "";
- Regex r = new Regex(pattern);
- Regex r2 = new Regex(pattern2);
- Regex imgr = new Regex(imgPattern);
- if (r.IsMatch(msg.Body))
- {
- string[] result = Regex.Split(msg.Body, " ");
- string what = "";
- foreach(string newres in result)
- {
- if(!newres.Contains("!"))
- what += newres + " ";
- }
- xmpp.Send(new Message(Room, MessageType.groupchat, SenderNickname + ": " + GetFromSite(result[0], what)));
- }
- else if (r2.IsMatch(msg.Body))
- { xmpp.Send(new Message(Room, MessageType.groupchat, SenderNickname + ": " + GetFromSite(msg.Body))); }
- else
- {
- if (msg.Body.Contains("Няшка: "))
- {
- Regex rgx = new Regex("^Няшка: ");
- string result = rgx.Replace(msg.Body, replacement);
- if (imgr.IsMatch(SenderNickname + ": " + msg.Body))
- {
- xmpp.Send(new Message(Room, MessageType.groupchat, SenderNickname + ": " + GetFromSite("image", result)));
- }
- else if (msg.Body.Contains("Няшка: "))
- {
- xmpp.Send(new Message(Room, MessageType.groupchat, SenderNickname + ": " + GetFromSite("talks", result)));
- }
- }
- }
- }
- public static string GetFromSite(string cmd, string what = "")
- {
- ### cuted ###
- }
- static void OnLoginEvent(object sender)
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Присоединён.");
- xmpp.SendMyPresence();
- MucManager mucManager = new MucManager(xmpp);
- Room = new Jid("gamecoma@conference.jabber.ru");
- mucManager.AcceptDefaultConfiguration(Room);
- mucManager.JoinRoom(Room, "Няшка");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement