Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Matrix;
- using Matrix.Xmpp;
- using Matrix.Xmpp.Client;
- using PVPNetConnect;
- namespace LoL_AutoAdder
- {
- public class Bot : IDisposable
- {
- // nested class
- public class LeagueRank
- {
- protected bool Equals(LeagueRank other)
- {
- return (int)Ranking + Division == (int)other.Ranking + other.Division;
- }
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != GetType()) return false;
- return Equals((LeagueRank)obj);
- }
- public override int GetHashCode()
- {
- unchecked
- {
- return ((int)Ranking * 397) ^ Division;
- }
- }
- public LeagueRank(Rank pRank, int pDiv)
- {
- Ranking = pRank;
- Division = pDiv;
- }
- public Rank Ranking { get; }
- public enum Rank
- {
- Unranked = 0x0,
- Bronze = 0x5,
- Silver = 0xA,
- Gold = 0xF,
- Platinum = 0x14,
- Diamond = 0x19,
- }
- public int Division { get; }
- public static bool operator ==(LeagueRank pLeague, LeagueRank pLeague2)
- {
- if (ReferenceEquals(pLeague, null))
- {
- return ReferenceEquals(pLeague2, null);
- }
- return pLeague.Equals(pLeague2);
- }
- public static bool operator !=(LeagueRank pLeague, LeagueRank pLeagu2)
- {
- return !(pLeague == pLeagu2);
- }
- public static bool operator <(LeagueRank pLeague, LeagueRank pLeague2)
- {
- return (int)pLeague.Ranking + (5 - pLeague.Division) < (int)pLeague2.Ranking + (5 - pLeague2.Division);
- }
- public static bool operator >(LeagueRank pLeague, LeagueRank pLeague2)
- {
- return (int)pLeague.Ranking + (5 - pLeague.Division) > (int)pLeague2.Ranking + (5 - pLeague2.Division);
- }
- public static bool operator <=(LeagueRank pLeague, LeagueRank pLeague2)
- {
- return pLeague == pLeague2 || pLeague < pLeague2;
- }
- public static bool operator >=(LeagueRank pLeague, LeagueRank pLeague2)
- {
- return pLeague == pLeague2 || pLeague > pLeague2;
- }
- public static LeagueRank ParseFromString(string pInput)
- {
- if (!pInput.Contains(' '))
- {
- return new LeagueRank(Rank.Unranked, 0);
- }
- else
- {
- string[] lParts = pInput.Split(' ');
- string lFirst = lParts[0];
- string lSecond = lParts[1];
- if (string.IsNullOrWhiteSpace(lSecond))
- return new LeagueRank(Rank.Unranked, 0);
- Rank lRank = Rank.Unranked;
- switch (lFirst)
- {
- case "BRONZE":
- lRank = Rank.Bronze;
- break;
- case "SILVER":
- lRank = Rank.Silver;
- break;
- case "GOLD":
- lRank = Rank.Gold;
- break;
- case "PLATINUM":
- lRank = Rank.Platinum;
- break;
- case "DIAMOND":
- lRank = Rank.Diamond;
- break;
- }
- int lVal = 0;
- if (lSecond.Length != 2)
- {
- foreach (var item in lSecond)
- {
- if (item == 'V')
- lVal = 4;
- else if (item == 'I')
- lVal++;
- }
- }
- else
- {
- foreach (var item in lSecond)
- {
- if (item == 'V')
- lVal = 5;
- else if (item == 'I')
- lVal++;
- }
- }
- return new LeagueRank(lRank, lVal);
- }
- }
- }
- public int ReconnectionCount { get; set; }
- bool _disposed;
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- public long FriendrequestsSend { get; private set; }
- public int CountFriends { get; private set; }
- public EventHandler Botdisposed;
- protected virtual void Dispose(bool disposing)
- {
- if (_disposed)
- return;
- if (disposing)
- {
- using (lol_usersEntities lContext = new lol_usersEntities())
- {
- for (var x = _actualOnes.Count - 1; x >= 0; x--)
- {
- int lValue = int.Parse(_actualOnes[x]);
- var lUser = from it in lContext.euw
- where it.SummonerID == lValue
- select it;
- var lName = UserName.ToLower();
- var lRegion = WebScraper.Region.ToLower();
- var lBot = from ad in lContext.euwbots
- where ad.SummonerName == lName && ad.Region == lRegion
- select ad;
- try
- {
- if (lUser.Any())
- {
- foreach (var user in lUser)
- {
- user.Scraped = false;
- }
- }
- if (lBot.Any())
- {
- foreach (var item in lBot)
- {
- item.Active = false;
- }
- }
- }
- catch (System.Reflection.TargetException ey)
- {
- Console.WriteLine(ey.Message);
- }
- }
- lContext.SaveChanges();
- }
- FriendrequestsSend = WebScraper.Logger.FriendrequestsSend;
- CountFriends = WebScraper.Logger.CountFriends;
- Botdisposed?.Invoke(this, System.EventArgs.Empty);
- WebScraper.Logger.LoggedIn = false;
- WebScraper.Stop();
- WebScraper = null;
- Chat?.Close();
- Client?.Disconnect();
- Chat = null;
- Client = null;
- _loggedIn = false;
- }
- _disposed = true;
- }
- //Chatclient
- public XmppClient Chat { get; private set; } = new XmppClient();
- //Gameclient
- public PVPNetConnection Client { get; private set; } = new PVPNetConnection();
- public bool SummSite { get; }
- public Region Region { get; private set; }
- public bool AcceptFriends { get; set; }
- //Taking the Username's from lolsummoners
- public Scraper WebScraper { get; set; }
- //Class to progress the Input
- private readonly Tokenizer _token = new Tokenizer();
- //Serverdomain of every Region
- private readonly Dictionary<Region, string> _regionDictionary = new Dictionary<Region, string>();
- private readonly Dictionary<string, Region> _newDict = new Dictionary<string, Region>();
- //All Commands
- private readonly Dictionary<string, ParamAction> _newAction = new Dictionary<string, ParamAction>();
- private static readonly ExpressionParser Express;
- public event EventHandler<SummonerEventArgs> GameStart;
- public event EventHandler<SummonerEventArgs> GameEnd;
- public event EventHandler LoginSucceed;
- /// <summary>
- /// Signature of commands
- /// </summary>
- /// <param name="pParameter">All parameters of commands</param>
- /// <returns></returns>
- public delegate Task<string> ParamAction(Jid summonerJid, params string[] pParameter);
- private bool _loggedIn;
- public bool LoggedIn
- {
- get { return _loggedIn; }
- set
- {
- _loggedIn = value;
- if (WebScraper != null)
- WebScraper.Logger.LoggedIn = value;
- }
- }
- /// <summary>
- /// Functionpointer to function that shall get executed when no command got matched by the message
- /// </summary>
- public ParamAction DefaultCommand { get; set; }
- /// <summary>
- /// starts the bot
- /// </summary>
- /// <param name="pUsername">Account name to log in</param>
- /// <param name="pPassword">Account password to log in</param>
- /// <param name="pRegion">Region to log in</param>
- public void Start(string pUsername, string pPassword, Region pRegion)
- {
- PrepareStart(pUsername, pPassword, pRegion);
- Start();
- }
- public void Start()
- {
- ChatLogin(UserName, Password, Region);
- if (SummSite) ClientLogin(UserName, Password, Region);
- }
- public void PrepareStart(string pUsername, string pPassword, Region pRegion)
- {
- Region = pRegion;
- UserName = pUsername;
- Password = pPassword;
- }
- public void Start(string pUsername, string pPassword, string pRegion)
- {
- pRegion = pRegion.Trim('\r').ToLower();
- pUsername = pUsername.Trim('\r');
- pPassword = pPassword.Trim('\r');
- if (!_newDict.ContainsKey(pRegion))
- return;
- WebScraper.Region = pRegion;
- WebScraper.Logger.Username = pUsername;
- Start(pUsername, pPassword, _newDict[pRegion]);
- }
- private readonly Random _random = new Random(DateTime.Now.Millisecond);
- public bool FullRequest { get; private set; }
- private readonly List<string> _users = new List<string>();
- private void Users_Found(object sender, UserFoundEventArgs e)
- {
- if (_disposed)
- {
- throw new ObjectDisposedException("Disposed");
- }
- _actualOnes = e.Users.ToList();
- using (new lol_usersEntities())
- {
- foreach (var item in e.Users)
- {
- //for (int i=0; i < 3; i++)
- //{
- if (_disposed)
- {
- return;
- }
- try
- {
- if (FullRequest)
- {
- System.Threading.Thread.Sleep(_waitTime + _max);
- }
- //while (lSummonerID == "0")
- //{
- // System.Threading.Thread.Sleep(10000);
- // lSummonerID = (await lID).SummonerId.ToString();
- //}
- var lJid = "sum" + item + "@pvp.net";
- AddFriend(lJid, false);
- _users.Add(lJid);
- //this.SendMessage(lJid, this.Spamtext);
- //this.RemoveFriend(lJid, true);
- //using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
- //{
- System.Threading.Thread.Sleep(_random.Next(_min, _max));
- //int isSuccess = Convert.ToInt32(item);
- //var lUser = from it in lContext.euw
- // where it.SummonerID == isSuccess
- // select it;
- try
- {
- //if (lUser.Count() > 0)
- //{
- // foreach (var user in lUser)
- // {
- // user.Friendreqest = true;
- // }
- // lContext.SaveChanges();
- //}
- }
- catch (System.Reflection.TargetException ey)
- {
- Console.WriteLine(ey.Message);
- }
- //}
- System.Threading.Thread.Sleep(_random.Next(_min, _max));
- _actualOnes.Remove(item);
- }
- catch
- {
- // ignored
- }
- }
- //System.Threading.Thread.Sleep(10000);
- }
- }
- private List<string> _actualOnes = new List<string>();
- /// <summary>
- /// Adds a new command
- /// </summary>
- /// <param name="pCommand">Text to execute the command (case insensitive)</param>
- /// <param name="pExecution">Functionpointer to function that shall get executed</param>
- /// <returns>True if successful otherwise false</returns>
- public bool AddCommand(string pCommand, ParamAction pExecution)
- {
- if (!_newAction.ContainsKey(pCommand.ToLower()))
- {
- _newAction.Add(pCommand.ToLower(), pExecution);
- return true;
- }
- return false;
- }
- /// <summary>
- /// Removes a existing command
- /// </summary>
- /// <param name="pCommand">Command to remove</param>
- /// <returns>True if successful otherwise false</returns>
- public bool RemoveCommand(string pCommand)
- {
- if (_newAction.ContainsKey(pCommand.ToLower()))
- {
- _newAction.Remove(pCommand.ToLower());
- return true;
- }
- return false;
- }
- private string _spamText;
- public string Spamtext
- {
- get { return _spamText; }
- set
- {
- _spamText = value;
- WebScraper.Logger.Message = value;
- }
- }
- private readonly int _min;
- private readonly int _max;
- private readonly int _waitTime;
- public Bot(LeagueRank pMin, LeagueRank pMax, int pMinim, int pMaxim, int pLvlmin, int pLvlmax, string pSpamtext,
- string pClientVersion, bool pSumm, int pWaitTime, DateTime pDate)
- {
- From = pMin;
- To = pMax;
- _min = pMinim;
- _max = pMaxim;
- Min = pLvlmin;
- Max = pLvlmax;
- _waitTime = pWaitTime;
- _clientVersion = pClientVersion;
- _regionDictionary.Add(Region.EUW, "euw1");
- _regionDictionary.Add(Region.EUN, "eun1");
- _regionDictionary.Add(Region.NA, "na2");
- _regionDictionary.Add(Region.TR, "tr");
- _regionDictionary.Add(Region.RU, "ru");
- _regionDictionary.Add(Region.BR, "br");
- _regionDictionary.Add(Region.OCE, "oc1");
- _regionDictionary.Add(Region.KR, "kr");
- _regionDictionary.Add(Region.LAN, "la1");
- _regionDictionary.Add(Region.LAS, "la2");
- _newDict.Add("euw", Region.EUW);
- _newDict.Add("eune", Region.EUN);
- _newDict.Add("na", Region.NA);
- _newDict.Add("tr", Region.TR);
- _newDict.Add("ru", Region.RU);
- _newDict.Add("br", Region.BR);
- _newDict.Add("oce", Region.OCE);
- _newDict.Add("kr", Region.KR);
- _newDict.Add("lan", Region.LAN);
- _newDict.Add("las", Region.LAS);
- //to be continued
- Client.OnLogin += Client_OnLogin;
- Chat.OnLogin += Chat_OnLogin;
- Chat.OnMessage += Chat_OnMessage;
- _token.Parsed += Token_Parsed;
- Chat.OnPresence += On_Presence;
- Client.OnDisconnect += Client_Disconnected;
- Chat.OnClose += Chat_Close;
- SummSite = pSumm;
- WebScraper = new DatabaseScraper(pMin, pMax, 0, pDate);
- WebScraper.UserFound += Users_Found;
- Chat.AutoRoster = false;
- Client.OnError += Client_Error;
- Chat.OnError += Chat_Error;
- Chat.OnRosterItem += Roster_Requested;
- Chat.OnRosterEnd += Roster_End;
- Spamtext = pSpamtext;
- DefaultCommand = Message;
- ReconnectionCount = 1;
- }
- public LeagueRank From { get; private set; }
- public LeagueRank To { get; private set; }
- private void Chat_Error(object sender, ExceptionEventArgs e)
- {
- FileLogger.AddMessage($@"Chat_Error: {e.Exception.Message}.
- Bot: LoggedIn={LoggedIn}, Username={UserName}, ReconnectionCount={ReconnectionCount}");
- Dispose();
- }
- private void Client_Error(object sender, PVPNetConnect.Error e)
- {
- FileLogger.AddMessage($@"Client_Error: {e.ErrorCode}, {e.Type}, {e.Message}.
- Bot: LoggedIn={ LoggedIn}, Username={ UserName}, ReconnectionCount={ReconnectionCount}");
- Dispose();
- }
- static Bot()
- {
- Express = new ExpressionParser();
- }
- public static IEnumerable<System.Tuple<string, string, string, Bot>> CreateFromString(string pInput, string pClientVersion, bool pEndsite)
- {
- return Express.ParseExpression(pInput, pClientVersion, pEndsite);
- }
- private void Chat_Close(object sender, Matrix.EventArgs e)
- {
- FileLogger.AddMessage($@"Chat_Close: {e.State}.
- Bot: LoggedIn={ LoggedIn}, Username={ UserName}, ReconnectionCount={ReconnectionCount}");
- Dispose();
- //this._chat = new XmppClient();
- //this._client = new PVPNetConnection();
- //this.Start(this._username, this._password, this._Region);
- }
- private void Client_Disconnected(object sender, System.EventArgs e)
- {
- //this._chat = new XmppClient();
- //this._client = new PVPNetConnection();
- //this.Start(this._username, this._password, this._Region);
- }
- /// <summary>
- /// Add user to friendlist
- /// </summary>
- /// <param name="pSummonerId">SummonerJID of User</param>
- /// <param name="pOut"></param>
- public void AddFriend(Jid pSummonerId, bool pOut)
- {
- if (Chat == null)
- return;
- Chat.Send(CreatePresence(pOut ? PresenceType.subscribed : PresenceType.subscribe, pSummonerId));
- if (!pOut) WebScraper.Logger.FriendrequestsSend++;
- }
- private Presence CreatePresence(PresenceType pType, Jid pSummonerId)
- {
- var newPresence = new Presence(pType)
- {
- Priority = 0,
- To = pSummonerId
- };
- return newPresence;
- }
- /// <summary>
- /// Remove friend of friendlist
- /// </summary>
- /// <param name="pSummonerId">SummonerJID of friend</param>
- /// <param name="pOut">???</param>
- public void RemoveFriend(Jid pSummonerId, bool pOut)
- {
- Chat?.Send(CreatePresence(pOut ? PresenceType.unsubscribed : PresenceType.unsubscribe, pSummonerId));
- }
- //private int _acceptedFriends;
- private async void On_Presence(object sender, PresenceEventArgs e)
- {
- if (e.Presence.Error != null && e.Presence.Error.Type == Matrix.Xmpp.Base.ErrorType.wait)
- {
- if (e.Presence.Error.Text == "max_outgoing_invites" || e.Presence.Error.Text == "max_incoming_invites")
- {
- FullRequest = true;
- await Task.Delay(_waitTime);
- var lList = _users.Select(item => (string)item.Clone()).ToList();
- foreach (var item in lList)
- {
- try
- {
- //while (lSummonerID == "0")
- //{
- // System.Threading.Thread.Sleep(10000);
- // lSummonerID = (await lID).SummonerId.ToString();
- //}
- RemoveFriend(item, false);
- //this.SendMessage(lJid, this.Spamtext);
- //this.RemoveFriend(lJid, true);
- await Task.Delay(_random.Next(_min, _max));
- }
- catch
- {
- // ignored
- }
- }
- _users.RemoveAll(elem => lList.Contains(elem));
- FullRequest = false;
- }
- else
- {
- using (lol_usersEntities lContext = new lol_usersEntities())
- {
- var lUser = from item in lContext.euwbots
- where item.SummonerName.ToLower() == UserName.ToLower()
- select item;
- try
- {
- if (lUser.Any())
- lUser.First().Fullfriendlist = true;
- lContext.SaveChanges();
- }
- catch (System.Reflection.TargetException ey)
- {
- Console.WriteLine(ey.Message);
- }
- FileLogger.AddMessage($@"On_Presence: {e.State}, {e.Presence.Error}, {e.Presence.Nick}.
- Bot: LoggedIn={ LoggedIn}, Username={ UserName}, ReconnectionCount={ReconnectionCount}");
- // Dispose();
- }
- }
- }
- if (e.Presence.Type == PresenceType.subscribe && AcceptFriends && !_disposed)
- {
- AddFriend(e.Presence.From, true);
- DefaultCommand?.BeginInvoke(e.Presence.From, new[] { string.Empty }, async item =>
- {
- Task<string> lResult = DefaultCommand.EndInvoke(item);
- var result = await lResult;
- SendMessage(e.Presence.From, result);
- RemoveFriend(e.Presence.From, false);
- lResult.Dispose();
- }, null);
- }
- else if (e.Presence.Type == PresenceType.subscribed && !_disposed)
- {
- //_acceptedFriends++;
- //_lastAccepted = DateTime.Now;
- WebScraper.Logger.CountFriends++;
- //using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
- //{
- // var lUser = from item in lContext.euw
- // where item.SummonerID.ToString() == e.Presence.From.User
- // select item;
- // try
- // {
- // if (lUser.Count() > 0)
- // lUser.First().Accept = true;
- // lContext.SaveChanges();
- // }
- // catch (System.Reflection.TargetException ey)
- // {
- // Console.WriteLine(ey.Message);
- // }
- //}
- DefaultCommand?.BeginInvoke(e.Presence.From, new[] { string.Empty }, async item =>
- {
- Task<string> lResult = DefaultCommand.EndInvoke(item);
- var result = await lResult;
- SendMessage(e.Presence.From, result);
- RemoveFriend(e.Presence.From, false);
- lResult.Dispose();
- }, null);
- }
- var presenceMessage = e.Presence.ToString();
- if (GameStarted(presenceMessage) && e.Presence.Show == Show.dnd && LoggedIn && GameStart != null)
- {
- GameStart(sender, new SummonerEventArgs(e.Presence.From));
- }
- else if (GameEnded(presenceMessage) && e.Presence.Show == Show.chat && LoggedIn)
- {
- GameEnd?.Invoke(sender, new SummonerEventArgs(e.Presence.From));
- }
- }
- public string UserName { get; private set; }
- public string Password { get; private set; }
- public int Min { get; private set; }
- public int Max { get; private set; }
- //private DateTime _lastAccepted;
- private void ChatLogin(string pUsername, string pPassword, Region pRegion)
- {
- pUsername = pUsername.Trim();
- pPassword = pPassword.Trim();
- UserName = pUsername;
- if (!_regionDictionary.ContainsKey(pRegion))
- throw new ArgumentException("Region not available yet");
- if (Chat == null)
- return;
- Chat.SetUsername(pUsername);
- Chat.SetXmppDomain("pvp.net");
- Chat.Port = 5223;
- Chat.Show = Show.chat;
- Chat.Password = "AIR_" + pPassword;
- Chat.Resource = "xiff";
- Chat.OldStyleSsl = true;
- Chat.Hostname = string.Concat("chat.", _regionDictionary[pRegion], ".lol.riotgames.com");
- Chat.Open();
- }
- public bool GameStarted(string presenceInput)
- {
- return presenceInput.Contains("gameStatus>inGame</gameStatus");
- }
- public bool GameEnded(string presenceInput)
- {
- return presenceInput.Contains("gameStatus>outOfGame</gameStatus");
- }
- private readonly string _clientVersion;
- private void ClientLogin(string pUsername, string pPassword, Region pRegion)
- {
- Client?.Connect(pUsername, pPassword, pRegion, _clientVersion);
- }
- public void ChangeStatus(int level, int wins, League league, string division)
- {
- Chat.SendPresence(Show.chat, "<body><profileIcon>508</profileIcon><statusMsg></statusMsg><dropInSpectateGameId>Shopuff</dropInSpectateGameId><featuredGameData>null</featuredGameData><level>" + level + "</level><wins>" + wins + "</wins><leaves>25</leaves><odinWins>148</odinWins><odinLeaves>1</odinLeaves><queueType /><rankedLosses>0</rankedLosses><rankedRating>0</rankedRating><tier>DIAMOND</tier><skinname>Lulu</skinname><gameQueueType>RANKED_SOLO_5x5</gameQueueType><timeStamp>1398886764092</timeStamp><gameStatus>outOfGame</gameStatus><rankedLeagueName></rankedLeagueName><rankedLeagueDivision>" + division + "</rankedLeagueDivision><rankedLeagueTier>" + league.ToStringValue() + "</rankedLeagueTier><rankedLeagueQueue>RANKED_SOLO_5x5</rankedLeagueQueue><rankedWins>" + wins + "</rankedWins></body>", 0);
- }
- public enum League
- {
- [StringValue("BRONZE")]
- Bronze,
- [StringValue("SILVER")]
- Silver,
- [StringValue("GOLD")]
- Gold,
- [StringValue("PLATINUM")]
- Platin,
- [StringValue("DIAMOND")]
- Diamond,
- [StringValue("CHALLENGER")]
- Challenger
- }
- private void Client_OnLogin(object sender, string username, string ipAddress)
- {
- //if (!this._lolSumm)
- // return;
- //Logged_In = true;
- //if (LoginSucceed != null)
- // LoginSucceed(this, System.EventArgs.Empty);
- //Action pAction = WebScraper.GetUserLoop;
- //pAction.BeginInvoke(pAction.EndInvoke, null);
- //ChangeStatus(69, 1337, League.Diamond, this._spamText);
- }
- private void Chat_OnLogin(object sender, Matrix.EventArgs e)
- {
- if (SummSite)
- return;
- LoggedIn = true;
- LoginSucceed?.Invoke(this, System.EventArgs.Empty);
- if (WebScraper == null)
- return;
- Action pAction = WebScraper.GetUserLoop;
- pAction.BeginInvoke(pAction.EndInvoke, null);
- ChangeStatus(69, 1337, League.Diamond, _spamText);
- }
- private async Task<string> Message(Jid summonerJid, params string[] pParams)
- {
- await Task.Delay(5000);
- Task<string> lRes = Spamtext.ToTask();
- var lText = await lRes;
- lRes.Dispose();
- return lText;
- }
- private void Chat_OnMessage(object sender, MessageEventArgs e)
- {
- //await Task.Run(() => //this is where I put async
- if (!LoggedIn)
- return;
- if (e.Message.Type == MessageType.chat)
- {
- _token.Parse(e.Message.Body.ToLower().Trim(), e.Message.From, _newAction.FirstOrDefault(item => e.Message.Body.ToLower().Trim().IndexOf(item.Key, StringComparison.Ordinal) == 0 && e.Message.Body.Length != item.Key.Length && e.Message.Body[item.Key.Length] == ' '));
- }
- }
- private bool _flag;
- public void Deletefriends()
- {
- if (_flag)
- return;
- _flag = true;
- Chat.RequestRoster();
- }
- private void Roster_Requested(object sender, Matrix.Xmpp.Roster.RosterEventArgs e)
- {
- if (_flag && Chat != null && _loggedIn && !_disposed)
- RemoveFriend(e.RosterItem.Jid, true);
- }
- private void Roster_End(object sender, Matrix.EventArgs e)
- {
- _flag = false;
- }
- void Token_Parsed(object sender, ParsedEventArgs e)
- {
- // Result = Answer
- // e.Params = Params (for example: !Command Param1 Param2 ...)
- string result;
- ParamAction pHolder;
- //Check whether the Command is registered or the Defaultcommand is enabled
- if (_newAction.ContainsKey(e.ActCommand))
- {
- pHolder = _newAction[e.ActCommand];
- }
- else if (DefaultCommand != null)
- {
- pHolder = DefaultCommand;
- }
- else
- {
- return;
- }
- //Call Function Asynchronous
- pHolder.BeginInvoke(e.User, e.Params, async item =>
- {
- var lRes = pHolder.EndInvoke(item);
- result = await lRes;
- SendMessage(e.User, result);
- lRes.Dispose();
- }, null);
- }
- public void SendMessage(Jid pUser, string pMessage)
- {
- if (Chat == null)
- return;
- Message newMessage = new Message
- {
- To = pUser,
- Type = MessageType.chat,
- Body = pMessage
- };
- Chat.Send(newMessage);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement