Guest User

Untitled

a guest
Sep 5th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.10 KB | None | 0 0
  1. using Matrix;
  2. using Matrix.Xmpp;
  3. using Matrix.Xmpp.Client;
  4. using Parser;
  5. using PVPNetConnect;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using BotEventArgs;
  12. using EnumConvertExtensions;
  13. using PVPNetConnect.RiotObjects.Platform.Summoner;
  14. using PVPNETExtensions;
  15.  
  16. public class Bot : IDisposable
  17. {
  18. // nested class
  19. public class LeagueRank
  20. {
  21. public LeagueRank(Rank pRank, int pDiv)
  22. {
  23. Ranking = pRank;
  24. Division = pDiv;
  25. }
  26. public Rank Ranking { get; private set; }
  27. public enum Rank
  28. {
  29. Unranked = 0x0,
  30. BRONZE = 0x5,
  31. SILVER = 0xA,
  32. GOLD = 0xF,
  33. PLATINUM = 0x14,
  34. DIAMOND = 0x19,
  35. }
  36. public int Division { get; private set; }
  37. public static bool operator ==(LeagueRank pLeague, LeagueRank pLeague2)
  38. {
  39. return (int)pLeague.Ranking + pLeague.Division == (int)pLeague2.Ranking + pLeague2.Division;
  40. }
  41. public static bool operator !=(LeagueRank pLeague, LeagueRank pLeagu2)
  42. {
  43. return !(pLeague == pLeagu2);
  44. }
  45. public static bool operator <(LeagueRank pLeague, LeagueRank pLeague2)
  46. {
  47. return (int)pLeague.Ranking + (5 - pLeague.Division) < (int)pLeague2.Ranking + (5 - pLeague2.Division);
  48. }
  49. public static bool operator >(LeagueRank pLeague, LeagueRank pLeague2)
  50. {
  51. return (int)pLeague.Ranking + (5 - pLeague.Division) > (int)pLeague2.Ranking + (5 - pLeague2.Division);
  52. }
  53. public static bool operator <=(LeagueRank pLeague, LeagueRank pLeague2)
  54. {
  55. return (pLeague == pLeague2 || pLeague < pLeague2);
  56. }
  57. public static bool operator >=(LeagueRank pLeague, LeagueRank pLeague2)
  58. {
  59. return (pLeague == pLeague2 || pLeague > pLeague2);
  60. }
  61. public static LeagueRank ParseFromString(string pInput)
  62. {
  63. if (!pInput.Contains(' '))
  64. {
  65. return new LeagueRank(Rank.Unranked, 0);
  66. }
  67. else
  68. {
  69. string[] lParts = pInput.Split(' ');
  70. string lFirst = lParts[0];
  71. string lSecond = lParts[1];
  72. if (string.IsNullOrWhiteSpace(lSecond))
  73. return new LeagueRank(Rank.Unranked, 0);
  74. Rank lRank = Rank.Unranked;
  75. switch (lFirst)
  76. {
  77. case "BRONZE":
  78. lRank = Rank.BRONZE;
  79. break;
  80. case "SILVER":
  81. lRank = Rank.SILVER;
  82. break;
  83. case "GOLD":
  84. lRank = Rank.GOLD;
  85. break;
  86. case "PLATINUM":
  87. lRank = Rank.PLATINUM;
  88. break;
  89. case "DIAMOND":
  90. lRank = Rank.DIAMOND;
  91. break;
  92. }
  93. int lVal = 0;
  94. if (lSecond.Length != 2)
  95. {
  96. foreach (var item in lSecond)
  97. {
  98. if (item == 'V')
  99. lVal = 4;
  100. else if (item == 'I')
  101. lVal++;
  102. }
  103. }
  104. else
  105. {
  106. foreach (var item in lSecond)
  107. {
  108. if (item == 'V')
  109. lVal = 5;
  110. else if (item == 'I')
  111. lVal++;
  112. }
  113. }
  114. return new LeagueRank(lRank, lVal);
  115.  
  116. }
  117. }
  118. }
  119. bool disposed = false;
  120. public void Dispose()
  121. {
  122. Dispose(true);
  123. }
  124. public EventHandler Botdisposed;
  125. protected virtual void Dispose(bool disposing)
  126. {
  127.  
  128. if (disposing && !disposed)
  129. {
  130.  
  131.  
  132. using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
  133. {
  134. for (var x = actualOnes.Count - 1; x >= 0; x--)
  135. {
  136.  
  137.  
  138. int lValue = int.Parse(actualOnes[x]);
  139.  
  140.  
  141.  
  142. var lUser = from it in lContext.euw
  143. where it.SummonerID == lValue
  144. select it;
  145. var lName = this.Username.ToLower();
  146. var lRegion = this.WebScraper.Region.ToLower();
  147. var lBot = from ad in lContext.euwbots
  148. where ad.SummonerName == lName && ad.Region == lRegion
  149. select ad;
  150.  
  151. try
  152. {
  153. if (lUser.Count() > 0)
  154. {
  155. foreach (var user in lUser)
  156. {
  157.  
  158. user.Scraped = false;
  159.  
  160. }
  161. }
  162. if (lBot.Count() > 0)
  163. {
  164. foreach (var item in lBot)
  165. {
  166. item.Active = false;
  167. }
  168. }
  169.  
  170. }
  171. catch (System.Reflection.TargetException ey)
  172. {
  173. Console.WriteLine(ey.Message);
  174. }
  175. }
  176. lContext.SaveChanges();
  177. }
  178.  
  179. if (Botdisposed != null)
  180. Botdisposed(this, System.EventArgs.Empty);
  181. WebScraper.Logger.LoggedIn = false;
  182. WebScraper.Stop();
  183. WebScraper = null;
  184. if (_chat != null)
  185. _chat.Close();
  186. if (_client != null)
  187. _client.Disconnect();
  188. _chat = null;
  189. _client = null;
  190. _logged_In = false;
  191. }
  192. disposed = true;
  193.  
  194. }
  195. //Chatclient
  196. private XmppClient _chat = new XmppClient();
  197. public XmppClient Chat
  198. {
  199. get { return _chat; }
  200. }
  201. //Gameclient
  202. private PVPNetConnection _client = new PVPNetConnection();
  203. public PVPNetConnection Client
  204. {
  205. get { return _client; }
  206. }
  207.  
  208. public bool SummSite
  209. {
  210. get { return _lolSumm; }
  211. }
  212.  
  213. private Region _Region;
  214. public Region Region
  215. {
  216. get { return _Region; }
  217. }
  218.  
  219. private bool _acceptFriends = false;
  220. public bool AcceptFriends
  221. {
  222. get { return _acceptFriends; }
  223. set { _acceptFriends = value; }
  224. }
  225.  
  226. //Taking the Username's from lolsummoners
  227. public Scraper WebScraper { get; set; }
  228.  
  229.  
  230.  
  231. //Class to progress the Input
  232. private Tokenizer Token = new Tokenizer();
  233.  
  234. //Serverdomain of every Region
  235. private Dictionary<Region, string> regionDictionary = new Dictionary<Region, string>();
  236. private Dictionary<string, Region> newDict = new Dictionary<string, Region>();
  237. //All Commands
  238. private Dictionary<string, ParamAction> newAction = new Dictionary<string, ParamAction>();
  239. private static ExpressionParser _express;
  240. public event EventHandler<SummonerEventArgs> Game_Start;
  241. public event EventHandler<SummonerEventArgs> Game_End;
  242. public event EventHandler LoginSucceed;
  243. /// <summary>
  244. /// Signature of commands
  245. /// </summary>
  246. /// <param name="pParameter">All parameters of commands</param>
  247. /// <returns></returns>
  248. public delegate Task<string> ParamAction(Jid SummonerJID, params string[] pParameter);
  249.  
  250.  
  251. private bool _logged_In = false;
  252. public bool Logged_In
  253. {
  254. get { return _logged_In; }
  255. set
  256. {
  257. this._logged_In = value;
  258. if (this.WebScraper != null)
  259. this.WebScraper.Logger.LoggedIn = value;
  260. }
  261. }
  262.  
  263. private ParamAction _defaultCommand;
  264.  
  265. /// <summary>
  266. /// Functionpointer to function that shall get executed when no command got matched by the message
  267. /// </summary>
  268. public ParamAction DefaultCommand
  269. {
  270. get { return _defaultCommand; }
  271. set { _defaultCommand = value; }
  272. }
  273. private string _username;
  274. /// <summary>
  275. /// starts the bot
  276. /// </summary>
  277. /// <param name="pUsername">Account name to log in</param>
  278. /// <param name="pPassword">Account password to log in</param>
  279. /// <param name="pRegion">Region to log in</param>
  280. public void Start(string pUsername, string pPassword, Region pRegion)
  281. {
  282. PrepareStart(pUsername, pPassword, pRegion);
  283. Start();
  284. }
  285. public void Start()
  286. {
  287. ChatLogin(this._username, this._password, this._Region);
  288. if (_lolSumm) ClientLogin(this._username, this._password, this._Region);
  289. }
  290. public void PrepareStart(string pUsername, string pPassword, Region pRegion)
  291. {
  292. _Region = pRegion;
  293. _username = pUsername;
  294. _password = pPassword;
  295. }
  296. private readonly bool _lolSumm;
  297. public void Start(string pUsername, string pPassword, string pRegion)
  298. {
  299. pRegion = pRegion.Trim('\r').ToLower();
  300. pUsername = pUsername.Trim('\r');
  301. pPassword = pPassword.Trim('\r');
  302. if (!newDict.ContainsKey(pRegion))
  303. return;
  304.  
  305. WebScraper.Region = pRegion;
  306. WebScraper.Logger.Username = pUsername;
  307. Start(pUsername, pPassword, newDict[pRegion]);
  308. }
  309. private Random _random = new Random(DateTime.Now.Millisecond);
  310. private bool isFullReq = false;
  311. public bool FullRequest { get { return isFullReq; } }
  312. private List<string> users = new List<string>();
  313. private void Users_Found(object sender, UserFoundEventArgs e)
  314. {
  315.  
  316. if (this.disposed)
  317. {
  318. throw new ObjectDisposedException("Disposed");
  319. }
  320.  
  321. actualOnes = e.Users.ToList();
  322. using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
  323. {
  324. foreach (var item in e.Users)
  325. {
  326. //for (int i=0; i < 3; i++)
  327. //{
  328.  
  329. if (this.disposed)
  330. {
  331.  
  332. return;
  333. }
  334. try
  335. {
  336. if (isFullReq)
  337. {
  338. System.Threading.Thread.Sleep(_waitTime + _max);
  339. }
  340. //while (lSummonerID == "0")
  341. //{
  342. // System.Threading.Thread.Sleep(10000);
  343. // lSummonerID = (await lID).SummonerId.ToString();
  344. //}
  345. var lJid = "sum" + item + "@pvp.net";
  346. this.AddFriend(lJid, false);
  347. users.Add(lJid);
  348. //this.SendMessage(lJid, this.Spamtext);
  349. //this.RemoveFriend(lJid, true);
  350. //using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
  351. //{
  352.  
  353.  
  354. int isSuccess = Convert.ToInt32(item);
  355.  
  356. var lUser = from it in lContext.euw
  357. where it.SummonerID == isSuccess
  358. select it;
  359. try
  360. {
  361. //if (lUser.Count() > 0)
  362. //{
  363. // foreach (var user in lUser)
  364. // {
  365. // user.Friendreqest = true;
  366. // }
  367. // lContext.SaveChanges();
  368. //}
  369.  
  370. }
  371.  
  372.  
  373. catch (System.Reflection.TargetException ey)
  374. {
  375. Console.WriteLine(ey.Message);
  376. }
  377. //}
  378.  
  379. System.Threading.Thread.Sleep(_random.Next(_min, _max));
  380. actualOnes.Remove(item);
  381. }
  382. catch { }
  383.  
  384. }
  385.  
  386. //System.Threading.Thread.Sleep(10000);
  387. }
  388. }
  389. private List<string> actualOnes = new List<string>();
  390.  
  391. /// <summary>
  392. /// Adds a new command
  393. /// </summary>
  394. /// <param name="pCommand">Text to execute the command (case insensitive)</param>
  395. /// <param name="pExecution">Functionpointer to function that shall get executed</param>
  396. /// <returns>True if successful otherwise false</returns>
  397. public bool AddCommand(string pCommand, ParamAction pExecution)
  398. {
  399. if (!newAction.ContainsKey(pCommand.ToLower()))
  400. {
  401. newAction.Add(pCommand.ToLower(), pExecution);
  402. return true;
  403. }
  404. return false;
  405. }
  406. private string _password;
  407. /// <summary>
  408. /// Removes a existing command
  409. /// </summary>
  410. /// <param name="pCommand">Command to remove</param>
  411. /// <returns>True if successful otherwise false</returns>
  412. public bool RemoveCommand(string pCommand)
  413. {
  414. if (newAction.ContainsKey(pCommand.ToLower()))
  415. {
  416. newAction.Remove(pCommand.ToLower());
  417. return true;
  418. }
  419. return false;
  420. }
  421. private string _spamText;
  422. public string Spamtext
  423. {
  424. get { return _spamText; }
  425. set
  426. {
  427. _spamText = value;
  428. this.WebScraper.Logger.Message = value;
  429. }
  430. }
  431. private int _min;
  432. private int _max;
  433. private int _waitTime;
  434. public Bot(LeagueRank pMin, LeagueRank pMax, int pMinim, int pMaxim, int pLvlmin, int pLvlmax, string pSpamtext, string pClientVersion, bool pSumm, int pWaitTime, DateTime pDate)
  435. {
  436. From = pMin;
  437. To = pMax;
  438. _min = pMinim;
  439. _max = pMaxim;
  440. Min = pLvlmin;
  441. Max = pLvlmax;
  442. _waitTime = pWaitTime;
  443. _clientVersion = pClientVersion;
  444. regionDictionary.Add(Region.EUW, "euw1");
  445. regionDictionary.Add(Region.EUN, "eun1");
  446. regionDictionary.Add(Region.NA, "na2");
  447. regionDictionary.Add(Region.TR, "tr");
  448. regionDictionary.Add(Region.RU, "ru");
  449. regionDictionary.Add(Region.BR, "br");
  450. regionDictionary.Add(Region.OCE, "oc1");
  451. regionDictionary.Add(Region.KR, "kr");
  452. regionDictionary.Add(Region.LAN, "la1");
  453. regionDictionary.Add(Region.LAS, "la2");
  454. newDict.Add("euw", Region.EUW);
  455. newDict.Add("eune", Region.EUN);
  456. newDict.Add("na", Region.NA);
  457. newDict.Add("tr", Region.TR);
  458. newDict.Add("ru", Region.RU);
  459. newDict.Add("br", Region.BR);
  460. newDict.Add("oce", Region.OCE);
  461. newDict.Add("kr", Region.KR);
  462. newDict.Add("lan", Region.LAN);
  463. newDict.Add("las", Region.LAS);
  464. //to be continued
  465. Client.OnLogin += new PVPNetConnection.OnLoginHandler(Client_OnLogin);
  466. Chat.OnLogin += new EventHandler<Matrix.EventArgs>(Chat_OnLogin);
  467. Chat.OnMessage += new EventHandler<MessageEventArgs>(Chat_OnMessage);
  468. Token.Parsed += new Tokenizer.ParsedEventHandler(Token_Parsed);
  469. Chat.OnPresence += new EventHandler<PresenceEventArgs>(On_Presence);
  470. Client.OnDisconnect += new PVPNetConnection.OnDisconnectHandler(Client_Disconnected);
  471. Chat.OnClose += new EventHandler<Matrix.EventArgs>(Chat_Close);
  472. _lolSumm = pSumm;
  473. WebScraper = new DatabaseScraper(pMin, pMax, 0, pDate);
  474. WebScraper.User_Found += new EventHandler<UserFoundEventArgs>(Users_Found);
  475. Chat.AutoRoster = false;
  476. Client.OnError += new PVPNetConnection.OnErrorHandler(Client_Error);
  477. Chat.OnError += new EventHandler<ExceptionEventArgs>(Chat_Error);
  478. Chat.OnRosterItem += new EventHandler<Matrix.Xmpp.Roster.RosterEventArgs>(Roster_Requested);
  479. Chat.OnRosterEnd += new EventHandler<Matrix.EventArgs>(Roster_End);
  480. this.Spamtext = pSpamtext;
  481. this.DefaultCommand = Message;
  482.  
  483. }
  484. public LeagueRank From { get; private set; }
  485. public LeagueRank To { get; private set; }
  486. private void Chat_Error(object sender, ExceptionEventArgs e)
  487. {
  488. this.Dispose();
  489.  
  490. }
  491. private void Client_Error(object sender, PVPNetConnect.Error e)
  492. {
  493. this.Dispose();
  494. }
  495. static Bot()
  496. {
  497. _express = new ExpressionParser();
  498. }
  499. public static IEnumerable<System.Tuple<string, string, string, Bot>> CreateFromString(string pInput, string pClientVersion, bool pEndsite)
  500. {
  501. return _express.ParseExpression(pInput, pClientVersion, pEndsite);
  502. }
  503. private void Chat_Close(object sender, Matrix.EventArgs e)
  504. {
  505.  
  506.  
  507. this.Dispose();
  508.  
  509. //this._chat = new XmppClient();
  510. //this._client = new PVPNetConnection();
  511. //this.Start(this._username, this._password, this._Region);
  512. }
  513. private void Client_Disconnected(object sender, System.EventArgs e)
  514. {
  515. //this._chat = new XmppClient();
  516. //this._client = new PVPNetConnection();
  517. //this.Start(this._username, this._password, this._Region);
  518. }
  519. /// <summary>
  520. /// Add user to friendlist
  521. /// </summary>
  522. /// <param name="pSummonerID">SummonerJID of User</param>
  523. public void AddFriend(Jid pSummonerID, bool pOut)
  524. {
  525. if (Chat == null)
  526. return;
  527. Chat.Send(createPresence(pOut ? PresenceType.subscribed : PresenceType.subscribe, pSummonerID));
  528. if (!pOut) this.WebScraper.Logger.FriendrequestsSend++;
  529. }
  530.  
  531. private Presence createPresence(PresenceType pType, Jid pSummonerID)
  532. {
  533. var newPresence = new Presence(pType);
  534. newPresence.Priority = 0;
  535. newPresence.To = pSummonerID;
  536. return newPresence;
  537. }
  538.  
  539. /// <summary>
  540. /// Remove friend of friendlist
  541. /// </summary>
  542. /// <param name="pSummonerID">SummonerJID of friend</param>
  543. public void RemoveFriend(Jid pSummonerID, bool pOut)
  544. {
  545. if (Chat != null)
  546. Chat.Send(createPresence(pOut ? PresenceType.unsubscribed : PresenceType.unsubscribe, pSummonerID));
  547. }
  548. private int _acceptedFriends = 0;
  549. private async void On_Presence(object sender, PresenceEventArgs e)
  550. {
  551. if (e.Presence.Error != null && e.Presence.Error.Type == Matrix.Xmpp.Base.ErrorType.wait)
  552. {
  553. if (e.Presence.Error.Text == "max_outgoing_invites")
  554. {
  555. isFullReq = true;
  556. await Task.Delay(_waitTime);
  557. var lList = users.Select((item) => (string)item.Clone()).ToList();
  558. foreach (var item in lList)
  559. {
  560. try
  561. {
  562. //while (lSummonerID == "0")
  563. //{
  564. // System.Threading.Thread.Sleep(10000);
  565. // lSummonerID = (await lID).SummonerId.ToString();
  566. //}
  567. this.RemoveFriend(item, false);
  568. //this.SendMessage(lJid, this.Spamtext);
  569. //this.RemoveFriend(lJid, true);
  570.  
  571.  
  572. await Task.Delay(_random.Next(_min, _max));
  573. }
  574. catch { }
  575. }
  576. users.RemoveAll((elem) => lList.Contains(elem));
  577. isFullReq = false;
  578. }
  579. else
  580. {
  581. using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
  582. {
  583.  
  584. var lUser = from item in lContext.euwbots
  585. where item.SummonerName == this.Username.ToLower()
  586. select item;
  587.  
  588. try
  589. {
  590. if (lUser.Count() > 0)
  591. lUser.First().Fullfriendlist = true;
  592. lContext.SaveChanges();
  593. }
  594. catch (System.Reflection.TargetException ey)
  595. {
  596. Console.WriteLine(ey.Message);
  597. }
  598. this.Dispose();
  599. }
  600. }
  601.  
  602.  
  603.  
  604. }
  605. if (e.Presence.Type == PresenceType.subscribe && this.AcceptFriends && !this.disposed)
  606. {
  607. AddFriend(e.Presence.From, true);
  608. if (DefaultCommand != null)
  609. {
  610. DefaultCommand.BeginInvoke(e.Presence.From, new string[] { string.Empty }, async item =>
  611. {
  612. Task<string> lResult = (DefaultCommand.EndInvoke(item));
  613. var Result = await lResult;
  614. SendMessage(e.Presence.From, Result);
  615. RemoveFriend(e.Presence.From, false);
  616. lResult.Dispose();
  617. }, null);
  618. }
  619. }
  620. else if (e.Presence.Type == PresenceType.subscribed && !this.disposed)
  621. {
  622. _acceptedFriends++;
  623. lastAccepted = DateTime.Now;
  624. this.WebScraper.Logger.CountFriends++;
  625. //using (LoL_AutoAdder.lol_usersEntities lContext = new LoL_AutoAdder.lol_usersEntities())
  626. //{
  627.  
  628.  
  629. // var lUser = from item in lContext.euw
  630. // where item.SummonerID.ToString() == e.Presence.From.User
  631. // select item;
  632.  
  633. // try
  634. // {
  635. // if (lUser.Count() > 0)
  636. // lUser.First().Accept = true;
  637. // lContext.SaveChanges();
  638. // }
  639. // catch (System.Reflection.TargetException ey)
  640. // {
  641. // Console.WriteLine(ey.Message);
  642. // }
  643. //}
  644. if (DefaultCommand != null)
  645. {
  646. DefaultCommand.BeginInvoke(e.Presence.From, new string[] { string.Empty }, async item =>
  647. {
  648. Task<string> lResult = (DefaultCommand.EndInvoke(item));
  649. var Result = await lResult;
  650. SendMessage(e.Presence.From, Result);
  651. RemoveFriend(e.Presence.From, false);
  652. lResult.Dispose();
  653. }, null);
  654. }
  655. }
  656.  
  657. var presenceMessage = e.Presence.ToString();
  658. if (GameStarted(presenceMessage) && e.Presence.Show == Show.dnd && Logged_In && Game_Start != null)
  659. {
  660. Game_Start(sender, new SummonerEventArgs(e.Presence.From));
  661. }
  662. else if (GameEnded(presenceMessage) && e.Presence.Show == Show.chat && Logged_In && Game_End != null)
  663. {
  664. Game_End(sender, new SummonerEventArgs(e.Presence.From));
  665. }
  666.  
  667. }
  668. public string Username { get; private set; }
  669. public int Min { get; private set; }
  670. public int Max { get; private set; }
  671. private DateTime lastAccepted;
  672. private void ChatLogin(string pUsername, string pPassword, Region pRegion)
  673. {
  674. pUsername = pUsername.Trim();
  675. pPassword = pPassword.Trim();
  676. Username = pUsername;
  677. if (!regionDictionary.ContainsKey(pRegion))
  678. throw new ArgumentException("Region not available yet");
  679. if (Chat == null)
  680. return;
  681. Chat.SetUsername(pUsername);
  682. Chat.SetXmppDomain("pvp.net");
  683. Chat.Port = 5223;
  684. Chat.Show = Matrix.Xmpp.Show.chat;
  685. Chat.Password = ("AIR_" + pPassword);
  686. Chat.Resource = "xiff";
  687. Chat.OldStyleSsl = true;
  688. Chat.Hostname = string.Concat("chat.", regionDictionary[pRegion], ".lol.riotgames.com");
  689. Chat.Open();
  690. }
  691.  
  692. public bool GameStarted(string presenceInput)
  693. {
  694. return presenceInput.Contains("gameStatus&gt;inGame&lt;/gameStatus");
  695. }
  696.  
  697. public bool GameEnded(string presenceInput)
  698. {
  699. return presenceInput.Contains("gameStatus&gt;outOfGame&lt;/gameStatus");
  700. }
  701. private string _clientVersion;
  702. private void ClientLogin(string pUsername, string pPassword, Region pRegion)
  703. {
  704. if (Client != null)
  705. Client.Connect(pUsername, pPassword, pRegion, _clientVersion);
  706. }
  707. public void ChangeStatus(int level, int wins, League league, string division)
  708. {
  709. 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);
  710. }
  711. public enum League
  712. {
  713. [StringValue("BRONZE")]
  714. Bronze,
  715. [StringValue("SILVER")]
  716. Silver,
  717. [StringValue("GOLD")]
  718. Gold,
  719. [StringValue("PLATINUM")]
  720. Platin,
  721. [StringValue("DIAMOND")]
  722. Diamond,
  723. [StringValue("CHALLENGER")]
  724. Challenger
  725. }
  726. private void Client_OnLogin(object sender, string username, string ipAddress)
  727. {
  728. //if (!this._lolSumm)
  729. // return;
  730. //Logged_In = true;
  731. //if (LoginSucceed != null)
  732. // LoginSucceed(this, System.EventArgs.Empty);
  733. //Action pAction = WebScraper.GetUserLoop;
  734. //pAction.BeginInvoke(pAction.EndInvoke, null);
  735. //ChangeStatus(69, 1337, League.Diamond, this._spamText);
  736. }
  737. private void Chat_OnLogin(object sender, Matrix.EventArgs e)
  738. {
  739. if (this._lolSumm)
  740. return;
  741. Logged_In = true;
  742. if (LoginSucceed != null)
  743. LoginSucceed(this, System.EventArgs.Empty);
  744. if (WebScraper == null)
  745. return;
  746. Action pAction = WebScraper.GetUserLoop;
  747. pAction.BeginInvoke(pAction.EndInvoke, null);
  748. ChangeStatus(69, 1337, League.Diamond, this._spamText);
  749. }
  750. private async Task<string> Message(Jid SummonerJID, params string[] pParams)
  751. {
  752. Task<string> lRes = Spamtext.ToTask<string>();
  753. var lText = await lRes;
  754. lRes.Dispose();
  755. return lText;
  756. }
  757.  
  758. private void Chat_OnMessage(object sender, Matrix.Xmpp.Client.MessageEventArgs e)
  759. {
  760. //await Task.Run(() => //this is where I put async
  761.  
  762. if (!this.Logged_In)
  763. return;
  764. if (e.Message.Type == MessageType.chat)
  765. {
  766. 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());
  767. }
  768.  
  769. }
  770. private bool _flag = false;
  771. public void Deletefriends()
  772. {
  773. if (_flag)
  774. return;
  775. _flag = true;
  776. this._chat.RequestRoster();
  777. }
  778. private void Roster_Requested(object sender, Matrix.Xmpp.Roster.RosterEventArgs e)
  779. {
  780. if (_flag && this.Chat != null && this._logged_In && !this.disposed)
  781. this.RemoveFriend(e.RosterItem.Jid, true);
  782. }
  783. private void Roster_End(object sender, Matrix.EventArgs e)
  784. {
  785. _flag = false;
  786. }
  787. void Token_Parsed(object sender, ParsedEventArgs e)
  788. {
  789. // Result = Answer
  790. // e.Params = Params (for example: !Command Param1 Param2 ...)
  791. string Result = String.Empty;
  792. ParamAction pHolder = null;
  793. //Check whether the Command is registered or the Defaultcommand is enabled
  794. if (newAction.ContainsKey(e.ActCommand))
  795. {
  796. pHolder = newAction[e.ActCommand];
  797. }
  798. else if (DefaultCommand != null)
  799. {
  800. pHolder = DefaultCommand;
  801. }
  802. else
  803. {
  804. return;
  805. }
  806. //Call Function Asynchronous
  807. pHolder.BeginInvoke(e.User, e.Params, async item =>
  808. {
  809. var lRes = pHolder.EndInvoke(item);
  810. Result = await lRes;
  811. SendMessage(e.User, Result);
  812. lRes.Dispose();
  813. }, null);
  814.  
  815. }
  816.  
  817. public void SendMessage(Jid pUser, string pMessage)
  818. {
  819. if (Chat == null)
  820. return;
  821. Matrix.Xmpp.Client.Message newMessage = new Matrix.Xmpp.Client.Message();
  822. newMessage.To = pUser;
  823. newMessage.Type = Matrix.Xmpp.MessageType.chat;
  824. newMessage.Body = pMessage;
  825. Chat.Send(newMessage);
  826. }
  827. }
Add Comment
Please, Sign In to add comment