Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Matrix;
- using Matrix.Xmpp;
- using Matrix.Xmpp.Client;
- using Parser;
- using PVPNetConnect;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BotEventArgs;
- using EnumConvertExtensions;
- using PVPNetConnect.RiotObjects.Platform.Summoner;
- using PVPNETExtensions;
- public class Bot : IDisposable
- {
- // nested class
- public class LeagueRank
- {
- public LeagueRank(Rank pRank, int pDiv)
- {
- Ranking = pRank;
- Division = pDiv;
- }
- public Rank Ranking { get; private set; }
- public enum Rank
- {
- Unranked = 0x0,
- BRONZE = 0x5,
- SILVER = 0xA,
- GOLD = 0xF,
- PLATINUM = 0x14,
- DIAMOND = 0x19,
- }
- public int Division { get; private set; }
- public static bool operator ==(LeagueRank pLeague, LeagueRank pLeague2)
- {
- return (int)pLeague.Ranking + pLeague.Division == (int)pLeague2.Ranking + pLeague2.Division;
- }
- 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);
- }
- }
- }
- bool disposed = false;
- public void Dispose()
- {
- Dispose(true);
- }
- public EventHandler Botdisposed;
- protected virtual void Dispose(bool disposing)
- {
- if (disposing && !disposed)
- {
- using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.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 = this.Username.ToLower();
- var lRegion = this.WebScraper.Region.ToLower();
- var lBot = from ad in lContext.euwbots
- where ad.SummonerName == lName && ad.Region == lRegion
- select ad;
- try
- {
- if (lUser.Count() > 0)
- {
- foreach (var user in lUser)
- {
- user.Scraped = false;
- }
- }
- if (lBot.Count() > 0)
- {
- foreach (var item in lBot)
- {
- item.Active = false;
- }
- }
- }
- catch (System.Reflection.TargetException ey)
- {
- Console.WriteLine(ey.Message);
- }
- }
- lContext.SaveChanges();
- }
- if (Botdisposed != null)
- Botdisposed(this, System.EventArgs.Empty);
- WebScraper.Logger.LoggedIn = false;
- WebScraper.Stop();
- WebScraper = null;
- if (_chat != null)
- _chat.Close();
- if (_client != null)
- _client.Disconnect();
- _chat = null;
- _client = null;
- _logged_In = false;
- }
- disposed = true;
- }
- //Chatclient
- private XmppClient _chat = new XmppClient();
- public XmppClient Chat
- {
- get { return _chat; }
- }
- //Gameclient
- private PVPNetConnection _client = new PVPNetConnection();
- public PVPNetConnection Client
- {
- get { return _client; }
- }
- public bool SummSite
- {
- get { return _lolSumm; }
- }
- private Region _Region;
- public Region Region
- {
- get { return _Region; }
- }
- private bool _acceptFriends = false;
- public bool AcceptFriends
- {
- get { return _acceptFriends; }
- set { _acceptFriends = value; }
- }
- //Taking the Username's from lolsummoners
- public Scraper WebScraper { get; set; }
- //Class to progress the Input
- private Tokenizer Token = new Tokenizer();
- //Serverdomain of every Region
- private Dictionary<Region, string> regionDictionary = new Dictionary<Region, string>();
- private Dictionary<string, Region> newDict = new Dictionary<string, Region>();
- //All Commands
- private Dictionary<string, ParamAction> newAction = new Dictionary<string, ParamAction>();
- private static ExpressionParser _express;
- public event EventHandler<SummonerEventArgs> Game_Start;
- public event EventHandler<SummonerEventArgs> Game_End;
- 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 _logged_In = false;
- public bool Logged_In
- {
- get { return _logged_In; }
- set
- {
- this._logged_In = value;
- if (this.WebScraper != null)
- this.WebScraper.Logger.LoggedIn = value;
- }
- }
- private ParamAction _defaultCommand;
- /// <summary>
- /// Functionpointer to function that shall get executed when no command got matched by the message
- /// </summary>
- public ParamAction DefaultCommand
- {
- get { return _defaultCommand; }
- set { _defaultCommand = value; }
- }
- private string _username;
- /// <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(this._username, this._password, this._Region);
- if (_lolSumm) ClientLogin(this._username, this._password, this._Region);
- }
- public void PrepareStart(string pUsername, string pPassword, Region pRegion)
- {
- _Region = pRegion;
- _username = pUsername;
- _password = pPassword;
- }
- private readonly bool _lolSumm;
- 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 Random _random = new Random(DateTime.Now.Millisecond);
- private bool isFullReq = false;
- public bool FullRequest { get { return isFullReq; } }
- private List<string> users = new List<string>();
- private void Users_Found(object sender, UserFoundEventArgs e)
- {
- if (this.disposed)
- {
- throw new ObjectDisposedException("Disposed");
- }
- actualOnes = e.Users.ToList();
- using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
- {
- foreach (var item in e.Users)
- {
- //for (int i=0; i < 3; i++)
- //{
- if (this.disposed)
- {
- return;
- }
- try
- {
- if (isFullReq)
- {
- 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";
- this.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())
- //{
- 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 { }
- }
- //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;
- }
- private string _password;
- /// <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;
- this.WebScraper.Logger.Message = value;
- }
- }
- private int _min;
- private int _max;
- private 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 += new PVPNetConnection.OnLoginHandler(Client_OnLogin);
- Chat.OnLogin += new EventHandler<Matrix.EventArgs>(Chat_OnLogin);
- Chat.OnMessage += new EventHandler<MessageEventArgs>(Chat_OnMessage);
- Token.Parsed += new Tokenizer.ParsedEventHandler(Token_Parsed);
- Chat.OnPresence += new EventHandler<PresenceEventArgs>(On_Presence);
- Client.OnDisconnect += new PVPNetConnection.OnDisconnectHandler(Client_Disconnected);
- Chat.OnClose += new EventHandler<Matrix.EventArgs>(Chat_Close);
- _lolSumm = pSumm;
- WebScraper = new DatabaseScraper(pMin, pMax, 0, pDate);
- WebScraper.User_Found += new EventHandler<UserFoundEventArgs>(Users_Found);
- Chat.AutoRoster = false;
- Client.OnError += new PVPNetConnection.OnErrorHandler(Client_Error);
- Chat.OnError += new EventHandler<ExceptionEventArgs>(Chat_Error);
- Chat.OnRosterItem += new EventHandler<Matrix.Xmpp.Roster.RosterEventArgs>(Roster_Requested);
- Chat.OnRosterEnd += new EventHandler<Matrix.EventArgs>(Roster_End);
- this.Spamtext = pSpamtext;
- this.DefaultCommand = Message;
- }
- public LeagueRank From { get; private set; }
- public LeagueRank To { get; private set; }
- private void Chat_Error(object sender, ExceptionEventArgs e)
- {
- this.Dispose();
- }
- private void Client_Error(object sender, PVPNetConnect.Error e)
- {
- this.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)
- {
- this.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>
- public void AddFriend(Jid pSummonerID, bool pOut)
- {
- if (Chat == null)
- return;
- Chat.Send(createPresence(pOut ? PresenceType.subscribed : PresenceType.subscribe, pSummonerID));
- if (!pOut) this.WebScraper.Logger.FriendrequestsSend++;
- }
- private Presence createPresence(PresenceType pType, Jid pSummonerID)
- {
- var newPresence = new Presence(pType);
- newPresence.Priority = 0;
- newPresence.To = pSummonerID;
- return newPresence;
- }
- /// <summary>
- /// Remove friend of friendlist
- /// </summary>
- /// <param name="pSummonerID">SummonerJID of friend</param>
- public void RemoveFriend(Jid pSummonerID, bool pOut)
- {
- if (Chat != null)
- Chat.Send(createPresence(pOut ? PresenceType.unsubscribed : PresenceType.unsubscribe, pSummonerID));
- }
- private int _acceptedFriends = 0;
- 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")
- {
- isFullReq = 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();
- //}
- this.RemoveFriend(item, false);
- //this.SendMessage(lJid, this.Spamtext);
- //this.RemoveFriend(lJid, true);
- await Task.Delay(_random.Next(_min, _max));
- }
- catch { }
- }
- users.RemoveAll((elem) => lList.Contains(elem));
- isFullReq = false;
- }
- else
- {
- using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
- {
- var lUser = from item in lContext.euwbots
- where item.SummonerName == this.Username.ToLower()
- select item;
- try
- {
- if (lUser.Count() > 0)
- lUser.First().Fullfriendlist = true;
- lContext.SaveChanges();
- }
- catch (System.Reflection.TargetException ey)
- {
- Console.WriteLine(ey.Message);
- }
- this.Dispose();
- }
- }
- }
- if (e.Presence.Type == PresenceType.subscribe && this.AcceptFriends && !this.disposed)
- {
- AddFriend(e.Presence.From, true);
- if (DefaultCommand != null)
- {
- DefaultCommand.BeginInvoke(e.Presence.From, new string[] { 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 && !this.disposed)
- {
- _acceptedFriends++;
- lastAccepted = DateTime.Now;
- this.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);
- // }
- //}
- if (DefaultCommand != null)
- {
- DefaultCommand.BeginInvoke(e.Presence.From, new string[] { 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 && Logged_In && Game_Start != null)
- {
- Game_Start(sender, new SummonerEventArgs(e.Presence.From));
- }
- else if (GameEnded(presenceMessage) && e.Presence.Show == Show.chat && Logged_In && Game_End != null)
- {
- Game_End(sender, new SummonerEventArgs(e.Presence.From));
- }
- }
- public string Username { 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 = Matrix.Xmpp.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 string _clientVersion;
- private void ClientLogin(string pUsername, string pPassword, Region pRegion)
- {
- if (Client != null)
- 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 (this._lolSumm)
- return;
- Logged_In = true;
- if (LoginSucceed != null)
- LoginSucceed(this, System.EventArgs.Empty);
- if (WebScraper == null)
- return;
- Action pAction = WebScraper.GetUserLoop;
- pAction.BeginInvoke(pAction.EndInvoke, null);
- ChangeStatus(69, 1337, League.Diamond, this._spamText);
- }
- private async Task<string> Message(Jid SummonerJID, params string[] pParams)
- {
- Task<string> lRes = Spamtext.ToTask<string>();
- var lText = await lRes;
- lRes.Dispose();
- return lText;
- }
- private void Chat_OnMessage(object sender, Matrix.Xmpp.Client.MessageEventArgs e)
- {
- //await Task.Run(() => //this is where I put async
- if (!this.Logged_In)
- return;
- if (e.Message.Type == MessageType.chat)
- {
- Token.Parse(e.Message.Body.ToLower().Trim(), e.Message.From, newAction.Where(item => e.Message.Body.ToLower().Trim().IndexOf(item.Key) == 0 && !(e.Message.Body.Length == item.Key.Length) && e.Message.Body[item.Key.Length] == ' ').FirstOrDefault());
- }
- }
- private bool _flag = false;
- public void Deletefriends()
- {
- if (_flag)
- return;
- _flag = true;
- this._chat.RequestRoster();
- }
- private void Roster_Requested(object sender, Matrix.Xmpp.Roster.RosterEventArgs e)
- {
- if (_flag && this.Chat != null && this._logged_In && !this.disposed)
- this.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 = String.Empty;
- ParamAction pHolder = null;
- //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;
- Matrix.Xmpp.Client.Message newMessage = new Matrix.Xmpp.Client.Message();
- newMessage.To = pUser;
- newMessage.Type = Matrix.Xmpp.MessageType.chat;
- newMessage.Body = pMessage;
- Chat.Send(newMessage);
- }
- }
Add Comment
Please, Sign In to add comment